/* ===========================================================================
   Fin Mini App — design system
   Light and dark are both *selected*, not auto-flipped: each mode has its own
   surfaces, inks and chart steps, taken from the validated palette
   (dataviz references/palette.md). data-theme follows Telegram's colorScheme.
   =========================================================================== */

/* --- tokens: light ------------------------------------------------------- */
:root {
  /* chart surfaces & inks (palette.md "Chart chrome & ink") */
  --surface:            #ffffff;
  --plane:              #f9f9f9;
  --ink:                #191919;
  --ink-2:              #666666;
  --grid:               #e7e7e7;
  --axis:               #c2c2c2;
  --hairline:           rgba(11, 11, 11, 0.10);
  --on-fill:            #ffffff;      /* label inside a categorical fill */
  --on-fill-dark:       #0b0b0b;      /* except on yellow/warning */

  /* brand + interactive */
  --brand:              #257de0;
  --brand-ink:          #0e3d7e;
  --brand-wash:         #eaf2fd;
  --brand-wash-2:       #cce3fd;

  /* status (fixed, never themed to brand; always paired with icon + label) */
  --good:               #0aac23;
  --good-text:          #006c10;
  --warning:            #fbb315;
  --serious:            #f18a59;
  --critical:           #dc3c3d;
  --good-wash:          #e8f8ea;
  --warning-wash:       #fdf3dd;
  --critical-wash:      #fdeaea;

  /* categorical series, fixed order, never cycled */
  --c1: #257de0; --c2: #f47230; --c3: #00b894; --c4: #f2a600;
  --c5: #ee7fac; --c6: #008a17; --c7: #6a4ce2; --c8: #ec4647;

  /* sequential blue ramp */
  --seq-100: #cce3fd; --seq-250: #84b9f3; --seq-400: #3d8ae8;
  --seq-550: #1f63b4; --seq-700: #0e3d7e;

  /* diverging: blue <-> red with a neutral gray midpoint */
  --div-neg: #257de0; --div-mid: #efefef; --div-pos: #ec4647;

  /* geometry */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-pill: 999px;
  --pad: 16px;
  --tap: 44px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow-1: 0 1px 2px rgba(11, 11, 11, .06), 0 1px 1px rgba(11, 11, 11, .04);
  --shadow-2: 0 8px 28px rgba(11, 11, 11, .14);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
}

/* --- tokens: dark (own steps, validated against #191919) ----------------- */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    --surface: #191919; --plane: #0b0b0b;
    --ink: #efefef; --ink-2: #9c9c9c;
    --grid: #303030; --axis: #474747;
    --hairline: rgba(255, 255, 255, 0.10);
    --brand: #338ced; --brand-ink: #84b9f3;
    --brand-wash: #18283c; --brand-wash-2: #1f3f66;
    --good: #0aac23; --good-text: #53c556;
    --good-wash: #14301a; --warning-wash: #332a12; --critical-wash: #331a1b;
    --c1: #338ced; --c2: #e76624; --c3: #00a888; --c4: #d28e05;
    --c5: #e24d8b; --c6: #0aac23; --c7: #9887ef; --c8: #eb6263;
    --div-mid: #383838;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-2: 0 8px 28px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  --surface: #191919; --plane: #0b0b0b;
  --ink: #efefef; --ink-2: #9c9c9c;
  --grid: #303030; --axis: #474747;
  --hairline: rgba(255, 255, 255, 0.10);
  --brand: #338ced; --brand-ink: #84b9f3;
  --brand-wash: #18283c; --brand-wash-2: #1f3f66;
  --good: #0aac23; --good-text: #53c556;
  --good-wash: #14301a; --warning-wash: #332a12; --critical-wash: #331a1b;
  --c1: #338ced; --c2: #e76624; --c3: #00a888; --c4: #d28e05;
  --c5: #e24d8b; --c6: #0aac23; --c7: #9887ef; --c8: #eb6263;
  --div-mid: #383838;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-2: 0 8px 28px rgba(0, 0, 0, .6);
}

