/* -------------------------------------------------------------------------
 * AI Labor Displacement Dashboard — Stylesheet
 * Clean, minimal, responsive.  Dark text on light background.
 * ------------------------------------------------------------------------- */

:root {
  --bg: #f7f8fa;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e0e3e8;
  --accent: #4a6fa5;
  --accent-light: #e8f0fa;
  --accent-dark: #3a5a8a;
  --trend-up: #2e7d32;
  --trend-down: #c62828;
  --trend-flat: #757575;
  --conf-measured: #2e7d32;
  --conf-extracted: #f57f17;
  --conf-unknown: #999;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #c62828;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-hover: 0 2px 8px rgba(0,0,0,0.12);
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===========================  Navbar  =================================== */

.navbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  white-space: nowrap;
}
.navbar a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
.navbar a:hover {
  background: var(--accent-light);
  color: var(--accent);
}
.navbar a.active {
  color: var(--accent);
  font-weight: 600;
}

/* ===========================  Layout  =================================== */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}
.page-header {
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}
.page-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}
.section-header {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 2rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}
.section-header:first-child {
  margin-top: 0;
}

/* ========================  Scenario hero  =============================== */

.scenario-hero {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 2rem;
}
.hero-title {
  font-size: 1.25rem;
  font-weight: 700;
}
.hero-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.scenario-bars {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.scenario-bar-row {}
.scenario-bar-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.scenario-name {
  font-weight: 600;
  font-size: 0.9rem;
}
.scenario-pct {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.95rem;
}
.scenario-bar-track {
  width: 100%;
  height: 24px;
  background: #eef0f4;
  border-radius: 4px;
  overflow: hidden;
}
.scenario-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #6a8fc5);
  border-radius: 4px;
  transition: width 0.6s ease;
}
.scenario-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.triggered-section {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
.triggered-section h3 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}
.triggered-list {
  list-style: none;
}
.triggered-item {
  padding: 0.75rem;
  background: #fafbfc;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--accent);
}
.triggered-item-head {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 4px;
}
.triggered-indicator {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
}
.triggered-name {
  font-size: 0.85rem;
}
.triggered-item-body {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.triggered-explanation {
  font-size: 0.8rem;
  color: var(--text);
}
.no-triggered {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* ==========================  Card grid  ================================= */

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

/* ============================  Cards  =================================== */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  transition: box-shadow 0.15s;
}
.card:hover {
  box-shadow: var(--shadow-hover);
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.metric-id {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
}
.card-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.card-value {
  font-size: 1.5rem;
  font-weight: 700;
}
.trend {
  font-size: 1rem;
}
.trend-up   { color: var(--trend-up); }
.trend-down { color: var(--trend-down); }
.trend-flat { color: var(--trend-flat); }

.card-sparkline {
  width: 100%;
  height: 32px;
  margin: 4px 0;
}
.card-read {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.card-as-of {
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 4px;
  margin-top: auto;
}

/* =======================  Confidence icons  ============================= */

.conf {
  font-size: 0.85rem;
  font-weight: 700;
  cursor: help;
}
.conf-measured  { color: var(--conf-measured); }
.conf-extracted { color: var(--conf-extracted); }
.conf-unknown   { color: var(--conf-unknown); }

/* =========================  Error banner  =============================== */

.error-banner {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* =======================  Metro explorer  =============================== */

.metro-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.metro-controls label {
  font-size: 0.85rem;
  font-weight: 600;
}
.metro-controls select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
}

table.metro-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table.metro-table th {
  background: #f0f2f5;
  text-align: left;
  padding: 0.6rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
table.metro-table th:hover {
  background: #e8ebef;
}
table.metro-table th.sorted-asc::after  { content: ' \25B2'; }
table.metro-table th.sorted-desc::after { content: ' \25BC'; }
table.metro-table td {
  padding: 0.55rem 0.8rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
table.metro-table tr {
  cursor: pointer;
  transition: background 0.1s;
}
table.metro-table tr:hover {
  background: #f7f8fa;
}
table.metro-table .metro-name-cell {
  font-weight: 600;
}

/* Shading classes for choropleth-like background tinting */
.shade-0 { background: #ffffff; }
.shade-1 { background: #eef4fb; }
.shade-2 { background: #d4e4f4; }
.shade-3 { background: #a8c8e6; }
.shade-4 { background: #6a98cf; }
.shade-5 { background: #4a6fa5; color: #fff; }

/* ===========================  Modal  ==================================== */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  max-width: 700px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 1.5rem;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.modal-header h2 {
  font-size: 1.2rem;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
}
.modal-close:hover {
  color: var(--text);
}
.modal-body {}
.modal-metric-row {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.modal-metric-row:last-child {
  border-bottom: none;
}
.modal-metric-name {
  color: var(--text-muted);
}
.modal-metric-value {
  font-weight: 600;
}
.modal-loading, .modal-no-data {
  color: var(--text-muted);
  font-style: italic;
  padding: 1rem 0;
}

/* ========================  Community page  ============================== */

.community-input {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  align-items: center;
}
.community-input label {
  font-size: 0.9rem;
  font-weight: 600;
}
.community-input input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
  width: 140px;
}
.community-input input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}
.community-input button {
  padding: 0.5rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.community-input button:hover {
  background: var(--accent-dark);
}
.community-input button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.community-header {
  margin-bottom: 1.5rem;
}
.community-copy {
  font-size: 1rem;
}
.community-split {
  font-size: 0.85rem;
  color: var(--conf-extracted);
  font-style: italic;
  margin-top: 0.25rem;
}

.community-grid {
  grid-template-columns: repeat(3, 1fr);
}
.community-card h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}
.geo-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--accent);
}
.cadence-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  font-style: italic;
}
.community-metrics {}
.community-metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  gap: 0.5rem;
}
.community-metric-row:last-child {
  border-bottom: none;
}
.cm-name {
  color: var(--text-muted);
  flex: 1;
}
.cm-value {
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}
.loading, .no-data {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}
.no-data-inline {
  color: var(--text-muted);
}

/* =======================  Responsive  =================================== */

@media (max-width: 1024px) and (min-width: 769px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .card-grid,
  .community-grid {
    grid-template-columns: 1fr;
  }
  .container {
    padding: 1rem;
  }
  .navbar {
    padding: 0 1rem;
    gap: 0.75rem;
    overflow-x: auto;
  }
  .navbar a {
    font-size: 0.8rem;
    padding: 0.4rem 0.5rem;
    white-space: nowrap;
  }
  .scenario-hero {
    padding: 1rem;
  }
  table.metro-table {
    font-size: 0.75rem;
  }
  table.metro-table th,
  table.metro-table td {
    padding: 0.4rem 0.5rem;
  }
  .card-value {
    font-size: 1.25rem;
  }
  .community-input input {
    width: 120px;
  }
}