/* ZonesRecon
   ---------------------------------------------------------------------------
   One stylesheet, no build step, no CDN. The CSP forbids remote style, so
   everything the app needs is here.

   Colour comes from the data-viz reference palette. The chart surfaces are that
   palette's own documented surfaces (#fcfcfb light, #1a1a19 dark) rather than
   values picked to match this page — the palette's validation results only hold
   against the surfaces they were measured on, so changing them would silently
   invalidate them.
   --------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  --surface-1:      #fcfcfb;   /* chart surface — palette-documented */
  --page:           #f4f4f1;
  --card:           #ffffff;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --border-strong:  rgba(11, 11, 11, 0.18);

  /* Categorical slots 1-3. These three validate on ALL pairs in both modes,
     which is why the composition chart is capped at three segments. */
  --series-1: #2a78d6;   /* blue   */
  --series-2: #eb6834;   /* orange */
  --series-3: #1baf7a;   /* aqua   */

  /* Status — fixed, never themed, never reused as a series colour. */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;

  --shadow: 0 1px 2px rgba(11, 11, 11, .05), 0 6px 18px rgba(11, 11, 11, .05);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --card:           #16171a;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --border-strong:  rgba(255, 255, 255, 0.18);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-text: #0ca30c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --card:           #16171a;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --border-strong:  rgba(255, 255, 255, 0.18);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good-text: #0ca30c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
}

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(1360px, calc(100% - 3rem)); margin-inline: auto; }

a { color: var(--series-1); text-decoration-color: color-mix(in srgb, var(--series-1) 40%, transparent); }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4rem; font-weight: 640; letter-spacing: -.011em; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8rem; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .86em; }

