/* Layout & components. Uses tokens from theme.css only -- no raw colors here. */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

/* The hidden attribute must win over component display rules (.stack, .grid...). */
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---- Site header (mirrors f3southcary.com) ----------------------------- */

.site-wrap { max-width: 1140px; margin: 0 auto; padding: 0 20px; }
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--chrome) 96%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--chrome-line);
}
.site-header .site-wrap { display: flex; align-items: center; justify-content: space-between; height: 68px; }
.site-brand { display: flex; align-items: center; gap: 12px; color: var(--chrome-strong); text-decoration: none; }
.site-brand img { width: 42px; height: 42px; border-radius: 50%; }
.site-brand span { font: 600 1.25rem/1 var(--font-head); letter-spacing: 0.04em; text-transform: uppercase; }
.site-nav { display: flex; align-items: center; gap: 4px; }
.site-nav a { color: var(--chrome-text); text-decoration: none; font-weight: 500; font-size: 0.95rem; padding: 10px 14px; border-radius: 8px; }
.site-nav a:hover { color: var(--chrome-strong); background: var(--chrome-hover); }
.site-nav a[aria-current="page"] { color: var(--chrome-strong); }
.site-nav .site-btn {
  margin-left: 8px; padding: 11px 18px; border-radius: 999px; font-weight: 600;
  background: var(--chrome-accent); color: var(--chrome-strong);
}
.site-nav .site-btn:hover { background: var(--chrome-accent-dark); }
.site-nav-toggle { display: none; background: none; border: 0; color: var(--chrome-strong); padding: 8px; cursor: pointer; }
.site-nav-toggle svg { width: 28px; height: 28px; }

@media (max-width: 1120px) {
  .site-nav-toggle { display: block; }
  .site-nav {
    position: absolute; top: 68px; left: 0; right: 0; flex-direction: column; align-items: stretch;
    background: var(--chrome); padding: 8px 16px 20px; gap: 2px;
    border-bottom: 1px solid var(--chrome-line);
    display: none;
  }
  .site-nav.open { display: flex; }
  .site-nav a { padding: 14px 12px; font-size: 1.05rem; }
  .site-nav .site-btn { margin: 10px 0 0; padding: 16px; text-align: center; }
}

/* ---- Stats tabs (sticky under the site header) ------------------------- */

