/* Svarog public kiosk — calm night-operations surface. */

:root {
  --bg: #060d0c;
  --panel: rgba(9, 18, 16, 0.86);
  --panel-solid: #0a1311;
  --line: rgba(150, 184, 172, 0.16);
  --line-soft: rgba(150, 184, 172, 0.09);
  --text: #dde8e3;
  --muted: #8ba098;
  --faint: #63766f;
  --ember: #ff7a3d;
  --ember-soft: #ffa25e;
  --ember-dim: rgba(255, 122, 61, 0.16);
  --earlier: #8293a0;
  --amber: #f2a92c;
  --amber-soft: #ffc95e;
  --ok: #4ecb8d;
  --warn: #e0b34a;
  --bad: #e0654c;
  --focus: #ffd27a;
  --font-display: "Chakra Petch", "IBM Plex Sans", sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --rail-w: 348px;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
}

#map {
  position: fixed;
  inset: 0;
}

#map .maplibregl-canvas {
  visibility: hidden;
}

body.map-ready #map .maplibregl-canvas {
  visibility: visible;
}

.mono { font-family: var(--font-mono); font-size: 0.92em; }

/* ---------- rail ---------- */

#rail {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  z-index: 5;
}

.rail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.mark {
  display: block;
  width: 34px;
  height: 34px;
  flex: none;
}

.rail-title h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text);
}

.rail-title p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.block {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.block-h {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: 8px;
}

.limitations {
  background: rgba(240, 179, 61, 0.04);
}

.limitations .block-h {
  color: var(--amber);
}

.limitations ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 17px;
}

.limitations li {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.limitations li::marker {
  color: var(--amber);
}

/* ---------- status ---------- */

.state-line {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--muted);
}

.state-line[data-state="online"] { color: var(--ok); }
.state-line[data-state="empty"] { color: var(--warn); }
.state-line[data-state="error"] { color: var(--bad); }

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
  animation: pulse 1.6s ease-in-out infinite;
}

