/* وصلها 4 — app shell. Phone: top bar + bottom tabs. Tablet: compact rail.
   Desktop: full rail. Focus mode (reader, quiz) hides navigation. */

.shell { min-height: 100dvh; }

/* ---------- Rail (tablet and desktop) ---------- */
.rail { display: none; }
.rail-brand { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-5); color: var(--text); text-decoration: none; }
.rail-brand img { width: 44px; height: auto; }
.rail-brand-name { display: grid; line-height: var(--leading-tight); }
.rail-brand-name strong { font-family: var(--font-display); font-weight: 900; font-size: var(--text-xl); }
.rail-brand-name small { color: var(--text-3); font-size: var(--text-xs); }
.rail-nav { display: grid; gap: var(--space-1); padding-inline: var(--space-3); }
.nav-item {
  position: relative; display: flex; align-items: center; gap: var(--space-3); min-height: var(--control-height); padding: 0 var(--space-4);
  border-radius: var(--radius-control); color: var(--text-2); font-weight: 600; text-decoration: none;
  transition: background var(--fast) var(--ease-out), color var(--fast) var(--ease-out);
}
.nav-item:hover { background: var(--surface-1); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.nav-item[aria-current="page"]::before { content: ''; position: absolute; inset-inline-start: calc(-1 * var(--space-3)); top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav-item[aria-current="page"] .icon { color: var(--accent); }
.nav-badge { margin-inline-start: auto; min-width: 22px; padding: 0 var(--space-1); border-radius: var(--radius-pill); background: var(--accent); color: var(--on-accent); font-size: var(--text-xs); font-weight: 700; text-align: center; line-height: 22px; }
.rail-foot { margin-top: auto; display: grid; gap: var(--space-1); padding: var(--space-4) var(--space-3) var(--space-5); border-block-start: 1px solid var(--line); }

/* ---------- Top bar (phone and tablet/desktop page bar) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--topbar-height); padding: var(--space-2) var(--space-4);
  padding-top: max(var(--space-2), env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(14px);
  border-block-end: 1px solid var(--line);
}
.topbar-brand { display: flex; align-items: center; gap: var(--space-2); color: var(--text); text-decoration: none; font-family: var(--font-display); font-weight: 900; font-size: var(--text-xl); }
.topbar-brand img { width: 36px; height: auto; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--space-2); }
@media (pointer: coarse) { .topbar-brand { min-height: var(--control-height); } }
.search-trigger {
  display: flex; align-items: center; gap: var(--space-2); min-height: var(--control-sm); padding: 0 var(--space-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill); background: var(--surface-1);
  color: var(--text-2); font-size: var(--text-sm);
}
@media (pointer: coarse) { .search-trigger { min-height: var(--control-height); } }
.search-trigger:hover { border-color: var(--control); color: var(--text); }
.search-trigger kbd { padding: 0 var(--space-1); border: 1px solid var(--line-strong); border-radius: 4px; font-size: var(--text-xs); color: var(--text-3); }
.search-trigger-label { display: none; }

/* ---------- Bottom tabs (phone) ---------- */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(5, 1fr);
  min-height: var(--tabbar-height); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface-1) 94%, transparent); backdrop-filter: blur(14px);
  border-block-start: 1px solid var(--line);
}
.tab-item { position: relative; display: grid; justify-items: center; align-content: center; gap: 2px; min-height: var(--tabbar-height); color: var(--text-3); font-size: var(--text-xs); font-weight: 600; line-height: var(--leading-tight); text-decoration: none; }
.tab-item .icon { width: 24px; height: 24px; }
.tab-item[aria-current="page"] { color: var(--text); }
.tab-item[aria-current="page"] .icon { color: var(--accent); }
.tab-item[aria-current="page"]::before { content: ''; position: absolute; top: 0; width: 32px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tab-item .nav-badge { position: absolute; top: 8px; inset-inline-start: calc(50% + 6px); margin: 0; min-width: 18px; line-height: 18px; font-size: var(--text-xs); }

/* ---------- Main ---------- */
.main { width: 100%; max-width: var(--content-max); margin-inline: auto; padding: var(--space-5) var(--space-4) calc(var(--tabbar-height) + var(--space-7) + env(safe-area-inset-bottom)); outline: none; }
.page { display: grid; gap: var(--page-gap); }
/* A mount point still waiting for its content (today's timetable, rooms) must not add a second gap. */
.page > :empty:not([aria-live]):not([role]) { display: none; }
/* Grid children may shrink below their content (scrolling tab strips, long words). */
.page > *, .split > *, .grid > *, .grid-2 > *, .grid-3 > * { min-width: 0; }
.page-head { display: grid; gap: var(--space-2); }
.page-head p { color: var(--text-2); max-width: 62ch; }
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--text-sm); line-height: var(--leading-ui); color: var(--text-3); }
.breadcrumb a { color: var(--text-2); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.site-foot { max-width: var(--content-max); margin-inline: auto; padding: var(--space-6) var(--space-4) calc(var(--tabbar-height) + var(--space-6)); color: var(--text-3); font-size: var(--text-sm); line-height: var(--leading-ui); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); justify-content: space-between; border-block-start: 1px solid var(--line); }
.site-foot a { color: var(--text-2); }

