/* ════════════════════════════════════════════════════════════════════
   CONTAGION// — design tokens
   ════════════════════════════════════════════════════════════════════ */
:root {
  --bg:        #0B0D12;
  --panel:     #12141B;
  --panel-2:   #181B24;
  --border:    #242733;
  --border-2:  #2E323F;

  --text:      #ECEEF3;
  --text-dim:  #8389A0;
  --text-faint:#4B4F5C;

  --accent:    #FF5A36;   /* signal — stress / danger */
  --accent-dim:#FF5A3622;
  --safe:      #2DD4A7;   /* safe / nominal */
  --warn:      #FFC857;   /* moderate */
  --info:      #5B8DEF;   /* secondary data / negative corr */
  --purple:    #9D7BFF;   /* structural / community accent */

  --font-display: 'Space Grotesk', sans-serif;
  --font-body:    'Inter', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  --radius: 8px;
  --sidebar-w: 300px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; }

::selection { background: var(--accent-dim); color: var(--text); }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ════════════════════════════════════════════════════════════════════
   HEADER
   ════════════════════════════════════════════════════════════════════ */
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.menu-btn span { width: 100%; height: 2px; background: var(--text); border-radius: 1px; }

.brand { display: flex; align-items: baseline; gap: 10px; }

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--safe);
  box-shadow: 0 0 0 0 var(--safe);
  animation: pulse 2.4s ease-out infinite;
  align-self: center;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(45, 212, 167, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(45, 212, 167, 0); }
  100% { box-shadow: 0 0 0 0 rgba(45, 212, 167, 0); }
}
.live-dot.danger { background: var(--accent); animation: pulseDanger 1.4s ease-out infinite; }
@keyframes pulseDanger {
  0%   { box-shadow: 0 0 0 0 rgba(255, 90, 54, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(255, 90, 54, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 90, 54, 0); }
}

.brand h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.5px;
  color: var(--text);
}
.brand-slash { color: var(--accent); }
.brand-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  display: none;
}
@media (min-width: 720px) { .brand-sub { display: inline; } }

.status-badge {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.5px;
}
.status-label { color: var(--text-faint); }
.status-value {
  color: var(--text-dim);
  border: 1px solid var(--border-2);
  border-radius: 4px;
  padding: 3px 8px;
  transition: color 0.3s, border-color 0.3s;
}
.status-value.ok      { color: var(--safe); border-color: var(--safe); }
.status-value.warn    { color: var(--warn); border-color: var(--warn); }
.status-value.danger  { color: var(--accent); border-color: var(--accent); }
.status-value.loading { color: var(--info); border-color: var(--info); }

/* ════════════════════════════════════════════════════════════════════
   SEISMOGRAPH — signature element
   ════════════════════════════════════════════════════════════════════ */
.seismo-wrap {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  padding: 6px 20px 4px;
  position: relative;
}
#seismograph { width: 100%; height: 78px; display: block; overflow: visible; }
.seismo-grid line { stroke: var(--border); stroke-width: 1; opacity: 0.5; }
.seismo-area { fill: url(#seismoFill); stroke: none; }
.seismo-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 4px rgba(255, 90, 54, 0.5));
  transition: d 0.4s ease;
}
.seismo-caption {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 2px 2px 4px;
}
#seismoPeak { color: var(--text-dim); }

/* ════════════════════════════════════════════════════════════════════
   LAYOUT
   ════════════════════════════════════════════════════════════════════ */
.layout {
  display: flex;
  min-height: calc(100vh - 58px - 92px - 40px);
}

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 18px 28px;
  overflow-y: auto;
}

.ctrl-section { margin-bottom: 22px; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.sidebar label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 14px;
  position: relative;
}
.sidebar label .val {
  float: right;
  font-family: var(--font-mono);
  color: var(--text);
  font-size: 11.5px;
}

.sidebar select,
.sidebar input[type="range"] {
  display: block;
  width: 100%;
  margin-top: 7px;
}

.sidebar select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 12.5px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238389A0'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.sidebar select:focus { outline: none; border-color: var(--accent); }

.sidebar input[type="range"] {
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border-2);
  outline: none;
}
.sidebar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}
.sidebar input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--bg);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.toggle-row input[type="checkbox"] { display: none; }
.toggle-track {
  width: 36px; height: 20px;
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 1px; left: 1px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.2s, background 0.2s;
}
.toggle-row input:checked + .toggle-track { background: var(--accent-dim); border-color: var(--accent); }
.toggle-row input:checked + .toggle-track::after { transform: translateX(16px); background: var(--accent); }

