/* ============================================================================
   Shell and patterns — docs/design-system.md §8, §9.17-§9.20, §9.24, §16

   Navy chrome framing a warm paper canvas. The chrome keeps its own colour
   scale and reads identically in both themes: it is the building the work
   happens in. The canvas is the document being read.

   Z-index ladder — the whole stacking contract:
     20 topbar · 30 rail · 50 overlays · 60 toasts · 70 tooltips
   ========================================================================= */

/* ── 8.1 The shell ───────────────────────────────────────────────────────── */

/* `position: relative` here is load-bearing: it makes the shell a containing
   block, so an absolutely-positioned descendant resolves against it and is
   clipped rather than stretching the document into a second scrollbar. */
.shell {
  position: relative;
  display: flex;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--paper);
}

.shell-main {
  display: flex;
  min-width: 0;
  flex: 1 1 0%;
  flex-direction: column;
}

.canvas { flex: 1 1 0%; overflow-y: auto; }

.canvas-inner {
  margin: 0 auto;
  width: 100%;
  max-width: var(--canvas-max);
  padding: 28px 24px;
}
@media (min-width: 1024px) { .canvas-inner { padding-left: 32px; padding-right: 32px; } }

/* Every page is the same four moves, spaced on one rhythm. */
.page       { display: flex; flex-direction: column; gap: 28px; padding-bottom: 16px; }
.page-wide  { gap: 32px; }   /* the dashboard */

/* ── 9.17 Rail ───────────────────────────────────────────────────────────── */

.rail {
  position: relative;
  z-index: 30;
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  width: var(--rail-w);
  background-color: var(--chrome);
  border-right: 1px solid var(--chrome-rule);
}
/* The width transition is suppressed until hydrated, so adopting the stored
   preference reads as the initial state rather than an animation nobody asked
   for. */
.rail[data-hydrated="true"] { transition: width 200ms var(--ease); }
.rail[data-collapsed="true"] { width: var(--rail-w-collapsed); }

.rail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  flex-shrink: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--chrome-rule);
}
.rail[data-collapsed="true"] .rail-head { padding: 0 16px; }

/* The SAHE crest, in place of a generic glyph. It is wider than it is tall,
   so it is sized by height and given room rather than squeezed into a tile. */
.rail-mark {
  display: flex;
  flex-shrink: 0;
  color: var(--chrome-text-strong);
}
.sahe-mark { height: 26px; width: auto; }
/* Collapsed, the rail is 68px wide: the crest steps down to fit its gutter. */
.rail[data-collapsed="true"] .sahe-mark { height: 18px; }
.rail-wordmark {
  min-width: 0;
  letter-spacing: 0.01em;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--chrome-text-strong);
}
.rail-descriptor {
  display: block;
  margin-top: 2px;
  font-size: 9px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--chrome-text-mute);
}

.rail-nav { flex: 1 1 0%; overflow-y: auto; padding: 12px 0; }
.rail-group + .rail-group { margin-top: 14px; }
.rail-group-label {
  padding: 6px 20px;
  font-size: 9px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--chrome-text-mute);
}
/* Collapsed, a group header becomes a divider — a word would not fit and an
   abbreviation would not mean anything. */
.rail[data-collapsed="true"] .rail-group-label {
  height: 1px;
  margin: 10px 16px;
  padding: 0;
  overflow: hidden;
  background-color: var(--chrome-rule);
  color: transparent;
}

.rail-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 8px;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--chrome-text);
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
.rail-item:hover {
  background-color: color-mix(in srgb, var(--chrome-alt) 60%, transparent);
  color: var(--chrome-text-strong);
}
.rail-item .icon { color: var(--chrome-text-mute); transition: color 160ms var(--ease); }
.rail-item:hover .icon { color: var(--chrome-text); }

.rail-item[aria-current="page"] {
  background-color: var(--chrome-alt);
  color: var(--chrome-text-strong);
}
.rail-item[aria-current="page"] .icon { color: var(--coral); }
/* the 2px coral marker */
.rail-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  margin-top: -10px;
  width: 2px; height: 20px;
  border-radius: 0 9999px 9999px 0;
  background-color: var(--coral);
}