/* --------------------------------------------------------------------------- */
/* Top bar                                                                      */
/* --------------------------------------------------------------------------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.topbar-inner { display: flex; align-items: center; gap: 1.5rem; min-height: 58px; }
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; color: inherit; font-weight: 660; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 5px;
  background: linear-gradient(135deg, var(--series-1), var(--series-3));
}
.brand-name { letter-spacing: -.02em; }

.nav { display: flex; gap: .15rem; margin-right: auto; flex-wrap: wrap; }
.nav a {
  padding: .38rem .7rem; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none; font-size: .92rem; font-weight: 520;
}
.nav a:hover { background: color-mix(in srgb, var(--text-primary) 6%, transparent); color: var(--text-primary); }
.nav a.is-current { background: color-mix(in srgb, var(--series-1) 12%, transparent); color: var(--series-1); }

.topbar-right { display: flex; align-items: center; gap: .5rem; }
.theme-toggle {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  width: 32px; height: 32px; cursor: pointer; color: var(--text-secondary); font-size: 1rem;
}
.theme-toggle:hover { border-color: var(--border-strong); color: var(--text-primary); }

.menu { position: relative; }
.menu summary {
  display: flex; align-items: center; gap: .5rem; cursor: pointer; list-style: none;
  padding: .25rem .5rem .25rem .25rem; border-radius: 999px; border: 1px solid var(--border);
}
.menu summary::-webkit-details-marker { display: none; }
.menu-label { font-size: .88rem; max-width: 15ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--series-1); color: #fff; font-size: .78rem; font-weight: 660;
}
.menu-panel {
  position: absolute; right: 0; top: calc(100% + .4rem); min-width: 232px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .4rem; display: grid; gap: .1rem; z-index: 50;
}
.menu-panel a, .menu-panel .linkish {
  display: block; width: 100%; text-align: left; padding: .45rem .6rem;
  border-radius: var(--radius-sm); text-decoration: none; color: var(--text-primary);
  background: none; border: 0; font: inherit; cursor: pointer;
}
.menu-panel a:hover, .menu-panel .linkish:hover { background: color-mix(in srgb, var(--text-primary) 6%, transparent); }
.menu-who { padding: .5rem .6rem; margin: 0 0 .2rem; border-bottom: 1px solid var(--border); font-size: .86rem; }

.footer { padding: 2rem 0 3rem; color: var(--text-muted); font-size: .84rem; }
.footer .wrap { display: flex; gap: .6rem; align-items: center; }

main { padding: 1.8rem 0 1rem; }

/* --------------------------------------------------------------------------- */
/* Cards, buttons, forms                                                        */
/* --------------------------------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.15rem 1.25rem; box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.card-header { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-header h2 { margin: 0; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  padding: .52rem .95rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--card); color: var(--text-primary); font: inherit; font-weight: 560;
  font-size: .92rem; cursor: pointer; text-decoration: none;
}
.btn:hover { background: color-mix(in srgb, var(--text-primary) 5%, var(--card)); }
.btn-primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--series-1) 85%, #000); }
.btn-danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--critical) 10%, transparent); }
.btn-sm { padding: .32rem .6rem; font-size: .84rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-size: .88rem; font-weight: 560; margin-bottom: .28rem; }
.field { margin-bottom: 1rem; }
.field-help { font-size: .84rem; color: var(--text-muted); margin: .3rem 0 0; }

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .5rem .65rem; font: inherit; font-size: .92rem;
  color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, textarea:focus-visible,
.btn:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 2px;
}
textarea { min-height: 90px; resize: vertical; }
.checkline { display: flex; align-items: flex-start; gap: .5rem; }
.checkline input { margin-top: .25rem; }
.checkline label { margin: 0; font-weight: 500; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }

.alert {
  padding: .7rem .9rem; border-radius: var(--radius-sm); margin-bottom: 1rem;
  border: 1px solid; font-size: .92rem;
}
.alert-error { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 35%, transparent); background: color-mix(in srgb, var(--critical) 8%, transparent); }
.alert-ok { color: var(--good-text); border-color: color-mix(in srgb, var(--good) 35%, transparent); background: color-mix(in srgb, var(--good) 8%, transparent); }
.alert-info { color: var(--text-secondary); border-color: var(--border-strong); background: var(--surface-1); }

.pill {
  display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .5rem;
  border-radius: 999px; font-size: .76rem; font-weight: 600; letter-spacing: .01em;
  border: 1px solid var(--border-strong); color: var(--text-secondary);
  white-space: nowrap;
}
/* Status colours always ship with their label, never colour alone. */
.pill-good     { color: var(--good-text); border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.pill-warn     { color: #8a5b00;          border-color: color-mix(in srgb, var(--warning) 55%, transparent); }
.pill-bad      { color: var(--critical);  border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.pill-running  { color: var(--series-1);  border-color: color-mix(in srgb, var(--series-1) 45%, transparent); }
:root[data-theme="dark"] .pill-warn,
:root:where(:not([data-theme="light"])) .pill-warn { color: var(--warning); }

/* --------------------------------------------------------------------------- */
/* Stat tiles — a KPI row, not a bar chart of eight bars                        */
/* --------------------------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: .75rem; margin-bottom: 1.1rem; }
.tile {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .85rem .95rem; box-shadow: var(--shadow);
}
.tile-label { font-size: .8rem; color: var(--text-secondary); font-weight: 560; margin-bottom: .25rem; }
.tile-value { font-size: 1.62rem; font-weight: 660; letter-spacing: -.02em; line-height: 1.15; }
.tile-note { font-size: .78rem; color: var(--text-muted); margin-top: .3rem; }
.tile-good .tile-value { color: var(--good-text); }
.tile-bad  .tile-value { color: var(--critical); }
.tile-warn .tile-value { color: var(--text-primary); }
.tile-warn::before, .tile-bad::before, .tile-good::before {
  content: ""; display: block; height: 3px; width: 30px; border-radius: 2px; margin-bottom: .5rem;
}
.tile-good::before { background: var(--good); }
.tile-warn::before { background: var(--warning); }
.tile-bad::before  { background: var(--critical); }

/* A tile that drills into its own rows. Styled as a card, not as a link:
   underlined blue text at 1.6rem would fight the number for attention, so the
   affordance is the hover lift and the cue line rather than link colouring. */
a.tile-link {
  display: block;
  text-decoration: none;
  color: inherit;
  position: relative;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
a.tile-link:hover {
  border-color: color-mix(in srgb, var(--series-1) 55%, transparent);
  box-shadow: 0 2px 4px rgba(11, 11, 11, .06), 0 10px 24px rgba(11, 11, 11, .09);
  transform: translateY(-1px);
}
a.tile-link:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.tile-cue {
  display: block;
  margin-top: .45rem;
  font-size: .76rem;
  font-weight: 560;
  color: var(--series-1);
  opacity: 0;
  transition: opacity .12s;
}
a.tile-link:hover .tile-cue,
a.tile-link:focus-visible .tile-cue { opacity: 1; }
/* Touch and keyboard users get no hover, so the cue is always visible there. */
@media (hover: none) { .tile-cue { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  a.tile-link, .tile-cue { transition: none; }
  a.tile-link:hover { transform: none; }
}

/* --------------------------------------------------------------------------- */
/* Composition bar — part-to-whole, three segments, direct-labelled             */
/* --------------------------------------------------------------------------- */
.composition { margin: .3rem 0 0; }
.comp-track {
  display: flex; width: 100%; height: 34px; border-radius: 5px; overflow: hidden;
  background: var(--surface-1); gap: 2px;   /* 2px surface gap between fills */
}
.comp-seg { height: 100%; min-width: 3px; }
.comp-seg-1 { background: var(--series-1); }
.comp-seg-2 { background: var(--series-2); }
.comp-seg-3 { background: var(--series-3); }
.comp-legend { display: flex; flex-wrap: wrap; gap: .35rem 1.4rem; margin-top: .7rem; }
.comp-item { display: flex; align-items: baseline; gap: .45rem; font-size: .86rem; }
.comp-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; transform: translateY(1px); }
.comp-name { color: var(--text-secondary); }
.comp-value { font-weight: 620; font-variant-numeric: tabular-nums; }

/* Magnitude, one hue, light -> dark. Sequential, not categorical. */
.bars { display: grid; gap: .4rem; margin-top: .5rem; }
.bar-row { display: grid; grid-template-columns: minmax(140px, 15rem) 1fr auto; gap: .7rem; align-items: center; font-size: .87rem; }
.bar-track { background: var(--surface-1); border-radius: 4px; height: 16px; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--series-1); }
.bar-count { font-variant-numeric: tabular-nums; color: var(--text-secondary); min-width: 5ch; text-align: right; }

/* --------------------------------------------------------------------------- */
/* Tables                                                                       */
/* --------------------------------------------------------------------------- */
/* A grid or flex child defaults to min-width:auto, which means "as wide as my
   content". A twenty-column table therefore pushes its own column open instead
   of scrolling inside it, the layout blows past the viewport, and the page picks
   up a horizontal scrollbar. Every ancestor between the grid and the scroll box
   has to be allowed to shrink, not just the scroll box itself. */
.split > *,
.stack,
.stack > *,
details.section,
details.section .section-body,
.exceptions,
.exceptions > * { min-width: 0; }

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  /* Keeps the sticky header from painting over the sidebar's cards. */
  position: relative;
  z-index: 0;
}
table.data { border-collapse: collapse; width: 100%; font-size: .86rem; }
table.data th, table.data td { padding: .45rem .6rem; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--grid); }
table.data thead th {
  position: sticky; top: 0; background: var(--card); z-index: 2; font-weight: 620;
  color: var(--text-secondary); border-bottom: 1px solid var(--axis); cursor: pointer;
  user-select: none;
}
table.data thead th::after { content: ""; display: inline-block; width: .8em; }
table.data thead th[aria-sort="ascending"]::after { content: " ▲"; }
table.data thead th[aria-sort="descending"]::after { content: " ▼"; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--series-1) 6%, transparent); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.neg { color: var(--critical); }
table.data tbody tr:last-child td { border-bottom: 0; }
.table-empty { padding: 1.4rem; color: var(--text-muted); text-align: center; font-size: .9rem; }

