/* Shared admin component system. Linked after tokens.css + theme.css on every
   admin page. All values come from tokens (var(--…)) so light/dark + future
   re-skins are free (per docs/ui-standards.md). Paired with js/admin-nav.js.

   The nav is a grouped LEFT SIDEBAR (js/admin-nav.js renders it into #adminNav);
   under ~860px it collapses to a header (☰ + brand + theme) plus a full-height
   grouped drawer. js/admin-nav.js adds `body.admin-shell`, which is what offsets
   page content clear of the fixed sidebar / mobile header. */

/* ── Shell ─────────────────────────────────────────────────────────────── */
/* Themed page background — the shared default for admin pages that don't set
   their own. Without this the <body> stayed browser-white while the token-based
   cards/header went dark in dark mode (and "black boxes" in light), i.e. not
   theme-sensitive. Pages with their own inline `body{}` (companies/feeds/pulse)
   still win via the cascade; this catches admin-home + admin-profiles. */
body { background: var(--bg); color: var(--text); font-family: var(--font-main); }
/* ^ font-family belongs on the shell too: admin-home / admin-profiles use the
   shared shell with no inline <style>, so without this they fell back to the
   browser default (serif) while Scout + the other admin pages used Epilogue.
   Pages still need the Epilogue webfont <link> in their <head> or var(--font-main)
   degrades to the generic sans-serif fallback. */

/* Content offset — clears the fixed sidebar (desktop) / mobile header. Applied
   only when js/admin-nav.js has mounted the shell, so pages never underlap it.
   Page containers (.page / .admin-main) keep their own max-width + margin:auto
   and simply centre within the remaining width. */
@media (min-width: 861px) {
  body.admin-shell { padding-left: 230px; }
}
@media (max-width: 860px) {
  body.admin-shell { padding-top: 52px; }
}

/* ── Left sidebar (desktop) ────────────────────────────────────────────── */
.admin-sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
  width: 230px;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.admin-sidebar-brand {
  display: flex; align-items: center; gap: 9px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
  text-decoration: none; flex-shrink: 0;
}
/* Flyover mark carries its own navy tile — no white chrome behind it. */
.admin-sidebar-logo { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.admin-sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.admin-sidebar-brand-name { font-size: 13px; font-weight: 800; color: var(--text); letter-spacing: -0.01em; }
.admin-sidebar-brand-sub { font-family: var(--font-mono); font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }

.admin-sidebar-scroll { flex: 1 1 auto; overflow-y: auto; padding: 12px 10px; }

.admin-nav-group { margin-bottom: 4px; }
.admin-nav-group-label {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 8px; margin: 0;
  background: none; border: none; border-radius: 6px;
  cursor: pointer; text-align: left; font-family: inherit;
}
.admin-nav-group-label:hover { background: var(--surface2); }
.admin-nav-group-name { font-family: var(--font-mono); font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text3); }
.admin-nav-group-caret { font-size: 10px; color: var(--text3); transition: transform .15s; }
.admin-nav-group.is-collapsed .admin-nav-group-caret { transform: rotate(-90deg); }
.admin-nav-group.is-collapsed .admin-nav-group-items { display: none; }

.admin-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--text2);
  text-decoration: none;
}
.admin-nav-item:hover { background: var(--surface2); color: var(--text); }
/* Active item: dim-accent fill + accent text, no left-border accent (per spec). */
.admin-nav-item.is-active { background: var(--accent-dim2); color: var(--accent); }
.admin-nav-item-ic { width: 16px; text-align: center; font-size: 13px; line-height: 1; flex-shrink: 0; }
.admin-nav-item-lbl { flex: 1 1 auto; }

.admin-sidebar-footer { flex-shrink: 0; padding: 10px; border-top: 1px solid var(--border); }
.admin-theme-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border-radius: 8px;
  background: none; border: 1px solid transparent;
  color: var(--text2); font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; text-align: left;
}
.admin-theme-btn:hover { background: var(--surface2); color: var(--text); }
.admin-theme-btn svg { flex-shrink: 0; }

/* ── Mobile header + drawer (≤860px) ───────────────────────────────────── */
.admin-mobile-header {
  display: none; /* shown at ≤860px */
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  height: 52px; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.admin-mobile-btn {
  width: 34px; height: 34px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text2); font-size: 15px; cursor: pointer;
}
.admin-mobile-brand { flex: 1 1 auto; display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; color: var(--text); text-decoration: none; }

.admin-drawer {
  display: none; /* .is-open shows it at ≤860px */
  position: fixed; top: 52px; left: 0; right: 0; bottom: 0; z-index: 55;
  background: rgba(0, 0, 0, .5);
}
.admin-drawer.is-open { display: block; }
.admin-drawer-panel {
  width: 78%; max-width: 320px; height: 100%; box-sizing: border-box;
  padding: 14px 10px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.admin-drawer-group { margin-bottom: 10px; }
.admin-drawer-group-name { font-family: var(--font-mono); font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text3); padding: 6px 8px; }
/* Larger touch targets inside the drawer (≥44px rows). */
.admin-drawer .admin-nav-item { padding: 11px 10px; }

