/* ── App shell ─────────────────────────────────────────────────────────────────
   Sidebar on a desktop, bottom tab bar on a phone: the layout of Google Drive and
   Classroom, which is where students already learned how to move around.
   Loaded only by the signed-in study pages (Today, Lectures, Courses, Progress);
   Review keeps its own immersive layout, and the lecture page is a full-width
   document, as in Docs. Colours come from the :root tokens in style.css. */

:root {
  --shell-w: 248px;
  --shell-tab-h: 60px;
  --due: #C5600A;
  --due-bg: #FEF1E6;
  --ok: #188038;
  --ok-bg: #E6F4EA;
  --highlight: #FDE047;
}

/* The page's own brand/nav strip is replaced by the shell. */
body.has-shell .study-nav,
body.has-shell .prog-nav,
body.has-shell .courses-nav { display: none !important; }

.shell-side, .shell-tabs, .shell-top, .shell-fab { font-family: var(--font); }

/* ── Sidebar (desktop) ───────────────────────────────────────────────────── */
.shell-side {
  position: fixed; inset: 0 auto 0 0; width: var(--shell-w);
  background: var(--white); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; z-index: 40;
  overflow-y: auto;
}
.shell-brand {
  display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px;
  text-decoration: none; color: var(--text); font-weight: 700; font-size: var(--step-md); letter-spacing: -.2px;
}
.shell-brand img { width: 32px; height: 32px; display: block; }
.shell-new {
  display: inline-flex; align-items: center; gap: 10px; height: 48px; padding: 0 20px 0 14px; margin: 0 4px 12px;
  border-radius: 4px; background: var(--primary); color: #fff; font-weight: 600; font-size: var(--step-md); text-decoration: none;
  box-shadow: var(--shadow-md); transition: background .15s, box-shadow .15s;
}
.shell-new:hover { background: var(--primary-dark); box-shadow: var(--shadow-lg); }
.shell-nav { display: flex; flex-direction: column; gap: 2px; }
.shell-link {
  display: flex; align-items: center; gap: 14px; min-height: 44px; padding: 0 14px; border-radius: 4px;
  color: var(--text); text-decoration: none; font-size: var(--step-sm); font-weight: 500; position: relative;
}
.shell-link:hover { background: var(--surface); }
.shell-link[aria-current="page"] { background: var(--primary-light); color: var(--primary-dark); font-weight: 700; }
.shell-link svg, .shell-new svg, .shell-tab svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.shell-badge {
  margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--due); color: #fff;
  font-size: var(--step-2xs); font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.shell-badge[hidden] { display: none; }
