/* ========================
   DESIGN TOKENS
   ======================== */
:root,
[data-theme='light'] {
  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-surface-2: #f8f9fa;
  --color-surface-offset: #e8ecf0;
  --color-border: #d1d8e0;
  --color-divider: #dde2e8;
  --color-text: #1a2332;
  --color-text-muted: #5a6a7a;
  --color-text-faint: #9aabb8;
  --color-primary: #0099aa;
  --color-primary-hover: #007a8a;
  --color-accent: #00b4c8;

  /* Status colors */
  --color-crit: #ef4444;
  --color-high: #f97316;
  --color-stan: #eab308;
  --color-green: #22c55e;
  --color-blue: #3b82f6;
  --color-purple: #a855f7;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --font-display: 'Cabinet Grotesk', 'Helvetica Neue', sans-serif;
  --font-body: 'Satoshi', 'Inter', sans-serif;

  --sidebar-width: 220px;
}

[data-theme='dark'] {
  --color-bg: #0a0e14;
  --color-surface: #111720;
  --color-surface-2: #161d28;
  --color-surface-offset: #1a2230;
  --color-border: #1f2d3d;
  --color-divider: #192030;
  --color-text: #c8d8e8;
  --color-text-muted: #6a8099;
  --color-text-faint: #3a5066;
  --color-primary: #00b4c8;
  --color-primary-hover: #00d4ec;
  --color-accent: #00cce0;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #0a0e14;
    --color-surface: #111720;
    --color-surface-2: #161d28;
    --color-surface-offset: #1a2230;
    --color-border: #1f2d3d;
    --color-divider: #192030;
    --color-text: #c8d8e8;
    --color-text-muted: #6a8099;
    --color-text-faint: #3a5066;
    --color-primary: #00b4c8;
    --color-primary-hover: #00d4ec;
    --color-accent: #00cce0;
  }
}

/* ========================
   RESET & BASE
   ======================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }

/* ========================
   DASHBOARD LAYOUT
   ======================== */
.dashboard {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100dvh;
  overflow: hidden;
}

/* ========================
   SIDEBAR
   ======================== */
.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 14px;
  border-bottom: 1px solid var(--color-divider);
}

.logo-mark { flex-shrink: 0; border-radius: 6px; }

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1;
  min-width: 0;
}
.logo-name {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--color-text);
  line-height: 1.1;
}
.logo-sub {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  line-height: 1;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--color-crit);
  background: rgba(239,68,68,0.1);
  padding: 3px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-crit);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* Nav */
.sidebar-nav {
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: all var(--transition);
}
.nav-item:hover { background: var(--color-surface-offset); color: var(--color-text); }
.nav-item.active { background: rgba(0,180,200,0.12); color: var(--color-primary); }
.nav-item svg { flex-shrink: 0; }

/* Section labels */
.sidebar-section-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--color-text-faint);
  padding: 12px 14px 4px;
}

/* Status cards */
.status-cards {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 10px 8px;
}
.status-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}
.status-label { font-size: 11px; color: var(--color-text-muted); }
.status-value { font-size: 11px; font-weight: 700; color: var(--color-text); font-variant-numeric: tabular-nums; }
.status-elevated { color: var(--color-stan); }

/* Region list */
.region-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 10px 12px;
}
.region-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
}
.region-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.dot-red { background: var(--color-crit); }
.dot-yellow { background: var(--color-stan); }
.dot-green { background: var(--color-green); }
.dot-blue { background: var(--color-blue); }
.region-tag {
  margin-left: auto;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--color-text-faint);
  background: var(--color-surface-offset);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Footer */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid var(--color-divider);
  display: flex;
  align-items: center;
  gap: 8px;
}
.theme-btn {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: all var(--transition);
}
.theme-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }
.footer-text { font-size: 11px; color: var(--color-text-faint); }

/* ========================
   MAIN CONTENT
   ======================== */
.main-content {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--color-bg);
}

/* ========================
   TOPBAR
   ======================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 5;
  gap: 16px;
  flex-shrink: 0;
}
.topbar-left { display: flex; flex-direction: column; gap: 1px; }
.page-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -0.01em;
}
.page-sub { font-size: 11px; color: var(--color-text-muted); letter-spacing: 0.03em; }

.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.threat-indicator { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.threat-label { font-size: 9px; font-weight: 600; letter-spacing: 0.1em; color: var(--color-text-faint); }
.threat-value {
  font-size: 12px; font-weight: 800; letter-spacing: 0.08em; padding: 2px 8px; border-radius: 4px;
}
.threat-high { background: rgba(239,68,68,0.15); color: var(--color-crit); }
.threat-elevated { background: rgba(234,179,8,0.15); color: var(--color-stan); }

.coord-display {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-faint);
  font-family: var(--font-body);
  white-space: nowrap;
  letter-spacing: 0;
}

.btn-refresh {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  padding: 6px 12px; border-radius: var(--radius-sm);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  transition: all var(--transition);
}
.btn-refresh:hover { background: var(--color-primary); color: white; border-color: var(--color-primary); }

/* ========================
   KPI ROW
   ======================== */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 14px 20px;
  flex-shrink: 0;
}
.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--color-text-muted); }
.kpi-value {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  color: var(--color-text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kpi-alert { color: var(--color-crit); }
.kpi-delta { font-size: 10px; font-weight: 500; color: var(--color-text-faint); }
.delta-up { color: var(--color-crit); }
.delta-down { color: var(--color-green); }
.delta-neutral { color: var(--color-text-faint); }

/* ========================
   CONTENT SPLIT
   ======================== */
.content-split {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 10px;
  padding: 0 20px;
  flex-shrink: 0;
  height: 440px;
}

/* ========================
   MAP PANEL
   ======================== */
.map-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.map-container {
  flex: 1;
  min-height: 0;
}
.map-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  font-size: 10px;
  color: var(--color-text-faint);
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface-2);
}
.map-footer a { color: var(--color-primary); }