/* ── Page layout ───────────────────────────────────────────────────────── */
.admin-main { max-width: 1180px; margin: 0 auto; padding: 22px 20px calc(64px + env(safe-area-inset-bottom, 0px)); }
.admin-page-head { margin-bottom: 20px; }
.admin-page-title { font-size: 22px; font-weight: 800; color: var(--text); letter-spacing: -0.01em; margin: 0; display: flex; align-items: center; gap: 9px; }
.admin-page-sub { font-size: 13px; color: var(--text3); margin-top: 6px; line-height: 1.55; max-width: 70ch; }
.admin-section-label { font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--text3); margin: 22px 0 10px; font-family: var(--font-mono); }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.admin-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; }
.admin-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
a.admin-tile {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; text-decoration: none; color: inherit;
  transition: border-color .12s, transform .05s, box-shadow .12s;
}
a.admin-tile:hover { border-color: var(--accent); box-shadow: 0 6px 22px rgba(0,0,0,.10); }
a.admin-tile:active { transform: translateY(1px); }
.admin-tile-top { display: flex; align-items: center; gap: 10px; }
.admin-tile-ic { font-size: 20px; line-height: 1; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; background: var(--surface2); border-radius: 9px; }
.admin-tile-name { font-size: 15px; font-weight: 700; color: var(--text); }
.admin-tile-desc { font-size: 12px; color: var(--text3); line-height: 1.5; flex: 1 1 auto; }
.admin-tile-stat { font-size: 12px; color: var(--text2); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.admin-tile-stat b { color: var(--text); font-weight: 800; }

/* ── KPI strip ─────────────────────────────────────────────────────────── */
.admin-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.admin-kpi { background: var(--surface); padding: 16px 18px; }
.admin-kpi-val { font-size: 22px; font-weight: 800; color: var(--text); line-height: 1.1; font-family: var(--font-mono); }
.admin-kpi-lbl { font-size: 11px; color: var(--text3); margin-top: 3px; }

/* ── Table ─────────────────────────────────────────────────────────────── */
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { text-align: left; padding: 9px 12px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text3); border-bottom: 1px solid var(--border); }
.admin-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); color: var(--text2); }
.admin-table tr:hover td { background: var(--surface2); }
/* Numeric columns: right-align + tabular figures so digits line up. Add .num to
   the <th>/<td> (or wrap the table region — see .admin-table--num). */
.admin-table th.num, .admin-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Mono cell for identifier/key columns (function name, model id, vendor…). */
.admin-table td.mono { font-family: var(--font-mono); font-size: 12px; color: var(--text2); }
/* Hit-rate / good-vs-idle metric cell. Colour comes from tokens, never a
   hardcoded green: >floor → var(--green), else muted var(--text3). */
.admin-hit { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.admin-hit.good { color: var(--green); }
.admin-hit.zero { color: var(--text3); }
/* Horizontal-scroll wrapper for wide tables (keeps the app's mobile pattern). */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Controls ──────────────────────────────────────────────────────────── */
.admin-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-input { width: 100%; box-sizing: border-box; background: var(--surface2); border: 1px solid var(--border); border-radius: 9px; padding: 10px 13px; color: var(--text); font-size: 14px; font-family: inherit; }
.admin-input:focus { outline: none; border-color: var(--accent); }
.admin-btn { display: inline-flex; align-items: center; gap: 6px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 13px; font-size: 13px; font-weight: 600; color: var(--text2); cursor: pointer; font-family: inherit; }
.admin-btn:hover { border-color: var(--accent2); color: var(--text); }
.admin-btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.admin-btn--primary:hover { filter: brightness(1.06); color: #fff; }

/* Segmented single-select range toggle (7d / 30d / 90d). Pill cluster on a
   surface2 track; active tab = accent fill. Swap is instant — no transition. */
.admin-range { display: inline-flex; align-items: center; gap: 0; background: var(--surface2); border: 1px solid var(--border); border-radius: 999px; padding: 2px; }
.admin-range-btn { font-family: var(--font-mono); font-size: 11px; line-height: 1; padding: 5px 12px; border: none; border-radius: 999px; background: transparent; color: var(--text3); cursor: pointer; }
.admin-range-btn:hover { color: var(--text2); }
.admin-range-btn.is-on { background: var(--accent); color: #fff; }
.admin-range-btn.is-on:hover { color: #fff; }

/* ── Pills / badges (status, role counts) ──────────────────────────────── */
/* Status colour is consistent (ui-standards.md): green healthy, amber activity,
   red error, muted off. Accent orange is reserved for ACTIONS, never status. */
.admin-pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text3); background: var(--surface2); }
.admin-pill--on { color: var(--green); border-color: var(--green); background: transparent; }
.admin-pill--warn { color: var(--amber); border-color: var(--amber); background: transparent; }
.admin-pill--err { color: var(--red); border-color: var(--red); background: transparent; }

/* ── Empty state ───────────────────────────────────────────────────────── */
/* Dashed hairline block for zero-row tables AND zero-result filters. */
.admin-empty { border: 1px dashed var(--border2); border-radius: 12px; padding: 26px; text-align: center; color: var(--text3); font-size: 13px; line-height: 1.55; }
/* When used as a table row (colspan cell), drop the dashed box — the surrounding
   .tbl-wrap already frames it; just the centred muted copy. */
td.admin-empty { border: none; border-radius: 0; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (min-width: 861px) {
  /* Never let the mobile chrome leak onto desktop. */
  .admin-mobile-header, .admin-drawer { display: none !important; }
}
@media (max-width: 860px) {
  .admin-sidebar { display: none; }
  .admin-mobile-header { display: flex; }
  .admin-kpis { grid-template-columns: repeat(2, 1fr); }
  /* Toolbar controls stack full-width, single column. */
  .admin-toolbar { flex-direction: column; align-items: stretch; }
  .admin-toolbar > .admin-btn { justify-content: center; }
  /* Range toggle becomes an equal-width 3-up row. */
  .admin-range { display: flex; width: 100%; }
  .admin-range-btn { flex: 1 1 0; text-align: center; padding: 9px 6px; }
  .admin-main { padding: 16px 12px calc(56px + env(safe-area-inset-bottom, 0px)); }
}