.grid { display: grid; gap: var(--space-4); }
.grid-2 { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }
.grid-3 { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }
.split { display: grid; gap: var(--space-6); }

@media (min-width: 600px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-trigger-label { display: inline; }
}

@media (min-width: 768px) {
  .shell { display: grid; grid-template-columns: var(--rail-compact) minmax(0, 1fr); }
  .rail {
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    border-inline-end: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 70%, var(--surface-1));
  }
  .rail-brand { justify-content: center; padding: var(--space-5) 0; }
  .rail-brand-name { display: none; }
  .rail-nav, .rail-foot { padding-inline: var(--space-2); }
  .nav-item { flex-direction: column; justify-content: center; gap: var(--space-1); min-height: var(--space-8); padding: var(--space-2) 0; font-size: var(--text-xs); line-height: var(--leading-tight); text-align: center; }
  .nav-item .icon { width: 24px; height: 24px; }
  .nav-item[aria-current="page"]::before { inset-inline-start: calc(-1 * var(--space-2)); }
  .nav-item .nav-badge { position: absolute; top: 6px; inset-inline-start: calc(50% + 8px); margin: 0; }
  .tabbar { display: none; }
  .topbar-brand, .topbar-more { display: none; }
  .main { padding: var(--space-6) var(--space-6) var(--space-7); }
  .site-foot { padding: var(--space-6); }
  .toast-region { bottom: var(--space-6); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
  .shell { grid-template-columns: var(--rail-width) minmax(0, 1fr); }
  .rail-brand { justify-content: flex-start; padding: var(--space-5); }
  .rail-brand-name { display: grid; }
  .rail-nav, .rail-foot { padding-inline: var(--space-3); }
  .nav-item { flex-direction: row; justify-content: flex-start; gap: var(--space-3); min-height: var(--control-height); padding: 0 var(--space-4); font-size: var(--text-md); line-height: var(--leading-ui); text-align: start; }
  .nav-item .icon { width: 1.25em; height: 1.25em; }
  .nav-item[aria-current="page"]::before { inset-inline-start: calc(-1 * var(--space-3)); }
  .nav-item .nav-badge { position: static; margin-inline-start: auto; }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .split > aside { position: sticky; top: calc(var(--topbar-height) + var(--space-4)); }
}

/* ---------- Focus mode: reader and quiz keep a clear way back, nothing else ---------- */
.shell.is-focus { display: block; }
.shell.is-focus .rail, .shell.is-focus .tabbar, .shell.is-focus .site-foot { display: none; }
.shell.is-focus .main { max-width: none; padding: 0 0 env(safe-area-inset-bottom); }
.shell.is-focus .topbar.app-topbar { display: none; }
