/* ==========================================================================
   bans.mowden.top - admin dashboard

   Design direction: "instrument panel". The subject is a shared ban ledger,
   and its native vernacular is addresses, CIDR masks, jail names and sequence
   numbers - so monospace carries the data and a compact grotesk carries the
   chrome. Surfaces are cool and quiet; the only saturated colour on the page
   belongs to data marks and status.

   Chart colours are the validated data-viz palette (blue / orange categorical,
   single-hue blue sequential ramp), checked against these exact surfaces.
   ========================================================================== */

/* -------------------------------------------------------------- fonts --- */
@font-face {
  font-family: "Space Grotesk";
  src: url("/admin/static/fonts/space-grotesk-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/admin/static/fonts/ibm-plex-mono-400-latin.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/admin/static/fonts/ibm-plex-mono-500-latin.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/admin/static/fonts/ibm-plex-mono-600-latin.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

/* ------------------------------------------------------------- tokens --- */
:root {
  color-scheme: light;

  --page:        #f4f6f9;
  --panel:       #ffffff;
  --sunken:      #eef1f5;
  --raised:      #ffffff;
  --border:      #dde3ea;
  --border-firm: #c3ccd7;

  --ink:         #121821;
  --ink-2:       #4a5666;
  --ink-3:       #7a8797;

  --accent:      #2a78d6;
  --accent-soft: #e8f1fc;
  --accent-ink:  #1c5cab;

  --series-1:    #2a78d6;
  --series-2:    #eb6834;

  --good:        #167e5c;
  --good-soft:   #e2f4ed;
  --warn:        #8a6100;
  --warn-soft:   #fcf1d9;
  --crit:        #c0322f;
  --crit-soft:   #fbe6e6;

  /* Sequential ramp, low -> high magnitude. The floor deliberately starts at a
     saturated blue rather than near-white: most countries have no data at all,
     so step 1 has to separate from --seq-0 by hue as well as lightness or the
     whole choropleth reads as one flat sheet. */
  --seq-0:  #e8ecf1;   /* no data -- neutral, never part of the ramp */
  --seq-1:  #b7d3f6;
  --seq-2:  #9ec5f4;
  --seq-3:  #6da7ec;
  --seq-4:  #3987e5;
  --seq-5:  #2a78d6;
  --seq-6:  #1c5cab;
  --seq-7:  #0d366b;

  --grid:        #e6eaef;
  --shadow:      0 1px 2px rgba(18, 24, 33, .05);

  --font-ui:   "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius:    6px;
  --radius-sm: 4px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --page:        #0e1218;
    --panel:       #181d25;
    --sunken:      #131820;
    --raised:      #1e242e;
    --border:      #262e39;
    --border-firm: #364150;

    --ink:         #e9edf3;
    --ink-2:       #9aa7b7;
    --ink-3:       #6b7889;

    --accent:      #3987e5;
    --accent-soft: #16283f;
    --accent-ink:  #86b6ef;

    --series-1:    #3987e5;
    --series-2:    #d95926;

    --good:        #3fbe94;
    --good-soft:   #11291f;
    --warn:        #d9a423;
    --warn-soft:   #2b2211;
    --crit:        #e66767;
    --crit-soft:   #2e1717;

    --seq-0:  #1f252e;
    --seq-1:  #1d4a7d;
    --seq-2:  #205fa4;
    --seq-3:  #2a78d6;
    --seq-4:  #3987e5;
    --seq-5:  #5598e7;
    --seq-6:  #86b6ef;
    --seq-7:  #b7d3f6;

    --grid:        #232b35;
    --shadow:      0 1px 2px rgba(0, 0, 0, .3);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.mono { font-family: var(--font-mono); font-variant-ligatures: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ----------------------------------------------------------- masthead --- */
.masthead {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 56px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.wordmark {
  display: flex;
  align-items: baseline;
  gap: 1px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.wordmark .domain {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-3);
}

.masthead-spacer { flex: 1; }

.masthead-readout {
  display: flex;
  align-items: center;
  gap: 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
}
.readout-item { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.readout-item .label {
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.readout-item .value { color: var(--ink); font-weight: 500; }

/* ---------------------------------------------------------------- nav --- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  border: 0;
  background: none;
  padding: 10px 12px 9px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-3);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.tab .count {
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--sunken);
  color: var(--ink-2);
  font-size: 10px;
}

/* --------------------------------------------------------------- main --- */
main { max-width: 1440px; margin: 0 auto; padding: 20px; }

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.view-head h1 { font-size: 20px; }
.view-head p { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; max-width: 62ch; }

/* -------------------------------------------------------------- panel --- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.panel-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.panel-note { font-size: 12px; color: var(--ink-3); }
.panel-body { padding: 16px; }
/* Inputs default to full width for forms; in a panel header they must not
   stretch across the whole bar. */
.panel-head select,
.panel-head input { width: auto; }
.panel-body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.split-wide { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.stack { display: grid; gap: 16px; }

@media (max-width: 1080px) {
  .grid.cols-2, .grid.cols-3, .grid.split-wide { grid-template-columns: minmax(0, 1fr); }
}

/* --------------------------------------------------------- stat tiles --- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
}
.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 13px;
  box-shadow: var(--shadow);
}
.tile .tile-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.tile .tile-value {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -.02em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.tile .tile-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.tile.is-alert .tile-value { color: var(--crit); }

/* ------------------------------------------------------------ tables --- */
.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th {
  text-align: left;
  padding: 9px 16px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--sunken);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.data td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: baseline;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--sunken); }
table.data td.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
table.data td.addr {
  font-family: var(--font-mono);
  font-weight: 500;
  white-space: nowrap;
}
table.data .muted { color: var(--ink-3); }

.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}
.empty strong { display: block; color: var(--ink-2); font-weight: 500; margin-bottom: 4px; }

/* ------------------------------------------------------------- pills --- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .02em;
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.pill.no-dot::before { display: none; }
.pill-banned      { background: var(--crit-soft);   color: var(--crit); }
.pill-expired     { background: var(--sunken);      color: var(--ink-3); }
.pill-whitelisted { background: var(--good-soft);   color: var(--good); }
.pill-suppressed  { background: var(--warn-soft);   color: var(--warn); }
.pill-neutral     { background: var(--sunken);      color: var(--ink-2); }
.pill-ok          { background: var(--good-soft);   color: var(--good); }
.pill-info        { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------------------------------------------------------- controls --- */
.btn {
  appearance: none;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-firm);
  background: var(--raised);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-danger { color: var(--crit); border-color: var(--border-firm); }
.btn-danger:hover { border-color: var(--crit); }
.btn-sm { padding: 4px 9px; font-size: 12px; }

.field { display: grid; gap: 5px; }
.field label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.field .hint { font-size: 12px; color: var(--ink-3); }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], select {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border-firm);
  border-radius: var(--radius-sm);
  background: var(--raised);
  color: var(--ink);
  width: 100%;
  min-width: 0;
}
input::placeholder { color: var(--ink-3); }

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar select { width: auto; }

/* ---------------------------------------------------------- sync rail --- */
/* The signature element: every machine plotted on the one axis the whole
   protocol turns on - the global sync sequence. Distance from the right edge
   is exactly how far behind that host's firewall is. */
.rail { display: grid; gap: 0; }
.rail-row {
  display: grid;
  grid-template-columns: minmax(90px, 150px) 1fr minmax(96px, auto);
  align-items: center;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.rail-row:last-child { border-bottom: 0; }
.rail-name {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail-track {
  position: relative;
  height: 22px;
}
.rail-track::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--grid);
  border-radius: 1px;
}
.rail-fill {
  position: absolute;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--accent);
  border-radius: 1px;
  opacity: .35;
}
.rail-marker {
  position: absolute;
  top: 50%;
  width: 10px; height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel);
}
.rail-marker.is-behind { background: var(--warn); }
.rail-marker.is-stale  { background: var(--crit); }
.rail-marker.is-never  { background: var(--ink-3); }
.rail-drift {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.rail-axis {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding-top: 6px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* -------------------------------------------------------------- chart --- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart .axis-label,
.chart .tick-label {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--ink-3);
}
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--border-firm); stroke-width: 1; }

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-2);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

