/* ========================================
   Federal Workforce Dependency Map
   Design: Dark-first analytical dashboard
   Palette: Navy/slate + amber accent (gov/fiscal analysis)
   ======================================== */

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

:root, [data-theme="light"] {
  --color-bg: #f5f4f0;
  --color-surface: #ffffff;
  --color-surface-2: #fafaf8;
  --color-border: #d5d3cd;
  --color-divider: #e2e0db;
  --color-text: #1a1a1a;
  --color-text-muted: #6b6b66;
  --color-text-faint: #a3a29d;
  --color-primary: #1b3a5c;
  --color-primary-hover: #14304d;
  --color-accent: #c47a1a;
  --color-accent-light: #f0d9a8;
  --color-negative: #a13544;
  --color-positive: #2d7a3a;
  --color-positive-light: #d4ecd8;
  --color-negative-light: #f2d4d8;
  --color-map-low: #dce8f4;
  --color-map-high: #1b3a5c;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --font-body: 'General Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;
  --radius: 6px;
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  --color-bg: #0d1117;
  --color-surface: #161b22;
  --color-surface-2: #1c2129;
  --color-border: #2d333b;
  --color-divider: #21262d;
  --color-text: #d0d3d8;
  --color-text-muted: #848d97;
  --color-text-faint: #545d68;
  --color-primary: #6ba3d6;
  --color-primary-hover: #8fbce4;
  --color-accent: #e8a838;
  --color-accent-light: #3d2e12;
  --color-negative: #f47067;
  --color-positive: #57ab5a;
  --color-positive-light: #1a2e1c;
  --color-negative-light: #3d1f24;
  --color-map-low: #0d2137;
  --color-map-high: #6ba3d6;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo { color: var(--color-accent); flex-shrink: 0; }
.app-header h1 {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.header-subtitle {
  font-size: 11px;
  color: var(--color-text-muted);
  font-weight: 400;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-border);
}
[data-theme-toggle] {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition);
  background: none;
  border: none;
}
[data-theme-toggle]:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

/* ---- Main ---- */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

/* ---- KPI Strip ---- */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 20px;
}
.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kpi-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  line-height: 1.2;
  font-variant-numeric: tabular-nums lining-nums;
}
.kpi-negative { color: var(--color-negative); }
.kpi-positive { color: var(--color-positive); }
.kpi-sub {
  font-size: 11px;
  color: var(--color-text-faint);
}

/* ---- Controls Bar ---- */
.controls-bar {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.control-group label {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.control-group select {
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23848d97' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  min-width: 180px;
  transition: border-color var(--transition);
}
.control-group select:hover,
.control-group select:focus {
  border-color: var(--color-primary);
  outline: none;
}

/* ---- Map Layout ---- */
.map-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  margin-top: 16px;
}
.map-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
}
.map-svg-wrap {
  width: 100%;
  aspect-ratio: 1.6;
  position: relative;
}
.map-svg-wrap svg {
  width: 100%;
  height: 100%;
}

/* Map paths */
.state-path {
  stroke: var(--color-border);
  stroke-width: 0.5;
  cursor: pointer;
  transition: opacity 0.15s, stroke-width 0.15s;
}
.state-path:hover {
  stroke: var(--color-text);
  stroke-width: 1.5;
  opacity: 0.85;
}
.state-path.active {
  stroke: var(--color-accent);
  stroke-width: 2;
}
.state-path.dimmed {
  opacity: 0.25;
}

/* Legend */
.legend-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-divider);
}
.legend-gradient {
  flex: 1;
  height: 8px;
  border-radius: 4px;
}
.legend-label {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ---- Detail Panel ---- */
.detail-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 260px);
  position: sticky;
  top: 72px;
}
.panel-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  gap: 12px;
  color: var(--color-text-faint);
  text-align: center;
  font-size: 13px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}
.panel-header h2 {
  font-size: 17px;
  font-weight: 600;
}
.panel-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.badge-high {
  background: var(--color-negative-light);
  color: var(--color-negative);
}
.badge-medium {
  background: var(--color-accent-light);
  color: var(--color-accent);
}
.badge-low {
  background: var(--color-positive-light);
  color: var(--color-positive);
}

.panel-section {
  padding: 12px 0;
  border-top: 1px solid var(--color-divider);
}
.panel-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.panel-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.panel-stat.full-width { grid-column: 1 / -1; }
.stat-value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  font-variant-numeric: tabular-nums lining-nums;
}
.stat-label {
  font-size: 11px;
  color: var(--color-text-muted);
}
.stat-negative { color: var(--color-negative); }
.stat-positive { color: var(--color-positive); }

/* Agency bars */
.agency-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.agency-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}
.agency-name {
  width: 100px;
  flex-shrink: 0;
  color: var(--color-text-muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agency-bar-wrap {
  flex: 1;
  height: 14px;
  background: var(--color-divider);
  border-radius: 3px;
  overflow: hidden;
}
.agency-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.agency-bar-val {
  width: 50px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text-muted);
}
.panel-note {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 8px;
  line-height: 1.5;
  font-style: italic;
}

/* ---- Data Table ---- */
.table-section {
  margin-top: 32px;
}
.table-header-bar {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}
.table-header-bar h2 {
  font-size: 15px;
  font-weight: 600;
}
.table-count {
  font-size: 12px;
  color: var(--color-text-muted);
}
.table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow-x: auto;
}
#data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
#data-table th {
  background: var(--color-surface-2);
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
#data-table th.num { text-align: right; }
#data-table th:hover { color: var(--color-text); }
#data-table th.sorted-asc::after { content: " ▲"; font-size: 9px; }
#data-table th.sorted-desc::after { content: " ▼"; font-size: 9px; }
#data-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--color-divider);
}
#data-table td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 12px;
}
#data-table tbody tr {
  cursor: pointer;
  transition: background var(--transition);
}
#data-table tbody tr:hover {
  background: var(--color-surface-2);
}
#data-table tbody tr.row-highlight {
  background: color-mix(in srgb, var(--color-accent) 10%, transparent);
}

/* ---- Tooltip ---- */
.tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 999;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  font-size: 12px;
  line-height: 1.5;
  max-width: 260px;
  opacity: 0;
  transition: opacity 0.12s;
}
.tooltip.visible { opacity: 1; }
.tooltip-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}
.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}
.tooltip-label { color: var(--color-text-muted); }
.tooltip-val {
  font-family: var(--font-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums lining-nums;
}

/* ---- Footer ---- */
.app-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--color-divider);
}
.source-block h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}
.source-block p {
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.7;
  max-width: 90ch;
}
.footer-note {
  margin-top: 16px;
  font-size: 12px;
  color: var(--color-text-faint);
  font-style: italic;
  max-width: 90ch;
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .map-layout {
    grid-template-columns: 1fr;
  }
  .detail-panel {
    position: static;
    max-height: none;
  }
  .kpi-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .kpi-strip {
    grid-template-columns: 1fr;
  }
  .controls-bar {
    flex-direction: column;
  }
  .control-group select {
    min-width: 100%;
  }
  .app-main {
    padding: 0 12px 32px;
  }
  #download-csv span { display: none; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
