/* ---------------------------------------------------------------------------
 * app.css — the single source of design tokens and layout primitives.
 *
 * Before this file, every page inlined its own :root block and two divergent
 * dark themes had already appeared. Pages now carry only page-specific rules.
 *
 * The chart surface is --panel (#161b22). The categorical palette below was
 * validated against exactly that surface and passes all six checks:
 *   node scripts/validate_palette.js \
 *     "#3987e5,#d95926,#199e70,#c98500,#d55181,#008300,#9085e9,#e66767" \
 *     --mode dark --surface "#161b22"
 * Changing --panel invalidates that result — re-run the validator if you do.
 *
 * Dark-only is a deliberate commitment. A light mode would need its own
 * selected-and-revalidated steps, never an automatic flip.
 * ------------------------------------------------------------------------- */

:root {
  color-scheme: dark;

  /* --- surfaces & ink ---------------------------------------------------- */
  --bg: #0d1117;
  --panel: #161b22;          /* chart surface — see note above */
  --panel-2: #1c2430;
  --border: #2b3543;
  --text: #e6edf3;           /* text-primary */
  --muted: #8b949e;          /* text-secondary */
  --faint: #6e7781;          /* text-muted / axis labels */
  --accent: #58a6ff;

  /* --- brand accents (non-data) ------------------------------------------ */
  --bronze: #cd7f32;
  --silver: #b3bcc7;
  --gold: #e3b341;

  /* --- categorical series, fixed order, NEVER cycled -------------------- */
  --series-1: #3987e5;   /* blue    */
  --series-2: #d95926;   /* orange  */
  --series-3: #199e70;   /* aqua    */
  --series-4: #c98500;   /* yellow  */
  --series-5: #d55181;   /* magenta */
  --series-6: #008300;   /* green   */
  --series-7: #9085e9;   /* violet  */
  --series-8: #e66767;   /* red     */
  --series-other: #6e7781;   /* the "Other" fold — never a 9th hue */

  /* --- sequential ramp: one hue, light -> dark --------------------------- */
  --seq-1: #cfe3fb;
  --seq-2: #a8ccf7;
  --seq-3: #7fb2f0;
  --seq-4: #5795e6;
  --seq-5: #3987e5;
  --seq-6: #2a6ec2;
  --seq-7: #1e559a;

  /* --- diverging: two hues + NEUTRAL GREY midpoint ---------------------- */
  --div-neg-2: #b8451f;
  --div-neg-1: #d95926;
  --div-mid: #8b949e;    /* grey, never a hue */
  --div-pos-1: #199e70;
  --div-pos-2: #0f7e59;

  /* --- status: RESERVED. Never reused as a series colour ---------------- */
  --status-good: #3fb950;
  --status-warning: #d29922;
  --status-serious: #db6d28;
  --status-critical: #f85149;

  /* Legacy aliases. explorer.html and login.html were written against these
     before app.css existed; same values as the status tokens above. Prefer the
     --status-* names in new code — those are the reserved data-viz slots. */
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;

  /* --- chart furniture --------------------------------------------------- */
  --grid: #232c39;           /* one step off surface, 1px solid, recessive */
  --axis: #313c4c;

  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 20px 64px; }

