/* Claims of Musk — chart chrome per dataviz reference palette */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;      /* chart surface */
  --page: #f9f9f7;           /* page plane */
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --status-critical: #d03b3b;   /* overdue / late slip bar */
  --status-good: #0ca30c;       /* delivered early */
  --success-text: #006300;
  --runway: #c3c2b7;            /* claim → promised connector */
  --pending: #898781;
  --hover-wash: rgba(11, 11, 11, 0.04);
  --today-line: #52514e;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --status-critical: #d03b3b;
    --status-good: #0ca30c;
    --success-text: #0ca30c;
    --runway: #52514e;
    --pending: #898781;
    --hover-wash: rgba(255, 255, 255, 0.05);
    --today-line: #c3c2b7;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --status-critical: #d03b3b;
  --status-good: #0ca30c;
  --success-text: #0ca30c;
  --runway: #52514e;
  --pending: #898781;
  --hover-wash: rgba(255, 255, 255, 0.05);
  --today-line: #c3c2b7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

/* ---------- header ---------- */

.site-header {
  padding: 28px 32px 16px;
  max-width: 1400px;
  margin: 0 auto;
}

.header-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 6px 0 0;
  color: var(--text-secondary);
  max-width: 640px;
}

.theme-toggle {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 18px;
  width: 38px;
  height: 38px;
  cursor: pointer;
}
.theme-toggle:hover { background: var(--hover-wash); }

/* ---------- stat tiles ---------- */

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  min-width: 140px;
  flex: 0 1 auto;
}

.stat-tile .stat-label {
  color: var(--text-secondary);
  font-size: 12px;
}

.stat-tile .stat-value {
  font-size: 26px;
  font-weight: 600;
  margin-top: 2px;
}

.stat-tile .stat-value.bad { color: var(--status-critical); }
.stat-tile .stat-value.good { color: var(--success-text); }

.stat-tile.stat-link { cursor: pointer; }
.stat-tile.stat-link:hover,
.stat-tile.stat-link:focus-visible {
  background: var(--hover-wash);
  border-color: var(--text-secondary);
}

/* ---------- controls ---------- */

.controls-row {
  max-width: 1400px;
  margin: 8px auto 0;
  padding: 8px 32px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.filter-chip:hover { background: var(--hover-wash); }
.filter-chip[aria-pressed="true"] {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  font-weight: 600;
}

.sort-group { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.sort-label { color: var(--text-muted); font-size: 12.5px; }

select, .table-toggle {
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.table-toggle[aria-pressed="true"] {
  border-color: var(--text-secondary);
  font-weight: 600;
}

/* ---------- legend ---------- */

.legend-row {
  max-width: 1400px;
  margin: 0 auto;
  padding: 4px 32px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  color: var(--text-secondary);
  font-size: 12.5px;
  align-items: center;
}

.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-swatch { display: inline-block; }

/* ---------- chart ---------- */

main {
  max-width: 1400px;
  margin: 0 auto 40px;
  padding: 0 32px;
}

.chart-container {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  /* clip (not hidden) so the sticky axis can pin to the viewport */
  overflow: clip;
}

.axis-sticky {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface-1);
  border-bottom: 1px solid var(--gridline);
}

.axis-sticky svg { display: block; }

.chart-body { position: relative; }
.chart-body svg { display: block; }

.row-label-text {
  fill: var(--text-primary);
  font-size: 12.5px;
}
.row-sublabel-text {
  fill: var(--text-muted);
  font-size: 10.5px;
}

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 340px;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  padding: 10px 12px;
  font-size: 12.5px;
  pointer-events: none;
}

.tooltip .tt-label { font-weight: 600; font-size: 13px; }
.tooltip .tt-quote {
  color: var(--text-secondary);
  font-style: italic;
  margin: 6px 0;
}
.tooltip .tt-dates { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin-top: 6px; }
.tooltip .tt-dates dt { color: var(--text-muted); }
.tooltip .tt-dates dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .tt-slip { margin-top: 6px; font-weight: 600; }
.tooltip .tt-slip.bad { color: var(--status-critical); }
.tooltip .tt-slip.good { color: var(--success-text); }
.tooltip .tt-hint { margin-top: 6px; color: var(--text-muted); font-size: 11px; }

/* ---------- detail panel ---------- */

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 92vw);
  z-index: 60;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.18);
  padding: 22px 24px;
  overflow-y: auto;
}

