/* StudyPal app shell: slim left sidebar (>=900px), top bar + drawer (<900px).
   Uses the palette tokens so every theme follows. No red; controls <=34px. */
:root {
  --sp-side-w: 220px; --sp-top-h: 48px;
  /* One width system for every app page. Lists and reading pages (Library, Tonight, Tests,
     Practice, Course) use --content-read; the guide reader and the calendar use --content-wide.
     Both are centred in the area right of the sidebar with --content-gutter on each side. */
  --content-read: 860px; --content-wide: 1200px; --content-gutter: 32px;
}

/* Hidden until this sheet has loaded (components.js sets sp-shell-ready). */
html:not(.sp-shell-ready) .sp-side, html:not(.sp-shell-ready) .sp-top { visibility: hidden; }

/* Course filtering lives in the sidebar now; the old Class strip is not shown.
   Its Ask StudyPal panel still opens from "Ask the tutor". */
#study-context-strip { display: none !important; }

.sp-side, .sp-top { font-family: var(--font-ui, system-ui, sans-serif); color: var(--text); box-sizing: border-box; }
.sp-side *, .sp-top * { box-sizing: border-box; }
.sp-ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.sp-logo { font-family: var(--font-head, Georgia, serif); font-size: 1.22rem; font-weight: 600; letter-spacing: -.01em; color: var(--text); text-decoration: none; }

/* ---- Sidebar */
.sp-side {
  position: fixed; top: 0; bottom: 0; left: 0; width: var(--sp-side-w); z-index: 60;
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 12px 14px; background: var(--bg); border-right: 1px solid var(--border);
  overflow-y: auto; overscroll-behavior: contain;
}
.sp-brand { padding: 0 8px; }

.sp-child { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); position: relative; }
.sp-child[hidden] { display: none; }
.sp-avatars { display: flex; gap: 4px; }
.sp-avatar { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border); background: var(--card); color: var(--text-secondary); font: 600 .74rem/1 var(--font-ui, sans-serif); cursor: pointer; padding: 0; }
.sp-avatar:hover:not(:disabled) { border-color: var(--primary); color: var(--text); }
.sp-avatar.is-active { background: var(--text); border-color: var(--text); color: var(--bg); }
.sp-avatar:disabled { cursor: default; }
.sp-who { display: flex; flex-direction: column; margin-left: auto; text-align: right; min-width: 0; }
.sp-who-name { font-size: .84rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-who-grade { font-size: .7rem; color: var(--text-secondary); }
.sp-status:empty { display: none; }
.sp-status { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; font-size: .72rem; color: var(--text-secondary); }

.sp-links { display: flex; flex-direction: column; gap: 1px; }
.sp-link {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 0 10px;
  border: 0; border-radius: 6px; background: none; color: var(--text-secondary);
  font: 500 .87rem/1.2 var(--font-ui, sans-serif); text-decoration: none; text-align: left; cursor: pointer;
}
.sp-link:hover { background: var(--card-alt); color: var(--text); }
.sp-link.is-active { background: var(--card-alt); color: var(--text); font-weight: 650; box-shadow: inset 2px 0 0 var(--primary); }
.sp-link[hidden] { display: none; }
.sp-count { margin-left: auto; font-size: .7rem; color: var(--text-secondary); font-weight: 400; }

.sp-courses { list-style: none; margin: 0 0 4px 18px; padding: 0 0 0 8px; border-left: 1px solid var(--border); }
.sp-courses:empty { display: none; }
.sp-course { display: flex; align-items: center; gap: 8px; min-height: 26px; padding: 0 8px; border-radius: 5px; color: var(--text-secondary); font-size: .76rem; text-decoration: none; }
.sp-course:hover { background: var(--card-alt); color: var(--text); }
.sp-course.is-active { color: var(--text); font-weight: 650; background: var(--card-alt); }
.sp-course-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--border); flex: none; }
.sp-course.is-active .sp-dot { background: var(--primary); }

