/* =========================================================================
   The rail shell — navigation down the left instead of across the top.
   =========================================================================
   One stylesheet and one function (`renderRail` in nav.js), not a second set
   of pages. Every rule here is scoped to `[data-shell="rail"]`, so loading it
   changes nothing until the shell is switched; `tests/test_web_assets.py`
   parses this file and fails on any unscoped selector. That test is the whole
   bet: without it the two GUIs quietly become two codebases.

   The shell is independent of the theme. Nothing here sets a colour — it only
   decides where the colours from style.css go.

   `renderRail` MOVES the brandmark and the page's own controls into the rail
   rather than rebuilding them, so every handler a page bound by id survives.
   ========================================================================= */

:root[data-shell="rail"]{ --rail-w:256px }

/* Hidden everywhere the shell is not on. The one deliberate unscoped rule. */
.rail{display:none}

[data-shell="rail"] body{padding-left:var(--rail-w); background:var(--bg)}

[data-shell="rail"] .rail{
  display:flex; flex-direction:column; gap:var(--s3);
  position:fixed; inset:0 auto 0 0; width:var(--rail-w); z-index:50;
  padding:var(--s4) var(--s3) var(--s3);
  background:var(--rail-bg); color:var(--ink);
  border-right:1px solid var(--line-soft);
  /* The nav never shrinks and never scrolls on its own; the rail does, if a
     window is genuinely too short for it. */
  overflow-y:auto; scrollbar-width:none;
}
[data-shell="rail"] .rail::-webkit-scrollbar{display:none}

[data-shell="rail"] .rail-top{display:flex; align-items:center; padding:0 var(--s2); min-height:32px}
[data-shell="rail"] .rail .brandmark .word{font-size:15px}
[data-shell="rail"] .rail .brandmark .mark{width:26px; height:26px}

[data-shell="rail"] .rail-search .navsearch{display:block; margin:0}
[data-shell="rail"] .rail-search input{width:100%; background-color:var(--field)}
[data-shell="rail"] .rail-search input:focus{width:100%}

/* `min-height:0` is load-bearing: a flex item will not shrink below its
   content without it, and on a short window the nav pushed the foot — the
   picker and the toggles — off the bottom of the screen. */
[data-shell="rail"] .rail-nav{display:flex; flex-direction:column; gap:2px; flex:none; min-height:0}
[data-shell="rail"] .rl{
  display:flex; align-items:center; gap:10px; width:100%; height:34px;
  padding:0 var(--s2); border-radius:var(--r-sm);
  font-size:var(--t-sm); font-weight:500; color:var(--ink-2); text-decoration:none;
  transition:color var(--fast) var(--ease), background-color var(--fast) var(--ease)}
[data-shell="rail"] .rl:hover{color:var(--ink); background:var(--surface-2)}
[data-shell="rail"] .rl.on{color:var(--ink); font-weight:600}
/* The selected fill, behind the text: its own element so it can slide
   between rows on a page change (nav.js nameHighlight). */
[data-shell="rail"] :is(.rl,.rc){position:relative; isolation:isolate}
[data-shell="rail"] .rail-hl{position:absolute; inset:0; z-index:-1; border-radius:inherit;
  background:var(--fill); pointer-events:none}
[data-shell="rail"] .rl-i{display:grid; place-items:center; width:20px; height:20px; flex:none}
[data-shell="rail"] .rl .ri{width:18px; height:18px; display:block}
[data-shell="rail"] .rl-t{flex:1; min-width:0; text-align:left}
[data-shell="rail"] .rl-b{flex:none; display:grid; place-items:center; min-width:20px; height:20px;
  padding:0 6px; border-radius:var(--r-pill); background:var(--danger); color:var(--on-accent);
  font-size:var(--t-xs); font-weight:600}
[data-shell="rail"] .rail-nav .morebtn{justify-content:flex-start; border:0; background:transparent;
  font:inherit; font-size:var(--t-sm); font-weight:500; line-height:normal}
[data-shell="rail"] .rail-nav .morebtn:hover{background:var(--surface-2)}
[data-shell="rail"] .rail-nav .morebtn.on{color:var(--accent-ink); background:var(--accent-soft)}