/* --- app header (rendered by shell.js) ---------------------------------- */
.app-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.app-logo {
  width: 42px; height: 42px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--bronze), var(--gold));
  display: grid; place-items: center; font-size: 22px;
}
.app-titles h1 { font-size: 21px; font-weight: 650; letter-spacing: -0.01em; }
.app-titles .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.app-head .spacer { margin-left: auto; }
.app-nav { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.app-nav a {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  padding: 5px 10px; border-radius: 7px; border: 1px solid transparent;
}
.app-nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.app-nav a[aria-current="page"] { color: var(--accent); border-color: var(--border); background: var(--panel); }
.app-who { font-size: 11.5px; color: var(--faint); text-align: right; margin-top: 6px; width: 100%; }

/* --- filter bar: ONE row, above the charts, scopes everything below ----- */
.filters {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 20px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.filters label { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.filters select, .filters button {
  font: inherit; font-size: 12.5px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 7px; padding: 5px 9px; cursor: pointer;
}
.filters select:hover, .filters button:hover:not(:disabled) { border-color: var(--accent); }
.filters button:disabled { opacity: .5; cursor: default; }
.filters .spacer { margin-left: auto; }
.asof { font-size: 11.5px; color: var(--faint); }
.asof .chip {
  display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px;
  font-weight: 600; font-size: 11px;
}
.asof .chip.stale { background: rgba(210,153,34,.14); color: var(--status-warning); }

/* --- hero figure + KPI row --------------------------------------------- */
.hero { margin-top: 26px; display: flex; align-items: flex-end; gap: 28px; flex-wrap: wrap; }
.hero .figure { font-size: 52px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero .label { color: var(--muted); font-size: 13px; margin-top: 6px; }

.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-top: 18px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 12px; }
.tile .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 26px; font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; }
.tile .d { font-size: 12px; margin-top: 3px; color: var(--muted); }
.tile .d.up { color: var(--status-good); }
.tile .d.down { color: var(--status-critical); }
.tile .spark { margin-top: 8px; display: block; }

/* --- chart grid + figure card ------------------------------------------ */
h2.section {
  font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin: 34px 0 12px;
}
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.full { grid-template-columns: 1fr; }

figure.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px 14px; margin: 0;
  min-width: 0;              /* let grid children shrink instead of overflowing */
}
figure.card > figcaption { margin-bottom: 2px; }
figure.card .title { font-size: 14.5px; font-weight: 650; }
figure.card .subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
figure.card .plot { margin-top: 12px; position: relative; }
figure.card .plot svg { display: block; width: 100%; height: auto; overflow: visible; }
figure.card.loading .plot { opacity: .45; transition: opacity .15s ease; }

.card-foot { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.card-foot .spacer { margin-left: auto; }
button.tableToggle {
  font: inherit; font-size: 11.5px; font-weight: 600; color: var(--muted);
  background: transparent; border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 9px; cursor: pointer;
}
button.tableToggle:hover { color: var(--accent); border-color: var(--accent); }

/* --- legend: rect for bars/areas, line for lines ----------------------- */
.legend { display: flex; gap: 12px; flex-wrap: wrap; }
.legend .item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted);
  background: none; border: 0; padding: 0; cursor: pointer; font-family: inherit;
}
.legend .item[aria-pressed="false"] { opacity: .4; }
.legend .swatch { width: 11px; height: 11px; border-radius: 2px; flex: none; }
.legend .swatch.line { height: 2px; width: 14px; border-radius: 2px; }

/* --- table view: the accessibility twin of every chart ------------------ */
.tableview { margin-top: 12px; overflow-x: auto; }
.tableview table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tableview th, .tableview td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tableview th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); }
.tableview td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tableview tr:last-child td { border-bottom: none; }
[hidden] { display: none !important; }

/* Role-gated regions start hidden and are revealed by shell.js once /.auth/me
   resolves, so a viewer never glimpses a section they cannot open. This is
   presentation only — the route rules in staticwebapp.config.json are what
   actually deny access. */
[data-pending] { display: none !important; }

/* --- tooltip ----------------------------------------------------------- */
.viz-tooltip {
  position: fixed; z-index: 40; pointer-events: none;
  background: #0b0f16; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  max-width: 300px;
}
.viz-tooltip .tt-head { color: var(--muted); font-size: 11px; margin-bottom: 5px; }
.viz-tooltip .tt-row { display: flex; align-items: baseline; gap: 8px; }
/* values lead, labels follow */
.viz-tooltip .tt-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.viz-tooltip .tt-name { color: var(--muted); }
.viz-tooltip .tt-key { width: 12px; height: 2px; border-radius: 2px; flex: none; align-self: center; }

/* --- status list (D4 freshness) — icon + label, never colour alone ----- */
.statuslist { display: flex; flex-direction: column; }
.statuslist .row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.statuslist .row:last-child { border-bottom: none; }
.statuslist .ico { width: 16px; text-align: center; flex: none; font-size: 13px; }
.statuslist .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statuslist .meta { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }
.statuslist .good .ico { color: var(--status-good); }
.statuslist .warning .ico { color: var(--status-warning); }
.statuslist .serious .ico { color: var(--status-serious); }
.statuslist .critical .ico { color: var(--status-critical); }

/* --- states ------------------------------------------------------------ */
.note { font-size: 12px; color: var(--muted); padding: 10px 12px; border-radius: 8px; background: var(--panel-2); }
.note.err { color: #ffb4ae; background: rgba(248,81,73,.09); border: 1px solid rgba(248,81,73,.32); }
.note.warn { color: #f0cf8a; background: rgba(210,153,34,.09); border: 1px solid rgba(210,153,34,.32); }
.empty { font-size: 12px; color: var(--muted); font-style: italic; padding: 14px 0; }

.banner {
  margin-top: 18px; padding: 13px 15px; border-radius: 10px; font-size: 13px;
  background: rgba(248,81,73,.1); border: 1px solid rgba(248,81,73,.4); color: #ffb4ae;
}
.banner strong { color: var(--status-critical); }

/* --- footer ------------------------------------------------------------ */
.app-foot {
  margin-top: 38px; padding-top: 16px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 12px;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
.app-foot code { background: var(--panel-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }
