/* ============================================================
   SITUROOM — dark ops theme
   No external fonts, no external CSS: offline is a core feature.
   ============================================================ */

:root {
  --bg:        #0a0a0f;
  --panel:     #12121a;
  --panel-2:   #16161f;   /* slightly raised rows */
  --border:    #1e293b;
  --text:      #f1f5f9;
  --muted:     #64748b;
  --cyan:      #22d3ee;   /* data accent */
  --amber:     #f59e0b;   /* warnings / stale */
  --red:       #ef4444;   /* critical */
  --green:     #10b981;   /* ok / live */

  --font-ui:   system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 8px;
  --topbar-h: 52px;
  --ticker-h: 44px;
}

* { box-sizing: border-box; }

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

body { overflow: hidden; }

/* Every number, timestamp and ticker is monospace */
.clock, .mono, .ticker, .chip, .row-ts, .row-mag, .bar-score, .map-legend, .tab, .formula-note code {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

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

button { font-family: inherit; }

/* Visible focus everywhere (a11y) */
:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* ---------------- top bar ---------------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(34, 211, 238, 0.04), transparent 70%),
    var(--panel);
}

.wordmark { display: flex; align-items: baseline; gap: 8px; }

.wordmark h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.wordmark-sub {
  font-size: 9px;
  letter-spacing: 0.3em;
  color: var(--muted);
}

.wordmark-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  align-self: center;
  animation: pulse-dot 2s ease-in-out infinite;
}

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

.clock {
  font-size: 13px;
  color: var(--cyan);
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.status-chips {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--bg);
  white-space: nowrap;
}

.chip i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

/* aggregate chip: hidden on desktop, replaces the six chips on mobile */
.chip-summary { display: none; cursor: pointer; }

.chip.live  i { background: var(--green); box-shadow: 0 0 6px var(--green); }
.chip.live    { color: var(--text); }
.chip.stale i { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.chip.stale   { color: var(--amber); }
.chip.snap  i { background: var(--cyan);  box-shadow: 0 0 6px var(--cyan); }
.chip.snap    { color: var(--cyan); }
.chip.err   i { background: var(--red);   box-shadow: 0 0 6px var(--red); }
.chip.err     { color: var(--red); }

.gear-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  width: 34px; height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 150ms, border-color 150ms, box-shadow 150ms;
}

.gear-btn:hover {
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.25);
}

/* ---------------- main grid ---------------- */

.grid {
  display: grid;
  grid-template-columns: 62% 1fr;
  grid-template-rows: 1fr var(--ticker-h);
  grid-template-areas:
    "map  side"
    "tick tick";
  height: calc(100vh - var(--topbar-h));
  gap: 0;
}

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

.map-wrap {
  grid-area: map;
  position: relative;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgba(34, 211, 238, 0.05), transparent),
    var(--bg);
}

#map { display: block; width: 100%; height: 100%; cursor: crosshair; }

.layer-chips {
  position: absolute;
  top: 10px; left: 10px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.layer-chip {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(18, 18, 26, 0.85);
  color: var(--muted);
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: color 150ms, border-color 150ms, box-shadow 150ms;
}

.layer-chip[aria-pressed="true"] {
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.2);
}

.layer-chip:hover { color: var(--text); }

.map-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(6px);
  font-size: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
}

.map-tooltip .tt-title { font-weight: 600; }
.map-tooltip .tt-meta  { color: var(--muted); font-family: var(--font-mono); font-size: 10px; margin-top: 2px; }

.map-legend {
  position: absolute;
  bottom: 10px; left: 10px;
  display: flex;
  gap: 12px;
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--muted);
  background: rgba(18, 18, 26, 0.7);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.map-legend span { display: inline-flex; align-items: center; gap: 5px; }
.map-legend .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-quake { background: var(--cyan);  box-shadow: 0 0 5px var(--cyan); }
.dot-event { background: var(--amber); box-shadow: 0 0 5px var(--amber); }
.dot-heat  { background: var(--red);   box-shadow: 0 0 5px var(--red); }

/* ---------------- right column ---------------- */

.side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.panel:last-child { border-bottom: none; }

#tension-panel   { flex: 0 0 auto; max-height: 34%; }
#headlines-panel { flex: 1 1 0; }
#hazards-panel   { flex: 0 0 30%; }

.panel-grow { flex: 1 1 auto; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(34, 211, 238, 0.03), transparent);
}

.panel-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 7px;
}

.panel-icon { color: var(--cyan); font-size: 10px; }

.link-btn {
  background: none;
  border: none;
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  cursor: pointer;
  padding: 2px 6px;
}

.link-btn:hover { text-decoration: underline; }

.panel-body {
  padding: 8px 12px;
  min-height: 0;
}

.panel-body.scroll {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#tension-body { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

.empty-note { color: var(--muted); font-size: 12px; margin: 6px 0; }

.formula-note {
  padding: 8px 12px;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: 11px;
}

.formula-note code { color: var(--cyan); font-size: 10px; }

/* tension bars */

.bar-row {
  display: grid;
  grid-template-columns: 84px 1fr 34px;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.bar-name {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-name .watch { color: var(--amber); }

.bar-track {
  display: block; /* spans: explicit, so width/height always apply */
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  display: block; /* inline spans ignore width — this makes the fill render */
  height: 100%;
  min-width: 3px; /* even score 1 shows a sliver */
  border-radius: 999px;
  transition: width 500ms cubic-bezier(0.16, 1, 0.3, 1);
}

.bar-score {
  font-size: 11px;
  text-align: right;
  color: var(--muted);
}

/* headline / hazard rows */

.row {
  display: block;
  padding: 7px 8px;
  margin: 0 -8px;
  border-radius: var(--radius);
  border-bottom: 1px solid rgba(30, 41, 59, 0.5);
  color: var(--text);
  transition: background 120ms;
}

.row:hover { background: var(--panel-2); text-decoration: none; }

.row-title {
  font-size: 12px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-meta {
  display: flex;
  gap: 8px;
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}

.row-meta .src { color: var(--cyan); }
.row-ts { white-space: nowrap; }

.row-mag {
  font-weight: 700;
  font-size: 12px;
  min-width: 40px;
}

.mag-low  { color: var(--green); }
.mag-mid  { color: var(--amber); }
.mag-high { color: var(--red); }

.hazard-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  align-items: baseline;
}

.cat-icon { font-size: 12px; }

/* tabs */

.tab-row { display: flex; gap: 4px; }

.tab {
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.12em;
  padding: 3px 9px;
  cursor: pointer;
}

.tab.active {
  color: var(--cyan);
  border-color: var(--cyan);
}

/* ---------------- markets ticker ---------------- */

.ticker {
  grid-area: tick;
  border-top: 1px solid var(--border);
  background: var(--panel);
  overflow: hidden;
  display: flex;
  align-items: center;
}

.ticker-track {
  display: flex;
  gap: 28px;
  padding: 0 16px;
  white-space: nowrap;
  align-items: center;
  animation: ticker-scroll 45s linear infinite;
}

.ticker-track:hover { animation-play-state: paused; }

@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

.tick-item {
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
}

.tick-sym { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; }
.tick-px  { color: var(--text); font-weight: 600; }
.tick-chg.up   { color: var(--green); }
.tick-chg.down { color: var(--red); }
.tick-chg.flat { color: var(--muted); }

/* ---------------- dialogs ---------------- */

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  width: min(480px, 92vw);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(34, 211, 238, 0.06);
}

dialog::backdrop { background: rgba(5, 5, 8, 0.7); backdrop-filter: blur(3px); }

.settings-form, .brief-box { padding: 20px; }

dialog h2 {
  margin: 0 0 14px;
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--cyan);
}

dialog fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 14px;
  padding: 12px;
}

dialog legend {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding: 0 6px;
  text-transform: uppercase;
}

dialog label {
  display: block;
  font-size: 11px;
  color: var(--text);
  margin: 8px 0 4px;
}

dialog label .muted { color: var(--muted); font-size: 10px; }

dialog input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 9px;
}

dialog input:focus { border-color: var(--cyan); outline: none; }

dialog .check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

dialog input[type="checkbox"] {
  width: auto;
  accent-color: var(--cyan);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  border-radius: 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  padding: 7px 16px;
  cursor: pointer;
}

.btn.ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
}

.btn.ghost:hover { color: var(--text); border-color: var(--muted); }

.btn.solid {
  background: var(--cyan);
  border: 1px solid var(--cyan);
  color: #06222a;
  font-weight: 700;
}

.btn.solid:hover { box-shadow: 0 0 16px rgba(34, 211, 238, 0.4); }

.brief-body { font-size: 13px; }
.brief-body ul { padding-left: 18px; margin: 8px 0 14px; }
.brief-body li { margin: 6px 0; }
.brief-body .err { color: var(--red); font-family: var(--font-mono); font-size: 11px; }

/* ---------------- responsive ---------------- */

@media (max-width: 900px) {
  body { overflow: auto; }

  /* top bar: collapse the six source chips into one aggregate chip that
     expands on tap; the bar wraps instead of clipping */
  .topbar {
    height: auto;
    min-height: var(--topbar-h);
    flex-wrap: wrap;
    padding: 8px 14px;
    row-gap: 8px;
  }

  .status-chips .chip { display: none; }
  .status-chips .chip-summary { display: inline-flex; }
  .status-chips.expanded { flex-basis: 100%; justify-content: flex-start; }
  .status-chips.expanded .chip { display: inline-flex; }

  .grid {
    grid-template-columns: 1fr;
    grid-template-rows: 55vh auto var(--ticker-h);
    grid-template-areas:
      "map"
      "side"
      "tick";
    height: auto;
  }

  .map-wrap { border-right: none; border-bottom: 1px solid var(--border); }

  .side { overflow: visible; }
  #tension-panel   { max-height: none; }
  #headlines-panel { flex-basis: auto; max-height: 320px; }
  #hazards-panel   { flex-basis: auto; max-height: 300px; }

  .wordmark-sub, .clock { display: none; }
}

/* ---------------- reduced motion (a11y) ---------------- */

@media (prefers-reduced-motion: reduce) {
  .wordmark-dot { animation: none; }
  .ticker-track { animation: none; }
  .bar-fill { transition: none; }
  /* map.js also checks this media query and disables canvas pulses */
}
