/* ==================================================================
   Components — the vocabulary every screen is built from
   ================================================================== */

/* ---- Buttons ----------------------------------------------------- */
.btn {
  --btn-bg: var(--surface);
  --btn-ink: var(--ink);
  --btn-line: var(--line-strong);
  --btn-shadow: var(--shadow-xs);
  position: relative;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 46px;
  padding: var(--s-3) var(--s-5);
  border: 1px solid var(--btn-line);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--btn-shadow);
  transition:
    transform var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast),
    background var(--t-fast),
    border-color var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { --btn-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.985); }
.btn svg {
  width: 18px; height: 18px;
  stroke: currentColor; fill: none;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}

.btn.primary {
  --btn-ink: #fff;
  --btn-line: transparent;
  --btn-shadow: var(--shadow-accent);
  background: linear-gradient(175deg, color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 45%, var(--accent-press) 130%);
}
.btn.primary:hover { background: linear-gradient(175deg, color-mix(in srgb, var(--accent) 80%, #fff), var(--accent-hover)); }

.btn.soft { --btn-bg: var(--accent-soft); --btn-ink: var(--accent-ink); --btn-line: transparent; }
.btn.soft:hover { --btn-bg: var(--accent-soft-2); }

.btn.ghost { --btn-bg: transparent; --btn-line: transparent; --btn-shadow: none; }
.btn.ghost:hover { --btn-bg: var(--surface-2); --btn-shadow: none; transform: none; }

.btn.outline { --btn-bg: transparent; --btn-line: var(--accent); --btn-ink: var(--accent); }

.btn.danger { --btn-ink: var(--bad-ink); --btn-line: var(--bad-line); --btn-bg: var(--bad-soft); }
.btn.success { --btn-ink: var(--ok-ink); --btn-line: var(--ok-line); --btn-bg: var(--ok-soft); }

.btn.xs { min-height: 30px; padding: var(--s-1) var(--s-2); font-size: var(--text-2xs); border-radius: var(--r-xs); }
.btn.sm { min-height: 38px; padding: var(--s-2) var(--s-3); font-size: var(--text-sm); border-radius: var(--r-sm); }
.btn.lg { min-height: 54px; padding: var(--s-4) var(--s-6); font-size: var(--text-md); border-radius: var(--r-lg); }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-disabled='true'] { opacity: 0.45; pointer-events: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast) var(--ease-spring);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg {
  width: 20px; height: 20px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn.on { color: var(--warn); }

/* The theme toggle shows whichever icon is not currently in effect. */
#nav-theme .ico-moon { display: none; }
:root[data-theme='dark'] #nav-theme .ico-sun { display: none; }
:root[data-theme='dark'] #nav-theme .ico-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root[data-theme='auto'] #nav-theme .ico-sun { display: none; }
  :root[data-theme='auto'] #nav-theme .ico-moon { display: block; }
}

/* ---- Layout helpers ------------------------------------------------ */
.row { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.row.tight { gap: var(--s-1); }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.row.nowrap { flex-wrap: nowrap; }
.stack { display: flex; flex-direction: column; gap: var(--s-3); }
.stack.tight { gap: var(--s-2); }
.stack.loose { gap: var(--s-5); }
.spacer { flex: 1; }

/* ---- Cards ---------------------------------------------------------- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow-xs);
}
.card + .card { margin-top: var(--s-3); }
.card.flush { padding: 0; overflow: hidden; }
.card.quiet { background: var(--surface-2); box-shadow: none; }
.card.pad-lg { padding: var(--s-5); }

a.card, button.card, .card.hit {
  display: block;
  width: 100%;
  text-align: start;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform var(--t-base) var(--ease-out),
    box-shadow var(--t-base),
    border-color var(--t-base);
  -webkit-tap-highlight-color: transparent;
}
a.card:hover, button.card:hover, .card.hit:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
}
a.card:active, button.card:active, .card.hit:active { transform: translateY(-1px) scale(0.994); }

/* A tinted spine ties a card to its subject. */
.card.accented {
  border-inline-start: 3px solid var(--hue, var(--accent));
  padding-inline-start: calc(var(--s-4) - 2px);
}
.card.accented::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(100deg, color-mix(in srgb, var(--hue, var(--accent)) 6%, transparent), transparent 42%);
  pointer-events: none;
}

/* ---- Subject hues ----------------------------------------------------- */
.hue-1 { --hue: var(--g1); }
.hue-2 { --hue: var(--g2); }
.hue-3 { --hue: var(--g3); }
.hue-4 { --hue: var(--g4); }
.hue-5 { --hue: var(--g5); }
.hue-6 { --hue: var(--g6); }
.hue-7 { --hue: var(--g7); }
.hue-8 { --hue: var(--g8); }

/* ---- Chips ------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 6px var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip b { font-variant-numeric: tabular-nums; }
.chip[aria-pressed='true'], .chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-accent);
}

.chip-row {
  display: flex;
  gap: var(--s-2);
  overflow-x: auto;
  padding: 2px 0 var(--s-2);
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip-row > * { scroll-snap-align: start; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--s-2);
  border-radius: var(--r-xs);
  background: var(--surface-3);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  font-weight: 640;
  letter-spacing: 0.015em;
  white-space: nowrap;
}
.tag.past   { background: var(--info-soft);   color: var(--info-ink); }
.tag.ai     { background: var(--accent-soft); color: var(--accent-ink); }
.tag.ok     { background: var(--ok-soft);     color: var(--ok-ink); }
.tag.bad    { background: var(--bad-soft);    color: var(--bad-ink); }
.tag.warn   { background: var(--warn-soft);   color: var(--warn-ink); }
.tag.hot    { background: var(--bad-soft);    color: var(--bad-ink); }
.tag.teal   { background: var(--teal-soft);   color: var(--teal-ink); }

/* ---- Meters -------------------------------------------------------------- */
.meter {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--line);
  overflow: hidden;
}
.meter > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--hue, var(--accent));
  transition: width var(--t-slower) var(--ease-out);
}
.meter.thin { height: 4px; }
.meter.thick { height: 9px; }
.meter.ok > i   { background: linear-gradient(90deg, var(--ok), color-mix(in srgb, var(--ok) 70%, var(--teal))); }
.meter.bad > i  { background: var(--bad); }
.meter.warn > i { background: var(--warn); }
.meter.brand > i { background: linear-gradient(90deg, var(--accent), var(--g4)); }