.sp-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 1px; }
.sp-small { font-size: .8rem; min-height: 30px; }
.sp-more { position: relative; }
.sp-more > summary { list-style: none; }
.sp-more > summary::-webkit-details-marker { display: none; }
.sp-more-menu {
  position: static; display: flex; flex-direction: column; margin: 2px 0 4px 26px; padding: 4px 0;
  border: 0; box-shadow: none; background: none; min-width: 0;
}
.sp-more-menu a { padding: 5px 10px; font-size: .8rem; color: var(--text-secondary); text-decoration: none; border-radius: 5px; }
.sp-more-menu a:hover { background: var(--card-alt); color: var(--text); }
.sp-more-menu .app-nav-menu-meta { padding: 8px 10px 0; font-size: .72rem; }
.sp-more-menu .theme-control { font-size: .78rem; }
.sp-more-menu .theme-control select { min-height: 30px; padding: 2px 24px 2px 8px; font-size: .78rem; }

.sp-side :focus-visible, .sp-top :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Content clears the sidebar. Margin (not padding) keeps each page's own gutter. */
@media (min-width: 900px) {
  body.sp-shell { margin-left: var(--sp-side-w) !important; }
  .sp-top, .sp-scrim { display: none !important; }
  .app-footer { display: none !important; }
}