/* The courses: the rail's middle, and the only part of it that scrolls on
   its own, so a term with many courses never pushes the foot off screen. */
[data-shell="rail"] .rail-courses{flex:1 1 auto; min-height:0; overflow-y:auto; scrollbar-width:none;
  display:flex; flex-direction:column; gap:2px; margin-top:var(--s2)}
[data-shell="rail"] .rail-courses::-webkit-scrollbar{display:none}
[data-shell="rail"] .rc-h{display:flex; align-items:baseline; justify-content:space-between; gap:var(--s2);
  padding:0 var(--s2) 6px; font-size:12px; font-weight:600; color:var(--ink-3)}
[data-shell="rail"] .rc-term{font-weight:500}
[data-shell="rail"] .rc{display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center;
  gap:10px; padding:7px var(--s2); border-radius:var(--r-sm); text-decoration:none; color:var(--ink)}
[data-shell="rail"] .rc:hover{background:var(--fill)}
[data-shell="rail"] .rc.on{background:transparent}
[data-shell="rail"] .rc-m{display:flex; flex-direction:column; min-width:0}
[data-shell="rail"] .rc-title{font-size:14px; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
[data-shell="rail"] .rc-sub{font-size:12px; color:var(--ink-3); overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
[data-shell="rail"] .rc-sub .warn{color:var(--warn); font-weight:600}
[data-shell="rail"] .rc-sub .rc-cta{color:var(--ink-3)}
[data-shell="rail"] .rc-x{font-size:12px; font-weight:600; color:var(--ink-2); font-variant-numeric:tabular-nums}
[data-shell="rail"] .rc-x.q{font-weight:500; color:var(--ink-3)}
[data-shell="rail"] .rc.has-warn .rc-title::after{content:""; display:inline-block; width:6px; height:6px;
  margin-left:6px; border-radius:50%; background:var(--warn); vertical-align:2px}
[data-shell="rail"] .rc-empty{padding:var(--s2); font-size:12px; color:var(--ink-3)}
[data-shell="rail"] .rc-done{margin-top:var(--s2)}
[data-shell="rail"] .rc-done > summary{display:flex; align-items:center; gap:6px; list-style:none; cursor:pointer;
  padding:6px var(--s2); font-size:12px; font-weight:600; color:var(--ink-3); border-radius:var(--r-sm)}
[data-shell="rail"] .rc-done > summary::-webkit-details-marker{display:none}
[data-shell="rail"] .rc-done > summary::before{content:""; width:5px; height:5px; margin-right:2px;
  border-right:1.5px solid currentColor; border-bottom:1.5px solid currentColor; transform:rotate(-45deg);
  transition:transform var(--fast) var(--ease)}
[data-shell="rail"] .rc-done[open] > summary::before{transform:rotate(45deg)}
[data-shell="rail"] .rc-done > summary:hover{color:var(--ink)}
[data-shell="rail"] .rc-done .rc{opacity:.6}
[data-shell="rail"] .rc-done .rc:hover{opacity:1}
[data-shell="rail"] .rc-n{font-weight:500}

/* The next session, at the foot of every page. */
[data-shell="rail"] .rail-next{display:flex; flex-direction:column; gap:2px; padding:10px 12px;
  border-radius:var(--r-md); background:var(--surface); text-decoration:none; color:var(--ink);
  box-shadow:inset 3px 0 0 var(--c, var(--now))}
[data-shell="rail"] .rail-next:hover{background:var(--surface-2)}
[data-shell="rail"] .rn-k{font-size:12px; font-weight:600; color:var(--now-ink)}
[data-shell="rail"] .rn-t{font-size:16px; font-weight:700; letter-spacing:-.01em}
[data-shell="rail"] .rn-w{font-size:12px; color:var(--ink-2); overflow:hidden; text-overflow:ellipsis; white-space:nowrap}

[data-shell="rail"] .rail-foot{display:flex; flex-direction:column; gap:var(--s2);
  flex:none; margin-top:auto; padding-top:var(--s3); border-top:1px solid var(--line-soft)}
/* The course picker is a CONTROL, and wears the search box's shape. It carries
   its own label and chevron: a bare <button> centres its text. */
[data-shell="rail"] .rail-foot .coursepick{display:block}
[data-shell="rail"] .rail-foot .course-jump{display:flex; align-items:center; gap:var(--s2);
  width:100%; height:var(--ctl-h); padding:0 10px 0 12px; text-align:left;
  font-weight:500; color:var(--ink-2); background:var(--field); border:1px solid var(--ctl-line)}
[data-shell="rail"] .rail-foot .course-jump:hover,
[data-shell="rail"] .rail-foot .course-jump[aria-expanded="true"]{color:var(--ink); border-color:var(--accent)}
[data-shell="rail"] .cj-t{flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
[data-shell="rail"] .cj-chev{flex:none; display:grid; place-items:center; color:var(--ink-3)}

[data-shell="rail"] .rail-actions{display:flex; gap:2px; align-items:center}
[data-shell="rail"] .rail-actions .ghost{width:var(--ctl-h); height:var(--ctl-h); flex:none; padding:0;
  display:grid; place-items:center; color:var(--ink-2)}
[data-shell="rail"] .rail-actions .ghost:hover{color:var(--ink); background:var(--surface-2)}
[data-shell="rail"] .rail-synced{padding:0 var(--s2); font-size:var(--t-xs); color:var(--ink-3)}

/* The canvas: no framed sheet. Pages sit on the ground exactly as they do in
   the bar shell; the rail is the only chrome. */
[data-shell="rail"] main.dash{max-width:calc(var(--page-max) + var(--s6) * 2)}
/* One scroller per page: the canvas grows and the window scrolls. */
[data-shell="rail"] main.dash{overflow:visible; flex:none}
[data-shell="rail"] .pagehead #course-switch{display:none}
/* The calendar is full-bleed; its toolbar sticks to the top of the window
   because there is no top bar above it. Any offset measured against the bar
   has to be re-measured against this. */
[data-shell="rail"] .subbar{top:0}
[data-shell="rail"] .daynames{top:0}
[data-shell="rail"] .course-side{top:var(--s4); max-height:calc(100vh - var(--s4) * 2)}

/* Narrow windows: an icon rail. Every destination stays one click away. */
@media (max-width:900px){
  :root[data-shell="rail"]{--rail-w:60px}
  [data-shell="rail"] .rail{padding:var(--s3) var(--s2); align-items:center}
  [data-shell="rail"] .rl-t,[data-shell="rail"] .rail-search,[data-shell="rail"] .rl-b,
  [data-shell="rail"] .rail .brandmark .word,[data-shell="rail"] .rail-foot .coursepick,
  [data-shell="rail"] .rail-synced,[data-shell="rail"] .rc-m,[data-shell="rail"] .rc-x,
  [data-shell="rail"] .rc-h,[data-shell="rail"] .rc-done,[data-shell="rail"] .rail-next{display:none}
  [data-shell="rail"] .rc{grid-template-columns:1fr; padding:6px}
  [data-shell="rail"] .rc-m{display:flex} [data-shell="rail"] .rc-tn,[data-shell="rail"] .rc-sub{display:none}
  [data-shell="rail"] .rail-top{padding:0}
  [data-shell="rail"] .rl{justify-content:center; width:40px; padding:0}
  [data-shell="rail"] .rail-actions{flex-direction:column}
  [data-shell="rail"] .rail-foot{align-items:center}
}

/* ---- course rows: the code in a pill of the course colour, as the course
   page's badge (chosen from a spine, week ticks and this) ---- */
[data-shell="rail"] .rc{grid-template-columns:minmax(0,1fr) auto; padding:8px 10px}
[data-shell="rail"] .rc-title{display:flex; align-items:center; gap:7px; min-width:0; font-size:14px; font-weight:600}
[data-shell="rail"] .rc-tn{min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
[data-shell="rail"] .rc-pill{display:inline-flex; align-items:center; height:20px; padding:0 7px; border-radius:999px;
  font-size:11px; font-weight:700; flex:none; color:var(--ink);
  background:color-mix(in srgb,var(--c) 30%,transparent); box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--c) 60%,transparent)}
[data-shell="rail"] .rc-sub{padding-left:1px; margin-top:2px}

/* Phones: the rail becomes a tab bar along the bottom, as iOS apps have it.
   Today, Week, Calendar, To-Do and Courses (which opens the course list as a
   sheet over the bar), then the Style menu. The rest of the rail (search,
   the next-session card, sync) is not shown: search and sync are in the
   palette, and the next session leads the Today page anyway. */
[data-shell="rail"] .rl-courses{display:none}
@media (max-width:700px){
  :root[data-shell="rail"]{--rail-w:0px}
  [data-shell="rail"] body{padding-left:0; padding-bottom:calc(64px + env(safe-area-inset-bottom))}
  [data-shell="rail"] .rail{inset:auto 0 0 0; width:auto; height:calc(64px + env(safe-area-inset-bottom));
    flex-direction:row; align-items:stretch; gap:0; padding:0 4px env(safe-area-inset-bottom);
    border-right:0; border-top:1px solid var(--line-soft); overflow:visible;
    background:transparent; isolation:isolate}
  /* The glass on a ::before, never on the rail: backdrop-filter would make the
     rail the containing block of the fixed course sheet inside it. */
  [data-shell="rail"] .rail::before{content:""; position:absolute; inset:0; z-index:-1;
    background:var(--glass); -webkit-backdrop-filter:blur(20px); backdrop-filter:blur(20px)}
  [data-shell="rail"] .rail-top,[data-shell="rail"] .rail-search,[data-shell="rail"] .rail-next,
  [data-shell="rail"] .rail-synced,[data-shell="rail"] #chrome-sync,
  [data-shell="rail"] .rail-actions [data-theme-toggle]{display:none}
  [data-shell="rail"] .rail-nav{flex:1; flex-direction:row; gap:0}
  [data-shell="rail"] .rl,[data-shell="rail"] .rl-courses{display:flex; flex:1; flex-direction:column;
    justify-content:center; align-items:center; gap:3px; width:auto; height:100%; padding:0;
    border-radius:0; background:transparent; font-size:10px; font-weight:500; color:var(--ink-3)}
  [data-shell="rail"] .rl .rl-t{display:block; flex:none; text-align:center}
  [data-shell="rail"] .rl .ri{width:22px; height:22px}
  [data-shell="rail"] .rl.on,[data-shell="rail"] .rl-courses[aria-expanded="true"]{color:var(--accent-ink); background:transparent}
  [data-shell="rail"] .rl .rail-hl{display:none}
  [data-shell="rail"] .rl-b{position:absolute; transform:translate(12px,-12px); min-width:16px; height:16px; font-size:10px}
  [data-shell="rail"] .rail-foot{flex:none; flex-direction:row; align-items:center; margin:0; padding:0 4px; border-top:0}
  [data-shell="rail"] .rail-actions{flex-direction:row}
  /* The course list, as a sheet above the bar. */
  [data-shell="rail"] .rail-courses{display:none}
  [data-shell="rail"] .rail.show-courses .rail-courses{display:flex; position:fixed; left:8px; right:8px;
    bottom:calc(72px + env(safe-area-inset-bottom)); max-height:60vh; overflow-y:auto; z-index:60;
    padding:12px 8px; border-radius:var(--r-lg); background:var(--surface-solid); box-shadow:var(--shadow)}
  [data-shell="rail"] .rail.show-courses .rc-x,[data-shell="rail"] .rail.show-courses .rc-done{display:revert}
  [data-shell="rail"] .rail.show-courses .rc-h{display:flex; padding:0 10px 8px}
  [data-shell="rail"] .rail.show-courses .rc{grid-template-columns:minmax(0,1fr) auto; padding:10px}
  [data-shell="rail"] .rail.show-courses .rc-m{display:flex}
  [data-shell="rail"] .rail.show-courses .rc-tn,[data-shell="rail"] .rail.show-courses .rc-sub{display:block}
}

/* The rail is the same on every page: give it its own view-transition name
   so a page change swaps the canvas and leaves the rail where it is. */
[data-shell="rail"] .rail{view-transition-name:life-rail}
[data-shell="rail"]::view-transition-old(life-rail),
[data-shell="rail"]::view-transition-new(life-rail){animation:none}