.tabs-bar {
  position: sticky;
  top: 68px;
  z-index: 10;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.tabs-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.tabs { display: flex; gap: 4px; margin-right: auto; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  color: var(--text-2);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---- Page -------------------------------------------------------------- */

main {
  max-width: 1140px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}

.page-title {
  margin: 4px 0 2px;
  font: 600 32px/1.1 var(--font-head);
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
.page-sub { margin: 0 0 16px; color: var(--text-2); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 0 0 18px;
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stack { display: grid; gap: 16px; }

/* ---- Segmented control (date presets) ---------------------------------- */

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 999px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 5px 12px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.custom-range { display: inline-flex; gap: 6px; align-items: center; color: var(--text-2); }

.input {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  min-width: 0;
}
.input::placeholder { color: var(--muted); }
input[type="date"].input { padding: 0 10px; }
.pax-search { width: min(100%, 280px); }

/* ---- Cards & stat tiles ------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 12px;
  min-width: 0;
}
.card-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.card-title { margin: 0; font-size: 15px; font-weight: 650; }
.card-sub { margin: 0; color: var(--muted); font-size: 13px; }
.card-head .spacer { flex: 1; }
.card-head { flex-wrap: wrap; }
.chart-title { margin: 4px 0 4px; font-size: 13.5px; font-weight: 600; color: var(--text-2); }

.link-btn {
  border: 0;
  background: none;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  white-space: nowrap;
}
.link-btn:hover { color: var(--text); background: var(--surface-2); }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.stat-label { color: var(--text-2); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.stat-value.small { font-size: 18px; line-height: 1.55; }
.stat-of { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.section-title { margin: 12px 0 -4px; font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }

/* ---- Charts ------------------------------------------------------------ */

.chart { position: relative; min-height: 120px; }
.chart svg { display: block; overflow: visible; }
/* Plot declares --plot-background: white on each svg (zero specificity); this wins. */
.chart svg { --plot-background: var(--surface); }
/* Axis & label ink inherit from here (Plot draws them in currentColor). */
.chart { color: var(--muted); font-size: 12px; }
.chart [aria-label="tip"] { color: var(--text); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 0 0 8px; }
.legend button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  background: none;
  color: var(--text-2);
  font-size: 12.5px;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  cursor: pointer;
}
.legend button:hover { background: var(--surface-2); color: var(--text); }
.legend button[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }
.legend button[aria-pressed="false"] .swatch { opacity: 0.25; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-box { margin: 0 0 8px; }
.legend-box .legend { margin: 6px 0 0; }
.legend-summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none;
  color: var(--text-2); font-size: 12.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2);
}
.legend-summary::-webkit-details-marker { display: none; }
.legend-summary::before { content: "▸"; font-size: 10px; transition: transform 0.15s; }
.legend-box[open] > .legend-summary::before { transform: rotate(90deg); }
.legend-summary:hover { color: var(--text); }
.legend .note { color: var(--muted); font-size: 12px; padding: 3px 4px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.data-table th, .data-table td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--grid); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { color: var(--text-2); font-weight: 600; }
.data-table td { font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* Typed tables (js/table.js): text left, numbers right, sortable sticky header. */
.data-table.typed th, .data-table.typed td { text-align: left; }
.data-table.typed .num { text-align: right; }
.table-sticky { overflow: auto; }
.table-sticky thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.data-table.typed td { white-space: nowrap; }
.sort-btn {
  border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer;
  display: inline-flex; gap: 4px; align-items: center;
}
.sort-btn:hover { color: var(--text); }
.sort-mark { font-size: 9px; color: var(--muted); min-width: 8px; }
.table-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.table-search { width: min(100%, 240px); }
.table-count { color: var(--muted); font-size: 12.5px; }

/* Line-chart key: a short stroke, solid or dashed, in the series color. */
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 12.5px; padding: 2px 8px 2px 0; }
.line-swatch { width: 18px; border-top: 2px solid currentColor; flex: none; }
.line-swatch.dashed { border-top-style: dashed; }

/* Heat ramp key (heatmap & calendar). */
.heat-key { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 8px; color: var(--text-2); font-size: 12.5px; }
.heat-key span { display: inline-flex; align-items: center; gap: 5px; }
.heat-key .ramp { width: 72px; height: 10px; border-radius: 3px; }

.select {
  height: 34px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  min-width: 0;
  max-width: 100%;
}

/* Streaker chips (112 Tracker). */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; flex-direction: column; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.chip b { font-weight: 650; }
.chip small { color: var(--text-2); }

.show-more { margin-top: 8px; }
.tabs a.nav-hidden:not([aria-current]) { display: none; }

/* ---- States ------------------------------------------------------------ */

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--page) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.empty, .error {
  padding: 28px 12px;
  text-align: center;
  color: var(--text-2);
}
.error { color: var(--text); }

main .stack { transition: opacity 0.2s; }
main.is-loading .stack { opacity: 0.55; }

/* ---- Footer: data freshness line, then the site footer ----------------- */

.footer {
  max-width: 1140px;
  margin: 0 auto;
  padding: 16px 20px;
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.footer b { color: var(--text-2); font-weight: 600; }

.site-footer { background: var(--chrome); color: var(--chrome-muted); padding: 56px 0 28px; font-size: 0.95rem; line-height: 1.6; }
.site-footer-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 32px; }
.site-footer h4 { color: var(--chrome-strong); font: 600 0.95rem/1.1 var(--font-head); letter-spacing: 0.1em; text-transform: uppercase; margin: 0 0 14px; }
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { margin-bottom: 8px; }
.site-footer a { color: var(--chrome-text); text-decoration: none; }
.site-footer a:hover { color: var(--chrome-strong); text-decoration: underline; }
.site-footer .site-brand { color: var(--chrome-strong); }
.site-footer-brand p { max-width: 320px; margin: 14px 0 0; }
.site-footer-bottom {
  border-top: 1px solid var(--chrome-line); margin-top: 40px; padding-top: 20px;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px;
  font-size: 0.85rem; color: var(--chrome-faint);
}
@media (max-width: 860px) { .site-footer-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .site-footer-grid { grid-template-columns: 1fr; } }

@media (max-width: 640px) {
  /* Presets become one swipeable row instead of wrapping. */
  .segmented { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .segmented::-webkit-scrollbar { display: none; }
  .pax-search, .select { width: 100%; }
  .tabs a { padding: 6px 11px; }
  .page-title { font-size: 26px; }
  .stat-value { font-size: 24px; }
}