.state-line[data-state="online"] .pulse { animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.retry {
  margin-top: 10px;
}

button.retry {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
}

button.retry:hover { border-color: var(--muted); background: rgba(150, 184, 172, 0.08); }

.feed-facts {
  margin: 12px 0 0;
  display: grid;
  gap: 6px;
}

.feed-facts div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.feed-facts dt {
  font-size: 12px;
  color: var(--faint);
}

.feed-facts dd {
  margin: 0;
  font-size: 12.5px;
  color: var(--text);
  text-align: right;
}

.source-health {
  margin-top: 12px;
}

.source-health summary {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  list-style: none;
}

.source-health summary::-webkit-details-marker {
  display: none;
}

.source-health summary::before {
  width: 6px;
  height: 6px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  content: "";
  flex: none;
  transform: rotate(-45deg);
  transition: transform 120ms ease;
}

.source-health[open] summary::before {
  transform: rotate(45deg);
}

.source-health summary::after {
  width: 7px;
  height: 7px;
  margin-left: auto;
  background: var(--ok);
  border-radius: 50%;
  content: "";
  flex: none;
}

.source-health[data-state="attention"] summary::after {
  background: var(--warn);
}

.source-health[data-state="unknown"] summary::after {
  background: var(--faint);
}

.source-health summary:hover,
.source-health summary:focus-visible {
  color: var(--text);
}

.sources {
  display: grid;
  gap: 4px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.sources:empty { display: none; }

.sources li {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.src-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}

.src-dot[data-s="online"] { background: var(--ok); }
.src-dot[data-s="pending"],
.src-dot[data-s="stale"] { background: var(--warn); }
.src-dot[data-s="degraded"] { background: var(--bad); }
.src-dot[data-s="not_configured"],
.src-dot[data-s="unknown"] { background: var(--faint); }

/* ---------- segmented threshold ---------- */

.segmented {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}

.seg { position: relative; }

.seg input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.seg span {
  display: block;
  text-align: center;
  padding: 8px 0;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border-left: 1px solid var(--line-soft);
  transition: background 120ms ease, color 120ms ease;
}

.seg:first-child span { border-left: none; }

.seg input:checked + span {
  background: var(--ember-dim);
  color: var(--ember-soft);
}

.seg input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.seg:hover input:not(:checked) + span { color: var(--text); }

/* ---------- counts ---------- */

.counts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.count {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 10px 12px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.count-n {
  font-size: 26px;
  font-weight: 500;
  line-height: 1.1;
}

.count-new .count-n { color: var(--ember-soft); }
.count-earlier .count-n { color: var(--earlier); }

.count-l {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}

.window-note {
  margin: 10px 0 0;
  padding: 9px 10px;
  border: 1px solid rgba(242, 169, 44, 0.3);
  border-radius: var(--radius);
  background: rgba(242, 169, 44, 0.07);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.45;
}

/* ---------- clusters ---------- */

.chip {
  background: rgba(242, 169, 44, 0.14);
  color: var(--amber-soft);
  border: 1px solid rgba(242, 169, 44, 0.35);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 11px;
}

.rule-text {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.cluster-order {
  margin: -3px 0 9px;
  color: var(--faint);
  font-family: var(--font-display);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cluster-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.cluster-list:empty { display: none; }

.cluster-item button {
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: rgba(242, 169, 44, 0.06);
  border: 1px solid rgba(242, 169, 44, 0.28);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  transition: background 120ms ease, border-color 120ms ease;
}

.cluster-item button:hover {
  background: rgba(242, 169, 44, 0.12);
  border-color: rgba(242, 169, 44, 0.5);
}

.cluster-item .c-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--amber-soft);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.cluster-item .c-title .mono { font-family: var(--font-mono); font-weight: 500; }

.cluster-item .c-meta {
  font-size: 12px;
  color: var(--muted);
}

.cluster-item .c-meta .mono { color: var(--text); }

.cluster-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.cluster-actions[hidden] { display: none; }

.cluster-action {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.cluster-action:hover {
  border-color: rgba(242, 169, 44, 0.5);
  color: var(--amber-soft);
}

.cluster-more {
  flex: 1;
  background: rgba(242, 169, 44, 0.06);
  border-color: rgba(242, 169, 44, 0.28);
  color: var(--amber-soft);
}

.empty-note {
  margin: 0;
  font-size: 12.5px;
  color: var(--faint);
}

/* ---------- map controls ---------- */

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
  cursor: pointer;
  position: relative;
  padding: 2px 0;
}

.switch-row + .switch-row {
  margin-top: 8px;
}

.switch-row input {
  position: absolute;
  right: 0;
  width: 44px;
  height: 24px;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.switch {
  width: 44px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(150, 184, 172, 0.1);
  position: relative;
  flex: none;
  transition: background 140ms ease, border-color 140ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 140ms ease, background 140ms ease;
}

.switch-row input:checked + .switch {
  background: var(--ember-dim);
  border-color: rgba(255, 122, 61, 0.5);
}

.switch-row input:checked + .switch::after {
  transform: translateX(20px);
  background: var(--ember-soft);
}

.switch-row input:focus-visible + .switch {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.legend {
  list-style: none;
  margin: 12px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--line-soft);
  display: grid;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
}

.legend li { display: flex; align-items: center; gap: 9px; }

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: none;
}

.dot-new {
  background: var(--ember);
  box-shadow: 0 0 6px 1px rgba(255, 122, 61, 0.55);
}

.dot-earlier { background: var(--earlier); opacity: 0.85; }

.ring {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px dashed var(--amber);
  flex: none;
}

/* ---------- footer ---------- */

.rail-foot {
  padding: 14px 18px 16px;
  margin-top: auto;
}

.rail-foot p { margin: 0; font-size: 12px; color: var(--faint); }

.rail-foot p + p { margin-top: 8px; }

.attrib { font-size: 11px !important; }

.signature {
  font-size: 11px !important;
  letter-spacing: 0.02em;
}

.rail-foot a {
  color: inherit;
  text-decoration-color: rgba(237, 242, 240, 0.35);
  text-underline-offset: 2px;
}

.rail-foot a:hover,
.rail-foot a:focus-visible {
  color: var(--text);
  text-decoration-color: currentColor;
}

/* ---------- map popups & cluster badges ---------- */

.maplibregl-popup-content {
  background: var(--panel-solid);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

.maplibregl-popup-tip { border-top-color: var(--panel-solid) !important; }

.maplibregl-popup-close-button {
  color: var(--muted);
  font-size: 16px;
  padding: 2px 8px;
}

.pop-title {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.pop-title[data-age="new"] { color: var(--ember-soft); }
.pop-title[data-age="earlier"] { color: var(--earlier); }

.pop-grid {
  display: grid;
  grid-template-columns: auto auto;
  gap: 3px 14px;
}

.pop-grid dt { color: var(--faint); font-size: 11.5px; }
.pop-grid dd { margin: 0; font-size: 12.5px; text-align: right; }

.cluster-badge {
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(10, 14, 12, 0.9);
  border: 1.5px dashed var(--amber);
  color: var(--amber-soft);
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ---------- focus ---------- */

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.maplibregl-canvas:focus-visible { outline-offset: -2px; }

/* ---------- mobile bottom sheet ---------- */

#sheet-toggle { display: none; }

@media (max-width: 760px) {
  #rail {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 68vh;
    border-radius: 16px 16px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    transform: translateY(calc(100% - 96px));
    transition: transform 240ms ease;
    padding-top: 34px;
  }

  #rail.open { transform: translateY(0); }

  #sheet-toggle {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(96px - 36px);
    margin: 0 auto;
    width: 100%;
    height: 38px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: transparent;
    border: none;
    color: var(--muted);
    font: inherit;
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-family: var(--font-display);
    cursor: pointer;
    z-index: 6;
    transition: bottom 240ms ease;
  }

  body.sheet-open #sheet-toggle { bottom: calc(68vh - 20px); }

  .sheet-toggle-bar {
    width: 34px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
    flex: none;
  }

  .rail-head { padding-top: 0; }
}

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

  #rail { transition: none; }
}
