/* =============================================================
   CTH — Base layer
   Reset, typography primitives, the signature background, layout
   helpers, and CSS utility classes for every control. React
   components reference these classes; static HTML can use them
   directly.
   ============================================================= */

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

body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text-strong);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}

img, svg { display: block; max-width: 100%; }
a { color: var(--text-strong); text-decoration: none; }
a:hover { color: var(--cth-mist); }
button { font-family: inherit; cursor: pointer; border: 0; background: transparent; white-space: nowrap; }
input, select, textarea { font-family: inherit; color: inherit; }
::selection { background: var(--cth-ink); color: var(--cth-cloud); }

/* -------------------------------------------------------------
   Typography primitives
   ------------------------------------------------------------- */
.display-hero {
  font-family: var(--font-display); font-weight: 700;
  font-size: var(--fs-hero); line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight); color: var(--text-strong); margin: 0;
}
.display-md {
  font-family: var(--font-display); font-weight: 700;
  font-size: var(--fs-display); line-height: 1.06;
  letter-spacing: var(--tracking-tight); margin: 0;
}
.heading-1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: var(--fs-h1); line-height: var(--lh-snug);
  letter-spacing: var(--tracking-snug); margin: 0;
}
.heading-2 {
  font-family: var(--font-display); font-weight: 600;
  font-size: var(--fs-h2); line-height: 1.22;
  letter-spacing: var(--tracking-snug); margin: 0;
}
.heading-3 {
  font-family: var(--font-display); font-weight: 600;
  font-size: var(--fs-h3); line-height: 1.3;
  letter-spacing: var(--tracking-snug); margin: 0;
}
.text-body { font-size: var(--fs-body); line-height: var(--lh-body); color: var(--text-strong); }
.text-body-lg { font-size: var(--fs-body-lg); line-height: 1.5; color: var(--text-strong); }
.text-muted { color: var(--text-muted); }
.text-soft { color: var(--text-soft); }
.text-small { font-size: var(--fs-small); line-height: 1.45; color: var(--text-muted); }
.text-label { font-size: var(--fs-label); font-weight: 500; line-height: 1.3; color: var(--text-muted); letter-spacing: var(--tracking-wide); }
.numeric { font-feature-settings: "tnum" 1, "lnum" 1; }

/* The signature italic accent — exactly once per hero (Instrument Sans italic). */
.accent-italic {
  font-family: var(--font-serif); font-style: italic; font-weight: 500;
  color: var(--text-accent); letter-spacing: -0.03em;
  font-size: 1em; padding-inline: 0.02em;
}

/* -------------------------------------------------------------
   Signature background — greyscale "open sky"
   A soft warm-grey wash with three off-white light pools. The
   only gradient in the system.
   ------------------------------------------------------------- */