/* --- reset -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* --- boot --------------------------------------------------------------- */
.boot {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--plane);
}
.boot__text { color: var(--ink-2); font-size: 14px; }
.boot__bar { width: 140px; height: 3px; border-radius: 2px; background: var(--grid); overflow: hidden; }
.boot__bar span {
  display: block; width: 40%; height: 100%; border-radius: 2px; background: var(--brand);
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

/* --- connection banner -------------------------------------------------- */
.netbanner {
  position: fixed; left: 0; right: 0; top: 0; z-index: 70;
  padding: 7px 14px; text-align: center;
  font-size: 13px; font-weight: 600;
  background: var(--warning-wash); color: var(--ink);
  border-bottom: 1px solid var(--hairline);
}
.netbanner[data-kind="error"] { background: var(--critical-wash); }

/* --- app bar ------------------------------------------------------------ */
.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 10px 12px; min-height: 54px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--hairline);
}
.appbar__titles { flex: 1; min-width: 0; }
.appbar__title { font-size: 18px; font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar__sub { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar__actions { display: flex; gap: 2px; }

.iconbtn {
  position: relative;
  display: inline-grid; place-items: center;
  min-width: 38px; min-height: 38px; padding: 0;
  border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--ink);
  cursor: pointer;
}
.iconbtn:active { background: var(--brand-wash); }
.iconbtn__dot {
  position: absolute; top: 7px; right: 7px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--critical); border: 2px solid var(--surface);
}

/* --- view & layout ------------------------------------------------------ */
.view {
  padding: var(--sp-4) var(--pad) calc(var(--tabbar-h) + var(--safe-bottom) + 86px);
  max-width: 560px; margin: 0 auto;
  outline: none;
}
.stack { display: grid; gap: var(--sp-4); }
.stack--tight { gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--ink-2); }
.tiny { font-size: 12px; }
.small { font-size: 13px; }
.strong { font-weight: 650; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- section heading ---------------------------------------------------- */
.shead { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.shead__h { font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); }
.shead__link { font-size: 13px; font-weight: 600; color: var(--brand); background: none; border: 0; padding: 4px; cursor: pointer; }

/* --- card --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--sp-4);
}
.card--flush { padding: 0; overflow: hidden; }
.card--quiet { box-shadow: none; background: transparent; border-style: dashed; }
.card__h { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.card__t { font-size: 15px; font-weight: 650; }

/* hero figure: proportional figures, system sans, no display face */
.hero { display: grid; gap: 2px; }
.hero__label { font-size: 13px; color: var(--ink-2); }
.hero__value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.hero__value--sm { font-size: 22px; }
.hero__note { font-size: 12px; color: var(--ink-2); }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp-3); }
.tile { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-md); padding: var(--sp-3); display: grid; gap: 2px; }
.tile__k { font-size: 12px; color: var(--ink-2); }
.tile__v { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }

/* --- list rows ---------------------------------------------------------- */
.list { display: grid; }
.list > * + * { border-top: 1px solid var(--hairline); }
.rowitem {
  display: grid; grid-template-columns: 38px 1fr auto; align-items: center;
  gap: var(--sp-3); width: 100%;
  padding: 11px var(--sp-4); min-height: var(--tap);
  background: none; border: 0; text-align: left; cursor: pointer; color: inherit;
}
.rowitem:active { background: var(--plane); }
.rowitem--static { cursor: default; }
.rowitem__ic {
  display: grid; place-items: center; width: 38px; height: 38px;
  border-radius: var(--r-pill); background: var(--brand-wash);
  font-size: 17px; line-height: 1;
}
.rowitem__t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rowitem__s { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rowitem__v { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rowitem__v .tiny { font-weight: 500; }
.amount--in { color: var(--good-text); }
.amount--out { color: var(--ink); }

.daygroup { padding: 10px var(--sp-4) 4px; font-size: 12px; font-weight: 700; color: var(--ink-2); background: var(--plane); }

/* --- chips / segmented -------------------------------------------------- */
.chips { display: flex; gap: var(--sp-2); overflow-x: auto; padding: 2px; margin: 0 -2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-height: 34px; padding: 6px 13px;
  border-radius: var(--r-pill); border: 1px solid var(--hairline);
  background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip[aria-pressed="true"], .chip[aria-selected="true"] {
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.seg { display: flex; padding: 3px; gap: 3px; background: var(--plane); border: 1px solid var(--hairline); border-radius: var(--r-pill); }
.seg__b {
  flex: 1; min-height: 36px; border: 0; border-radius: var(--r-pill);
  background: transparent; font-size: 13px; font-weight: 650; cursor: pointer; color: var(--ink-2);
}
.seg__b[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* --- buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 10px 18px;
  border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--brand); color: #fff;
  font-size: 15px; font-weight: 650; cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--ghost { background: transparent; color: var(--brand); border-color: var(--hairline); }
.btn--quiet { background: var(--plane); color: var(--ink); border-color: var(--hairline); }
.btn--danger { background: var(--critical); color: #fff; }
.btn--sm { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: var(--r-sm); }
.btnrow { display: flex; gap: var(--sp-2); }
.btnrow > * { flex: 1; }

.fab {
  position: fixed; z-index: 45;
  right: max(var(--pad), calc(50vw - 280px + var(--pad)));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  width: 56px; height: 56px; border: 0; border-radius: 50%;
  background: var(--brand); color: #fff; box-shadow: var(--shadow-2);
  display: grid; place-items: center; cursor: pointer;
}
.fab:active { transform: scale(.96); }

/* --- tab bar ------------------------------------------------------------ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 44;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--hairline);
}
.tab {
  display: grid; justify-items: center; align-content: center; gap: 2px;
  min-height: var(--tabbar-h); padding: 6px 2px 4px;
  border: 0; background: none; color: var(--ink-2);
  font-size: 10.5px; font-weight: 600; cursor: pointer;
}
.tab[aria-current="page"] { color: var(--brand); }
.tab svg { width: 23px; height: 23px; }

/* --- forms -------------------------------------------------------------- */
.field { display: grid; gap: 6px; }
.field__l { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field__hint { font-size: 12px; color: var(--ink-2); }
.field__err { font-size: 12px; font-weight: 600; color: var(--critical); display: flex; gap: 5px; align-items: center; }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 11px 13px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--grid); border-radius: var(--r-md);
  appearance: none;
}
.textarea { min-height: 88px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-wash); }
.input[aria-invalid="true"] { border-color: var(--critical); }
.input--amount { font-size: 26px; font-weight: 700; letter-spacing: -.02em; text-align: right; font-variant-numeric: tabular-nums; }
.select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%); background-position: calc(100% - 19px) 51%, calc(100% - 13px) 51%; background-size: 6px 6px, 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.switchrow { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); min-height: var(--tap); }
.switch { position: relative; width: 48px; height: 29px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }
.switch__t { position: absolute; inset: 0; border-radius: var(--r-pill); background: var(--axis); transition: background .15s; }
.switch__t::after { content: ""; position: absolute; top: 3px; left: 3px; width: 23px; height: 23px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: var(--shadow-1); }
.switch input:checked + .switch__t { background: var(--good); }
.switch input:checked + .switch__t::after { transform: translateX(19px); }
.switch input:focus-visible + .switch__t { outline: 2px solid var(--brand); outline-offset: 2px; }

/* --- notes, banners, badges -------------------------------------------- */
.note {
  display: grid; grid-template-columns: 20px 1fr; gap: var(--sp-2);
  padding: 11px 13px; border-radius: var(--r-md);
  background: var(--plane); border: 1px solid var(--hairline);
  font-size: 13px; line-height: 1.4;
}
.note--info { background: var(--brand-wash); border-color: transparent; }
.note--warn { background: var(--warning-wash); border-color: transparent; }
.note--bad  { background: var(--critical-wash); border-color: transparent; }
.note--good { background: var(--good-wash); border-color: transparent; }
.note__ic { display: grid; place-items: center; font-size: 14px; line-height: 1.3; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--r-pill);
  font-size: 11.5px; font-weight: 650; white-space: nowrap;
  background: var(--plane); color: var(--ink-2); border: 1px solid var(--hairline);
}
.badge--est { background: var(--brand-wash); color: var(--brand-ink); border-color: transparent; }
.badge--good { background: var(--good-wash); color: var(--good-text); border-color: transparent; }
.badge--warn { background: var(--warning-wash); color: var(--ink); border-color: transparent; }
.badge--bad  { background: var(--critical-wash); color: var(--critical); border-color: transparent; }
.badge--pending { background: var(--plane); }

