/* ==========================================================================
   Components (CLAUDE.md 8.1). Uses ONLY tokens from tokens.css.
   Every component is shown in every state on web/styleguide.html.
   ========================================================================== */

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: var(--leading-tight); font-weight: var(--weight-semibold); }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
p { margin: 0; }

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

:focus-visible,
.is-focus {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--color-muted); }
.text-2 { color: var(--color-text-2); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

.icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.25em; }
.icon-sm { width: 1em; height: 1em; vertical-align: -0.125em; }

/* ==========================================================================
   App shell: top bar, bottom tab bar (mobile), side rail (≥ 900 px)
   ========================================================================== */
.shell { min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: var(--z-bar);
  display: flex; align-items: center; gap: var(--space-2);
  min-height: var(--topbar-h);
  padding: 0 var(--gutter);
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--color-bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
}
.topbar__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); flex: 1; min-width: 0; }
.topbar__actions { display: flex; align-items: center; gap: var(--space-1); }

.freshness {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--tap-min); min-height: var(--tap-min);
  background: none; border: 0; cursor: pointer; border-radius: var(--radius-full);
}
.freshness__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--color-positive); }
.freshness[data-state="stale"] .freshness__dot { background: var(--color-warning); }
.freshness[data-state="failed"] .freshness__dot { background: var(--color-negative); }
.freshness[data-state="failed"] .freshness__dot,
.freshness[data-state="stale"] .freshness__dot { box-shadow: 0 0 0 3px var(--color-warning-bg); }

.content {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-4) var(--gutter);
  padding-bottom: calc(var(--tabbar-h) + var(--space-6) + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-bar);
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--color-surface) 94%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--color-border);
}
.tabbar__item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--tap-min);
  color: var(--color-muted); font-size: var(--text-xs); font-weight: var(--weight-medium);
  text-decoration: none;
}
.tabbar__item:hover { text-decoration: none; color: var(--color-text-2); }
.tabbar__item[aria-current="page"] { color: var(--color-accent); }
.tabbar__item .icon { width: 24px; height: 24px; }

.rail { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: var(--rail-w) 1fr; }
  .tabbar { display: none; }
  .rail {
    display: flex; flex-direction: column; gap: var(--space-1);
    position: sticky; top: 0; height: 100vh;
    padding: var(--space-4) var(--space-3);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
  }
  .rail__brand { font-weight: var(--weight-bold); padding: var(--space-2) var(--space-3) var(--space-4); }
  .rail__item {
    display: flex; align-items: center; gap: var(--space-3);
    min-height: var(--tap-min); padding: 0 var(--space-3);
    border-radius: var(--radius-md); color: var(--color-text-2); font-weight: var(--weight-medium);
  }
  .rail__item:hover { background: var(--color-raised); text-decoration: none; }
  .rail__item[aria-current="page"] { background: var(--color-info-bg); color: var(--color-accent); }
  .content { padding-bottom: var(--space-12); }
  .split { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: var(--space-6); align-items: start; }
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap-min); padding: 0 var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-md);
  font-weight: var(--weight-semibold); font-size: var(--text-md); line-height: 1;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled), .btn.is-pressed { transform: scale(0.98); filter: brightness(0.92); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn--block { width: 100%; }

.btn--primary { background: var(--color-accent); color: var(--color-on-accent); }
.btn--primary:hover:not(:disabled), .btn--primary.is-hover { background: var(--color-accent-hover); }

.btn--secondary { background: var(--color-raised); border-color: var(--color-border-strong); color: var(--color-text); }
.btn--secondary:hover:not(:disabled), .btn--secondary.is-hover { border-color: var(--color-muted); }

.btn--ghost { background: transparent; color: var(--color-accent); }
.btn--ghost:hover:not(:disabled), .btn--ghost.is-hover { background: var(--color-info-bg); }

.btn--destructive { background: transparent; border-color: var(--color-negative); color: var(--color-negative); }
.btn--destructive:hover:not(:disabled), .btn--destructive.is-hover { background: var(--color-negative-bg); }

.btn[aria-busy="true"] { pointer-events: none; }
.btn[aria-busy="true"]::before {
  content: ""; width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap-min); height: var(--tap-min); flex: none;
  background: none; border: 0; border-radius: var(--radius-full);
  color: var(--color-text-2); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--color-raised); color: var(--color-text); }
.icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ==========================================================================
   Form controls
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field__label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text-2); }
.field__hint { font-size: var(--text-sm); color: var(--color-muted); }
.field__error { font-size: var(--text-sm); color: var(--color-negative); display: flex; gap: var(--space-1); align-items: flex-start; }

.input, .select {
  width: 100%; min-height: var(--tap-min); padding: var(--space-2) var(--space-3);
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-md);
  font-size: var(--text-md); /* 16px: prevents iOS zoom on focus */
  transition: border-color var(--dur-fast) var(--ease);
}
.input::placeholder { color: var(--color-muted); }
.input:hover:not(:disabled), .select:hover:not(:disabled), .input.is-hover { border-color: var(--color-muted); }
.input:focus-visible, .select:focus-visible, .input.is-focus { outline: 2px solid var(--color-focus); outline-offset: 0; border-color: transparent; }
.input[aria-invalid="true"] { border-color: var(--color-negative); }
.input:disabled, .select:disabled { opacity: 0.5; cursor: not-allowed; }
.select {
  appearance: none; padding-right: var(--space-8);
  background-image: linear-gradient(45deg, transparent 50%, var(--color-muted) 50%),
    linear-gradient(135deg, var(--color-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* segmented control */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  max-width: 100%; overflow-x: auto;
}
.segmented button {
  min-height: var(--tap-min); min-width: var(--tap-min); padding: 0 var(--space-3);
  background: none; border: 0; border-radius: calc(var(--radius-md) - 3px);
  color: var(--color-text-2); font-size: var(--text-sm); font-weight: var(--weight-medium);
  cursor: pointer; white-space: nowrap; flex: 1 0 auto;
}
.segmented button[aria-pressed="true"] { background: var(--color-raised); color: var(--color-text); font-weight: var(--weight-semibold); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--color-border-strong); }
.segmented button:disabled { opacity: 0.45; cursor: not-allowed; }

/* toggle switch (role=switch button) */
.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  min-height: var(--tap-min); width: 100%;
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer;
}
.toggle__track {
  position: relative; flex: none; width: 46px; height: 28px; border-radius: var(--radius-full);
  background: var(--color-border-strong); transition: background var(--dur-base) var(--ease);
}
.toggle__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-1); transition: transform var(--dur-base) var(--ease);
}
.toggle[aria-checked="true"] .toggle__track { background: var(--color-accent); }
.toggle[aria-checked="true"] .toggle__track::after { transform: translateX(18px); }
.toggle:disabled { opacity: 0.45; cursor: not-allowed; }

/* slider */
.slider { width: 100%; accent-color: var(--color-accent); min-height: var(--tap-min); }

/* ==========================================================================
   Cards & lists
   ========================================================================== */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: var(--space-4);
}
.card__title { font-size: var(--text-md); font-weight: var(--weight-semibold); margin-bottom: var(--space-3); }
.section-title {
  font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-muted);
  text-transform: uppercase; letter-spacing: 0.04em; margin: var(--space-6) 0 var(--space-2);
}

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }

/* stock card */
.stock {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "head head" "price spark" "meta spark";
  gap: 2px var(--space-3); align-items: center;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  color: var(--color-text); text-decoration: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
a.stock:hover { text-decoration: none; border-color: var(--color-border-strong); }
a.stock:active { background: var(--color-raised); }
a.stock[aria-current="page"] { border-color: var(--color-accent); box-shadow: inset 3px 0 0 var(--color-accent); }
.stock__head { grid-area: head; display: flex; align-items: flex-start; gap: var(--space-2); min-width: 0; margin-bottom: var(--space-1); }
.stock__id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.stock__ticker { font-weight: var(--weight-bold); flex: none; }
.stock__name { color: var(--color-muted); font-size: var(--text-sm); }
.stock__score { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-1); }
.stock__price { grid-area: price; display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-3); font-size: var(--text-sm); min-width: 0; }
.stock__meta { grid-area: meta; font-size: var(--text-sm); color: var(--color-muted); white-space: nowrap; }
.stock__price strong { font-size: var(--text-md); font-weight: var(--weight-semibold); }
.stock__spark { grid-area: spark; justify-self: end; color: var(--color-muted); }
.stock__note { grid-column: 1 / -1; font-size: var(--text-sm); color: var(--color-muted); }

/* change indicator */
.chg { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: var(--weight-medium); }
.chg[data-dir="up"] { color: var(--color-positive); }
.chg[data-dir="down"] { color: var(--color-negative); }
.chg[data-dir="flat"] { color: var(--color-muted); }

/* ==========================================================================
   Badges
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: 28px; padding: 0 var(--space-2);
  border: 1px solid transparent; border-radius: var(--radius-full);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); line-height: 1; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
button.badge { cursor: pointer; font-family: inherit; }
button.badge:hover { filter: brightness(1.12); }
/* make small tappable badges still hit 44 px */
button.badge { position: relative; }
button.badge::after { content: ""; position: absolute; inset: -8px -4px; }

.badge--normal  { background: var(--score-normal-bg);  color: var(--score-normal); }
.badge--watch   { background: var(--score-watch-bg);   color: var(--score-watch); }
.badge--strong  { background: var(--score-strong-bg);  color: var(--score-strong); }
.badge--extreme { background: var(--score-extreme-bg); color: var(--score-extreme); }
.badge--top-normal { background: var(--top-normal-bg); color: var(--top-normal); }
.badge--top-hot    { background: var(--top-hot-bg);    color: var(--top-hot); }
.badge--top-trim   { background: var(--top-trim-bg);   color: var(--top-trim); }
.badge--pending { background: var(--color-raised); color: var(--color-muted); font-weight: var(--weight-medium); }
.badge--error   { background: var(--color-negative-bg); color: var(--color-negative); font-weight: var(--weight-medium); }

.verdict {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-full);
  border: 1px solid currentColor; font-size: var(--text-sm); font-weight: var(--weight-semibold);
}
.verdict__dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.verdict--sale  { color: var(--verdict-sale); }
.verdict--check { color: var(--verdict-check); }
.verdict--trap  { color: var(--verdict-trap); }
.verdict--none  { color: var(--verdict-none); }

/* ==========================================================================
   Signal row
   ========================================================================== */
.signals { list-style: none; margin: 0; padding: 0; }
.signal {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: var(--space-1) var(--space-2);
  align-items: start; padding: var(--space-3) 0; border-top: 1px solid var(--color-border);
}
.signal:first-child { border-top: 0; }
.signal__icon { line-height: 1.4; }
.signal__icon .icon { width: 22px; height: 22px; }
.signal[data-state="passed"] .signal__icon { color: var(--color-positive); }
.signal[data-state="failed"] .signal__icon { color: var(--color-muted); }
.signal[data-state="na"] .signal__icon { color: var(--color-muted); }
.signal__name { font-weight: var(--weight-semibold); }
.signal__detail { grid-column: 2; font-size: var(--text-sm); color: var(--color-text-2); font-variant-numeric: tabular-nums; }
.signal__info { grid-row: 1 / span 2; grid-column: 3; margin: -10px -10px 0 0; }

/* ==========================================================================
   Stat tile & range bar
   ========================================================================== */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-2); }