.sky {
  background-color: var(--cth-page);
  background-image:
    radial-gradient(62% 38% at 18% 82%, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0) 62%),
    radial-gradient(52% 34% at 84% 72%, rgba(255,255,255,0.85) 0%, rgba(255,255,255,0) 60%),
    radial-gradient(48% 30% at 50% 14%, rgba(255,255,255,0.80) 0%, rgba(255,255,255,0) 60%),
    linear-gradient(180deg, var(--sky-top, #ebebeb) 0%, var(--cth-page) 76%);
  background-repeat: no-repeat;
}
.sky-soft {
  background-color: var(--cth-page);
  background-image:
    radial-gradient(60% 40% at 20% 80%, rgba(255,255,255,0.85) 0%, rgba(255,255,255,0) 65%),
    radial-gradient(55% 38% at 85% 30%, rgba(255,255,255,0.70) 0%, rgba(255,255,255,0) 60%),
    linear-gradient(180deg, var(--sky-top, #efefef) 0%, var(--cth-page) 80%);
  background-repeat: no-repeat;
}

/* -------------------------------------------------------------
   Layout primitives
   ------------------------------------------------------------- */
.container { width: 100%; max-width: var(--container-max); margin-inline: auto; padding-inline: var(--container-pad); }
.stack { display: flex; flex-direction: column; }
.stack-1 { gap: var(--space-1); } .stack-2 { gap: var(--space-2); }
.stack-3 { gap: var(--space-3); } .stack-4 { gap: var(--space-4); }
.stack-6 { gap: var(--space-6); } .stack-8 { gap: var(--space-8); }
.stack-12 { gap: var(--space-12); }
.row { display: flex; align-items: center; }
.row-2 { gap: var(--space-2); } .row-3 { gap: var(--space-3); }
.row-4 { gap: var(--space-4); } .row-6 { gap: var(--space-6); }
.row-8 { gap: var(--space-8); }
.row-wrap { flex-wrap: wrap; } .row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; } .row-center { justify-content: center; }
.row-baseline { align-items: baseline; } .row-start { align-items: flex-start; }
.center-x { text-align: center; }
.grid { display: grid; gap: var(--space-6); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 880px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.section { padding-block: var(--space-24); }
.section-tight { padding-block: var(--space-16); }

/* -------------------------------------------------------------
   Buttons — full pill, two variants + ghost
   ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding-inline: 22px; border-radius: var(--radius-pill);
  font-family: var(--font-sans); font-size: var(--fs-body); font-weight: 500;
  line-height: 1; letter-spacing: -0.005em; white-space: nowrap;
  border: 1px solid transparent;
  transition: transform var(--dur-quick) var(--ease-soft),
    background-color var(--dur-base) var(--ease-soft),
    color var(--dur-base) var(--ease-soft), box-shadow var(--dur-base) var(--ease-soft);
}
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:active { transform: translateY(1px); }
.btn .icon { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary { background: var(--cth-ink); color: var(--cth-cloud); }
.btn-primary:hover { background: var(--cth-ink-hover); }
.btn-secondary { background: var(--cth-cloud); color: var(--text-strong); border-color: var(--cth-edge); }
.btn-secondary:hover { background: var(--surface-sunken); }
.btn-ghost { background: transparent; color: var(--text-strong); }
.btn-ghost:hover { background: rgba(0,0,0,0.05); }
.btn-sm { height: 36px; padding-inline: 16px; font-size: var(--fs-small); }
.btn-lg { height: 52px; padding-inline: 26px; font-size: var(--fs-body-lg); }
.btn-icon { width: 44px; height: 44px; padding: 0; border-radius: var(--radius-pill); }
.btn[disabled], .btn:disabled { opacity: 0.45; pointer-events: none; }

/* -------------------------------------------------------------
   Inputs — pill, hairline border
   ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: var(--fs-label); font-weight: 500; color: var(--text-muted); letter-spacing: var(--tracking-wide); }
.input {
  display: inline-flex; align-items: center; gap: 10px; height: 44px;
  padding-inline: 18px; background: var(--cth-cloud); border: var(--border-hairline);
  border-radius: var(--radius-input); font-size: var(--fs-body); color: var(--text-strong);
  transition: border-color var(--dur-base) var(--ease-soft), box-shadow var(--dur-base) var(--ease-soft);
}
.input::placeholder { color: var(--text-soft); }
.input:focus, .input:focus-within {
  outline: none; border-color: var(--cth-ink); box-shadow: var(--focus-ring);
}
.input .icon { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
.input-search { width: 240px; }
.textarea {
  display: block; width: 100%; min-height: 96px; padding: 14px 18px;
  background: var(--cth-cloud); border: var(--border-hairline); border-radius: 22px;
  font-size: var(--fs-body); resize: vertical;
}
.textarea:focus { outline: none; border-color: var(--cth-ink); box-shadow: var(--focus-ring); }

/* -------------------------------------------------------------
   Cards
   ------------------------------------------------------------- */
.card {
  background: var(--surface-card); border: var(--border-hairline);
  border-radius: var(--radius-card); box-shadow: var(--shadow-tier-1); padding: 32px;
}
.card-compact { padding: 22px 24px; }
.card-flush { padding: 0; overflow: hidden; }
.slab {
  background: var(--surface-card); border: var(--border-hairline);
  border-radius: var(--radius-slab); box-shadow: var(--shadow-tier-2); padding: 28px;
}
.card-title { font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: var(--tracking-snug); color: var(--text-strong); margin: 0; }
.card-sub { font-size: var(--fs-body); color: var(--text-muted); margin: 0; }

/* Icon tile inside cards */
.icon-tile {
  width: 44px; height: 44px; border-radius: 16px; background: var(--cth-ink);
  color: var(--cth-cloud); display: grid; place-items: center;
}
.icon-tile .icon { width: 22px; height: 22px; }

/* Stat tile */
.stat { display: flex; flex-direction: column; gap: 6px; padding: 18px 0; }
.stat-label { font-size: var(--fs-label); font-weight: 500; color: var(--text-muted); letter-spacing: var(--tracking-wide); }
.stat-value { font-family: var(--font-display); font-weight: 700; font-size: 28px; letter-spacing: var(--tracking-tight); color: var(--text-strong); font-variant-numeric: tabular-nums; }
.stat-delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-small); font-weight: 500; }
.stat-delta--up { color: var(--cth-ink); }
.stat-delta--down { color: var(--cth-soft); }
.stat-delta--flat { color: var(--text-muted); }
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 0; }
.stat-row > .stat { padding-inline: 24px; border-right: var(--border-hairline); }
.stat-row > .stat:first-child { padding-left: 0; }
.stat-row > .stat:last-child { padding-right: 0; border-right: 0; }
@media (max-width: 880px) {
  .stat-row { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stat-row > .stat { border-right: 0; padding-inline: 0; }
}

/* -------------------------------------------------------------
   Nav pill
   ------------------------------------------------------------- */
.nav { position: relative; display: flex; align-items: center; justify-content: space-between; padding-block: 20px; gap: var(--space-6); }
.nav-brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 600; font-size: 18px; letter-spacing: -0.02em; color: var(--text-strong); }
.brand-mark { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: var(--radius-pill); background: var(--cth-ink); color: var(--cth-cloud); }
.brand-mark img, .brand-mark svg { width: 19px; height: 19px; }
.nav-pill { display: inline-flex; align-items: center; gap: 2px; background: var(--cth-cloud); border: var(--border-hairline); border-radius: var(--radius-pill); padding: 5px; box-shadow: var(--shadow-tier-1); }
.nav-link { display: inline-flex; align-items: center; padding: 8px 16px; font-size: var(--fs-body); font-weight: 500; color: var(--text-muted); border-radius: var(--radius-pill); transition: color var(--dur-quick) var(--ease-soft), background-color var(--dur-quick) var(--ease-soft); }
.nav-link:hover { color: var(--text-strong); }
.nav-link.is-active { color: var(--cth-cloud); background: var(--cth-ink); }