.tooltip {
  position: absolute;
  z-index: 30;
  pointer-events: none;
  min-width: 120px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border-firm);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px rgba(18, 24, 33, .14);
  font-size: 12px;
  opacity: 0;
  transition: opacity .08s linear;
}
.tooltip[data-visible="true"] { opacity: 1; }
.tooltip .tip-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--ink);
}
.tooltip .tip-row {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-2);
  white-space: nowrap;
}
.tooltip .tip-row .swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tooltip .tip-row .val {
  margin-left: auto;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------- heatmap --- */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 16px; }
@media (max-width: 900px) { .map-layout { grid-template-columns: minmax(0, 1fr); } }

.map svg { width: 100%; height: auto; display: block; }
.map .country {
  /* No `fill` here on purpose. A CSS declaration outranks an SVG presentation
     attribute, so styling fill in the sheet would silently override the value
     the choropleth sets per country and paint the whole map one colour. */
  stroke: var(--panel);
  stroke-width: .4;
  transition: fill .1s linear;
}
.map .country[data-active="true"] { cursor: pointer; }
.map .country:hover { stroke: var(--ink); stroke-width: .9; }

.map-legend { display: grid; gap: 8px; align-content: start; }
.ramp { display: flex; height: 9px; border-radius: 2px; overflow: hidden; }
.ramp span { flex: 1; }
.ramp-scale {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
}

.country-list { display: grid; gap: 1px; }
.country-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: default;
}
.country-row:hover, .country-row.is-hot { background: var(--sunken); }
.country-row .code {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
}
.country-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-2);
}
.country-row .n {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* --------------------------------------------------------- gate/auth --- */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.gate-card .wordmark { font-size: 20px; margin-bottom: 4px; }
.gate-card p.lede { color: var(--ink-2); font-size: 13px; margin: 0 0 20px; }
.gate-card form { display: grid; gap: 14px; }
.gate-card .btn { width: 100%; justify-content: center; padding: 9px; }

.notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1.45;
}
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-error { background: var(--crit-soft); color: var(--crit); }
.notice-info { background: var(--accent-soft); color: var(--accent-ink); }

/* -------------------------------------------------------------- modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 14, 20, .45);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(10, 14, 20, .28);
  max-height: 90dvh;
  overflow-y: auto;
}
.modal-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
}
.modal-body { padding: 18px; display: grid; gap: 14px; }
.modal-foot {
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.key-reveal {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  line-height: 1.5;
}

/* -------------------------------------------------------------- toast --- */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  display: grid;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-firm);
  background: var(--panel);
  box-shadow: 0 6px 20px rgba(10, 14, 20, .18);
  font-size: 13px;
}
.toast.is-error { border-color: var(--crit); color: var(--crit); }
.toast.is-ok { border-color: var(--good); }

/* ------------------------------------------------------------ loading --- */
.skeleton {
  background: var(--sunken);
  border-radius: var(--radius-sm);
  height: 1em;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
