:root {
  --bg-primary: #040d15;
  --bg-secondary: #071522;
  --bg-card: #0f1c2a;
  --bg-hover: #15283a;
  --border: rgba(243, 239, 228, 0.16);
  --text-primary: #f3efe4;
  --text-secondary: #ded8ca;
  --text-muted: #a9a496;
  --accent: #d7b46a;
  --accent-hover: #e7c882;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #77b8cf;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-sans: Inter, 'Helvetica Neue', Arial, ui-sans-serif, system-ui, sans-serif;
  --font-serif: 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --radius: 2px;
  --shadow: 0 2rem 5rem rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at 76% 10%, rgba(215, 180, 106, 0.08), transparent 25rem),
    linear-gradient(145deg, var(--bg-primary), #071522 58%, #0b2133);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
a:focus-visible, button:focus-visible { outline: 3px solid var(--accent-hover); outline-offset: 3px; }

.header {
  background: rgba(4, 13, 21, 0.94);
  border-bottom: 1px solid var(--border);
  padding: 0.8rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-brand h1 {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text-primary);
}

.brand-mark {
  width: 42px;
  height: 42px;
  object-fit: contain;
  flex: 0 0 auto;
}

.header-brand .logo {
  min-width: 36px;
  height: 28px;
  border: 1px solid var(--accent);
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  padding: 0 0.4rem;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  color: var(--accent);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.header-meta .live-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

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

.nav-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
}

.nav-tab {
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  background: transparent;
  font: inherit;
  transition: all 0.2s;
}

.nav-tab:hover { color: var(--text-primary); }
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.main { padding: 2rem; max-width: 1600px; margin: 0 auto; overflow-x: hidden; }

.grid { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-map { grid-template-columns: 1fr 380px; align-items: start; min-width: 0; }
.grid-map > div:first-child { min-width: 0; overflow: hidden; }

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

.card {
  background: rgba(15, 28, 42, 0.86);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  overflow-x: auto;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

@media (max-width: 768px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: linear-gradient(145deg, rgba(15, 28, 42, 0.96), rgba(7, 21, 34, 0.9));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-hover);
  font-family: var(--font-mono);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.stat-delta {
  font-size: 0.75rem;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
}

.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }
.stat-delta.neutral { color: var(--text-muted); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.6875rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-info { background: rgba(6,182,212,0.15); color: var(--info); }

.map-container {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 500px;
  position: relative;
  overflow: hidden;
  width: 100%;
}

.map-container svg { width: 100%; height: 100%; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child { border-bottom: none; }

.list-item-title { font-size: 0.875rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.list-item-meta { font-size: 0.75rem; color: var(--text-muted); }

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

.data-table th {
  text-align: left;
  padding: 0.625rem 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid rgba(45,55,72,0.5);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tr:hover td { background: var(--bg-hover); }

.score-bar {
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
  flex: 1;
  min-width: 80px;
}

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.score-high { background: var(--danger); }
.score-medium { background: var(--warning); }
.score-low { background: var(--success); }

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

.chart-container svg { width: 100%; height: 100%; }
.chart-empty { display: grid; height: 100%; place-items: center; color: var(--text-muted); font-family: var(--font-mono); font-size: 0.75rem; }

.footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

.footer p:first-child { color: var(--text-secondary); font-family: var(--font-serif); font-size: 0.9rem; }
.footer a { text-decoration: underline; text-underline-offset: 0.2em; }

.tag-source {
  font-size: 0.625rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  background: var(--bg-primary);
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}

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

.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.8125rem;
  margin-bottom: 1rem;
  border-left: 3px solid;
}

.alert-info { background: rgba(6,182,212,0.1); border-color: var(--info); }
.alert-warning { background: rgba(245,158,11,0.1); border-color: var(--warning); }
.alert-danger { background: rgba(239,68,68,0.1); border-color: var(--danger); }

.axis text { fill: var(--text-muted); font-size: 10px; }
.axis path, .axis line { stroke: var(--border); }

.tooltip {
  position: absolute;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  font-size: 0.75rem;
  pointer-events: none;
  z-index: 1000;
  box-shadow: var(--shadow);
  max-width: 250px;
}

.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 1001; padding: 0.75rem 1rem; color: var(--bg-primary); background: var(--accent-hover); }
.skip-link:focus { top: 1rem; }

@media (max-width: 720px) {
  .header { position: static; padding: 0.8rem 1rem; align-items: flex-start; }
  .header-meta { gap: 0.6rem; flex-wrap: wrap; justify-content: flex-end; }
  .header-meta span:nth-of-type(2) { display: none; }
  .nav-tabs { padding: 0 0.5rem; overflow-x: auto; }
  .nav-tab { padding: 0.7rem 0.9rem; white-space: nowrap; }
  .main { padding: 1rem; }
  .card { padding: 1rem; }
}

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