/* -------------------------------------------------------------
   Tabs
   ------------------------------------------------------------- */
.tabs { display: inline-flex; align-items: center; gap: 4px; padding: 6px; border-radius: var(--radius-pill); }
.tab { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; height: 36px; border-radius: var(--radius-pill); font-size: var(--fs-body); font-weight: 500; color: var(--text-strong); background: transparent; white-space: nowrap; transition: background-color var(--dur-base) var(--ease-soft), color var(--dur-base) var(--ease-soft); }
.tab .icon { width: 14px; height: 14px; }
.tab:hover { background: rgba(0,0,0,0.05); }
.tab.is-active { background: var(--cth-ink); color: var(--cth-cloud); box-shadow: var(--shadow-tier-2); }

/* -------------------------------------------------------------
   Checkbox
   ------------------------------------------------------------- */
.checkbox { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--fs-body); color: var(--text-strong); }
.checkbox input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; width: 18px; height: 18px;
  border: 1.5px solid var(--cth-edge); border-radius: var(--radius-check);
  background: var(--cth-cloud); display: inline-grid; place-items: center; position: relative;
  transition: background-color var(--dur-base) var(--ease-soft), border-color var(--dur-base) var(--ease-soft);
}
.checkbox input[type="checkbox"]:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.checkbox input[type="checkbox"]:checked { background: var(--cth-ink); border-color: var(--cth-ink); }
.checkbox input[type="checkbox"]:checked::after {
  content: ""; width: 10px; height: 10px; background-repeat: no-repeat; background-size: contain;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
}

/* -------------------------------------------------------------
   Sidebar icon rail
   ------------------------------------------------------------- */
.rail { display: inline-flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px; background: var(--cth-cloud); border: var(--border-hairline); border-radius: var(--radius-pill); box-shadow: var(--shadow-tier-1); }
.rail-item { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-pill); background: transparent; color: var(--text-muted); transition: background-color var(--dur-base) var(--ease-soft), color var(--dur-base) var(--ease-soft); }
.rail-item .icon { width: 18px; height: 18px; }
.rail-item:hover { background: var(--surface-sunken); color: var(--text-strong); }
.rail-item.is-active { background: var(--cth-ink); color: var(--cth-cloud); }

/* -------------------------------------------------------------
   Avatar
   ------------------------------------------------------------- */
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--surface-sunken); border: var(--border-hairline); overflow: hidden; font-family: var(--font-display); font-weight: 600; font-size: 14px; color: var(--text-strong); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-lg { width: 56px; height: 56px; font-size: 18px; }

/* -------------------------------------------------------------
   Chips — real, dynamic data only
   ------------------------------------------------------------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-pill); background: var(--cth-cloud); border: var(--border-hairline); font-size: var(--fs-small); font-weight: 500; color: var(--text-strong); }
.chip .icon { width: 14px; height: 14px; color: var(--text-muted); }
.chip-ink { background: var(--cth-ink); color: var(--cth-cloud); border-color: var(--cth-ink); }
.chip-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* -------------------------------------------------------------
   Chart primitives — greyscale bars, dashed grid, legend
   ------------------------------------------------------------- */
.chart { position: relative; width: 100%; }
.chart-grid { position: absolute; inset: 0; background-image: linear-gradient(to top, var(--cth-edge) 1px, transparent 1px); background-size: 100% 25%; opacity: 0.7; pointer-events: none; }
.bar-track { position: relative; display: flex; align-items: flex-end; gap: 14px; height: 220px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bar-fill { width: 100%; border-radius: 12px; position: relative; overflow: hidden; }
.bar-fill--1 { background: var(--data-1); }
.bar-fill--2 { background: var(--data-2); }
.bar-fill--3 { background: var(--data-3); }
.bar-fill--4 { background: repeating-linear-gradient(135deg, var(--cth-edge) 0 6px, transparent 6px 12px); border: 1px solid var(--cth-edge); }
.legend { display: inline-flex; align-items: center; gap: 18px; font-size: var(--fs-small); color: var(--text-muted); }
.legend-dot { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.legend-dot--1 { color: var(--data-1); }
.legend-dot--2 { color: var(--data-2); }
.legend-dot--3 { color: var(--data-3); }

/* -------------------------------------------------------------
   Icon sizing — keep Lucide SVGs inside their .icon boxes
   ------------------------------------------------------------- */
.icon { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon > svg { width: 100%; height: 100%; display: block; }
