/* App frame: sidebar, top bar, content grid. Reads tokens.css only. */

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100svh;
  background: var(--surface-sunken);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* Every figure in the kit is tabular, so a value animating from 9 to 10
     never shifts the text beside it. */
  font-variant-numeric: tabular-nums;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100svh;
  transition: grid-template-columns var(--dur) ease;
}
.app[data-collapsed="true"] { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ---------- sidebar ---------- */

.sidebar {
  /* Sticky and viewport-tall. As a plain grid child it stretched to the height
     of the DOCUMENT, which put the nav's own controls a full page scroll away
     on any long view. */
  position: sticky;
  top: 0;
  height: 100svh;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  padding: var(--sp-4) var(--sp-3);
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}

.brand { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-2); min-height: var(--control-h); }
.brand__mark {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--signal); color: var(--signal-ink);
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 700;
  letter-spacing: -0.02em;
}
.brand__name {
  font-family: var(--font-display);
  font-weight: 600; font-size: var(--text-base);
  letter-spacing: -0.02em; white-space: nowrap;
}
/* Collapse lives on the brand row, where the sidebar's own identity is, rather
   than pinned to the foot where it reads as a footnote. */
.brand__collapse { margin-left: auto; width: 26px; height: 26px; }
.brand__collapse .btn__icon { width: 14px; height: 14px; }
[data-collapsed="true"] .brand__collapse { display: none; }

.nav { position: relative; display: flex; flex-direction: column; gap: 2px; }
/* One indicator for the whole nav, moved by GSAP: the current page owns it,
   and it follows the pointer while you are choosing. */
.nav__indicator {
  position: absolute; left: 0; top: 0; z-index: 0;
  width: 100%; height: var(--control-h);
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  pointer-events: none;
  opacity: 0;
}
.nav__indicator::before {
  content: ''; position: absolute; left: 0; top: 50%;
  width: 2px; height: 16px; margin-top: -8px;
  border-radius: var(--radius-pill);
  background: var(--signal);
}
.nav__label {
  padding: 0 var(--sp-2) var(--sp-1);
  color: var(--ink-faint);
  font-family: var(--font-mono); font-size: var(--text-xs);
  letter-spacing: var(--tracking-label); text-transform: uppercase; white-space: nowrap;
}
.nav__item {
  position: relative;
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--control-h);
  padding: 0 var(--sp-2);
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-muted);
  cursor: pointer; font: inherit; text-align: left; text-decoration: none;
  white-space: nowrap;
}
/* The hover surface is the shared indicator, not a background on the item, so
   only one thing ever moves. Colour is still per item. */
.nav__item { z-index: 1; transition: color var(--dur-fast) ease; }
.nav__item:hover { color: var(--ink); }
.nav__item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav__item[aria-current="page"] { color: var(--ink); }
.nav__icon {
  flex: 0 0 auto; width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.75;
  transition: color var(--dur-fast) ease;
}
.nav__item[aria-current="page"] .nav__icon { color: var(--accent); }
.nav__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav__badge {
  margin-left: auto; padding: 1px var(--sp-2);
  border-radius: var(--radius-pill);
  background: var(--danger-wash); color: var(--danger);
  font-family: var(--font-mono); font-size: var(--text-xs);
}

.sidebar__foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--sp-2); }
/* The one ambient thing in the frame. Live is the only state that glows, which
   is why the signal colour is not spent anywhere decorative. */
.sysline {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-2);
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-family: var(--font-mono); font-size: var(--text-xs);
  letter-spacing: 0.02em; white-space: nowrap;
}
.sysline__dot, .page-eyebrow__dot {
  flex: 0 0 auto; width: 6px; height: 6px; border-radius: 50%;
  background: var(--signal);
  /* The ring is two animated custom properties composed with the signal token,
     so a re-skin re-colours the pulse and the JS holds no colour of its own. */
  --pulse-r: 0px;
  --pulse-a: 45%;
  box-shadow: 0 0 0 var(--pulse-r) color-mix(in srgb, var(--signal) var(--pulse-a), transparent);
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--sp-4);
  height: var(--topbar-h);
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar__crumbs {
  display: flex; align-items: center; gap: var(--sp-2); min-width: 0;
  color: var(--ink-faint);
  font-family: var(--font-mono); font-size: var(--text-xs);
  letter-spacing: 0.04em; text-transform: uppercase;
}
.topbar__crumbs strong { color: var(--ink); font-weight: 500; }
.topbar__sep { color: var(--line-strong); }
/* A real affordance, not chrome: the command bar's shortcut, shown where you
   would look for it. */
