/* syncKn design system — single source of truth.
 *
 * Replaces the :root block that was copy-pasted into 5 of 6 templates.
 * Every colour here that carries text has been checked against WCAG AA at the
 * size it actually renders (pills are 11px, so the 3:1 large-text allowance
 * does NOT apply). See docs/UI-REVIEW.md for the audit that drove these values.
 */

/* ---------------------------------------------------------------- tokens -- */
:root {
  /* surfaces */
  --bg:        #0f1720;
  --panel:     #17212b;
  --panel-2:   #1c2833;   /* hover / nested surface */
  --line:      #3d4b5a;   /* was #26333f at 1.26:1 — near-invisible once
                             multiplied across a widget grid */
  --line-soft: #26333f;   /* internal dividers only, never a widget boundary */

  /* text */
  --ink:       #e6edf3;   /* 13.79:1 on panel */
  --dim:       #8b98a5;   /*  5.53:1 on panel — passes, kept as-is */

  /* status — foregrounds are the AA-corrected values, not the tint colours */
  --ok:        #3fb950;
  --ok-fg:     #56d364;
  --warn:      #d29922;
  --warn-fg:   #e3b341;
  --bad:       #f85149;
  --bad-fg:    #ff7b72;
  --off:       #6e7681;
  --off-fg:    #a1a8b2;
  --accent:    #3b82f6;
  --accent-fg: #79c0ff;   /* 8.38:1 — use for text, --accent for fills */
  --susp-fg:   #ffa198;
  --ai:        #a371f7;
  --ai-fg:     #d2a8ff;

  /* spacing — 4px base. Was 24 distinct padding values. */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;

  /* radii — was 9 distinct values (7/8/10/12/14/999) */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-pill: 999px;

  /* type — was 8 sizes / 5 weights. 650 collapsed to 700 on Segoe UI anyway. */
  --t-xs: 11px; --t-sm: 12px; --t-md: 13px; --t-base: 14px;
  --t-lg: 16px; --t-xl: 18px; --t-2xl: 26px;
  --w-normal: 400; --w-semi: 600; --w-bold: 700;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--t-base)/1.5 var(--font);
}