.rail-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-count {
  margin-left: auto;
  flex-shrink: 0;
  border-radius: 9999px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background-color: var(--chrome-alt);
  color: var(--chrome-text);
}
.rail-item[aria-current="page"] .rail-count { background-color: #fff; color: var(--coral-strong); }

.rail[data-collapsed="true"] .rail-item { justify-content: center; padding: 8px 0; }
.rail[data-collapsed="true"] .rail-label,
.rail[data-collapsed="true"] .rail-wordmark,
.rail[data-collapsed="true"] .rail-widget,
.rail[data-collapsed="true"] .rail-toggle-label { display: none; }
/* Collapsed, a count degrades to a 6px coral dot in the corner. */
.rail[data-collapsed="true"] .rail-count {
  position: absolute;
  top: 4px; right: 10px;
  width: 6px; height: 6px;
  padding: 0;
  overflow: hidden;
  color: transparent;
  background-color: var(--coral);
}

/* ── 9.18 The one ticking element ────────────────────────────────────────── */

.rail-widget { border-top: 1px solid var(--chrome-rule); padding: 16px; }
.rail-widget-label { font-size: 9px; color: var(--chrome-text-mute); }
.rail-widget-name {
  margin-top: 4px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  color: var(--chrome-text-strong);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rail-widget-meta {
  margin-top: 2px;
  font-size: 11px;
  color: var(--chrome-text-mute);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.countdown { margin-top: 12px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.countdown-tile {
  border-radius: var(--radius-md);
  background-color: var(--chrome-alt);
  padding: 6px 0;
  text-align: center;
}
.countdown-value {
  display: block;
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  line-height: 1;
  font-weight: 600;
  color: var(--chrome-text-strong);
}
.countdown-label {
  display: block;
  margin-top: 3px;
  font-size: 8px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--chrome-text-mute);
}
.rail-widget-track {
  margin-top: 12px;
  height: 4px;
  overflow: hidden;
  border-radius: 9999px;
  background-color: var(--chrome-alt);
}
.rail-widget-fill {
  height: 100%;
  border-radius: 9999px;
  background-color: var(--coral);
  transition: width 700ms var(--ease);
}
.rail-widget-count {
  margin-top: 6px;
  text-align: right;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--chrome-text-mute);
}

.rail-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  flex-shrink: 0;
  padding: 0 20px;
  border-top: 1px solid var(--chrome-rule);
  font-size: 12px;
  color: var(--chrome-text-mute);
  transition: color 160ms var(--ease);
}
.rail-toggle:hover { color: var(--chrome-text-strong); }
.rail[data-collapsed="true"] .rail-toggle { justify-content: center; padding: 0; }

/* Below lg the rail becomes an overlay rather than squeezing the canvas. */
@media (max-width: 1023px) {
  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 200ms var(--ease);
    box-shadow: var(--shadow-float);
  }
  .rail[data-open="true"] { transform: none; }
  .rail-scrim {
    position: fixed;
    inset: 0;
    z-index: 29;
    background-color: color-mix(in srgb, var(--chrome) 35%, transparent);
    backdrop-filter: blur(2px);
    animation: fade 0.18s var(--ease) both;
  }
}
@media (min-width: 1024px) { .rail-open-btn, .rail-scrim { display: none; } }

/* ── 9.19 Topbar ─────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: var(--topbar-h);
  flex-shrink: 0;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--rule);
  /* content scrolling under the topbar stays faintly visible, which is what
     makes the shell feel like a window onto a document */
  background-color: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(12px);
  padding: 0 24px;
}
.breadcrumb { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.breadcrumb-current {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--ink);
  white-space: nowrap;
}
.breadcrumb-sep { color: var(--ink-faint); }
.breadcrumb-context {
  font-size: var(--text-xs);
  color: var(--ink-mute);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* The search trigger is a button, not an input — it opens the palette. */
.search-trigger {
  margin-left: auto;
  display: flex;
  height: 36px;
  width: 224px;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--rule);
  background-color: var(--surface-alt);
  padding: 0 12px;
  text-align: left;
  font-size: var(--text-xs);
  color: var(--ink-mute);
  transition: border-color 160ms var(--ease), color 160ms var(--ease);
}
.search-trigger:hover { border-color: var(--rule-strong); color: var(--ink-soft); }
.search-trigger .kbd { margin-left: auto; }
@media (min-width: 1024px) { .search-trigger { width: 288px; } }
@media (max-width: 640px) { .search-trigger { width: 36px; padding: 0; justify-content: center; } .search-trigger span, .search-trigger .kbd { display: none; } }

/* ── 16. Theme toggle — Light · System · Dark ────────────────────────────── */

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: var(--radius-md);
  border: 1px solid var(--rule);
  background-color: var(--surface-alt);
  padding: 2px;
}
.theme-option {
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  border-radius: 4px;
  color: var(--ink-mute);
  transition: background-color 150ms var(--ease), color 150ms var(--ease), box-shadow 150ms var(--ease);
}
.theme-option:hover { color: var(--ink); }
.theme-option[aria-checked="true"] {
  background-color: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-raise);
}

/* ── The user menu ───────────────────────────────────────────────────────── */

.menu-anchor { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 50;
  width: 256px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--rule);
  background-color: var(--surface);
  box-shadow: var(--shadow-float);
  animation: rise 0.24s var(--ease) both;
}
.menu-head { padding: 12px 14px; border-bottom: 1px solid var(--rule); }
.menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font-size: var(--text-sm);
  color: var(--ink-soft);
  text-align: left;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
.menu-item:hover { background-color: var(--surface-alt); color: var(--ink); }
.menu-item .icon { color: var(--ink-faint); }
.menu-sep { height: 1px; background-color: var(--rule); }
/* Destructive intent signalled on hover, without a red button sitting there
   permanently. */
.menu-item-danger:hover {
  background-color: var(--crimson-soft);
  color: var(--crimson-strong);
}
.menu-item-danger:hover .icon { color: var(--crimson-strong); }

/* ── 9.20 Command palette ────────────────────────────────────────────────── */