.tile {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  padding: var(--space-3); background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
}
.tile__label { font-size: var(--text-xs); color: var(--color-muted); font-weight: var(--weight-medium); text-transform: uppercase; letter-spacing: 0.04em; display: flex; align-items: center; justify-content: space-between; gap: var(--space-1); }
.tile__value { font-size: var(--text-lg); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.tile__word { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.tile__context { font-size: var(--text-xs); color: var(--color-text-2); }
.tile__trend { color: var(--color-muted); height: 20px; }

.range { display: flex; flex-direction: column; gap: var(--space-1); }
.range__track {
  position: relative; height: 8px; border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--color-positive-bg), var(--color-raised) 50%, var(--color-negative-bg));
  border: 1px solid var(--color-border);
}
.range__marker {
  position: absolute; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  border-radius: 50%; background: var(--color-text); border: 3px solid var(--color-surface);
  box-shadow: var(--shadow-1);
}
.range__labels { display: flex; justify-content: space-between; font-size: var(--text-xs); color: var(--color-muted); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Banners, toasts
   ========================================================================== */
.banner {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  border: 1px solid; font-size: var(--text-sm);
}
.banner__body { flex: 1; min-width: 0; }
.banner__action { margin: -10px -8px -10px 0; }
.banner__title { font-weight: var(--weight-semibold); }
.banner--info    { background: var(--color-info-bg);     border-color: color-mix(in srgb, var(--color-info) 40%, transparent);     }
.banner--warning { background: var(--color-warning-bg);  border-color: color-mix(in srgb, var(--color-warning) 45%, transparent);  }
.banner--negative{ background: var(--color-negative-bg); border-color: color-mix(in srgb, var(--color-negative) 40%, transparent); }
.banner--positive{ background: var(--color-positive-bg); border-color: color-mix(in srgb, var(--color-positive) 40%, transparent); }
.banner--info .banner__icon { color: var(--color-info); }
.banner--warning .banner__icon { color: var(--color-warning); }
.banner--negative .banner__icon { color: var(--color-negative); }
.banner--positive .banner__icon { color: var(--color-positive); }

.toast-region {
  position: fixed; z-index: var(--z-toast); left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--space-3) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--space-2);
  width: min(440px, calc(100% - 2 * var(--gutter)));
  pointer-events: none;
}
@media (min-width: 900px) { .toast-region { bottom: var(--space-6); } }
.toast {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  min-height: 52px; border-radius: var(--radius-md);
  background: var(--color-text); color: var(--color-bg); box-shadow: var(--shadow-3);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  pointer-events: auto;
  animation: rise var(--dur-slow) var(--ease);
}
.toast__msg { flex: 1; }
.toast .btn--ghost { color: var(--color-bg); text-decoration: underline; }
.toast .btn--ghost:hover { background: color-mix(in srgb, var(--color-bg) 12%, transparent); }
@keyframes rise { from { transform: translateY(16px); } to { transform: none; } }

/* ==========================================================================
   Bottom sheet (mobile) / side panel (desktop) / dialog
   ========================================================================== */
.sheet {
  border: 0; padding: 0; margin: 0;
  width: 100%; max-width: 100%; max-height: 85vh;
  inset: auto 0 0 0;
  background: var(--color-raised); color: var(--color-text);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-3);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet[open] { animation: sheet-up var(--dur-slow) var(--ease); }
.sheet::backdrop { background: var(--color-overlay); }
.sheet__grip { width: 40px; height: 4px; border-radius: var(--radius-full); background: var(--color-border-strong); margin: var(--space-2) auto 0; }
.sheet__head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); }
.sheet__title { flex: 1; font-size: var(--text-lg); }
.sheet__body { padding: 0 var(--space-4) var(--space-6); overflow-y: auto; max-height: calc(85vh - 64px); }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

@media (min-width: 900px) {
  .sheet {
    inset: 0 0 0 auto; width: 420px; max-height: 100vh; height: 100vh;
    border-radius: 0; border-left: 1px solid var(--color-border);
  }
  .sheet__grip { display: none; }
  .sheet__body { max-height: calc(100vh - 64px); }
  .sheet[open] { animation: panel-in var(--dur-slow) var(--ease); }
  @keyframes panel-in { from { transform: translateX(100%); } to { transform: none; } }
}