.shell-spacer { flex: 1; min-height: 12px; }
.shell-streak {
  display: flex; align-items: center; gap: 8px; margin: 0 4px 8px; padding: 10px 12px; border-radius: 6px;
  background: var(--due-bg); color: #7A3A05; font-size: var(--step-xs); font-weight: 600;
}
.shell-streak[hidden] { display: none; }
.shell-streak svg { width: 18px; height: 18px; fill: var(--due); stroke: none; }
.shell-account { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px; }
.shell-me { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.shell-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex: none; font-size: var(--step-md);
}
.shell-me-text { min-width: 0; line-height: 1.25; }
.shell-me-name { font-size: var(--step-sm); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shell-me-sub { font-size: var(--step-xs); color: var(--text-muted); }
.shell-upgrade, .shell-signin {
  display: block; margin: 8px 4px 0; text-align: center; padding: 10px 12px; border-radius: 10px; font-size: var(--step-sm);
  font-weight: 600; text-decoration: none; border: 1px solid var(--border); color: var(--primary-dark); background: var(--white); cursor: pointer; font-family: var(--font);
}
.shell-upgrade:hover, .shell-signin:hover { background: var(--primary-light); }
.shell-foot { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 12px 8px 0; font-size: var(--step-2xs); }
.shell-foot a { color: var(--text-muted); text-decoration: none; }
.shell-foot a:hover { text-decoration: underline; }

body.has-shell { padding-left: var(--shell-w); background: var(--bg); }
body.has-shell .lib-wrap, body.has-shell .prog-wrap, body.has-shell .courses-wrap, body.has-shell .today-wrap { margin-left: auto; margin-right: auto; }

/* ── Phone: top bar + bottom tabs ────────────────────────────────────────── */
.shell-top, .shell-tabs, .shell-fab { display: none; }

@media (max-width: 899px) {
  .shell-side { display: none; }
  body.has-shell { padding-left: 0; padding-top: 52px; padding-bottom: calc(var(--shell-tab-h) + 16px + env(safe-area-inset-bottom)); }
  .shell-top {
    display: flex; align-items: center; justify-content: space-between; position: fixed; inset: 0 0 auto 0; height: 52px;
    padding: 0 12px 0 14px; background: var(--white); border-bottom: 1px solid var(--border); z-index: 40;
  }
  .shell-top .shell-brand { padding: 0; font-size: var(--step-md); }
  .shell-top .shell-brand img { width: 28px; height: 28px; }
  .shell-top .shell-avatar { width: 40px; height: 40px; font-size: var(--step-xs); text-decoration: none; }
  .shell-tabs {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0;
    height: calc(var(--shell-tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--white); border-top: 1px solid var(--border); z-index: 40;
  }
  .shell-tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px;
    color: var(--text-muted); text-decoration: none; font-size: var(--step-2xs); font-weight: 600; position: relative;
  }
  .shell-tab[aria-current="page"] { color: var(--primary-dark); }
  .shell-tab[aria-current="page"] .shell-tab-ico { background: var(--primary-light); }
  .shell-tab-ico { width: 52px; height: 30px; border-radius: 15px; display: flex; align-items: center; justify-content: center; position: relative; }
  .shell-tab .shell-badge { position: absolute; top: -4px; right: -2px; margin: 0; min-width: 18px; height: 18px; font-size: var(--step-2xs); padding: 0 5px; }
  .shell-fab {
    display: inline-flex; align-items: center; justify-content: center; position: fixed; right: 16px;
    bottom: calc(var(--shell-tab-h) + 16px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 4px;
    background: var(--primary); color: #fff; box-shadow: var(--shadow-lg); z-index: 41; text-decoration: none;
  }
  .shell-fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
}

@media (prefers-reduced-motion: reduce) { .shell-new, .shell-link { transition: none; } }

/* ── Page chrome the shell makes redundant ─────────────────────────────────── */
body.has-shell .lib-head-left > a[aria-label="Back to App"],
body.has-shell .lib-head > a.btn,
body.has-shell .lib-fab { display: none !important; }
body.has-shell .lib-head { margin-bottom: 4px; }

/* ── Shell on the lecture page: it replaces the site header and the upload intro ── */
body.has-shell[data-shell="on-lecture"] > .header,
body.has-shell[data-shell="on-lecture"] .mobile-nav,
body.has-shell[data-shell="on-lecture"] .app-page-header { display: none !important; }
body.has-shell[data-shell="on-lecture"] .lec-back { display: none; }
body.has-shell[data-shell="on-lecture"] .app-page-wrap { max-width: 980px; margin-left: auto; margin-right: auto; }

/* Phones: every control on a shell page is at least a thumb tall. */
@media (max-width: 899px) {
  body.has-shell button:not(.ts-seekable):not(.ne-del),
  body.has-shell .btn,
  body.has-shell select,
  body.has-shell input[type="text"],
  body.has-shell input[type="search"],
  body.has-shell .study-chip, body.has-shell .lib-chip, body.has-shell .lib-filter-btn, body.has-shell [class*="filter"] button { min-height: 44px; }
  body.has-shell .tab-btn { min-height: 46px; }
  body.has-shell .lib-wrap a, body.has-shell .shell-brand { min-height: 44px; display: inline-flex; align-items: center; }
}

/* Phones: the support bubble sits above the "+" button, not on top of the tab bar. */
@media (max-width: 899px) {
  body.has-shell .sw-widget { bottom: calc(var(--shell-tab-h) + 88px + env(safe-area-inset-bottom)) !important; right: 16px !important; }
  body.has-shell .sw-bubble { width: 48px; height: 48px; }
}

/* `overflow-x: hidden` on <body> makes it a scroll container, which silently disables
   position: sticky for everything inside (the lecture rail, the player). `clip` stops sideways
   scrolling just the same without creating one. Browsers without `clip` keep the old behaviour. */
@supports (overflow: clip) {
  body.has-shell { overflow-x: clip; }
}

/* Wide screens: the lecture card grows to hold the notes and the rail side by side. At 1360px that
   leaves the notes ~690px; the two max-widths below were 980px and 900px, which squeezed the notes
   to ~500px beside a 290px rail. */
@media (min-width: 1360px) {
  body.has-shell[data-shell="on-lecture"] .app-page-wrap { max-width: 1280px; }
  body.has-shell[data-shell="on-lecture"] #app-grid.result-active .result-panel,
  body.has-shell[data-shell="on-lecture"] .result-panel { max-width: 1220px; }
}
