/* ============================================================================
 * CORE — reset, shell, and the primitives every screen shares.
 * Consumes tokens.css. Screen-specific rules live in app.css.
 * ============================================================================ */

*,*::before,*::after{box-sizing:border-box}

html,body{
  margin:0;padding:0;
  /* UX_PRINCIPLES §11: "a page that scrolls sideways feels broken." */
  overflow-x:hidden;max-width:100vw;
}

body{
  background:var(--bg);
  color:var(--text);
  font-family:var(--font);
  font-size:15px;line-height:1.5;
  -webkit-font-smoothing:antialiased;
  -webkit-text-size-adjust:100%;
}

h1,h2,h3,h4{margin:0;font-weight:600;line-height:1.25}
p{margin:0 0 .75em}
a{color:inherit;text-decoration:none}
a:hover{color:var(--text)}

/* Numerals must line up down a column. Data-Views §5: "alignment: numbers
   right, tabular-nums — non-negotiable for numeric columns." */
.num,td.num,th.num,.stat-value,.big-number{
  font-variant-numeric:tabular-nums;
  font-feature-settings:"tnum" 1;
}

/* Every focusable thing gets a visible ring. UX_PRINCIPLES §15: six states, and
   focus is the one people forget — keyboard users must see where they are. */
:focus-visible{
  outline:2px solid var(--accent-text);
  outline-offset:2px;
  border-radius:var(--radius-sm);
}

@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{
    animation-duration:.01ms !important;
    transition-duration:.01ms !important;
    scroll-behavior:auto !important;
  }
}

/* ── Icons ───────────────────────────────────────────────────────────────────
 * Inherit currentColor so they take the state of whatever they sit in — muted
 * at rest, white on hover, accent when the nav item is active. No emoji, ever
 * (UX_PRINCIPLES §14). */
.ic{width:1em;height:1em;vertical-align:-.14em;flex:none}
.sb-ic{width:18px;height:18px;flex:none}

/* ── Layout shell ────────────────────────────────────────────────────────── */

.shell{display:flex;min-height:100vh}

.sidebar{
  width:var(--sidebar-w);flex:none;
  background:var(--chrome-solid);
  border-right:1px solid var(--border);
  display:flex;flex-direction:column;
  position:sticky;top:0;height:100vh;
}

.sb-brand{
  padding:20px 18px 16px;
  border-bottom:1px solid var(--border);
}
.sb-brand-name{font-size:15px;font-weight:700;letter-spacing:-.01em}
.sb-brand-sub{
  font-size:11px;color:var(--muted);
  text-transform:uppercase;letter-spacing:.08em;margin-top:3px;
}

.sb-nav{padding:10px 8px;flex:1;overflow-y:auto}
.sb-link{
  display:flex;align-items:center;gap:10px;
  padding:9px 10px;margin-bottom:1px;
  border-radius:var(--radius-md);
  color:var(--muted);font-size:14px;font-weight:500;
  position:relative;
  transition:background .12s,color .12s;
}
.sb-link:hover{background:var(--state-hover);color:var(--text)}
.sb-link.active{background:var(--state-selected);color:var(--text)}
/* The one accent, doing its one job: saying where you are. */
.sb-link.active::before{
  content:"";position:absolute;left:-8px;top:8px;bottom:8px;width:3px;
  background:var(--accent);border-radius:0 2px 2px 0;
}
.sb-link.active .sb-ic{color:var(--accent-text)}

.sb-badge{
  margin-left:auto;min-width:20px;height:20px;padding:0 6px;
  border-radius:var(--radius-pill);
  font-size:11px;font-weight:700;
  display:inline-flex;align-items:center;justify-content:center;
  font-variant-numeric:tabular-nums;
}
.sb-badge.red{background:rgba(var(--danger-rgb),.18);color:var(--danger)}
.sb-badge.amber{background:rgba(var(--amber-rgb),.18);color:var(--amber)}
.sb-badge.unknown{background:rgba(var(--unknown-rgb),.2);color:var(--unknown)}