.progress-rail {
  position: fixed;
  top: var(--topbar-h);
  inset-inline: 0;
  height: 3px;
  background: var(--line);
  z-index: 39;
}
.progress-rail > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--g4) 60%, var(--teal));
  transition: width var(--t-base) var(--ease-out);
}

/* ---- Stat tiles ------------------------------------------------------------ */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: var(--s-2);
}
.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-2);
  text-align: center;
  overflow: hidden;
}
.stat b {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--text-xl);
  font-weight: 680;
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-none);
}
.stat span {
  display: block;
  margin-top: 5px;
  font-size: var(--text-2xs);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  font-weight: 650;
}
.stat.ok b     { color: var(--ok); }
.stat.bad b    { color: var(--bad); }
.stat.accent b { color: var(--accent); }
.stat.teal b   { color: var(--teal); }

/* ---- Section headings --------------------------------------------------------- */
.group-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin: var(--s-7) 0 var(--s-3);
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--ink-3);
}
.group-head::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
}
.group-head:first-child { margin-top: 0; }

/* ---- Callouts -------------------------------------------------------------------- */
.callout {
  position: relative;
  border: 1px solid var(--warn-line);
  background: var(--warn-soft);
  border-radius: var(--r-md);
  padding: var(--s-4);
  margin-bottom: var(--s-3);
}
.callout > h4 {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-bottom: var(--s-2);
  font-size: var(--text-sm);
  color: var(--warn-ink);
}
.callout > h4 .tag { background: var(--warn); color: #fff; }
.callout p {
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--ink);
}
.callout.info { border-color: transparent; background: var(--info-soft); }
.callout.info > h4 { color: var(--info-ink); }
.callout.info > h4 .tag { background: var(--info); }