.dialog {
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-6); width: min(420px, calc(100% - 2 * var(--gutter)));
  background: var(--color-raised); color: var(--color-text); box-shadow: var(--shadow-3);
}
.dialog::backdrop { background: var(--color-overlay); }
.dialog__title { font-size: var(--text-lg); margin-bottom: var(--space-2); }
.dialog__actions { display: flex; gap: var(--space-2); justify-content: flex-end; flex-wrap: wrap; margin-top: var(--space-6); }

/* ==========================================================================
   States: empty, error, skeleton
   ========================================================================== */
.state {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  background: var(--color-surface); border: 1px dashed var(--color-border-strong); border-radius: var(--radius-lg);
}
.state__icon { width: 40px; height: 40px; color: var(--color-muted); margin-bottom: var(--space-1); }
.state--error .state__icon { color: var(--color-negative); }
.state--calm .state__icon { color: var(--color-positive); }
.state__title { font-size: var(--text-md); font-weight: var(--weight-semibold); }
.state__body { color: var(--color-text-2); font-size: var(--text-sm); max-width: 34ch; }
.state .btn { margin-top: var(--space-3); }
.state details { font-size: var(--text-sm); color: var(--color-muted); margin-top: var(--space-2); }
.state summary { cursor: pointer; min-height: var(--tap-min); display: inline-flex; align-items: center; }

.skeleton {
  display: block; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 50%, var(--skeleton-base) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton--text { height: 0.9em; }
.skeleton--title { height: 1.2em; width: 40%; }
.skeleton-card {
  display: grid; grid-template-columns: 1fr auto; gap: var(--space-2) var(--space-3);
  padding: var(--space-3) var(--space-4); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); background: var(--color-surface);
}

/* glossary info button */
.info-btn { color: var(--color-muted); }
.info-btn .icon { width: 18px; height: 18px; }
/* compact icon button: looks 32 px, tap area 44 px via ::after */
.icon-btn--sm { width: 32px; height: 32px; position: relative; margin: -8px -8px -8px 0; }
.icon-btn--sm::after { content: ""; position: absolute; inset: -6px; }

/* ==========================================================================
   Screen-level components (added for Phase 1 screens; shown in the style guide)
   ========================================================================== */

/* page header with back button (detail screens) */
.page-head { display: flex; align-items: flex-start; gap: var(--space-2); margin-bottom: var(--space-4); }
.page-head__back { margin: -6px 0 0 -12px; }
.page-head__titles { flex: 1; min-width: 0; }
.page-head__aside { text-align: right; flex: none; }

/* one-line summary at the top of Today */
.summary { font-size: var(--text-lg); font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
.summary__meta { margin-top: var(--space-1); font-size: var(--text-sm); color: var(--color-text-2); }

/* "needs your attention" card */
.attention {
  display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: var(--space-1) var(--space-3);
  padding: var(--space-4); background: var(--color-surface);
  border: 1px solid var(--color-border); border-left: 4px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
}
.attention__icon { color: var(--color-muted); padding-top: 2px; }
.attention__title { font-weight: var(--weight-semibold); }
.attention__body { grid-column: 2; font-size: var(--text-sm); color: var(--color-text-2); }
.attention__action { grid-column: 2; justify-self: start; margin-top: var(--space-2); }
.attention--strong { border-left-color: var(--score-strong); }
.attention--strong .attention__icon { color: var(--score-strong); }
.attention--watch { border-left-color: var(--score-watch); }
.attention--watch .attention__icon { color: var(--score-watch); }
.attention--info { border-left-color: var(--color-info); }
.attention--info .attention__icon { color: var(--color-info); }
.attention--warning { border-left-color: var(--color-warning); }
.attention--warning .attention__icon { color: var(--color-warning); }

/* filter chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: var(--tap-min); padding: 0 var(--space-2) 0 var(--space-3);
  background: var(--color-info-bg); color: var(--color-text); border: 1px solid transparent;
  border-radius: var(--radius-full); font-size: var(--text-sm); font-weight: var(--weight-medium); cursor: pointer;
}
.chip .icon { width: 16px; height: 16px; color: var(--color-text-2); }
.chip--choice { background: var(--color-surface); border-color: var(--color-border-strong); padding: 0 var(--space-3); }
.chip--choice[aria-pressed="true"] { background: var(--color-info-bg); border-color: var(--color-accent); }

/* toolbar row above lists */
.toolbar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-3); }
.toolbar__grow { flex: 1; min-width: 0; }