.sb-foot{padding:12px 14px;border-top:1px solid var(--border);font-size:12px;color:var(--muted)}
.sb-foot form{margin:0 0 6px}
.sb-signout{
  background:none;border:0;padding:0;cursor:pointer;
  color:var(--muted);font:inherit;font-size:12px;
}
.sb-signout:hover{color:var(--text)}

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

.page{
  padding:26px 28px 60px;
  width:100%;max-width:var(--page-max);
  flex:1;min-width:0;
}
.page-head{margin-bottom:22px}
.page-title{font-size:24px;letter-spacing:-.02em}
/* The pre-interpreted sentence. UX_PRINCIPLES §9: "the sentence reads the
   chart" — so it sits directly under the title, at readable size, not as a
   caption nobody notices. */
.page-summary{margin-top:6px;font-size:15px;color:var(--text-soft);max-width:64ch}

.topbar{display:none}

/* ── Buttons ─────────────────────────────────────────────────────────────────
 * UX_PRINCIPLES §15. One primary per group; the primary is both more prominent
 * AND physically separated; six states; 44px minimum target on touch. */

.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:7px;
  min-height:38px;padding:0 14px;
  border-radius:var(--radius-md);border:1px solid var(--border-mid);
  background:var(--surface2);color:var(--text);
  font:inherit;font-size:14px;font-weight:500;
  cursor:pointer;white-space:nowrap;
  transition:background .12s,border-color .12s,opacity .12s;
}
.btn:hover{background:var(--surface-3);border-color:var(--border-emph)}
.btn:active{background:var(--surface-4)}
.btn[disabled],.btn[aria-disabled="true"]{
  opacity:.45;cursor:not-allowed;
}
.btn.primary{
  background:var(--accent);border-color:var(--accent);color:var(--on-accent);
  font-weight:600;
}
.btn.primary:hover{background:var(--accent-deep);border-color:var(--accent-deep)}
.btn.ghost{background:transparent;border-color:transparent;color:var(--muted)}
.btn.ghost:hover{background:var(--state-hover);color:var(--text)}
.btn.sm{min-height:32px;padding:0 10px;font-size:13px}
.btn.is-loading{pointer-events:none;opacity:.6}

.btn-row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
/* "The primary is physically separated from the rest" — §15's Amazon failure
   case is three adjacent same-weight buttons. */
.btn-row .primary{margin-left:auto}

/* ── Cards & panels ──────────────────────────────────────────────────────── */

.panel{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  padding:18px 20px;
}
.panel + .panel{margin-top:16px}
/* Panel titles are plain text, no icon — docs/admin_icons.md conventions. */
.panel-title{font-size:13px;font-weight:600;letter-spacing:.02em;margin-bottom:14px}
.panel-title .sub{font-weight:400;color:var(--muted);margin-left:8px}

.grid{display:grid;gap:16px}
.grid.two{grid-template-columns:repeat(2,minmax(0,1fr))}
.grid.three{grid-template-columns:repeat(3,minmax(0,1fr))}

/* ── The big number ──────────────────────────────────────────────────────────
 * UX_PRINCIPLES §9: "the most important number is the biggest." Exactly one of
 * these per screen. If a second appears, neither is the most important. */
.big-number{
  font-size:clamp(38px,6vw,56px);
  font-weight:700;letter-spacing:-.03em;line-height:1;
}
.big-label{
  font-size:11px;text-transform:uppercase;letter-spacing:.1em;
  color:var(--muted);margin-bottom:10px;
}
.big-sub{margin-top:10px;font-size:14px;color:var(--text-soft)}
/* §9: "Negative numbers are red, positive green, neutral white."
   Colour is signal — never decoration. */
.delta.up{color:var(--green)}
.delta.down{color:var(--danger)}
.delta.flat{color:var(--muted)}

/* ── Stat strip ──────────────────────────────────────────────────────────────
 * Data-Views §6: "numerals in a number-grid, generous space between, muted
 * uppercase labels — read at a glance, never as prose." */
