/* =============================================================================
   Halo — design tokens + components.
   Light is the default; dark applies via [data-theme="dark"] or, when no theme
   is chosen, the OS preference. The theme menu stores the choice in
   localStorage ("ddos_theme": light | dark | system).
   ========================================================================== */

:root {
  color-scheme: light;
  --page:        #f4f5f3;
  --surface:     #fcfcfb;
  --surface-2:   #f3f3f0;
  --surface-3:   #e9e9e4;
  --sidebar:     #ffffff;
  --border:      #e1e0d9;
  --border-strong:#c3c2b7;
  --text:        #0b0b0b;
  --text-2:      #52514e;
  --muted:       #898781;
  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --accent-soft: rgba(42,120,214,.10);
  --focus:       rgba(42,120,214,.35);

  /* Data series (validated categorical order: blue, orange, aqua, yellow …) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --grid:     #e1e0d9;
  --axis:     #c3c2b7;

  /* Status — reserved, always paired with an icon/label */
  --good:     #0ca30c;  --good-ink: #006300;  --good-soft: rgba(12,163,12,.10);
  --warning:  #fab219;  --warning-ink: #8a5a00; --warning-soft: rgba(250,178,25,.16);
  --serious:  #ec835a;  --serious-ink: #a8431a; --serious-soft: rgba(236,131,90,.14);
  --critical: #d03b3b;  --critical-ink: #b02a2a; --critical-soft: rgba(208,59,59,.10);

  --radius:    10px;
  --radius-sm: 7px;
  --shadow:    0 1px 2px rgba(11,11,11,.04), 0 1px 1px rgba(11,11,11,.03);
  --shadow-lg: 0 12px 32px rgba(11,11,11,.14), 0 2px 6px rgba(11,11,11,.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:        #0d0d0d;
    --surface:     #1a1a19;
    --surface-2:   #222221;
    --surface-3:   #2c2c2a;
    --sidebar:     #141413;
    --border:      #2c2c2a;
    --border-strong:#383835;
    --text:        #ffffff;
    --text-2:      #c3c2b7;
    --muted:       #898781;
    --accent:      #3987e5;
    --accent-soft: rgba(57,135,229,.16);
    --focus:       rgba(57,135,229,.45);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --grid: #2c2c2a; --axis: #383835;
    --good-ink: #0ca30c; --good-soft: rgba(12,163,12,.16);
    --warning-ink: #fab219; --warning-soft: rgba(250,178,25,.14);
    --serious-ink: #ec835a; --serious-soft: rgba(236,131,90,.16);
    --critical-ink: #e66767; --critical-soft: rgba(208,59,59,.18);
    --shadow: none;
    --shadow-lg: 0 16px 40px rgba(0,0,0,.55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #222221;
  --surface-3:   #2c2c2a;
  --sidebar:     #141413;
  --border:      #2c2c2a;
  --border-strong:#383835;
  --text:        #ffffff;
  --text-2:      #c3c2b7;
  --muted:       #898781;
  --accent:      #3987e5;
  --accent-soft: rgba(57,135,229,.16);
  --focus:       rgba(57,135,229,.45);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --grid: #2c2c2a; --axis: #383835;
  --good-ink: #0ca30c; --good-soft: rgba(12,163,12,.16);
  --warning-ink: #fab219; --warning-soft: rgba(250,178,25,.14);
  --serious-ink: #ec835a; --serious-soft: rgba(236,131,90,.16);
  --critical-ink: #e66767; --critical-soft: rgba(208,59,59,.18);
  --shadow: none;
  --shadow-lg: 0 16px 40px rgba(0,0,0,.55);
}

/* ---------------------------------------------------------------- base ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* -------------------------------------------------------------- layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  z-index: 30;
}
.brand { display: flex; flex-direction: column; gap: 8px; padding: 20px 18px 14px; color: inherit; }
.brand:hover { text-decoration: none; }
.brand small { font-weight: 600; font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }

/* Company wordmark (single <img>; app.js picks the light/dark file). */
.brand-logo { display: block; height: 22px; width: auto; max-width: 100%; }
.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav .section { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a svg { flex: 0 0 18px; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 24px; min-height: 60px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .title { display: flex; flex-direction: column; margin-right: auto; min-width: 0; }
.topbar .title .crumb { font-size: 12px; color: var(--muted); }
.topbar .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.menu-btn { display: none; }
.content { padding: 20px 24px 40px; max-width: 1600px; width: 100%; margin: 0 auto; }

@media (max-width: 980px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px; }
}

/* ------------------------------------------------------------- controls --- */
button, .btn, select, input, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 11px; min-height: 34px;
}
textarea { min-height: 80px; resize: vertical; width: 100%; }
input::placeholder, textarea::placeholder { color: var(--muted); }
select { padding-right: 28px; cursor: pointer; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover, button.primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--critical-ink); }
.btn-danger:hover { background: var(--critical-soft); border-color: var(--critical); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 4px 9px; min-height: 28px; font-size: 13px; }
.icon-btn { padding: 0; width: 34px; }
.btn-group { display: inline-flex; }
.btn-group > * { border-radius: 0; margin-left: -1px; }
.btn-group > *:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group > *:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group > .on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); position: relative; z-index: 1; }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--text-2); }
label.field input, label.field select, label.field textarea { width: 100%; color: var(--text); font-weight: 400; }
.field .help { font-weight: 400; font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input, label.field .check input { min-height: 0; width: 16px; height: 16px; flex: 0 0 16px; accent-color: var(--accent); }

.switch { position: relative; display: inline-block; width: 34px; height: 20px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(14px); }

/* ---------------------------------------------------------------- cards --- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; } .col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; } .col-7 { grid-column: span 7; } .col-8 { grid-column: span 8; }
.col-12 { grid-column: span 12; }
@media (max-width: 1200px) { .col-3 { grid-column: span 6; } .col-4, .col-5 { grid-column: span 6; } .col-7, .col-8 { grid-column: span 12; } }
@media (max-width: 760px) { .col-3, .col-4, .col-5, .col-6, .col-7, .col-8 { grid-column: span 12; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 0;
}
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 16px 0;
}
.card-head h2 { margin-right: auto; }
.card-head .sub { width: 100%; margin-top: -6px; font-size: 12.5px; color: var(--muted); }
.card-body { padding: 14px 16px 16px; }
.card-body.flush { padding: 10px 0 0; }
.chart-box { position: relative; height: 240px; }
.chart-box.sm { height: 170px; }
.chart-box.lg { height: 300px; }

/* ---------------------------------------------------------------- tiles --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value .unit { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.tile .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.hero { grid-column: span 2; }
.tile.hero .value { font-size: 40px; }
@media (max-width: 760px) { .tile.hero { grid-column: span 1; } .tile.hero .value { font-size: 30px; } }

/* --------------------------------------------------------------- tables --- */
.table-wrap { overflow: auto; max-height: 560px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted::after { content: " ↓"; } th.sorted.asc::after { content: " ↑"; }
td { font-size: 13.5px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
td .bar-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
td .bar-cell .bar { height: 6px; border-radius: 3px; background: var(--series-1); opacity: .85; min-width: 2px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* --------------------------------------------------------------- badges --- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border); white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.good { background: var(--good-soft); color: var(--good-ink); border-color: transparent; }
.badge.warning { background: var(--warning-soft); color: var(--warning-ink); border-color: transparent; }
.badge.serious { background: var(--serious-soft); color: var(--serious-ink); border-color: transparent; }
.badge.critical { background: var(--critical-soft); color: var(--critical-ink); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.live .dot { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ----------------------------------------------------------------- misc --- */
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.small { font-size: 12.5px; }
.status-line { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); }
.status-line .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.status-line.warn .dot { background: var(--warning); }
.status-line.bad .dot { background: var(--critical); }
.callout { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.callout.warning { background: var(--warning-soft); border-color: transparent; }
.callout.critical { background: var(--critical-soft); border-color: transparent; color: var(--critical-ink); }
.callout.good { background: var(--good-soft); border-color: transparent; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.secret-box { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--border-strong); font-family: var(--mono); font-size: 13px; word-break: break-all; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; color: transparent !important; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ----------------------------------------------------------------- tabs --- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------------------------------------------------- dropdown / popover --- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu .item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0;
  background: none; border-radius: var(--radius-sm); color: var(--text); text-align: left; min-height: 0; font-weight: 400;
}
.dropdown-menu .item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-menu .item .check-mark { margin-left: auto; font-weight: 700; visibility: hidden; }
.dropdown-menu .item.selected .check-mark { visibility: visible; }
.dropdown-menu .sep { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown-menu .head { padding: 8px 10px 6px; font-size: 12px; color: var(--muted); }
.dropdown-menu .custom { padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.dropdown-menu .custom input { width: 100%; }

/* ---------------------------------------------------------------- modal --- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 620px; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin-right: auto; font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
.modal .error-msg { color: var(--critical-ink); font-size: 13px; margin-right: auto; align-self: center; }

/* ---------------------------------------------------------------- toast --- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px; animation: toast-in .18s ease-out; }
.toast.error { background: var(--critical); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------------------------------------------------------------- login --- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-art {
  background: radial-gradient(1200px 600px at 10% 10%, rgba(57,135,229,.35), transparent 60%),
              radial-gradient(800px 500px at 90% 90%, rgba(235,104,52,.22), transparent 60%), #0f1215;
  color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
}
.login-art h1 { font-size: 30px; max-width: 420px; line-height: 1.2; }
.login-art p { color: #c3c2b7; max-width: 440px; }
.login-form-wrap { display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 22px; margin-bottom: 4px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 24px; }
.login-card button[type=submit] { min-height: 40px; }
.login-card .error-msg { color: var(--critical-ink); font-size: 13px; min-height: 18px; }
.login-mobile-logo { display: none; margin-bottom: 28px; }
@media (max-width: 860px) { .login-page { grid-template-columns: 1fr; } .login-art { display: none; } .login-mobile-logo { display: block; } }

/* ---------------------------------------------------------- attack map --- */
.viz-overlay { position: fixed; inset: 0; z-index: 150; background: var(--page); display: flex; flex-direction: column; }
.viz-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.viz-title { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.viz-controls { flex-wrap: nowrap; }
.viz-controls input[type=range] { width: 220px; padding: 0; min-height: 0; border: 0; background: none; accent-color: var(--accent); }
.viz-controls.viz-no-timeline input, .viz-controls.viz-no-timeline button { display: none; }
.viz-body { flex: 1; display: flex; min-height: 0; }
.viz-map { flex: 1; min-width: 0; position: relative; }
.viz-map svg { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.viz-map svg:active { cursor: grabbing; }
.viz-flow, .viz-land { vector-effect: non-scaling-stroke; }
.viz-zoom { position: absolute; left: 12px; top: 12px; display: flex; flex-direction: column; gap: 4px; }
.viz-zoom button { width: 32px; height: 32px; min-height: 0; padding: 0; font-size: 16px; box-shadow: var(--shadow); }
.viz-side { width: 300px; flex: 0 0 300px; overflow-y: auto; padding: 16px; border-left: 1px solid var(--border); background: var(--surface); font-size: 13px; }
.viz-side h3 { margin: 4px 0 6px; }
.viz-legend { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.viz-key { display: inline-block; width: 18px; height: 3px; border-radius: 2px; margin-right: 8px; vertical-align: middle; }
.viz-key-ring { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--text-2); background: none; }
.viz-table { width: 100%; }
.viz-table td { padding: 4px 4px; border: 0; font-size: 12.5px; }
.viz-bar { display: inline-block; width: 70px; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; vertical-align: middle; }
.viz-bar span { display: block; height: 100%; border-radius: 3px; }

.viz-sphere { fill: #cfe0f1; }
.viz-land { fill: #f4f4f1; stroke: #b9b8af; stroke-width: .5; }
.viz-land-src { fill: #e34948; }
.viz-land-dst { fill: #0ca30c; fill-opacity: .35; }
.viz-flow { fill: none; stroke-linecap: round; stroke-dasharray: 2 9; animation: viz-flow 1s linear infinite; }
.viz-green { stroke-dasharray: 2 7; opacity: .9; }
@keyframes viz-flow { to { stroke-dashoffset: -22; } }
.viz-paused .viz-flow, .viz-paused .viz-dest-pulse { animation-play-state: paused; }
.viz-site-halo { fill: rgba(227, 73, 72, .16); stroke: #e34948; stroke-width: 1; }
.viz-site-core { fill: #ffffff; stroke: #1f1f1d; stroke-width: 2; }
.viz-dest-core { fill: #0ca30c; stroke: #ffffff; stroke-width: 2; }
.viz-dest-pulse { fill: none; stroke: #0ca30c; stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: viz-pulse 1.8s ease-out infinite; }
@keyframes viz-pulse { from { transform: scale(.6); opacity: .9; } to { transform: scale(2.6); opacity: 0; } }
.viz-label { font-size: 11px; font-weight: 600; fill: #1f1f1d; paint-order: stroke; stroke: rgba(255,255,255,.85); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.viz-label-dest { font-size: 12px; }

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-sphere { fill: #0f1a26; }
  :root:where(:not([data-theme="light"])) .viz-land { fill: #2a2a28; stroke: #45453f; }
  :root:where(:not([data-theme="light"])) .viz-land-src { fill: #e66767; }
  :root:where(:not([data-theme="light"])) .viz-site-core { fill: #1a1a19; stroke: #ffffff; }
  :root:where(:not([data-theme="light"])) .viz-label { fill: #ffffff; stroke: rgba(0,0,0,.75); }
}
:root[data-theme="dark"] .viz-sphere { fill: #0f1a26; }
:root[data-theme="dark"] .viz-land { fill: #2a2a28; stroke: #45453f; }
:root[data-theme="dark"] .viz-land-src { fill: #e66767; }
:root[data-theme="dark"] .viz-site-core { fill: #1a1a19; stroke: #ffffff; }
:root[data-theme="dark"] .viz-label { fill: #ffffff; stroke: rgba(0,0,0,.75); }

@media (prefers-reduced-motion: reduce) { .viz-flow, .viz-dest-pulse { animation: none; } }
@media (max-width: 860px) {
  .viz-body { flex-direction: column; overflow-y: auto; }
  .viz-map { flex: 0 0 auto; height: min(58vh, 72vw); }   /* world map is ~2:1 */
  .viz-side { width: auto; flex: 0 0 auto; border-left: 0; border-top: 1px solid var(--border); }
  .viz-head { position: relative; padding: 10px 14px; gap: 10px; }
  .viz-title { padding-right: 40px; }
  #vizClose { position: absolute; top: 8px; right: 8px; }
  .viz-controls { width: 100%; flex-wrap: wrap; gap: 6px 10px; }
  .viz-controls input[type=range] { flex: 1 1 140px; width: auto; }
  #vizClock, #vizRate { white-space: nowrap; }
}

/* ---------------------------------------------------------------- phone --- */
@media (max-width: 640px) {
  /* Two tiles per row (the headline tile spans both) instead of a long stack. */
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px; }
  .tile .value { font-size: 22px; }
  .tile.hero { grid-column: span 2; }
  .tile.hero .value { font-size: 30px; }
  /* Tables scroll sideways inside their card rather than crushing columns. */
  .table-wrap table { min-width: 620px; }
  .card-head { padding: 12px 12px 0; }
  .card-body { padding: 12px; }
  .grid { gap: 12px; }
  .topbar .actions { width: 100%; }
  .topbar .actions select { flex: 1; min-width: 0; }
  .modal-body, .modal-head, .modal-foot { padding-left: 14px; padding-right: 14px; }
}

/* ---------------------------------------------------------------- print --- */
@media print {
  .sidebar, .topbar .actions, .no-print { display: none !important; }
  .layout, .main { display: block; }
  .card, .tile { break-inside: avoid; box-shadow: none; }
}

/* ------------------------------------------------- prefix protection --- */
.pfx-flag { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.pfx-flag .switch { margin-top: 2px; }
.pfx-flag b { display: block; font-weight: 600; font-size: 13.5px; }
.pfx-flag .help { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.pfx-flag .help.warn { color: var(--warning-ink); }
.pfx-flag:has(input:disabled) { cursor: default; }
.pfx-filter select { flex: 1 1 260px; min-width: 0; }
.pfx-filter input { flex: 1 1 220px; min-width: 0; }
.pfx-savebar {
  position: sticky; bottom: 0; z-index: 5; margin-top: 16px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.pfx-diff { margin: 10px 0 0; padding-left: 18px; font-size: 13px; }
.pfx-diff li { margin: 3px 0; }
.crumb a { color: inherit; }
.pfx-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; font-weight: 400; }
@media (max-width: 640px) { .pfx-cols { grid-template-columns: 1fr; } }