/* --- progress / meter --------------------------------------------------- */
.meter { height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.meter__f { height: 100%; border-radius: 4px; background: var(--brand); }
.meter__f[data-state="ok"] { background: var(--good); }
.meter__f[data-state="warning"] { background: var(--warning); }
.meter__f[data-state="critical"] { background: var(--serious); }
.meter__f[data-state="over"] { background: var(--critical); }

/* --- empty / loading / error ------------------------------------------- */
.empty { display: grid; justify-items: center; gap: var(--sp-3); padding: var(--sp-6) var(--sp-4); text-align: center; }
.empty__ic { width: 56px; height: 56px; border-radius: var(--r-pill); display: grid; place-items: center; background: var(--brand-wash); font-size: 24px; }
.empty__t { font-size: 16px; font-weight: 650; }
.empty__s { font-size: 13px; color: var(--ink-2); max-width: 34ch; }

.skel { background: var(--grid); border-radius: var(--r-sm); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.skel--line { height: 12px; }
.skel--title { height: 22px; width: 60%; }
.skel--card { height: 104px; border-radius: var(--r-lg); }
.skel--row { height: 56px; border-radius: var(--r-md); }

/* --- sheet -------------------------------------------------------------- */
.sheet-host { position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; justify-content: center; }
.sheet-host__scrim { position: absolute; inset: 0; background: rgba(11, 11, 11, .45); animation: fade .16s ease-out; }
.sheet {
  position: relative; width: 100%; max-width: 560px;
  max-height: 92vh; display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-2);
  animation: rise .2s cubic-bezier(.2, .8, .2, 1);
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); opacity: .6; } }
.sheet__bar { display: flex; align-items: center; gap: var(--sp-2); padding: 14px var(--pad) 10px; border-bottom: 1px solid var(--hairline); }
.sheet__grip { position: absolute; top: 7px; left: 50%; transform: translateX(-50%); width: 38px; height: 4px; border-radius: 2px; background: var(--grid); }
.sheet__title { flex: 1; font-size: 16px; font-weight: 700; }
.sheet__body { padding: var(--sp-4) var(--pad) calc(var(--sp-5) + var(--safe-bottom)); overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* --- toast -------------------------------------------------------------- */
.toast-host {
  position: fixed; left: 0; right: 0; z-index: 85;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 76px);
  display: grid; gap: var(--sp-2); justify-items: center; pointer-events: none;
}
.toast {
  max-width: min(92vw, 420px); padding: 10px 15px;
  border-radius: var(--r-pill); box-shadow: var(--shadow-2);
  background: var(--ink); color: var(--surface);
  font-size: 13.5px; font-weight: 600;
  display: flex; align-items: center; gap: var(--sp-2);
  animation: rise .18s ease-out;
}
.toast[data-kind="error"] { background: var(--critical); color: #fff; }
.toast[data-kind="success"] { background: var(--good-text); color: #fff; }

/* ===========================================================================
   Charts — marks follow the fixed specs: bars <= 24px with a 4px rounded
   data-end, 2px lines, >= 8px markers, 10% area wash, 1px solid recessive
   grid, 2px surface gaps and rings. Text always wears text tokens.
   =========================================================================== */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart__grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart__axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart__tick { fill: var(--ink-2); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart__label { fill: var(--ink); font-size: 11px; font-weight: 650; }
.chart__line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart__dot { stroke: var(--surface); stroke-width: 2; }
.chart__hit { fill: transparent; cursor: pointer; }
.chart__cross { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 0; }
.chart__bar { }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-3); }
.legend__i { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.legend__sw { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 128px; max-width: 220px; padding: 8px 10px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: var(--r-sm);
  box-shadow: var(--shadow-2); font-size: 12px; line-height: 1.4;
  transform: translate(-50%, -112%);
}
.chart-tip__k { font-weight: 700; margin-bottom: 3px; }
.chart-tip__r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.chart-tip__r b { font-variant-numeric: tabular-nums; }
.chart-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin-top: var(--sp-2); }

/* table view: the accessible fallback for every chart */
.tableview { width: 100%; border-collapse: collapse; font-size: 13px; }
.tableview th, .tableview td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--hairline); }
.tableview th:first-child, .tableview td:first-child { text-align: left; }
.tableview thead th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); font-weight: 700; }
.tableview td { font-variant-numeric: tabular-nums; }
.tablewrap { overflow-x: auto; }