.stats{
  display:grid;gap:20px;
  grid-template-columns:repeat(auto-fit,minmax(112px,1fr));
}
.stat-label{
  font-size:10px;text-transform:uppercase;letter-spacing:.09em;
  color:var(--muted);margin-bottom:5px;
}
.stat-value{font-size:20px;font-weight:600;letter-spacing:-.01em}
.stat-value.small{font-size:15px;font-weight:500}

/* ── Status lights ───────────────────────────────────────────────────────── */

.light{
  width:9px;height:9px;border-radius:50%;flex:none;
  display:inline-block;
}
.light.green{background:var(--green);box-shadow:0 0 0 3px rgba(var(--green-rgb),.14)}
.light.amber{background:var(--amber);box-shadow:0 0 0 3px rgba(var(--amber-rgb),.14)}
.light.red{background:var(--danger);box-shadow:0 0 0 3px rgba(var(--danger-rgb),.16)}
.light.unknown{
  background:transparent;border:1.5px solid var(--unknown);
  /* Hollow, not filled. "Not reporting" should read as absence at a glance,
     which a ring does and a dot does not — and it stays distinguishable from
     the other three for a red-green colourblind operator, who is otherwise
     relying on position alone. */
}

.pill{
  display:inline-flex;align-items:center;gap:6px;
  height:22px;padding:0 9px;border-radius:var(--radius-pill);
  font-size:11px;font-weight:600;letter-spacing:.02em;
  white-space:nowrap;
}
.pill.green{background:rgba(var(--green-rgb),.14);color:var(--green)}
.pill.amber{background:rgba(var(--amber-rgb),.14);color:var(--amber)}
.pill.red{background:rgba(var(--danger-rgb),.15);color:var(--danger)}
.pill.unknown{background:rgba(var(--unknown-rgb),.16);color:var(--unknown)}
.pill.neutral{background:var(--surface-tint);color:var(--muted)}
.pill.accent{background:rgba(var(--accent-rgb),.18);color:var(--accent-text)}

/* ── Tables ──────────────────────────────────────────────────────────────────
 * Data-Views §5: first column is the human anchor and visually heavier; numbers
 * right and tabular; thin dividers not gridlines; sticky header; hover row. */

.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}
table.data{width:100%;border-collapse:collapse;font-size:13.5px}
table.data th{
  text-align:left;font-size:10px;font-weight:600;
  text-transform:uppercase;letter-spacing:.08em;color:var(--muted);
  padding:0 12px 8px;white-space:nowrap;
  position:sticky;top:0;background:var(--surface);z-index:1;
}
table.data th.num,table.data td.num{text-align:right}
table.data td{
  padding:9px 12px;
  border-top:1px solid var(--border);
  vertical-align:middle;
}
table.data tbody tr:hover{background:var(--state-hover)}
table.data td:first-child,table.data th:first-child{padding-left:2px}
table.data td:last-child,table.data th:last-child{padding-right:2px}
/* The anchor column carries the weight. */
table.data td.anchor{font-weight:600;color:var(--text)}
table.data td.meta{color:var(--muted)}

/* ── Empty / error states ────────────────────────────────────────────────────
 * Data-Views §11.7: designed, never blank. UX_PRINCIPLES §9: "empty states are
 * encouraging, not alarming." */
.empty{
  padding:34px 22px;text-align:center;color:var(--muted);
}
.empty-title{color:var(--text-soft);font-size:15px;font-weight:500;margin-bottom:5px}
.empty-body{font-size:13.5px;max-width:44ch;margin:0 auto}
.empty-body a{color:var(--accent-text);text-decoration:underline;text-underline-offset:2px}
td.empty{padding:26px 12px}

.notice{
  padding:10px 13px;border-radius:var(--radius-md);
  font-size:13px;line-height:1.45;
  border:1px solid var(--border-mid);background:var(--surface2);
  color:var(--text-soft);
}
.notice.warn{
  border-color:rgba(var(--amber-rgb),.35);
  background:rgba(var(--amber-rgb),.08);color:var(--amber);
}
.notice.error{
  border-color:rgba(var(--danger-rgb),.4);
  background:rgba(var(--danger-rgb),.09);color:var(--danger);
}