/* list item with a separate quick-action button */
.row-actions { display: grid; grid-template-columns: minmax(0, 1fr) var(--tap-min); gap: var(--space-1); align-items: stretch; }
.row-actions > .icon-btn { height: auto; border-radius: var(--radius-lg); }

/* menu list (More screen) */
.menu { list-style: none; margin: 0; padding: 0; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.menu li + li { border-top: 1px solid var(--color-border); }
.menu__item {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  min-height: 52px; padding: 0 var(--space-4);
  background: none; border: 0; color: var(--color-text); text-align: left; cursor: pointer; text-decoration: none;
}
.menu__item:hover { background: var(--color-raised); text-decoration: none; }
.menu__item > .icon:first-child { color: var(--color-text-2); }
.menu__label { flex: 1; min-width: 0; }
.menu__hint { display: block; font-size: var(--text-sm); color: var(--color-muted); }
.menu__item--danger { color: var(--color-negative); }
.menu__item--danger > .icon:first-child { color: var(--color-negative); }

/* settings row */
.setting { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-4) 0; border-top: 1px solid var(--color-border); }
.setting:first-child { border-top: 0; padding-top: 0; }
.setting__label { font-weight: var(--weight-semibold); }
.setting__hint { font-size: var(--text-sm); color: var(--color-text-2); }

/* in-page tabs (Overview · Chart · My notes) */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--color-border); margin: var(--space-4) 0; overflow-x: auto; }
.tabs button {
  min-height: var(--tap-min); padding: 0 var(--space-3);
  background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  color: var(--color-text-2); font-weight: var(--weight-medium); cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--color-text); border-bottom-color: var(--color-accent); font-weight: var(--weight-semibold); }

/* chart */
.chart-box { height: 320px; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--color-border); background: var(--color-surface); }
@media (min-width: 768px) { .chart-box { height: 420px; } }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: var(--text-sm); color: var(--color-text-2); margin-top: var(--space-2); }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: var(--space-1); }

/* floating primary action (phones) */
.fab {
  position: fixed; z-index: var(--z-bar); right: var(--gutter);
  bottom: calc(var(--tabbar-h) + var(--space-4) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-2); border-radius: var(--radius-full);
}
@media (min-width: 900px) { .fab { position: static; box-shadow: none; } }

/* step dots (onboarding) */
.steps { display: flex; gap: var(--space-2); justify-content: center; }
.steps span { width: 8px; height: 8px; border-radius: 50%; background: var(--color-border-strong); }
.steps span[aria-current="step"] { background: var(--color-accent); width: 24px; border-radius: var(--radius-full); }

/* centred narrow card (login, onboarding) */
.narrow { max-width: 440px; margin: var(--space-8) auto 0; }

/* desktop split: list + detail */
.split__detail-empty { display: none; }
@media (min-width: 900px) {
  .split__detail-empty { display: flex; }
  .split__list { position: sticky; top: calc(var(--topbar-h) + var(--space-4)); max-height: calc(100vh - var(--topbar-h) - var(--space-8)); overflow-y: auto; padding-right: var(--space-1); }
}

/* screens without a tab bar (login, onboarding) need no room for it */
.no-tabbar .content { padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom)); }
