/* Learnium portal: shell.css (phase R2, docs/plans/PORTAL_REDESIGN_PROPOSAL.md Part 5).
   The app shell: staff sidebar (232 px, icon rail under 1100 px, drawer under 760 px), the 52 / 56 px top bar,
   the phone bottom tab bar, the routed views (<section data-view>) and their page header, the avatar menu,
   the side panel footer, the shortcuts sheet. Tokens only (tokens.css); radius 0; only transform and opacity animate.
   Markup is built by js/shell.js into the mounts #shell-side, #shell-top, #shell-bottom (tools/check_portal_shell.py
   asserts every page carries the same mount). Load order: style.css, tokens.css, components.css, shell.css, portal.css. */

/* ---- the body no longer carries a fixed public header; --header-h now means the shell top bar (sticky offsets) ---- */
.portal-body.has-shell { padding-top: 0; --header-h: 52px; }
.portal-body.has-shell.shell-student, .portal-body.has-shell.shell-guest { --header-h: 56px; }
.portal-body.has-shell.focus-mode { --header-h: 0px; }

.shell { display: flex; min-height: 100vh; flex: 1; }
.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page { flex: 1; width: 100%; max-width: calc(var(--content-max) + 2 * var(--gutter)); margin: 0 auto; padding: 24px var(--gutter) 80px; box-sizing: border-box; }
.has-shell .portal-main { padding: 24px 0 80px; }

