/* ═══════════════════════════════════════════════════════
   gdelt-pulse — design system
   newsroom research console: warm-dark, editorial, dense.
   ═══════════════════════════════════════════════════════ */

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Design Tokens ─────────────────────────────────────── */
:root {
  /* Backgrounds — warm dark with a hint of olive */
  --bg:         #0d0e0a;
  --bg-subtle:  #131410;
  --surface:    #181a14;
  --surface-2:  #1f2118;
  --surface-3:  #2a2c22;

  /* Borders — visible warm grays, not timid */
  --border:      #2a2c22;
  --border-hover: #3a3d2f;
  --border-active: #4f4d3f;

  /* Text — bone white instead of pure white */
  --text:   #ece8d8;
  --text-2: #b7b2a0;
  --text-3: #7b7864;
  --text-4: #4f4d3f;

  /* Accent — terminal amber */
  --accent:      #f59e0b;
  --accent-dim:  rgba(245, 158, 11, 0.08);
  --accent-text: #fbb24c;
  --accent-hot:  #c4d147;   /* lime-olive for "very high" */

  /* Semantic colors (data only, not UI chrome) */
  --positive: #84cc16;
  --negative: #e57373;
  --warning:  #f59e0b;
  --info:     #94b8d4;

  /* Entity tag tints — muted, used by search badges */
  --tag-loc:   #a3d4a0;
  --tag-theme: #d4c376;
  --tag-pers:  #c8a8d4;
  --tag-org:   #94b8d4;

  /* Category colors — re-tuned to warm palette */
  --cat-conflict:    #e57373;
  --cat-economy:     #f59e0b;
  --cat-politics:    #c8a8d4;
  --cat-health:      #84cc16;
  --cat-environment: #a3d4a0;
  --cat-technology:  #94b8d4;
  --cat-society:     #fbb24c;
  --cat-general:     #7b7864;

  /* Typography */
  --font:       'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  --font-serif: 'Newsreader', 'Iowan Old Style', Georgia, serif;

  /* Spacing scale (4px base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;
  --sp-9: 96px;
  --sp-10: 128px;

  /* Radii — sharp, almost rectangular */
  --radius-sm: 2px;
  --radius:    3px;
  --radius-lg: 4px;
  --radius-xl: 6px;
  --radius-full: 9999px;

  /* Motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --duration: 0.15s;
  --duration-lg: 0.32s;
}

/* ── Base ──────────────────────────────────────────────── */
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100vh;
  font-feature-settings: 'ss01' 1, 'ss02' 1, 'cv11' 1;
  position: relative;
}

/* Subtle grain overlay to break the flatness */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.04;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
body > * { position: relative; z-index: 2; }

::selection {
  background: rgba(245, 158, 11, 0.32);
  color: var(--text);
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

a { color: inherit; text-decoration: none; }
button { font-family: var(--font); }
img { display: block; max-width: 100%; }

/* ── Typography ────────────────────────────────────────── */
.t-display {
  font-size: clamp(2.8rem, 6vw, 4.5rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.t-h1 {
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.t-h2 {
  font-size: clamp(1.25rem, 2vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.t-h3 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.35;
}

.t-body { font-size: 0.9375rem; line-height: 1.6; }
.t-small { font-size: 0.8125rem; line-height: 1.55; }
.t-caption { font-size: 0.75rem; line-height: 1.5; }
.t-overline {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.t-num {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.t-muted { color: var(--text-2); }
.t-dim { color: var(--text-3); }

/* ── Layout ────────────────────────────────────────────── */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 var(--sp-5);
}

.container-narrow {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 var(--sp-5);
}

.container-wide {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--sp-5);
}

/* ── Navigation / Topbar ───────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 var(--sp-5);
  background: rgba(9, 9, 11, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: background var(--duration) var(--ease);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 600;
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.topbar-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-left: auto;
}

.topbar-link {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 450;
  color: var(--text-3);
  transition: color var(--duration), background var(--duration);
  cursor: pointer;
  border: none;
  background: none;
  text-decoration: none;
}

.topbar-link:hover { color: var(--text); }
.topbar-link.active {
  color: var(--text);
  background: var(--surface);
}

/* Back button for subpages */
.topbar-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 450;
  color: var(--text-3);
  cursor: pointer;
  border: none;
  background: none;
  transition: color var(--duration);
  text-decoration: none;
}
.topbar-back:hover { color: var(--text); }
.topbar-back svg { width: 14px; height: 14px; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-2);
  background: transparent;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
}

.btn:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--surface);
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.35; pointer-events: none; }

.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.btn-primary:hover {
  background: var(--text-2);
  border-color: var(--text-2);
  color: var(--bg);
}

.btn-sm { padding: 7px 14px; font-size: 0.8125rem; }
.btn-lg { padding: 14px 28px; font-size: 0.9375rem; }
.btn-icon { padding: 8px; }

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  transition: border-color var(--duration) var(--ease), background var(--duration) var(--ease);
}

.card:hover {
  border-color: var(--border-hover);
}

.card-interactive {
  cursor: pointer;
}
.card-interactive:hover {
  border-color: var(--border-active);
  background: var(--surface-2);
}

/* ── Stat cards ────────────────────────────────────────── */
.stat-grid {
  display: grid;
  gap: var(--sp-3);
}

.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stat-grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5) var(--sp-4);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  margin-bottom: 2px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-3);
  font-weight: 450;
}

/* ── Tags / Badges ─────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.badge-accent {
  background: var(--accent-dim);
  color: var(--accent-text);
  border-color: rgba(139, 139, 245, 0.12);
}

.tag {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.6875rem;
  font-weight: 500;
}

.tag-loc { color: var(--positive); background: rgba(52, 211, 153, 0.08); }
.tag-per { color: var(--warning); background: rgba(251, 191, 36, 0.08); }
.tag-org { color: var(--negative); background: rgba(248, 113, 113, 0.08); }

/* ── Inputs ────────────────────────────────────────────── */
.input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--duration), box-shadow var(--duration);
}

.input:focus {
  border-color: var(--border-active);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.03);
}

.input::placeholder { color: var(--text-3); }

.input-lg {
  padding: 14px 18px;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

/* Range slider */
input[type="range"] {
  accent-color: var(--text-2);
  height: 4px;
}

/* Select */
.select {
  padding: 8px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.8125rem;
  font-family: var(--font);
  outline: none;
  cursor: pointer;
}
.select:focus { border-color: var(--border-active); }

/* ── Tables ────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}

.table tr:last-child td { border-bottom: none; }

.table tr:hover td { background: var(--surface-2); }

.table th.sortable { cursor: pointer; }
.table th.sortable:hover { color: var(--text-2); }
.table th.sorted { color: var(--text); }

/* ── Modal / Overlay ───────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}

.overlay.open {
  display: flex;
  animation: fadeIn 0.15s var(--ease-out);
}

.modal {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 700px;
  max-height: 80vh;
  overflow-y: auto;
  padding: var(--sp-6);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  animation: modalIn 0.2s var(--ease);
}

.modal::-webkit-scrollbar { width: 4px; }
.modal::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

.modal-close {
  float: right;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-3);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration);
}
.modal-close:hover { color: var(--text); border-color: var(--border-hover); }

/* ── Loading States ────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-5);
  color: var(--text-3);
  font-size: 0.875rem;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--text-3);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.empty {
  text-align: center;
  padding: var(--sp-8) var(--sp-5);
  color: var(--text-3);
  font-size: 0.875rem;
}

/* ── Divider ───────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-6) 0;
}

/* ── Page intro (hero) for subpages ────────────────────── */
.page-intro {
  text-align: center;
  padding: var(--sp-10) var(--sp-5) var(--sp-7);
}

.page-intro h1 {
  font-size: clamp(1.75rem, 3.5vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: var(--sp-3);
}

.page-intro p {
  font-size: 0.9375rem;
  color: var(--text-3);
  max-width: 480px;
  margin: 0 auto;
}

/* ── Tooltip ───────────────────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  color: var(--text-2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  max-width: 280px;
}

/* ── Two-column layout ─────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-5);
}

/* ── Chart section ─────────────────────────────────────── */
.chart-section {
  margin-bottom: var(--sp-6);
}

.chart-section h3 {
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  margin-bottom: var(--sp-2);
}

.chart-section .chart-sub {
  font-size: 0.75rem;
  color: var(--text-3);
  margin-bottom: var(--sp-4);
}

.chart-container {
  position: relative;
  height: 320px;
}

.chart-container.tall { height: 400px; }

/* ── Animations ────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.animate-in {
  animation: slideUp 0.5s var(--ease) both;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
  .stat-grid-3, .stat-grid-4 { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .topbar-nav { display: none; }
  .page-intro { padding: var(--sp-8) var(--sp-4) var(--sp-6); }
  .container, .container-narrow { padding: 0 var(--sp-4); }
}

@media (max-width: 480px) {
  .stat-grid-3, .stat-grid-4 { grid-template-columns: 1fr; }
}