/* ---- Desktop header: date, search, Ask, Add, across the top of every page. */
.sp-head { display: none; }
@media (min-width: 900px) {
  .sp-head { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 28px; border-bottom: 1px solid var(--border); background: var(--bg);
    font-family: var(--font-ui, system-ui, sans-serif); color: var(--text); box-sizing: border-box; }
  .sp-head * { box-sizing: border-box; }
  .sp-head-date { flex: none; font-size: .86rem; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
  .sp-head-search { flex: 1; display: flex; justify-content: center; min-width: 0; }
  .sp-head-search input { width: 100%; max-width: 440px; height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; font-size: .88rem; }
  .sp-head-search input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
  .library-pilot .sp-head-search input { visibility: hidden; } /* the Library has its own search box */
  .sp-head-btn { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; font-size: .85rem; font-weight: 600; text-decoration: none; cursor: pointer; }
  .sp-head-btn:hover { border-color: var(--primary); }
  .sp-head-btn[hidden] { display: none; }
  .sp-head-add { background: var(--primary); border-color: var(--primary); color: var(--card); }
  .sp-head-add:hover { background: var(--primary-dark); }
}

/* ---- Phone / narrow: compact top bar, the sidebar becomes a drawer. */
.sp-top {
  position: sticky; top: 0; z-index: 55; height: var(--sp-top-h);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.sp-menu { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); cursor: pointer; padding: 0; }
.sp-menu .sp-ico { width: 18px; height: 18px; }
.sp-scrim { position: fixed; inset: 0; z-index: 1001; background: rgba(20, 30, 35, .32); }
.sp-scrim[hidden] { display: none; }
@media (max-width: 899px) {
  .sp-side { z-index: 1002; width: min(280px, 86vw); transform: translateX(-102%); transition: transform .18s ease; box-shadow: none; visibility: hidden; }
  .sp-side.is-open { transform: none; box-shadow: 8px 0 24px rgba(20, 30, 35, .12); visibility: visible; }
  html.sp-drawer-open { overflow: hidden; }
  .app-footer { display: flex; }
}
/* Short landscape screens (car browsers, phones on their side): the fixed bottom bar
   would cover a big slice of the page, so drop it; the menu button has every link. */
@media (max-width: 899px) and (orientation: landscape) and (max-height: 700px) {
  .app-footer { display: none !important; }
  body.sp-shell { padding-bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) { .sp-side { transition: none; } }
@media print { .sp-side, .sp-top, .sp-head, .sp-scrim, .app-footer { display: none !important; } body.sp-shell { margin-left: 0 !important; } }
.sp-heading, .sp-heading:hover { cursor: default; background: none; color: var(--text-secondary); margin-top: 6px; }

/* ---- Reading (>=900px): the sidebar folds to a 56px icon rail so the lesson gets the room.
   Hover or keyboard focus opens it over the page (fixed, so nothing shifts). Focus mode hides it. */
@media (min-width: 900px) {
  body.sp-shell.reader-open { --sp-side-w: 56px; }
  body.reader-open .sp-side { width: 56px; padding: 14px 8px; gap: 10px; overflow-x: hidden; transition: width .14s ease, box-shadow .14s ease; }
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-brand,
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-label,
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-count,
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-heading,
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-courses,
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-who,
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-status,
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-more-menu,
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-avatar:not(.is-active) { display: none !important; }
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-child { padding: 0; border: 0; background: none; justify-content: center; }
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-link { justify-content: center; padding: 0; }
  body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-link .sp-ico { width: 18px; height: 18px; }
  body.reader-open .sp-side:hover, body.reader-open .sp-side:focus-within {
    width: 220px; padding: 18px 12px 14px; gap: 14px; z-index: 1003; box-shadow: 8px 0 24px rgba(20, 30, 35, .12);
  }
  body.reader-open.reader-full .sp-side { display: none; }
  body.sp-shell.reader-open.reader-full { margin-left: 0 !important; }
}
@media (min-width: 900px) and (prefers-reduced-motion: reduce) { body.reader-open .sp-side { transition: none; } }

/* ---- One page frame for every app page (>=900px): same left edge, same cap, same type.
   Pattern from sidebar apps (Linear, Notion, Stripe): the column never jumps between pages. */
@media (min-width: 900px) {
  body.sp-shell { --page-max: var(--content-read); --page-gutter: var(--content-gutter); }
  body.sp-shell.narrow { --page-max: 640px; }
  body.sp-shell.reading, body.sp-shell > :is(.cal, .day-wrap) { --page-max: var(--content-wide); }
  /* Fixed bottom bars start after the sidebar, not under it. */
  body.sp-shell .bar { left: var(--sp-side-w) !important; }
  body.sp-shell > :is(main, .page, .container, .wrap, .day-wrap, .cal, .head, .course-wrap, .content) {
    margin-left: auto !important; margin-right: auto !important;
    padding-left: var(--page-gutter) !important; padding-right: var(--page-gutter) !important;
    box-sizing: border-box; width: auto;
    max-width: calc(var(--page-max) + 2 * var(--page-gutter)) !important;
  }
}
body.sp-shell { font-family: var(--font-ui); }
body.sp-shell > :is(main, .page, .container, .wrap, .day-wrap, .cal, .head) h1:first-of-type {
  font-family: var(--font-head); font-weight: 500; font-size: 1.9rem; line-height: 1.15; letter-spacing: -.01em;
}

/* Sidebar section label (Study): quiet, like Linear/Notion group titles. */
.sp-section { margin: 10px 8px 2px; font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-secondary); }
@media (min-width: 900px) { body.reader-open .sp-side:not(:hover):not(:focus-within) .sp-section { display: none; } }

/* One control shape on every app page (palette: --ctl-r). Pills and chips keep their round shape. */
body.sp-shell > :is(main, .page, .container, .wrap, .day-wrap, .cal) :is(button, .btn, a.go, input[type=submit]):not(.sp-link):not([class*=chip]):not([class*=pill]):not([class*=tab]) {
  border-radius: var(--ctl-r, 8px);
}
body.sp-shell .start-btn { background: var(--primary); color: #fff; }
body.sp-shell .course-card { border-color: var(--border); }

/* One card on every app page: Day view's card (10px, 1px border, flat). DESIGN.md: quiet rules, no glowing shadows. */
body.sp-shell > :is(main, .page, .container, .wrap, .day-wrap, .cal) :is(.card, .course-card, .exam-card) {
  border-radius: 10px; border: 1px solid var(--border); box-shadow: none; background: var(--card);
}