details.section { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); margin-bottom: .8rem; box-shadow: var(--shadow); }
details.section > summary { padding: .85rem 1.1rem; cursor: pointer; font-weight: 620; display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: "▸"; color: var(--text-muted); }
details.section[open] > summary::before { content: "▾"; }
details.section .section-body { padding: 0 1.1rem 1.1rem; }
.section-count { font-weight: 500; color: var(--text-muted); font-size: .88rem; }
.section-blurb { font-size: .88rem; color: var(--text-secondary); margin: 0 0 .7rem; max-width: 78ch; }

/* --------------------------------------------------------------------------- */
/* Upload drop zones                                                            */
/* --------------------------------------------------------------------------- */
.drops { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.drop {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 1rem; background: var(--surface-1); position: relative; transition: border-color .12s, background .12s;
}
.drop.is-over { border-color: var(--series-1); background: color-mix(in srgb, var(--series-1) 7%, var(--surface-1)); }
.drop.has-file { border-style: solid; border-color: color-mix(in srgb, var(--good) 50%, transparent); }
.drop-title { font-weight: 620; font-size: .93rem; }
.drop-req { font-size: .74rem; color: var(--text-muted); font-weight: 500; }
.drop-help { font-size: .82rem; color: var(--text-secondary); margin: .35rem 0 .6rem; }
.drop-file { font-size: .85rem; margin-top: .5rem; display: none; word-break: break-all; }
.drop.has-file .drop-file { display: block; color: var(--good-text); }
.drop input[type=file] { font-size: .84rem; width: 100%; }
.drop-example { font-size: .76rem; color: var(--text-muted); font-family: var(--mono); }

/* --------------------------------------------------------------------------- */
/* Run progress                                                                 */
/* --------------------------------------------------------------------------- */
.progress { display: flex; align-items: center; gap: .8rem; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 2px solid var(--grid); border-top-color: var(--series-1);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.logbox {
  font-family: var(--mono); font-size: .8rem; line-height: 1.5; white-space: pre-wrap;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .7rem .85rem; max-height: 340px; overflow: auto; color: var(--text-secondary);
}

.notes { display: grid; gap: .7rem; }
.note { border-left: 3px solid var(--series-1); padding: .1rem 0 .1rem .8rem; }
.note-meta { font-size: .8rem; color: var(--text-muted); }
.note-body { white-space: pre-wrap; margin: .2rem 0 0; }

.secret {
  font-family: var(--mono); font-size: .9rem; word-break: break-all; user-select: all;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: .6rem .75rem; margin: .5rem 0;
}

.stack { display: grid; gap: 1rem; }
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 22rem);
  gap: 1rem;
  align-items: start;
}
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

.exceptions { margin-top: 1.6rem; }
.exceptions > h2 { margin-bottom: .2rem; }

/* Nothing in this app should make the PAGE scroll sideways. Wide content
   scrolls inside its own box; this is the backstop if something escapes.
   `clip` rather than `hidden` on purpose: overflow-x:hidden forces the other
   axis to `auto`, which turns the body into a scroll container and breaks both
   the normal page scroll and any position:sticky inside it. `clip` leaves
   overflow-y visible. */
html, body { max-width: 100%; overflow-x: clip; }

.auth-page { max-width: 400px; margin: 8vh auto 0; }
.auth-page .brand { justify-content: center; margin-bottom: 1.2rem; font-size: 1.2rem; }

.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.toolbar input[type=search] { max-width: 250px; }
.toolbar select { width: auto; }
.spacer { flex: 1; }

.dl-list { display: flex; gap: .5rem; flex-wrap: wrap; }

.pager { display: flex; gap: .5rem; align-items: center; justify-content: center; margin-top: 1rem; font-size: .88rem; }

.skip {
  position: absolute; left: -9999px;
}
.skip:focus { left: 1rem; top: 1rem; background: var(--card); padding: .5rem .8rem; border-radius: var(--radius-sm); z-index: 100; }