.kbd-hint {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  height: var(--control-h-sm); padding: 0 var(--sp-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-raised); color: var(--ink-faint);
  font-family: var(--font-mono); font-size: var(--text-xs);
  cursor: pointer;
  transition: color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.kbd-hint:hover { color: var(--ink); border-color: var(--line-strong); }
.kbd-hint:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kbd-hint kbd { font: inherit; color: var(--ink-muted); }
@media (max-width: 700px) { .kbd-hint { display: none; } }
.topbar__tools { display: flex; align-items: center; gap: var(--sp-3); margin-left: auto; }
/* The sidebar toggle lives in the top bar at every width: above 820px it
   collapses the rail, below it opens the off-canvas panel. It used to be
   mobile-only, which left the collapsed rail toggleable only from a control
   inside itself. */
[data-sidebar-toggle] { display: inline-flex; }

/* ---------- shared control primitives every component reuses ---------- */

.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--control-h); padding: 0 var(--sp-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-raised); color: var(--ink);
  /* Lit from above, like every raised surface in the kit. */
  box-shadow: inset 0 1px 0 var(--edge);
  cursor: pointer; font: inherit; font-size: var(--text-sm); font-weight: 500;
  letter-spacing: -0.005em; white-space: nowrap;
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.btn:hover { background: var(--surface-hover); border-color: var(--line-strong); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--primary {
  border-color: transparent; background: var(--signal); color: var(--signal-ink);
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: box-shadow var(--dur) ease, background-color var(--dur-fast) ease;
}
.btn--primary:hover {
  background: var(--accent-hover);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 6px 22px var(--signal-glow);
}
.btn--ghost { border-color: transparent; background: transparent; color: var(--ink-muted); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--ink); }
.btn--icon { width: var(--control-h); padding: 0; }
.btn__icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.75; }

.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  /* Raised, top-lit, and washed for the first 140px: a flat fill plus a
     1px border is the look every dark dashboard template ships with, and it
     is the thing that makes a card read as a rectangle rather than a panel. */
  background:
    linear-gradient(180deg, var(--edge) 0, transparent 140px),
    var(--surface-raised);
  box-shadow: inset 0 1px 0 var(--edge-strong), var(--shadow-1);
  transition: border-color var(--dur) ease;
}
.card:hover { border-color: var(--line-strong); }
.card__head {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
}
/* The rule under a card head fades out at both ends rather than butting into
   the border radius, which is the difference between a drawn panel and a
   stack of boxes. */
.card__head::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--line) 12%, var(--line) 88%, transparent);
}
.card__eyebrow {
  display: block; margin-bottom: var(--sp-1);
  color: var(--ink-faint);
  font-family: var(--font-mono); font-size: var(--text-xs);
  letter-spacing: var(--tracking-label); text-transform: uppercase;
}
.card__title { font-size: var(--text-base); font-weight: 600; letter-spacing: -0.015em; }
.card__sub { color: var(--ink-muted); font-size: var(--text-sm); }
.card__body { padding: var(--sp-5); }

.tag {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: 0.02em;
}
.tag--ok { background: var(--ok-wash); color: var(--ok); }
.tag--warn { background: var(--warn-wash); color: var(--warn); }
.tag--danger { background: var(--danger-wash); color: var(--danger); }
.tag--info { background: var(--info-wash); color: var(--info); }

/* ---------- content ---------- */

.content { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-5); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.page-eyebrow {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-bottom: var(--sp-2);
  color: var(--ink-faint);
  font-family: var(--font-mono); font-size: var(--text-xs);
  letter-spacing: var(--tracking-label); text-transform: uppercase;
}
.page-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl); font-weight: 600;
  letter-spacing: -0.045em; line-height: 1.05;
}
.page-sub { margin-top: var(--sp-1); color: var(--ink-muted); font-size: var(--text-sm); }

.grid { display: grid; gap: var(--sp-5); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--wide-narrow { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  .grid--3, .grid--wide-narrow, .grid--2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .app, .app[data-collapsed="true"] { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    width: var(--sidebar-w);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow-3);
  }
  /* Off-canvas is a JS state, not a CSS transform: GSAP owns this element's
     transform, and a CSS one underneath would be read as a pixel offset it
     never returns from. Without JS the sidebar simply stays visible. */
  .has-js .sidebar { visibility: hidden; }
  .has-js .sidebar[data-open="true"] { visibility: visible; }
  .content { padding: var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); }
}

@media (pointer: coarse) {
  .btn { min-height: var(--tap-min); }
  .btn--icon { width: var(--tap-min); }
  .nav__item { min-height: var(--tap-min); }
}