/* ============ Top bar ============ */
.shell-top {
  position: sticky; top: 0; z-index: 60; display: flex; align-items: center; gap: 12px;
  height: var(--header-h); padding: 0 var(--gutter); border-bottom: 1px solid var(--border); color: var(--fg);
}
.shell-brand { display: inline-flex; align-items: center; gap: 10px; color: var(--fg); text-decoration: none; min-width: 0; flex: 0 1 auto; }
.shell-brand > span { min-width: 0; overflow: hidden; }
.shell-brand svg { height: 24px; width: auto; display: block; fill: currentColor; }
.shell-brand .shell-brand-name { font-family: var(--font-head); font-weight: 400; font-size: 16px; line-height: 20px; white-space: nowrap; }
.shell-brand .shell-brand-name, .shell-brand .shell-brand-tag { display: block; overflow: hidden; text-overflow: ellipsis; }
.shell-brand svg { flex: none; }
.shell-brand .shell-brand-tag { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-muted); white-space: nowrap; }
.shell-crumb { font: 500 14px/20px var(--font-body); color: var(--fg); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-crumb .crumb-sep { color: var(--fg-subtle); margin: 0 6px; }

.shell-nav { display: flex; align-items: stretch; gap: 0; height: 100%; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.shell-nav::-webkit-scrollbar { display: none; }
.shell-link {
  display: inline-flex; align-items: center; gap: 8px; height: 100%; padding: 0 12px; box-sizing: border-box;
  font: 500 14px/20px var(--font-body); color: var(--fg-muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; border-top: 2px solid transparent;
  transition: color var(--dur-fast), border-color var(--dur-fast);
}
.shell-link:hover { color: var(--fg); }
.shell-link.is-active { color: var(--fg); border-bottom-color: var(--accent); }
.shell-link:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

.shell-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
.shell-iconbtn {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0;
  background: transparent; color: var(--fg-muted); border: 1px solid transparent; border-radius: 0; cursor: pointer;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.shell-iconbtn:hover { background: var(--surface-2); color: var(--fg); }
.shell-iconbtn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.shell-iconbtn .i { width: 20px; height: 20px; }
.shell-actions .theme-btn { border-color: transparent; }
.shell-back { font: 500 13px/20px var(--font-body); color: var(--fg-muted); text-decoration: none; white-space: nowrap; }
.shell-back:hover { color: var(--fg); }
.shell-back + .shell-back { margin-left: 12px; }

/* the search box opens the palette: a button dressed as an input */
.shell-search {
  display: inline-flex; align-items: center; gap: 8px; width: 280px; height: 32px; padding: 0 10px; box-sizing: border-box;
  background: var(--surface); color: var(--fg-subtle); border: 1px solid var(--border-strong); border-radius: 0; cursor: text;
  font: 400 13px/18px var(--font-body); text-align: left;
}
.shell-search:hover { border-color: var(--fg-subtle); }
.shell-search:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.shell-search span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-search kbd { flex: none; }
.shell-search-sm { display: none; }

/* ============ Avatar menu (popover) ============ */
.shell-user { position: relative; flex: none; }
.shell-avatar-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 4px 0 0; background: transparent;
  border: 1px solid transparent; border-radius: 0; cursor: pointer; color: var(--fg);
}
.shell-avatar-btn:hover { background: var(--surface-2); }
.shell-avatar-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.shell-avatar-btn .i { color: var(--fg-muted); }
.shell-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 90; width: 260px; padding: 8px;
  background: var(--surface-raised); color: var(--fg); border: 1px solid var(--elev-border, var(--border)); box-shadow: var(--shadow-md);
  animation: lc-pop var(--dur) var(--ease-out);
}
.shell-pop[hidden] { display: none; }
.shell-pop-who { padding: 8px 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.shell-pop-name { display: block; font: 500 14px/20px var(--font-body); color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-pop-role { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; font-size: 12px; line-height: 16px; color: var(--fg-muted); }
.shell-pop-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 8px; box-sizing: border-box;
  background: transparent; border: 0; border-radius: 0; color: var(--fg); text-decoration: none; text-align: left;
  font: 400 14px/20px var(--font-body); cursor: pointer;
}
.shell-pop-item:hover { background: var(--surface-2); }
.shell-pop-item:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.shell-pop-item .i { color: var(--fg-muted); }
.shell-pop-label { padding: 10px 8px 4px; font: 500 12px/16px var(--font-body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-muted); }
.shell-pop-sep { height: 1px; background: var(--border); margin: 6px 0; }
/* student top nav between 761 and 940 px: the last links fold into the account menu instead of being cut off */
.shell-pop-overflow { display: none; }
@media (min-width: 761px) and (max-width: 940px) {
  .shell-link-overflow { display: none; }
  .shell-pop-overflow:not([hidden]) { display: flex; }
}
@media (max-width: 760px) { .shell-pop-overflow:not([hidden]) { display: flex; } }

/* Appearance: System / Light / Dark segmented control (also on Settings and My data) */
.seg { display: inline-flex; border: 1px solid var(--border-strong); background: var(--surface); }
.seg button {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; background: transparent; border: 0; border-radius: 0;
  font: 500 13px/18px var(--font-body); color: var(--fg-muted); cursor: pointer; transition: background-color var(--dur-fast), color var(--dur-fast);
}
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-soft-text); }
.seg button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.shell-pop .seg { display: flex; margin: 0 8px 8px; }
.shell-pop .seg button { flex: 1 1 0; min-width: 0; justify-content: center; padding: 0 6px; }
.shell-pop .seg button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ Sidebar (staff) ============ */
.shell-side {
  position: sticky; top: 0; align-self: flex-start; height: 100vh; width: 232px; flex: none; display: flex; flex-direction: column;
  background: var(--bg-subtle); border-right: 1px solid var(--border); overflow-y: auto; overflow-x: hidden; z-index: 70;
}
.shell-side[hidden] { display: none; }
.shell-side-brand { display: flex; align-items: center; gap: 10px; height: var(--header-h); padding: 0 16px; flex: none; color: var(--fg); text-decoration: none; border-bottom: 1px solid var(--border); }
.shell-side-brand svg { height: 24px; width: auto; display: block; fill: currentColor; flex: none; }
.shell-side-brand span { font-family: var(--font-head); font-size: 15px; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shell-side-close { margin-left: auto; display: none; }
.shell-groups { flex: 1; padding: 8px 8px 16px; }
.shell-group { padding: 8px 0 4px; }
.shell-group-label { padding: 0 8px 6px; font: 500 12px/16px var(--font-body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-muted); white-space: nowrap; }
.shell-items { display: grid; gap: 2px; }
.shell-item {
  position: relative; display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 8px; box-sizing: border-box;
  font: 500 13px/18px var(--font-body); color: var(--fg-muted); text-decoration: none; white-space: nowrap; overflow: hidden;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.shell-item .i { flex: none; }
.shell-item span { overflow: hidden; text-overflow: ellipsis; }
.shell-item:hover { background: var(--surface-2); color: var(--fg); }
.shell-item.is-active { background: var(--surface-2); color: var(--fg); }
.shell-item.is-active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--accent); }
.shell-item:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.shell-item .i-ext { margin-left: auto; width: 12px; height: 12px; color: var(--fg-subtle); }
.shell-side-foot { flex: none; padding: 8px; border-top: 1px solid var(--border); }
.shell-side-user { display: flex; align-items: center; gap: 10px; padding: 8px; min-width: 0; }
.shell-side-user .shell-side-name { display: block; font: 500 13px/18px var(--font-body); color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-side-user .shell-side-role { display: block; font-size: 12px; line-height: 16px; color: var(--fg-muted); white-space: nowrap; }
.shell-side-user > div { min-width: 0; }
.shell-scrim { position: fixed; inset: 0; z-index: 65; background: var(--overlay); display: none; }
.shell-menu-btn { display: none; }

/* ============ Routed views, page header, page-enter motion ============ */
.page .view[hidden] { display: none; }
.page-hd { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; margin: 0 0 24px; }
.page-hd h1 { font-family: var(--font-head); font-weight: 400; font-size: var(--fs-page); line-height: var(--lh-page); margin: 0; color: var(--fg); }
.page-hd p { margin: 4px 0 0; font-size: 14px; line-height: 20px; color: var(--fg-muted); max-width: 64ch; }
.page-hd .page-hd-action { flex: none; }
.page-hd[hidden] { display: none; }
.page-meta { margin: -12px 0 20px; }
#billing-panel:not([hidden]) + #billing-empty { display: none; }

/* settings view (built by shell.js) */
.settings-block { margin-bottom: 32px; }
.settings-block h2 { font-size: var(--fs-section); line-height: var(--lh-section); margin: 0 0 8px; }
.settings-block > p { margin: 0 0 12px; font-size: 14px; line-height: 20px; color: var(--fg-muted); }
.shortcuts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 14px; line-height: 20px; }
.shortcuts dt { white-space: nowrap; }
.shortcuts dd { margin: 0; color: var(--fg-muted); }
.shortcuts kbd + kbd { margin-left: 4px; }

/* ============ Bottom tab bar (phones) ============ */
.shell-bottom { display: none; }

/* ============ Side panel footer and scrim (the panel itself is in components.css) ============ */
.side-panel-ft { flex: none; display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.side-panel-ft:empty { display: none; }
.side-panel-scrim { position: fixed; inset: 0; z-index: 199; background: var(--overlay); opacity: 0; visibility: hidden; transition: opacity var(--dur), visibility 0s linear var(--dur); }
.side-panel-scrim.is-open { opacity: 1; visibility: visible; transition-delay: 0s; }
.side-panel-close { margin-left: auto; }
.side-panel-body .field { margin-bottom: 16px; }

/* ============ Toast text and the shortcuts sheet ============ */
.toast-text { flex: 1; min-width: 0; }
.toast-close { flex: none; }
.lc-dialog .shortcuts { margin-bottom: 16px; }

/* ============ Focus mode: exam and flashcard flows hide the chrome ============ */
.focus-mode .shell-side, .focus-mode .shell-top, .focus-mode .shell-bottom, .focus-mode .demo-banner, .focus-mode .portal-footer { display: none !important; }
.focus-mode .page { padding-top: 12px; }

/* ============ Icon rail under 1100 px ============ */
@media (max-width: 1100px) {
  .shell-side { width: 56px; }
  .shell-side-brand { justify-content: center; padding: 0; }
  .shell-side-brand span, .shell-group-label, .shell-item span, .shell-item .i-ext, .shell-side-user > div { display: none; }
  .shell-groups { padding: 8px 4px 16px; }
  .shell-group { padding: 6px 0 2px; border-top: 1px solid var(--border); }
  .shell-group:first-child { border-top: 0; }
  .shell-item { justify-content: center; padding: 0; height: 40px; }
  .shell-item .i { width: 20px; height: 20px; }
  .shell-side-user { justify-content: center; padding: 8px 0; }
  .shell-search { width: 200px; }
}

/* ============ Drawer and bottom tabs under 760 px ============ */
@media (max-width: 760px) {
  .shell-top { padding: 0 16px; gap: 8px; }
  .shell-menu-btn { display: inline-flex; }
  .shell-nav { display: none; }
  .shell-search { display: none; }
  .shell-search-sm { display: inline-flex; }
  .shell-crumb { font-size: 15px; }
  .shell-brand .shell-brand-tag { display: none; }
  .shell-side {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); height: auto; align-self: stretch; z-index: 80;   /* stretch: flex-start would size the drawer to its content and clip the last items */
    transform: translateX(-100%); visibility: hidden;
    transition: transform var(--dur) var(--ease-out), visibility 0s linear var(--dur);
  }
  .shell-side.is-open { transform: none; visibility: visible; transition-delay: 0s; }
  .shell-side-brand { justify-content: flex-start; padding: 0 16px; }
  .shell-side-brand span, .shell-group-label, .shell-item span, .shell-item .i-ext, .shell-side-user > div { display: block; }
  .shell-item .i-ext { display: inline-block; }
  .shell-side-close { display: inline-flex; }
  .shell-groups { padding: 8px 8px 16px; }
  .shell-group { border-top: 0; padding: 8px 0 4px; }
  .shell-item { justify-content: flex-start; padding: 0 8px; height: 44px; }
  .shell-item .i { width: 16px; height: 16px; }
  .shell-side-user { justify-content: flex-start; padding: 8px; }
  .shell-scrim.is-open { display: block; }
  .shell-bottom:not([hidden]) {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; height: 56px;
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .shell-tab {
    flex: 1; display: grid; place-items: center; align-content: center; gap: 2px; min-width: 0; padding: 0 4px;
    background: transparent; border: 0; border-radius: 0; color: var(--fg-muted); text-decoration: none;
    font: 500 12px/14px var(--font-body); cursor: pointer;
  }
  .shell-tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .shell-tab .i { width: 20px; height: 20px; }
  .shell-tab.is-active { color: var(--accent-text); }
  .shell-tab:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
  .has-shell .page, .has-shell .portal-main { padding-bottom: 96px; }
  .has-shell .portal-footer { padding-bottom: 72px; }
  .page-hd { margin-bottom: 16px; }
  .page { padding-left: 16px; padding-right: 16px; }
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  .shell-side, .shell-scrim, .side-panel-scrim, .shell-link, .shell-item, .shell-iconbtn, .seg button { transition: none; }
  .shell-pop { animation: none; }
}

/* ============ Touch and phone: icon buttons are 44 px hit areas (the glyph stays 20 px) ============ */
@media (pointer: coarse), (max-width: 760px) {
  .shell-iconbtn { width: 44px; height: 44px; flex: none; }
  .shell-actions .theme-btn { width: 44px; height: 44px; }
  .shell-avatar-btn { min-height: 44px; }
}