/* Leaflet dark override */
[data-theme='dark'] .leaflet-container {
  background: #0d1520;
}
[data-theme='dark'] .leaflet-tile {
  filter: brightness(0.65) saturate(0.5) hue-rotate(180deg) invert(1);
}
.leaflet-popup-content-wrapper {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
  font-family: var(--font-body) !important;
  font-size: 12px !important;
}
.leaflet-popup-tip { background: var(--color-surface) !important; }

/* Map legend */
.map-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  padding: 0 8px;
}
.legend-item {
  display: flex; align-items: center; gap: 4px;
  font-size: 10px; color: var(--color-text-muted);
}
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ========================
   PANEL HEADER (shared)
   ======================== */
.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
}
.panel-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--color-text);
  text-transform: uppercase;
  white-space: nowrap;
}
.btn-external {
  margin-left: auto;
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; color: var(--color-primary);
  padding: 3px 8px; border-radius: 4px;
  border: 1px solid rgba(0,180,200,0.3);
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-external:hover { background: rgba(0,180,200,0.1); }

/* ========================
   INTEL FEED
   ======================== */
.feed-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.feed-filters { display: flex; gap: 4px; }
.filter-btn {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  padding: 3px 7px; border-radius: 4px;
  color: var(--color-text-faint);
  border: 1px solid transparent;
  transition: all var(--transition);
}
.filter-btn:hover { color: var(--color-text); background: var(--color-surface-offset); }
.filter-btn.active { background: rgba(0,180,200,0.15); color: var(--color-primary); border-color: rgba(0,180,200,0.25); }

.feed-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 4px;
}

.feed-item {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-divider);
  transition: background var(--transition);
  cursor: default;
}
.feed-item:hover { background: var(--color-surface-2); }
.feed-item:last-child { border-bottom: none; }

.feed-severity {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 2px 5px;
  border-radius: 3px;
  flex-shrink: 0;
  height: fit-content;
  margin-top: 1px;
}
.sev-crit { background: rgba(239,68,68,0.15); color: var(--color-crit); }
.sev-high { background: rgba(249,115,22,0.15); color: var(--color-high); }
.sev-stan { background: rgba(234,179,8,0.15); color: var(--color-stan); }
.sev-info { background: rgba(59,130,246,0.15); color: var(--color-blue); }

.feed-body { flex: 1; min-width: 0; }
.feed-headline {
  font-size: 12px; font-weight: 600; color: var(--color-text);
  line-height: 1.35; margin-bottom: 3px;
}
.feed-meta {
  font-size: 10px; color: var(--color-text-faint);
  display: flex; gap: 6px;
}
.feed-location { color: var(--color-primary); font-weight: 600; }

/* ========================
   NEWS SECTION
   ======================== */
.news-section {
  margin: 10px 20px 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.feed-note { font-size: 10px; color: var(--color-text-faint); margin-left: auto; }
.news-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
}
.news-card {
  padding: 14px 16px;
  border-right: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
  transition: background var(--transition);
  cursor: pointer;
}
.news-card:nth-child(3n) { border-right: none; }
.news-card:hover { background: var(--color-surface-2); }
.news-source {
  font-size: 9px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--color-primary); margin-bottom: 4px;
  text-transform: uppercase;
}
.news-headline {
  font-size: 12px; font-weight: 600; color: var(--color-text);
  line-height: 1.4; margin-bottom: 5px;
}
.news-time { font-size: 10px; color: var(--color-text-faint); }

/* Skeleton loader */
.skeleton {
  min-height: 80px;
  background: linear-gradient(90deg, var(--color-surface-offset) 25%, var(--color-surface-2) 50%, var(--color-surface-offset) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
  .content-split { grid-template-columns: 1fr; height: auto; }
  .content-split .map-panel { height: 420px; }
  .content-split .feed-panel { height: 400px; }
  .news-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { display: none; }
  .dashboard { grid-template-columns: 1fr; }
  .main-content { overflow-y: auto; }
  html, body { overflow: auto; height: auto; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); padding: 10px 12px; gap: 8px; }
  .content-split { grid-template-columns: 1fr; height: auto; padding: 0 12px; }
  .content-split .map-panel { height: 380px; }
  .content-split .feed-panel { height: 380px; margin-top: 10px; }
  .news-section { margin: 10px 12px 20px; }
  .news-grid { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .page-title { font-size: 13px; }
  .topbar-right { gap: 8px; }
  .coord-display { display: none; }
  .map-legend { display: none; }
  .kpi-value { font-size: 20px; }
}