.hidden { display: none !important; }

.run-btn {
  width: 100%;
  background: var(--accent);
  color: #1A0A04;
  border: none;
  border-radius: var(--radius);
  padding: 13px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  margin-top: 6px;
}
.run-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(255, 90, 54, 0.35); background: #FF6F4D; }
.run-btn:active { transform: translateY(0); }
.run-btn:disabled { opacity: 0.5; cursor: wait; transform: none; box-shadow: none; }

.sidebar-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 12px;
  line-height: 1.5;
}

/* ════════════════════════════════════════════════════════════════════
   MAIN
   ════════════════════════════════════════════════════════════════════ */
.main { flex: 1; min-width: 0; padding: 18px 22px 30px; }

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 9px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-num { color: var(--text-faint); font-size: 10.5px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab.active .tab-num { color: var(--accent); }

/* ─── Ticker strip (metrics) ─── */
.ticker-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.ticker-cell {
  padding: 12px 16px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ticker-cell:last-child { border-right: none; }
.ticker-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.ticker-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.risk-cell { justify-content: center; }

.risk-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 3px 11px;
  border-radius: 14px;
  width: fit-content;
}
.risk-badge.low      { background: #052e1f; color: var(--safe); border: 1px solid #16a37766; }
.risk-badge.medium   { background: #3a2705; color: var(--warn); border: 1px solid #c8911766; }
.risk-badge.high     { background: #3a1206; color: var(--accent); border: 1px solid #ff5a3666; }
.risk-badge.critical { background: #3a0000; color: #ff3333; border: 1px solid #ff000088; }

/* ─── Shock banner ─── */
.shock-banner {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 10px 14px;
  margin-bottom: 16px;
}
.shock-banner::before { content: '> '; color: var(--accent); }

/* ─── Panels ─── */
.panels { position: relative; }
.panel { display: none; animation: fadeIn 0.25s ease; }
.panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.chart-row { display: flex; gap: 16px; align-items: flex-start; }
.plot-main {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.plot-tall { height: 560px; }

.side-stats {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.side-stats h3 {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 16px 0 8px;
}
.side-stats h3:first-child { margin-top: 0; }
.side-stats dl { margin: 0; font-size: 12px; }
.side-stats dl div { display: flex; justify-content: space-between; padding: 3px 0; color: var(--text-dim); }
.side-stats dl div span:last-child { color: var(--text); font-family: var(--font-mono); }

.communities-list { font-size: 11px; color: var(--text-dim); line-height: 1.7; }
.model-info { font-size: 11.5px; color: var(--text-dim); line-height: 1.6; font-family: var(--font-mono); }

.info-line { font-size: 12px; color: var(--text-faint); margin-top: 12px; }

h3 {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 22px 0 10px;
}

/* ─── Tables ─── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table th {
  background: var(--panel-2);
  color: var(--text-dim);
  text-align: left;
  padding: 9px 12px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
table td { padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: var(--panel-2); }
.stress-bar-cell { display: flex; align-items: center; gap: 8px; }
.stress-bar-track { width: 60px; height: 6px; background: var(--border-2); border-radius: 3px; overflow: hidden; }
.stress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--safe), var(--warn), var(--accent)); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 8px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ─── JSON expander ─── */
.json-expander {
  margin-top: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.json-expander summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}
.json-expander pre {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
  margin-top: 12px;
}

/* ─── Export ─── */
.export-row { display: flex; gap: 12px; flex-wrap: wrap; }
.export-btn {
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 9px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.export-btn:hover { background: var(--accent-dim); }

/* ════════════════════════════════════════════════════════════════════
   FOOTER
   ════════════════════════════════════════════════════════════════════ */
.footer {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  padding: 16px;
  border-top: 1px solid var(--border);
  letter-spacing: 0.3px;
}

/* ════════════════════════════════════════════════════════════════════
   LOADING OVERLAY
   ════════════════════════════════════════════════════════════════════ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 13, 18, 0.82);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.loading-overlay.active { display: flex; }
.loading-box { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
  letter-spacing: 0.4px;
}

/* ════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 980px) {
  .menu-btn { display: flex; }
  .layout { position: relative; }
  .sidebar {
    position: fixed;
    top: 58px;
    left: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,0.4);
  }
  .sidebar.open { transform: translateX(0); }
  .chart-row { flex-direction: column; }
  .side-stats { width: 100%; }
}

@media (max-width: 600px) {
  .plot-tall { height: 420px; }
  .main { padding: 14px; }
  .status-badge { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot, .loading-spinner { animation: none; }
  .panel { animation: none; }
}