.palette-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background-color: color-mix(in srgb, var(--chrome) 45%, transparent);
  backdrop-filter: blur(2px);
  padding: 16px;
  padding-top: 12vh;   /* opens where the eye already is, not centred */
  animation: fade 0.18s var(--ease) both;
}
.palette {
  width: 100%;
  max-width: 36rem;
  overflow: hidden;
  /* 14px is used here and nowhere else — it is what makes the palette feel
     like a distinct object rather than another dialog. */
  border-radius: var(--radius-xl);
  border: 1px solid var(--rule);
  background-color: var(--surface);
  box-shadow: var(--shadow-float);
  animation: rise 0.24s var(--ease) both;
}
.palette-query {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-faint);
}
.palette-input {
  flex: 1 1 0%;
  border: 0;
  background: none;
  font-size: var(--text-body);
  color: var(--ink);
  outline: none;
}
.palette-input::placeholder { color: var(--ink-faint); }
.palette-spinner {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border-radius: 9999px;
  border: 1.5px solid var(--rule);
  border-top-color: var(--coral);
  animation: spin 0.7s linear infinite;
}
.palette-results { max-height: 52vh; overflow-y: auto; padding: 6px 0; }
.palette-group-label { padding: 8px 16px 4px; color: var(--ink-mute); }
.palette-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: var(--text-sm);
  color: var(--ink-soft);
  text-align: left;
}
.palette-item .icon { color: var(--ink-faint); }
.palette-item[data-active="true"] { background-color: var(--surface-alt); color: var(--ink); }
.palette-item[data-active="true"] .icon { color: var(--coral); }
.palette-item-desc { margin-left: auto; font-size: var(--text-xs); color: var(--ink-faint); }
.palette-empty { padding: 28px 16px; text-align: center; font-size: var(--text-sm); color: var(--ink-mute); }
.palette-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  border-top: 1px solid var(--rule);
  background-color: var(--surface-alt);
  padding: 8px 16px;
  font-size: var(--text-xs);
  color: var(--ink-mute);
}

/* ── 8.4 PageHeader ──────────────────────────────────────────────────────── */

.page-header { border-bottom: 1px solid var(--rule); padding-bottom: 20px; }
.page-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  column-gap: 24px;
  row-gap: 16px;
}
.page-eyebrow { color: var(--ink-mute); }
.page-title {
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: var(--text-h1);
  line-height: var(--text-h1-lh);
  letter-spacing: var(--text-h1-ls);
  font-weight: 500;
  color: var(--ink);
}
.page-meta {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 8px;
  font-size: var(--text-sm);
  color: var(--ink-soft);
}
.page-meta .sep { color: var(--ink-faint); }
/* The primary action goes LAST, because the eye finishes there. */
.page-actions { display: flex; flex-shrink: 0; align-items: center; gap: 8px; }

/* ── 8.5 Section — caps label, fading rule, optional action ──────────────── */

.section-head { display: flex; align-items: center; gap: 16px; }
.section-title { flex-shrink: 0; color: var(--ink); }
.section-rule { flex: 1 1 0%; min-width: 24px; }
.section-actions { display: flex; flex-shrink: 0; align-items: center; gap: 6px; }
.section-desc { margin-top: 8px; max-width: 68ch; font-size: var(--text-sm); color: var(--ink-mute); }
.section-body { margin-top: 16px; }

/* ── 9.25 Split auth layout — the one expressive page ────────────────────── */

.auth {
  display: grid;
  min-height: 100dvh;
}
.auth-panel {
  position: relative;
  display: none;   /* shown from lg up; below that the form stands alone */
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  background-color: var(--chrome);
  padding: 48px;
}
.auth-statement {
  font-family: var(--font-display);
  font-size: 34px;
  line-height: 1.2;
  font-weight: 300;
  letter-spacing: -0.018em;
  color: var(--chrome-text-strong);
}
.auth-statement .accent { color: var(--coral); }
.auth-facts {
  display: flex;
  gap: 40px;
  border-top: 1px solid var(--chrome-rule);
  padding-top: 24px;
}
.auth-fact-label { color: var(--chrome-text-mute); }
.auth-fact-value { margin-top: 4px; font-size: var(--text-sm); color: var(--chrome-text); }
/* The asymmetric split. Declared after .auth-panel so it actually wins. */
@media (min-width: 1024px) {
  .auth { grid-template-columns: 1fr min(46%, 640px); }
  .auth-panel { display: flex; }
}

.auth-form-side {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--paper);
  padding: 48px 24px;
}
.auth-form { width: 100%; max-width: 24rem; }
.auth-title {
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: var(--text-h1);
  line-height: var(--text-h1-lh);
  letter-spacing: var(--text-h1-ls);
  font-weight: 500;
  color: var(--ink);
}

/* ── The test-environment marker ─────────────────────────────────────────── */

.env-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background-color: var(--amber-soft);
  border-bottom: 1px solid var(--amber-line);
  color: var(--amber-strong);
  padding: 3px 0;
  font-size: var(--text-label);
  letter-spacing: var(--text-label-ls);
  text-transform: uppercase;
  font-weight: 600;
}