a { color: var(--accent-fg); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ----------------------------------------------------------------- focus --
 * The audit found ZERO :focus styles across every template, with the primary
 * drill-down on <tr onclick>. Keyboard users had no way to see or reach it.
 */
:focus-visible {
  outline: 2px solid var(--accent-fg);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.skip-link {
  position: absolute; left: -9999px;
  background: var(--accent); color: #fff;
  padding: var(--s2) var(--s4); border-radius: var(--r-sm); z-index: 100;
}
.skip-link:focus { left: var(--s3); top: var(--s3); }

/* ---------------------------------------------------------------- header -- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4); padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.app-header h1 { font-size: var(--t-xl); margin: 0; font-weight: var(--w-semi); }
.app-header .sub { color: var(--dim); font-size: var(--t-sm); }
.app-nav { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }

.wrap { padding: var(--s5); margin: 0 auto; }
.wrap--narrow { max-width: 1100px; }
.wrap--wide   { max-width: 1600px; }

/* ------------------------------------------------------------ flash msgs --
 * Blocker 3: every mutation was a bare redirect with no confirmation.
 */
.flashes { margin: 0 0 var(--s4); padding: 0; list-style: none; }
.flash {
  display: flex; align-items: flex-start; gap: var(--s2);
  padding: var(--s3) var(--s4); margin-bottom: var(--s2);
  border: 1px solid var(--line); border-radius: var(--r-md);
  font-size: var(--t-md); font-weight: var(--w-semi);
}
.flash.success { background: rgba(63,185,80,.14);  border-color: #2c5a34; color: var(--ok-fg); }
.flash.error   { background: rgba(248,81,73,.14);  border-color: #5a2420; color: var(--bad-fg); }
.flash.info    { background: rgba(59,130,246,.14); border-color: #23446e; color: var(--accent-fg); }
.flash .x { margin-left: auto; background: none; border: 0; color: inherit;
            cursor: pointer; font-size: var(--t-lg); line-height: 1; padding: 0 var(--s1); }

/* ----------------------------------------------------------------- cards -- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--s4); margin-bottom: var(--s4);
}
.card h2 {
  font-size: var(--t-sm); text-transform: uppercase; letter-spacing: .05em;
  color: var(--dim); margin: 0 0 var(--s3); font-weight: var(--w-semi);
}

/* ----------------------------------------------------------------- tiles -- */
.tiles { display: flex; gap: var(--s3); flex-wrap: wrap; }
.tile {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s3) var(--s4);
  min-width: 116px; flex: 1; text-decoration: none; color: inherit;
  transition: border-color .12s, background .12s;
}
a.tile:hover { border-color: var(--accent-fg); text-decoration: none; background: var(--panel-2); }
a.tile[aria-current="true"] { border-color: var(--accent-fg); box-shadow: inset 0 0 0 1px var(--accent-fg); }
.tile .n { font-size: var(--t-2xl); font-weight: var(--w-bold); line-height: 1.1; }
.tile .l { color: var(--dim); font-size: var(--t-sm); text-transform: uppercase; letter-spacing: .04em; }
.tile.ok   .n { color: var(--ok-fg); }
.tile.warn .n { color: var(--warn-fg); }
.tile.bad  .n { color: var(--bad-fg); }
.tile.off  .n { color: var(--off-fg); }
.tile.reg  .n { color: var(--accent-fg); }
.tile.susp .n { color: var(--susp-fg); }
.tile.ai   .n { color: var(--ai-fg); }

/* ----------------------------------------------------------------- pills --
 * Foregrounds recomputed: offline was 2.83:1, registered 3.65, healthy 3.95,
 * unhealthy 4.12, badge.ai 3.90 — all now >= 5.2:1 on their tinted grounds.
 */
.pill, .badge {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-pill);
  font-size: var(--t-xs); font-weight: var(--w-semi); white-space: nowrap;
}
.pill.healthy    { background: rgba(63,185,80,.18);  color: var(--ok-fg); }
.pill.stale      { background: rgba(210,153,34,.18); color: var(--warn-fg); }
.pill.unhealthy  { background: rgba(248,81,73,.18);  color: var(--bad-fg); }
.pill.offline    { background: rgba(110,118,129,.22);color: var(--off-fg); }
.pill.registered { background: rgba(59,130,246,.18); color: var(--accent-fg); }
.pill.suspended  { background: rgba(248,81,73,.26);  color: var(--susp-fg); }
.badge.ai    { background: rgba(163,113,247,.20); color: var(--ai-fg); }
.badge.meas  { background: rgba(63,185,80,.18);   color: var(--ok-fg); }
.badge.visit { background: rgba(59,130,246,.18);  color: var(--accent-fg); }
.badge.app   { background: rgba(139,152,165,.16); color: var(--off-fg); }

.chip {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: var(--s1) var(--s3);
  font-size: var(--t-sm); color: var(--dim); display: inline-block;
}
.chip b { color: var(--ink); }
.chip[aria-current="true"] { border-color: var(--accent-fg); color: var(--ink); }

/* --------------------------------------------------------------- buttons -- */
.btn {
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  border-radius: var(--r-sm); padding: var(--s2) var(--s3);
  font-size: var(--t-md); font-weight: var(--w-semi); cursor: pointer;
  font-family: inherit; transition: border-color .12s, background .12s;
}
.btn:hover { border-color: var(--accent-fg); background: var(--panel-2); }
.btn.sm  { padding: var(--s1) var(--s2); font-size: var(--t-sm); }
.btn.bad { border-color: #5a2420; color: var(--bad-fg); background: rgba(248,81,73,.08); }
.btn.ok  { border-color: #2c5a34; color: var(--ok-fg);  background: rgba(63,185,80,.08); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

input, textarea, select {
  background: var(--bg); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--r-sm); padding: var(--s2) var(--s3); font: inherit; width: 100%;
}
textarea { min-height: 64px; resize: vertical; }
label { font-size: var(--t-sm); color: var(--dim); display: block; margin-bottom: var(--s1); }

/* ---------------------------------------------------------------- tables -- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td {
  text-align: left; padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--line-soft); font-size: var(--t-md);
}
.tbl th {
  color: var(--dim); font-size: var(--t-xs); text-transform: uppercase;
  letter-spacing: .04em; font-weight: var(--w-semi);
  position: sticky; top: 0; background: var(--panel); z-index: 2;
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--panel-2); }
.tbl tbody tr.susp td { background: rgba(248,81,73,.06); }
/* Row drill-down is a real link now, not <tr onclick> — keyboard reachable. */
.tbl tbody tr:focus-within td { background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--accent-fg); }
.tbl .nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------ feed -- */
.feed { display: flex; flex-direction: column; }
.ev {
  display: flex; gap: var(--s3); padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--line-soft); font-size: var(--t-md);
}
.ev:last-child { border-bottom: 0; }
.ev .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--dim); }
.ev.info .dot     { background: var(--ok-fg); }
.ev.warn .dot     { background: var(--warn-fg); }
.ev.critical .dot { background: var(--bad-fg); }
.ev .who { color: var(--dim); font-size: var(--t-xs); }
.ev .t   { color: var(--dim); font-size: var(--t-xs); margin-left: auto; white-space: nowrap; }

/* --------------------------------------------------------------- helpers -- */
.dim  { color: var(--dim); }
.mono { font-family: var(--mono); font-size: var(--t-sm); }
.empty { padding: var(--s6); text-align: center; color: var(--dim); font-size: var(--t-md); }
.row { display: flex; gap: var(--s2); align-items: end; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: var(--s1) var(--s3); font-size: var(--t-md); }
.kv .k { color: var(--dim); }
.kv .v { word-break: break-word; }
.pager { display: flex; gap: var(--s3); justify-content: center; margin-top: var(--s4); color: var(--dim); }
.banner { border-radius: var(--r-md); padding: var(--s3) var(--s4); margin-bottom: var(--s4); font-weight: var(--w-semi); }
.banner.susp { background: rgba(248,81,73,.12); border: 1px solid #5a2420; color: var(--susp-fg); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