/* category bar list (horizontal bars, value at the tip) */
.catbar { display: grid; gap: 10px; }
.catbar__i { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.catbar__n { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catbar__v { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.catbar__t { grid-column: 1 / -1; height: 10px; border-radius: 0 4px 4px 0; background: var(--grid); overflow: hidden; }
.catbar__f { height: 100%; border-radius: 0 4px 4px 0; }

/* --- AI chat ------------------------------------------------------------ */
.chat { display: grid; gap: var(--sp-3); }
.bubble { max-width: 88%; padding: 11px 14px; border-radius: var(--r-lg); font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; }
.bubble--me { justify-self: end; background: var(--brand); color: #fff; border-bottom-right-radius: 6px; }
.bubble--ai { justify-self: start; background: var(--surface); border: 1px solid var(--hairline); border-bottom-left-radius: 6px; }
.bubble--refusal { background: var(--warning-wash); border-color: transparent; }
.bubble__meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--sp-2); }
.bubble__acts { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); }
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 46;
  padding: var(--sp-2) var(--pad) calc(var(--sp-2) + var(--safe-bottom));
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--hairline);
}
.composer__in { display: flex; gap: var(--sp-2); max-width: 560px; margin: 0 auto; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 44px; max-height: 120px; padding: 11px 13px; border-radius: var(--r-xl); border: 1px solid var(--grid); background: var(--surface); resize: none; }
.composer .btn { min-width: 44px; width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.view--chat { padding-bottom: 140px; }

/* --- misc --------------------------------------------------------------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--sp-3); font-size: 13px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.divider { height: 1px; background: var(--hairline); margin: var(--sp-2) 0; }
.pillgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: var(--sp-2); }
.tilebtn {
  display: grid; justify-items: center; gap: 6px; padding: 14px 8px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-md);
  font-size: 12px; font-weight: 600; cursor: pointer; color: inherit; min-height: 78px;
}
.tilebtn__ic { font-size: 21px; }
.tilebtn:disabled { opacity: .55; }
.timeline { display: grid; gap: 0; }
.timeline__i { display: grid; grid-template-columns: 14px 1fr; gap: var(--sp-3); padding-bottom: var(--sp-3); }
.timeline__d { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); margin-top: 5px; box-shadow: 0 0 0 2px var(--surface); }
.timeline__i:not(:last-child) { background: linear-gradient(var(--grid), var(--grid)) no-repeat 4px 14px / 1px 100%; }
.quiz__o { display: block; width: 100%; text-align: left; padding: 11px 13px; margin-bottom: var(--sp-2); border: 1px solid var(--grid); border-radius: var(--r-md); background: var(--surface); cursor: pointer; }
.quiz__o[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-wash); font-weight: 650; }
.lesson { font-size: 15px; line-height: 1.6; }
.lesson p { margin: 0 0 var(--sp-3); }
.lesson h3 { font-size: 16px; margin: var(--sp-4) 0 var(--sp-2); }
.lesson li { margin-left: 18px; list-style: disc; margin-bottom: 5px; }

@media (min-width: 600px) {
  .view { padding-left: 24px; padding-right: 24px; }
}
@media (forced-colors: active) {
  .card, .input, .chip, .btn { border: 1px solid CanvasText; }
  .meter__f, .catbar__f { forced-color-adjust: none; }
}