/* ── Forms ───────────────────────────────────────────────────────────────────
 * UX_PRINCIPLES §2: one column top-to-bottom, real labels ABOVE the field,
 * errors next to the field that broke, 16px minimum so iOS does not zoom. */

.field{margin-bottom:16px;max-width:520px}
.field label{
  display:block;font-size:12px;font-weight:600;
  color:var(--text-soft);margin-bottom:6px;
}
.field .hint{font-size:12px;color:var(--muted);margin-top:5px;line-height:1.45}
.field .field-error{font-size:12.5px;color:var(--danger);margin-top:5px}
.field .optional{color:var(--muted);font-weight:400;margin-left:5px}

input[type=text],input[type=email],input[type=password],input[type=url],
input[type=number],select,textarea{
  width:100%;
  /* 16px is not a style choice — below it, iOS Safari zooms the page on focus.
     UX_PRINCIPLES §2 and Data-Views §9. */
  font:inherit;font-size:16px;
  padding:9px 11px;
  color:var(--text);
  background:var(--bg-input);
  border:1px solid var(--border-input);
  border-radius:var(--radius-md);
  min-height:42px;
}
textarea{min-height:88px;resize:vertical;line-height:1.5}
input::placeholder,textarea::placeholder{color:var(--placeholder)}
input:focus,select:focus,textarea:focus{
  outline:none;border-color:var(--accent);
  box-shadow:0 0 0 3px rgba(var(--accent-rgb),.2);
}
input[aria-invalid="true"]{border-color:var(--danger)}
select{
  appearance:none;-webkit-appearance:none;
  background-image:var(--select-chevron);
  background-repeat:no-repeat;
  background-position:right 11px center;
  padding-right:32px;
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.muted{color:var(--muted)}
.soft{color:var(--text-soft)}
.mono{font-family:var(--font-mono);font-size:12.5px}
.right{text-align:right}
.nowrap{white-space:nowrap}
.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.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;
}
.stack-sm > * + *{margin-top:8px}
.stack > * + *{margin-top:16px}

/* ── Phone ───────────────────────────────────────────────────────────────────
 * Data-Views §9. The sidebar becomes a top bar with a horizontally scrolling
 * nav row — never a wrapped grid of cramped targets. */

@media (max-width:980px){
  .shell{flex-direction:column}

  .sidebar{
    position:sticky;top:0;z-index:30;
    width:100%;height:auto;
    border-right:0;border-bottom:1px solid var(--border);
    flex-direction:column;
  }
  .sb-brand{
    display:flex;align-items:baseline;gap:9px;
    padding:12px 16px;border-bottom:0;min-height:var(--topbar-h);
  }
  .sb-brand-sub{margin-top:0}

  .sb-nav{
    display:flex;gap:4px;padding:0 10px 8px;
    /* §9: chip/tab rows scroll horizontally, nowrap. */
    overflow-x:auto;overflow-y:hidden;
    scrollbar-width:none;
  }
  .sb-nav::-webkit-scrollbar{display:none}
  .sb-link{
    margin-bottom:0;white-space:nowrap;
    min-height:38px;padding:0 12px;
  }
  .sb-link.active::before{
    left:0;right:0;top:auto;bottom:-8px;width:auto;height:2px;border-radius:2px 2px 0 0;
  }
  .sb-foot{
    display:flex;align-items:center;gap:14px;
    padding:8px 16px;border-top:1px solid var(--border);
  }
  .sb-foot form{margin:0}

  .page{padding:18px 16px 80px}
  .page-title{font-size:20px}
  .grid.two,.grid.three{grid-template-columns:1fr}
}

@media (max-width:640px){
  .stats{gap:14px;grid-template-columns:repeat(auto-fit,minmax(88px,1fr))}
  .panel{padding:15px 14px;border-radius:var(--radius-md)}
  /* §9: primary actions go full-width on a phone. */
  .btn-row .btn{flex:1 1 100%}
  .btn-row .primary{margin-left:0;order:-1}
}