/* ---- Tables ------------------------------------------------------------------------ */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}
table.data { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
table.data th, table.data td {
  padding: var(--s-2) var(--s-3);
  text-align: start;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}
table.data thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  font-family: var(--font-sans);
  font-weight: 660;
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--ink-2);
  white-space: nowrap;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td:first-child { font-weight: 600; }

/* ---- Toasts -------------------------------------------------------------------------- */
.toast-host {
  position: fixed;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s-3));
  inset-inline: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  pointer-events: none;
  padding: 0 var(--gutter);
}
.toast {
  pointer-events: auto;
  max-width: 30rem;
  padding: var(--s-3) var(--s-5);
  border-radius: var(--r-full);
  background: var(--surface-invert);
  color: var(--ink-invert);
  font-size: var(--text-sm);
  font-weight: 560;
  box-shadow: var(--shadow-xl);
  animation: toast-in var(--t-base) var(--ease-spring) both;
}
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok  { background: var(--ok); color: #fff; }
.toast.leaving { animation: toast-out var(--t-base) var(--ease-in-out) both; }

@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.97); } }

/* ---- Sheet ------------------------------------------------------------------------------ */
.sheet-host {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  align-items: end;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in var(--t-base) var(--ease-out) both;
}
@media (min-width: 720px) { .sheet-host { align-items: center; justify-items: center; } }

.sheet {
  width: 100%;
  max-width: 34rem;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  padding: var(--s-5) var(--s-5) calc(var(--s-6) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-xl);
  animation: sheet-up var(--t-slow) var(--ease-out) both;
}
@media (min-width: 720px) {
  .sheet { border-radius: var(--r-xl); border-bottom: 1px solid var(--line); animation-name: sheet-pop; }
}

.sheet-grip {
  width: 40px; height: 4px;
  border-radius: var(--r-full);
  background: var(--line-strong);
  margin: 0 auto var(--s-4);
}
@media (min-width: 720px) { .sheet-grip { display: none; } }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-pop { from { opacity: 0; transform: scale(0.96) translateY(12px); } to { opacity: 1; transform: none; } }

/* ---- Fields --------------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field > label {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 620;
  color: var(--ink-2);
}

.input {
  width: 100%;
  min-height: 46px;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input::placeholder { color: var(--ink-4); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

.search-field { position: relative; }
.search-field .input { padding-inline-start: 2.85rem; }
.search-field > svg {
  position: absolute;
  inset-inline-start: var(--s-4);
  top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  stroke: var(--ink-3); fill: none; stroke-width: 1.9;
  pointer-events: none;
}

.range { width: 100%; accent-color: var(--accent); }

/* A card that behaves like a radio: the mode picker is built from these. */
.option-card {
  display: flex;
  gap: var(--s-3);
  width: 100%;
  text-align: start;
  padding: var(--s-3) var(--s-4);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: inherit;
  cursor: pointer;
  transition: all var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.option-card:hover { border-color: var(--line-strong); background: var(--surface-2); }
.option-card strong {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 620;
}
.option-card small { display: block; font-size: var(--text-xs); color: var(--ink-3); line-height: var(--leading-snug); }
.option-card .pip {
  width: 18px; height: 18px;
  flex-shrink: 0;
  margin-top: 3px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  transition: all var(--t-fast);
}
.option-card[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: var(--ring);
}
.option-card[aria-pressed='true'] .pip {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 3px var(--surface);
}
.option-card[aria-pressed='true'] strong { color: var(--accent-ink); }

/* ---- States ------------------------------------------------------------------------------------ */
.empty-state {
  display: grid;
  place-items: center;
  gap: var(--s-3);
  text-align: center;
  padding: var(--s-16) var(--s-4);
  color: var(--ink-2);
}
.empty-state h1, .empty-state h2 { color: var(--ink); }
.empty-state p { max-width: 28rem; }

.skeleton {
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
