/* ServerGuard dashboard. Tokens first; light and dark are both selected (not auto-inverted). */
:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #e0dfd9;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #76756f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --chart: #2a78d6;
  --grid: #e6e5e0;
  --crit: #d03b3b;
  --high: #ec835a;
  --med: #fab219;
  --low: #2a78d6;
  --info: #9a998f;
  --good: #0ca30c;
  --danger-bg: #fbeaea;
  --warn-bg: #fdf3dc;
  --ok-bg: #e5f5e5;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .04);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #33332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --chart: #3987e5;
    --grid: #2c2c29;
    --danger-bg: #3a1d1d;
    --warn-bg: #3a3018;
    --ok-bg: #18301a;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #242422;
  --border: #33332f;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f8e86;
  --accent: #3987e5;
  --chart: #3987e5;
  --grid: #2c2c29;
  --danger-bg: #3a1d1d;
  --warn-bg: #3a3018;
  --ok-bg: #18301a;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, "Segoe UI", -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
code, pre { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; font-weight: 650; font-size: 16px; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar .spacer { flex: 1; }
.userbox { border-top: 1px solid var(--border); padding: 12px 8px 0; display: grid; gap: 8px; }
.userbox .who { font-size: 12px; color: var(--text-2); word-break: break-all; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin-right: auto; }
.content { padding: 20px 24px 40px; display: grid; gap: 16px; max-width: 1400px; }

.grid { display: grid; gap: 16px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid > *, .content > * { min-width: 0; }
a.tile { color: inherit; text-decoration: none; }
a.tile:hover { border-color: var(--accent); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; flex-wrap: wrap; }
.card-h h2 { margin-right: auto; }
.card-b { padding: 0 16px 16px; }
.card-b.flush { padding: 0; }

.tile { padding: 14px 16px; }
.tile .label { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font-weight: 550; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn svg { width: 16px; height: 16px; }
input[type=text], input[type=password], input[type=number], select {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .nav a:focus-visible, tr.clickable:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.field { display: grid; gap: 4px; }
.field label { font-size: 12px; color: var(--text-2); font-weight: 550; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }

/* ---------- badges (icon + label: never color alone) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 6px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--info); flex: none; }
.badge.sev-Critical .dot { background: var(--crit); }
.badge.sev-High .dot { background: var(--high); }
.badge.sev-Medium .dot { background: var(--med); }
.badge.sev-Low .dot { background: var(--low); }
.badge.ok .dot { background: var(--good); }
.badge.warn { background: var(--warn-bg); }
.badge.bad { background: var(--danger-bg); }
.badge.good { background: var(--ok-bg); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-top: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--text-2); font-weight: 600; border-top: 0; background: var(--surface-2); position: sticky; top: 0; }
td.wrap { white-space: pre-wrap; word-break: break-word; max-width: 560px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.detail td { background: var(--surface-2); }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.kv dt { color: var(--text-2); font-size: 12px; }
.kv dd { margin: 0; }
pre.cmd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; word-break: break-all; margin: 6px 0 0; }

/* ---------- chart ---------- */
.chart { position: relative; }
.chart svg { display: block; max-width: 100%; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--chart); pointer-events: none; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.active { filter: brightness(1.15); }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; min-width: 150px; z-index: 3; transform: translate(-50%, calc(-100% - 10px));
}
.tooltip .t { font-weight: 600; margin-bottom: 4px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 12px; }

/* ---------- score ring ---------- */
.score { display: flex; align-items: center; gap: 14px; }
.score svg { width: 64px; height: 64px; }
.score .ring-bg { stroke: var(--surface-2); }
.score .ring { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .4s; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; display: grid; gap: 16px; }
.login .brand { padding: 0; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; border: 1px solid var(--border); }
.alert.error { background: var(--danger-bg); }
.alert.warn { background: var(--warn-bg); }
.alert.ok { background: var(--ok-bg); }

/* ---------- modal & toasts ---------- */
.modal-bg { position: fixed; inset: 0; background: rgb(0 0 0 / .45); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 20px; display: grid; gap: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 30; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); white-space: pre-wrap; }
.toast.error { border-left-color: var(--crit); }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 12px; }
  .brand { padding: 4px 8px; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav a span { display: none; }
  .sidebar .spacer { display: none; }
  .userbox { border: 0; padding: 0; margin-left: auto; grid-auto-flow: column; align-items: center; }
  .userbox .who { display: none; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .cols-2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- series colors (validated: blue/orange pass CVD + contrast in both themes) ---------- */
:root { --s1: #2a78d6; --s2: #eb6834; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --s1: #3987e5; --s2: #d95926; } }
:root[data-theme="dark"] { --s1: #3987e5; --s2: #d95926; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--s1); } .chart .line.s2 { stroke: var(--s2); }
.chart .dotm.s1 { fill: var(--s1); } .chart .dotm.s2 { fill: var(--s2); }
.chart .dotm { stroke: var(--surface); stroke-width: 2; }
.chart .direct-label { fill: var(--text-2); font-size: 11px; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.legend > span, .tooltip .r > span { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.key.s1 { background: var(--s1); } .key.s2 { background: var(--s2); }
.tile .value.small-value { font-size: 17px; line-height: 1.3; }
.meter { width: 120px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--s1); border-radius: 4px; }
.meter.bad > span { background: var(--crit); }

/* ---------- banner ---------- */
.banner { margin: 16px 24px 0; padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--warn-bg);
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { padding: 8px 12px; border-radius: 8px 8px 0 0; color: var(--text-2); text-decoration: none; white-space: nowrap; font-weight: 550; }
.tabs a[aria-selected="true"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.tabs a:hover { background: var(--surface-2); }

/* ---------- settings ---------- */
.settings { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; align-items: start; }
.settings-nav { display: grid; padding: 8px; gap: 2px; }
.settings-nav a { padding: 7px 10px; border-radius: 8px; color: var(--text-2); text-decoration: none; }
.settings-nav a:hover { background: var(--surface-2); color: var(--text); }
.settings-nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.settings-form { gap: 18px; max-width: 760px; }
.setting { display: grid; gap: 5px; }
.setting > label { font-weight: 600; font-size: 13px; }
.setting .help { font-size: 12px; color: var(--muted); }
.setting input[type=text], .setting input[type=password], .setting input[type=number], .setting select, .setting textarea { width: 100%; max-width: 520px; }
textarea { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; font: 13px/1.4 var(--mono); color: inherit; resize: vertical; }
.field-error { font-size: 12px; color: var(--crit); }
.risky-tag { color: var(--high); }
.map-editor { display: grid; gap: 6px; max-width: 520px; }
.map-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: 6px; }
.object-list { display: grid; gap: 10px; }
.object-item { border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: grid; gap: 12px; background: var(--surface-2); }
.object-item > .row { justify-content: space-between; }
.subcard { box-shadow: none; }
ul.changes { margin: 6px 0 0; padding-left: 18px; font-family: var(--mono); font-size: 12.5px; max-height: 220px; overflow: auto; }
ul.changes li.risky { color: var(--high); font-weight: 600; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
@media (max-width: 860px) {
  .settings { grid-template-columns: 1fr; }
  .settings-nav { grid-auto-flow: column; overflow-x: auto; }
  .banner { margin: 12px 16px 0; }
}
.object-list > .btn, .map-editor > .btn { justify-self: start; }

/* ---------- bell & notifications ---------- */
.bell { position: relative; }
.bell-btn { position: relative; padding: 6px 8px; }
.bell-btn svg { width: 20px; height: 20px; }
.bell-count { position: absolute; top: -2px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--crit); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.bell-panel { position: absolute; right: 0; top: calc(100% + 6px); width: min(420px, calc(100vw - 32px)); z-index: 15; }
.bell-list { max-height: 60vh; overflow: auto; border-top: 1px solid var(--border); }
.bell-item { display: grid; gap: 4px; padding: 10px 16px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.bell-item:hover { background: var(--surface-2); }
.toast.notify { cursor: pointer; display: grid; gap: 4px; }
.toast.notify.sev-Critical { border-left-color: var(--crit); }
.toast.notify.sev-High { border-left-color: var(--high); }
.toast.notify.sev-Medium { border-left-color: var(--med); }

/* ---------- live ---------- */
.feed { max-height: 560px; overflow: auto; border-top: 1px solid var(--border); }
.feed-item { display: grid; gap: 3px; padding: 9px 16px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; border-left: 3px solid transparent; }
.feed-item:hover { background: var(--surface-2); }
.feed-item.sev-Critical { border-left-color: var(--crit); }
.feed-item.sev-High { border-left-color: var(--high); }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }

/* ---------- horizontal bars (counts) ---------- */
.hbar-row { display: grid; grid-template-columns: minmax(110px, 200px) 1fr auto auto; gap: 10px; align-items: center; padding: 4px 0; }
.hbar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.hbar > span { display: block; height: 100%; background: var(--s1); border-radius: 5px; }
.hbar-value { font-size: 12.5px; min-width: 36px; text-align: right; }

/* ---------- attack map (one-hue sequential ramp; near-zero recedes toward the surface) ---------- */
.map svg { width: 100%; height: auto; }
.map .country { fill: var(--surface-2); stroke: var(--surface); stroke-width: .6; }
.map .country:hover { stroke: var(--text); stroke-width: 1.2; }
:root { --m0: #cde2fb; --m1: #86b6ef; --m2: #3987e5; --m3: #1c5cab; --m4: #0d366b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --m0: #104281; --m1: #1c5cab; --m2: #2a78d6; --m3: #6da7ec; --m4: #b7d3f6; } }
:root[data-theme="dark"] { --m0: #104281; --m1: #1c5cab; --m2: #2a78d6; --m3: #6da7ec; --m4: #b7d3f6; }
.map .country.b0, .swatch.b0 { fill: var(--m0); background: var(--m0); }
.map .country.b1, .swatch.b1 { fill: var(--m1); background: var(--m1); }
.map .country.b2, .swatch.b2 { fill: var(--m2); background: var(--m2); }
.map .country.b3, .swatch.b3 { fill: var(--m3); background: var(--m3); }
.map .country.b4, .swatch.b4 { fill: var(--m4); background: var(--m4); }
.map .country[class*=" b"] { cursor: pointer; }
.map-legend { display: flex; align-items: center; gap: 4px; }
.swatch { width: 22px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------- actions & details ---------- */
.action-card { box-shadow: none; }
.action-card.done { opacity: .75; }
.big-ip { font-size: 22px; }
.country-big { font-size: 16px; }
.wrap { white-space: pre-wrap; word-break: break-word; }
.nowrap { white-space: nowrap; }