.detail-panel .dp-close {
  /* fixed, not absolute: stays reachable when the panel content scrolls */
  position: fixed;
  top: 14px;
  right: 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 20px;
  line-height: 1;
  width: 30px;
  height: 30px;
  cursor: pointer;
}
.detail-panel .dp-close:hover { background: var(--hover-wash); }

.detail-panel h2 { margin: 0 40px 4px 0; font-size: 18px; }
.detail-panel .dp-category { color: var(--text-muted); font-size: 12px; }
.detail-panel blockquote {
  margin: 14px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--baseline);
  color: var(--text-secondary);
  font-style: italic;
}
.detail-panel .dp-venue { color: var(--text-muted); font-size: 12px; font-style: normal; }
.detail-panel .dp-dates { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 14px 0; }
.detail-panel .dp-dates dt { color: var(--text-muted); }
.detail-panel .dp-dates dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.detail-panel .dp-status { font-weight: 700; }
.detail-panel .dp-status.bad { color: var(--status-critical); }
.detail-panel .dp-status.good { color: var(--success-text); }
.detail-panel .dp-status.pending { color: var(--text-secondary); }
.detail-panel .dp-notes { color: var(--text-secondary); }
.detail-panel .dp-ambiguous {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 12.5px;
}
.detail-panel h3 { font-size: 13px; margin: 18px 0 6px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.detail-panel ul { margin: 0; padding-left: 18px; }
.detail-panel a { color: inherit; word-break: break-all; }

/* ---------- table view ---------- */

.table-container {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
}

.table-container table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.table-container th, .table-container td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: top;
}
.table-container th { color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.table-container td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-container td .t-bad { color: var(--status-critical); font-weight: 600; }
.table-container td .t-good { color: var(--success-text); font-weight: 600; }

/* ---------- undated claims ---------- */

.undated-section { margin-top: 36px; }

.undated-section h2 {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.undated-section .undated-intro {
  margin: 0 0 16px;
  color: var(--text-secondary);
  max-width: 640px;
}

.undated-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.undated-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.undated-card h3 {
  margin: 0;
  font-size: 14.5px;
}

.undated-card .uc-meta { color: var(--text-muted); font-size: 11.5px; }

.undated-card blockquote {
  margin: 0;
  padding: 8px 12px;
  border-left: 3px solid var(--baseline);
  color: var(--text-secondary);
  font-style: italic;
  font-size: 12.5px;
}

.undated-card .uc-badge {
  align-self: flex-start;
  border: 1px solid var(--status-critical);
  color: var(--status-critical);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 600;
}

.undated-card .uc-notes { color: var(--text-secondary); font-size: 12.5px; }

.undated-card .uc-sources { font-size: 11.5px; color: var(--text-muted); }
.undated-card .uc-sources a { color: inherit; margin-right: 8px; }

/* ---------- footer ---------- */

.site-footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 32px 32px;
  color: var(--text-muted);
  font-size: 12px;
}

.last-updated {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.last-updated time { font-variant-numeric: tabular-nums; }
.last-updated .stale-note { display: block; margin-top: 2px; opacity: 0.85; }

@media (max-width: 720px) {
  .site-header, .controls-row, .legend-row, main, .site-footer { padding-left: 14px; padding-right: 14px; }
  h1 { font-size: 24px; }
  .site-header { padding-top: 18px; }

  /* stat tiles: tidy 2-up grid instead of ragged wrapping */
  .stat-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
  }
  .stat-tile { min-width: 0; padding: 10px 12px; }
  .stat-tile .stat-value { font-size: 20px; }

  /* filter chips: one horizontally scrollable row per group */
  .filter-group {
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .filter-group::-webkit-scrollbar { display: none; }
  .filter-chip { flex: 0 0 auto; }
  .sort-group { margin-left: 0; }

  .legend-row { gap: 6px 14px; }

  .tooltip { max-width: calc(100vw - 24px); }

  .detail-panel {
    width: 100%;
    border-left: none;
    padding: 20px 16px;
  }
  .detail-panel .dp-close {
    width: 42px;
    height: 42px;
    font-size: 26px;
  }

  .undated-grid { grid-template-columns: 1fr; }
}
