/* ORION Global Monitor
   Obsidian and gold design system (Quanta Analytica palette). */

:root {
  --bg: #07090c;
  --bg-panel: rgba(12, 14, 18, 0.94);
  --bg-raised: #12151b;
  --bg-hover: #1a1e26;
  --line: #262b35;
  --line-soft: #1b1f27;
  --text: #e6e4de;
  --text-dim: #a29f96;
  --text-faint: #6f6c65;
  --gold: #c8a24a;
  --gold-bright: #e2bd62;
  --gold-dim: #7a6430;

  --src-usgs: #f2b544;
  --src-gdacs: #5fb3d9;
  --src-eonet: #8fcf7a;
  --src-gdelt: #b79cf0;
  --src-rss: #d9d4c7;

  --sev-3: #ff4d4d;
  --sev-2: #ff9a3c;
  --sev-1: #f5d547;
  --sev-0: #5d6470;

  --ok: #4fc38a;
  --warn: #f0b23c;
  --err: #ff5c5c;

  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --topbar-h: 48px;
  --ticker-h: 32px;
  --panel-w: 300px;
  --panel-r-w: 360px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
}
.mono { font-family: var(--mono); }
.muted { color: var(--text-faint); }
.small { font-size: 11px; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2c313c; border-radius: 3px; }

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* Top bar */
.topbar {
  position: relative;
  z-index: 1000;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: #050608;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 20px; height: 20px; color: var(--gold); flex: none; }
.brand-name { font-family: var(--mono); font-weight: 600; letter-spacing: 0.22em; color: var(--gold); }
.brand-sub { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-dim); white-space: nowrap; }
.topbar-status { display: flex; align-items: center; gap: 18px; font-size: 11px; color: var(--text-dim); }
.clock-label { color: var(--text-faint); }
.health { padding: 2px 8px; border: 1px solid var(--line); border-radius: 3px; }
.health b { color: var(--text); font-weight: 600; }
.health.is-ok { border-color: #1f4d37; color: var(--ok); }
.health.is-partial { border-color: #5a4518; color: var(--warn); }
.health.is-down { border-color: #5a1f1f; color: var(--err); }
.topbar-actions { display: flex; gap: 6px; }

.btn {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: #3a404c; }
.btn-gold { border-color: var(--gold-dim); color: var(--gold-bright); }
.btn-gold:hover { background: #1d1a10; border-color: var(--gold); }
.btn[aria-pressed="true"] { color: var(--warn); border-color: #5a4518; }
.btn.is-busy { opacity: 0.6; pointer-events: none; }

/* Workspace */
.workspace { position: relative; height: calc(100% - var(--topbar-h)); overflow: hidden; }
#map { position: absolute; inset: 0 0 var(--ticker-h) 0; background: #0b0e12; }

.panel {
  position: absolute;
  top: 0;
  bottom: var(--ticker-h);
  z-index: 900;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.panel-left { left: 0; width: var(--panel-w); border-right: 1px solid var(--line); }
.panel-right { right: 0; width: var(--panel-r-w); border-left: 1px solid var(--line); overflow: hidden; }
.panel-section { padding: 14px; border-bottom: 1px solid var(--line-soft); }
.section-title {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

/* Layers */
.layer-list { display: grid; gap: 4px; }
.layer {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 3px;
  cursor: pointer;
}
.layer:hover { background: var(--bg-hover); }
.layer input { position: absolute; opacity: 0; pointer-events: none; }
.layer .swatch { width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; }
.layer input:checked + .swatch { background: currentColor; }
.layer .layer-name { color: var(--text); }
.layer .layer-count { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.layer:has(input:not(:checked)) .layer-name { color: var(--text-faint); text-decoration: line-through; }
.layer:has(input:focus-visible) { outline: 2px solid var(--gold); }

/* Fields */
.field { display: grid; gap: 4px; margin: 0 0 10px; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend { font-size: 11px; color: var(--text-dim); padding: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
select, input[type="search"], input[type="text"] {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 5px 7px;
  font-size: 12px;
}
select:hover, input:hover { border-color: #3a404c; }
.inline { display: flex; gap: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-raised);
  cursor: pointer;
  user-select: none;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:not(:checked)) { opacity: 0.45; }
.chip:has(input:focus-visible) { outline: 2px solid var(--gold); }
button.chip { color: var(--text-dim); }
button.chip.active { border-color: var(--gold-dim); color: var(--gold-bright); }
.sev { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.sev-3 { background: var(--sev-3); }
.sev-2 { background: var(--sev-2); }
.sev-1 { background: var(--sev-1); }
.sev-0 { background: var(--sev-0); }

/* Status table */
.status-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.status-table th { text-align: left; color: var(--text-faint); font-weight: 500; padding: 0 4px 6px 0; }
.status-table td { padding: 4px 4px 4px 0; border-top: 1px solid var(--line-soft); white-space: nowrap; }
.status-table td:first-child { white-space: normal; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--sev-0); vertical-align: 1px; }
.dot.ok { background: var(--ok); }
.dot.loading { background: var(--gold); animation: blink 0.9s infinite; }
.dot.error { background: var(--err); }
.dot.stale { background: var(--warn); }
@keyframes blink { 50% { opacity: 0.25; } }

.legend-row { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-dim); margin: 4px 0; }
.ring { width: 12px; height: 12px; border-radius: 50%; background: #2a2f39; flex: none; }
.ring-3 { box-shadow: 0 0 0 2px var(--sev-3); }
.ring-2 { box-shadow: 0 0 0 2px var(--sev-2); }
.ring-1 { box-shadow: 0 0 0 2px var(--sev-1); }
.ring-0 { box-shadow: 0 0 0 1px #12151b; }

/* Tabs */
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}
.tab.active { color: var(--gold-bright); border-bottom-color: var(--gold); }
.tab .count { font-size: 10px; color: var(--text-faint); margin-left: 4px; letter-spacing: 0; }
.tab-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.toolbar { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line-soft); flex: none; }
.toolbar select { width: auto; }
.toolbar-col { flex-direction: column; gap: 8px; }
.toolbar-col .field { margin: 0; }
.gdelt-form { display: grid; gap: 6px; }

/* Item lists */
.item-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px 8px 10px;
  border: 0;
  border-left: 3px solid var(--line);
  border-bottom: 1px solid var(--line-soft);
  background: none;
  cursor: pointer;
  color: inherit;
  text-decoration: none;
}
.item:hover { background: var(--bg-hover); }
.item-meta { display: flex; justify-content: space-between; gap: 8px; font-family: var(--mono); font-size: 10px; color: var(--text-faint); text-transform: uppercase; }
.item-src { font-weight: 600; letter-spacing: 0.06em; }
.item-title { font-size: 12.5px; color: var(--text); margin: 2px 0 1px; overflow-wrap: anywhere; }
.item-sub { font-size: 11px; color: var(--text-dim); overflow-wrap: anywhere; }
.item .sev { margin-right: 4px; }
.empty { padding: 16px 12px; color: var(--text-faint); font-size: 12px; }

/* Ticker */
.ticker {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: var(--ticker-h);
  z-index: 950;
  display: flex;
  align-items: center;
  background: #050608;
  border-top: 1px solid var(--line);
}
.ticker-label {
  flex: none;
  padding: 0 12px;
  height: 100%;
  display: flex;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: #050608;
  background: var(--gold);
}
.ticker-viewport { position: relative; overflow: hidden; flex: 1; height: 100%; }
.ticker-track {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 36px;
  white-space: nowrap;
  font-size: 11px;
  color: var(--text-dim);
  padding-left: 16px;
  animation: ticker var(--ticker-dur, 60s) linear infinite;
}
.ticker:hover .ticker-track { animation-play-state: paused; }
.ticker-track a { color: inherit; text-decoration: none; }
.ticker-track a:hover { color: var(--gold-bright); }
.ticker-track .t-src { color: var(--gold); margin-right: 6px; }
@keyframes ticker { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) {
  .ticker-track { animation: none; }
  .ticker-viewport { overflow-x: auto; }
}

/* Leaflet overrides */
.leaflet-container { background: #0b0e12; font-family: var(--sans); }
.leaflet-control-attribution {
  background: rgba(5, 6, 8, 0.8) !important;
  color: var(--text-faint) !important;
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-bar a, .leaflet-bar a:hover {
  background: var(--bg-raised);
  color: var(--text);
  border-bottom-color: var(--line);
}
.leaflet-bar { border: 1px solid var(--line) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: #0f1217;
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
}
.leaflet-popup-content-wrapper { border-radius: 4px; }
.leaflet-popup-content { margin: 10px 12px; min-width: 220px; max-width: 300px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-dim); }
.pop-src { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; }
.pop-title { font-weight: 600; font-size: 13px; margin: 3px 0 6px; }
.pop-grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 11px; }
.pop-grid dt { color: var(--text-faint); }
.pop-grid dd { margin: 0; color: var(--text-dim); overflow-wrap: anywhere; }
.pop-link { display: inline-block; margin-top: 8px; font-size: 11px; color: var(--gold-bright) !important; }

.leaflet-control-layers { background: var(--bg-raised) !important; color: var(--text); border: 1px solid var(--line) !important; }
.leaflet-control-layers-toggle { filter: invert(0.85); }
.leaflet-control-layers-expanded { padding: 8px 10px; font-size: 12px; }

/* Map controls positioned clear of the panels */
.leaflet-left .leaflet-control { margin-left: calc(var(--panel-w) + 10px); }
.leaflet-right .leaflet-control { margin-right: calc(var(--panel-r-w) + 10px); }

.show-md { display: none; }

@media (max-width: 1100px) {
  :root { --panel-w: 270px; --panel-r-w: 320px; }
}

@media (max-width: 900px) {
  .show-md { display: inline-block; }
  .hide-sm { display: none; }
  .brand-sub { display: none; }
  .topbar-status { gap: 10px; }
  .panel { z-index: 1100; width: min(92vw, 360px); transition: transform 0.2s ease; box-shadow: 0 0 30px rgba(0, 0, 0, 0.7); }
  .panel-left { transform: translateX(-102%); }
  .panel-right { transform: translateX(102%); }
  .panel.open { transform: translateX(0); }
  .leaflet-left .leaflet-control { margin-left: 10px; }
  .leaflet-right .leaflet-control { margin-right: 10px; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 8px; gap: 6px; }
  .brand-mark { display: none; }
  #health { display: none; }
  .btn { padding: 5px 7px; font-size: 11px; }
}
