/* ==========================================================================
   App styles. Only references tokens from tokens.css; no raw colours,
   sizes or radii here.
   ========================================================================== */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  font-feature-settings: "cv11", "ss01";        /* Inter: single-storey a, open digits */
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }

.num, .amount { font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: var(--s-2); top: -100px; z-index: 100;
  padding: var(--s-1) var(--s-2); background: var(--surface); border-radius: var(--radius-sm);
  border: var(--border-width) solid var(--border);
}
.skip-link:focus { top: calc(env(safe-area-inset-top) + var(--s-1)); }

/* ---- Shell ------------------------------------------------------------- */

.shell { min-height: 100dvh; }

main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + var(--s-3))
    calc(env(safe-area-inset-right) + var(--s-2))
    calc(env(safe-area-inset-bottom) + var(--tabbar-h) + var(--s-6) + var(--s-3))
    calc(env(safe-area-inset-left) + var(--s-2));
  outline: none;
}

/* ---- Navigation: bottom tab bar on phone, sidebar on desktop ----------- */

.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  background: color-mix(in oklab, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: var(--border-width) solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav > .nav__brand, .nav > .nav__add { display: none; }   /* sidebar-only */
.nav__list {
  display: grid; grid-template-columns: repeat(4, 1fr);
  list-style: none; margin: 0; padding: 0;
}
.nav__link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabbar-h);
  color: var(--text-muted); text-decoration: none;
  font-size: var(--fs-xs); font-weight: var(--fw-medium);
}
.nav__link[aria-current="page"] { color: var(--accent-text); }
.nav__link svg { width: 24px; height: 24px; }
.nav__badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-pill);
  background: var(--accent); color: var(--accent-contrast);
  font-size: 11px; font-weight: var(--fw-semibold); line-height: 18px; text-align: center;
}
.nav__link .nav__badge { position: absolute; transform: translate(14px, -12px); }
.nav__badge:empty { display: none; }

@media (min-width: 900px) {
  .nav {
    inset: 0 auto 0 0; width: var(--sidebar-w);
    border-top: 0; border-right: var(--border-width) solid var(--border);
    background: var(--surface);
    -webkit-backdrop-filter: none; backdrop-filter: none;
    padding: var(--s-3) var(--s-2);
    display: flex; flex-direction: column; gap: var(--s-3);
  }
  .nav > .nav__brand {
    display: flex; align-items: center; gap: var(--s-1);
    padding: 0 var(--s-1); font-weight: var(--fw-semibold);
  }
  .nav__brand img { width: 28px; height: 28px; border-radius: 7px; }
  .nav > .nav__add { display: inline-flex; }
  .nav__list { display: flex; flex-direction: column; gap: var(--s-half); }
  .nav__link {
    flex-direction: row; justify-content: flex-start; gap: var(--s-1);
    min-height: var(--touch); padding: 0 var(--s-1); border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
  }
  .nav__link svg { width: 20px; height: 20px; }
  .nav__link:hover { background: var(--surface-2); color: var(--text); }
  .nav__link[aria-current="page"] { background: var(--accent-soft); }
  .nav__link .nav__badge { position: static; transform: none; margin-left: auto; }

  main {
    margin-left: calc(var(--sidebar-w) + max(0px, (100vw - var(--sidebar-w) - var(--content-max)) / 2));
    padding: var(--s-5) var(--s-4);
  }
}

/* ---- Floating add button ------------------------------------------------ */

.fab {
  position: fixed; z-index: 21;
  right: calc(env(safe-area-inset-right) + var(--s-2));
  bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h) + var(--s-2));
  width: 56px; height: 56px; border-radius: var(--radius-pill);
  display: grid; place-items: center;
  border: 0; background: var(--accent); color: var(--accent-contrast);
  box-shadow: var(--shadow-overlay); cursor: pointer;
}
.fab svg { width: 24px; height: 24px; }
.fab:active { transform: scale(0.96); }
@media (min-width: 900px) { .fab { display: none; } }   /* desktop uses the sidebar button */

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

.page-header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.page-title {
  font-size: var(--fs-2xl); font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-tight); line-height: var(--lh-tight);
}
.page-title:focus { outline: none; }   /* focused only so screen readers announce the new screen */
.page-subtitle { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--s-half); }

/* ---- Cards & sections --------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: var(--s-2); }
.grid-2 { display: grid; gap: var(--s-2); }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.card {
  background: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-2);
  box-shadow: var(--shadow-1);
}
@media (min-width: 640px) { .card { padding: var(--s-3); } }

.label {
  color: var(--text-muted); font-size: var(--fs-sm); font-weight: var(--fw-medium);
}
.big-number {
  font-size: var(--fs-display); font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-tight); line-height: var(--lh-tight);
  font-variant-numeric: tabular-nums;
}
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }

.section-title {
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-muted);
  margin: var(--s-3) 0 var(--s-1);
}
.section-title:first-child { margin-top: 0; }

/* ---- Grouped list (settings rows, transactions) ------------------------ */

.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.list > li + li { border-top: var(--border-width) solid var(--border); }
.row {
  display: flex; align-items: center; gap: var(--s-2);
  min-height: calc(var(--touch) + var(--s-1));
  padding: var(--s-1) var(--s-2);
}
.row__main { flex: 1; min-width: 0; }
.row__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__hint { color: var(--text-muted); font-size: var(--fs-sm); }
.row--stack { flex-direction: column; align-items: stretch; gap: var(--s-1); padding-block: var(--s-2); }

.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: var(--radius-pill);
  background: var(--dot, var(--text-muted)); flex: none;
}

/* ---- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-1);
  min-height: var(--touch); padding: 0 var(--s-2);
  border-radius: var(--radius-sm); border: var(--border-width) solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  cursor: pointer; text-decoration: none;
  transition: background var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 18px; height: 18px; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { background: color-mix(in oklab, var(--accent) 88%, black); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--accent-text); }
.btn--ghost:hover { background: var(--accent-soft); }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Form controls ------------------------------------------------------ */

.field { display: flex; flex-direction: column; gap: var(--s-half); }
.input, .select {
  min-height: var(--touch); width: 100%;
  padding: 0 var(--s-2);
  border: var(--border-width) solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); font-size: var(--fs-md);      /* ≥16px: no iOS zoom on focus */
}
.select { appearance: none; padding-right: var(--s-5);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat;
}

/* Segmented control (radio group) */
.segmented {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 2px; gap: 2px; width: 100%;
  background: var(--surface-2); border-radius: var(--radius-sm);
  border: 0; margin: 0;
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(var(--touch) - 4px); padding: 0 var(--s-1);
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-muted);
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.segmented input:focus-visible + span { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

/* Colour swatches (radio group) */
.swatches { display: flex; flex-wrap: wrap; gap: var(--s-1); border: 0; margin: 0; padding: 0; }
.swatch { position: relative; width: var(--touch); height: var(--touch); display: grid; place-items: center; }
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatch span {
  width: 28px; height: 28px; border-radius: var(--radius-pill); background: var(--swatch);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--text) 20%, transparent);   /* keeps dark swatches visible on dark surfaces */
}
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--swatch); }
.swatch input:focus-visible + span { outline: 2px solid var(--focus-ring); outline-offset: 4px; }
.swatch--custom input[type="color"] { opacity: 0; }
.swatch--custom span { background: conic-gradient(from 0deg, var(--cat-3), var(--cat-8), var(--cat-2), var(--cat-5), var(--cat-1), var(--cat-7), var(--cat-3)); }

/* ---- Progress bar ------------------------------------------------------- */

.bar { height: 8px; border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; width: var(--pct, 0%); background: var(--bar-color, var(--accent)); border-radius: inherit; }
.bar--over > span { background: var(--negative); }

/* ---- Empty state -------------------------------------------------------- */

.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-1);
  padding: var(--s-5) var(--s-3);
  color: var(--text-muted);
}
.empty__title { color: var(--text); font-weight: var(--fw-semibold); }
.empty svg { width: 32px; height: 32px; margin-bottom: var(--s-1); }

/* ---- Toast -------------------------------------------------------------- */

.toast-region {
  position: fixed; z-index: 50; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h) + var(--s-2));
  display: flex; flex-direction: column; gap: var(--s-1);
  width: min(480px, calc(100vw - 2 * var(--s-2)));
  pointer-events: none;
}
@media (min-width: 900px) { .toast-region { bottom: var(--s-3); left: calc(50% + var(--sidebar-w) / 2); } }
.toast {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-1) var(--s-1) var(--s-1) var(--s-2); min-height: calc(var(--touch) + var(--s-1));
  background: var(--text); color: var(--bg);
  border-radius: var(--radius); box-shadow: var(--shadow-overlay);
  font-size: var(--fs-sm); pointer-events: auto;
}
.toast__msg { flex: 1; }
.toast .btn--ghost { color: var(--bg); }
.toast .btn--ghost:hover { background: color-mix(in oklab, var(--bg) 14%, transparent); }

/* ---- Link rows, icon buttons, back link -------------------------------- */

.row--link { color: inherit; text-decoration: none; }
.row--link:hover { background: var(--surface-2); }
.row--link > svg, .row__btn > svg { width: 18px; height: 18px; color: var(--text-muted); flex: none; }
.row__value { font-size: var(--fs-sm); }
.row__lead { font-size: var(--fs-lg); width: var(--s-3); text-align: center; flex: none; }
.row__btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s-2);
  min-height: var(--touch); padding: 0; margin: 0;
  background: none; border: 0; text-align: left; cursor: pointer;
}
.row__actions { display: flex; gap: var(--s-half); flex: none; }

.icon-btn {
  width: var(--touch); height: var(--touch); flex: none;
  display: inline-grid; place-items: center;
  background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn svg { width: 20px; height: 20px; }

.back-link {
  display: inline-flex; align-items: center; gap: var(--s-half);
  min-height: var(--touch); margin: calc(-1 * var(--s-1)) 0 var(--s-1) calc(-1 * var(--s-1)); padding: 0 var(--s-1);
  color: var(--accent-text); text-decoration: none; font-size: var(--fs-sm); font-weight: var(--fw-medium);
}
.back-link svg { width: 18px; height: 18px; }

.btn--danger { color: var(--negative); }
.btn--danger:hover { background: var(--negative-soft); }

.toolbar { display: flex; gap: var(--s-1); align-items: center; margin-bottom: var(--s-2); }
.toolbar > .input { flex: 1; }

.badge {
  display: inline-block; padding: 0 var(--s-1); border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: var(--fw-medium); line-height: 20px;
}

/* ---- Form layout -------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: var(--s-2); }
.form-row { display: grid; grid-template-columns: 88px 1fr; gap: var(--s-2); }
.input--emoji { text-align: center; font-size: var(--fs-xl); padding: 0; }
.input[aria-invalid="true"] { border-color: var(--negative); }
.field__error { color: var(--negative); }
.danger-zone { display: flex; flex-wrap: wrap; gap: var(--s-1); padding-top: var(--s-2); border-top: var(--border-width) solid var(--border); }

/* ---- Dialog: bottom sheet on phones, centred on larger screens --------- */

.dialog {
  width: 100%; max-width: 560px; max-height: 90dvh;
  margin: auto auto 0; padding: 0;
  border: var(--border-width) solid var(--border); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-overlay);
}
.dialog::backdrop { background: var(--scrim); }
.dialog__form { display: flex; flex-direction: column; max-height: 90dvh; }
.dialog__header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-1);
  padding: var(--s-1) var(--s-1) var(--s-1) var(--s-2);
  border-bottom: var(--border-width) solid var(--border);
}
.dialog__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.dialog__body { padding: var(--s-2); overflow-y: auto; }
.dialog__footer {
  display: flex; justify-content: flex-end; gap: var(--s-1);
  padding: var(--s-1) var(--s-2) calc(env(safe-area-inset-bottom) + var(--s-1));
  border-top: var(--border-width) solid var(--border);
}
.dialog__footer .btn { flex: 1; }
@media (min-width: 640px) {
  .dialog { margin: auto; border-bottom: var(--border-width) solid var(--border); border-radius: var(--radius); }
  .dialog__footer { padding-bottom: var(--s-1); }
  .dialog__footer .btn { flex: none; }
}

/* ---- Transaction form --------------------------------------------------- */

.amount-input {
  display: flex; align-items: baseline; gap: var(--s-1);
  padding: var(--s-1) var(--s-2);
  border: var(--border-width) solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface);
}
.amount-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.amount-input__symbol { font-size: var(--fs-2xl); color: var(--text-muted); }
.amount-input__field {
  flex: 1; min-width: 0; border: 0; background: none; outline: none;
  font-size: var(--fs-display); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-tight);
}
.amount-input__field[aria-invalid="true"] { color: var(--negative); }
.amount-input + .field__error, .amount-input ~ .field__error { margin-top: calc(-1 * var(--s-1)); }

.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-1); border: 0; margin: 0; padding: 0; }
@media (min-width: 480px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }
.cat-grid legend { margin-bottom: var(--s-1); padding: 0; }
.cat-chip { position: relative; }
.cat-chip input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.cat-chip__body {
  display: flex; align-items: center; gap: var(--s-1);
  min-height: var(--touch); padding: var(--s-1);
  border: var(--border-width) solid var(--border); border-radius: var(--radius-sm);
  font-size: var(--fs-sm); line-height: var(--lh-tight);
}
.cat-chip__name { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cat-chip input:checked + .cat-chip__body {
  border-color: var(--dot); box-shadow: inset 0 0 0 1px var(--dot);
  background: color-mix(in oklab, var(--dot) 10%, transparent);
}
.cat-chip input:focus-visible + .cat-chip__body { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.details > summary {
  display: flex; align-items: center; min-height: var(--touch); cursor: pointer;
  color: var(--accent-text); font-size: var(--fs-sm); font-weight: var(--fw-medium);
  list-style: none;
}
.details > summary::-webkit-details-marker { display: none; }
.details > summary::after { content: "›"; margin-left: var(--s-1); transition: transform var(--dur) var(--ease); }
.details[open] > summary::after { transform: rotate(90deg); }
.details > .form { padding-top: var(--s-1); }

.check { display: flex; align-items: center; gap: var(--s-1); min-height: var(--touch); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; flex: none; }
.textarea { min-height: calc(var(--touch) * 1.5); padding: var(--s-1) var(--s-2); resize: vertical; }
[hidden] { display: none !important; }

/* ---- Transactions list -------------------------------------------------- */

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-1); }
@media (min-width: 900px) { .filters { grid-template-columns: repeat(4, 1fr); } }
.select--sm { font-size: var(--fs-md); padding-left: var(--s-1); }

.chip {
  display: inline-flex; align-items: center; gap: var(--s-1);
  min-height: var(--touch); padding: 0 var(--s-2); margin-bottom: var(--s-2);
  border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent-text);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); text-decoration: none;
}
.chip svg { width: 18px; height: 18px; }

.day-heading {
  display: flex; justify-content: space-between; gap: var(--s-2);
  margin: var(--s-1) var(--s-2) var(--s-1);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-muted);
}
.tx-row { width: 100%; padding: var(--s-1) var(--s-2); }
.row--select { cursor: pointer; }
.row--select input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; margin: 0; }
.row__amount { text-align: right; flex: none; font-weight: var(--fw-medium); }
.row__hint .badge { margin-left: var(--s-half); vertical-align: 1px; }

.bulk-bar {
  position: fixed; z-index: 22; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h));
  display: flex; align-items: center; gap: var(--s-1);
  padding: var(--s-1) var(--s-2);
  background: var(--surface); border-top: var(--border-width) solid var(--border);
  box-shadow: var(--shadow-overlay);
}
.bulk-bar__count { flex: 1; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
@media (min-width: 900px) { .bulk-bar { left: var(--sidebar-w); bottom: 0; } }
.kb-proxy { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; border: 0; padding: 0; pointer-events: none; }
.cat-icon {
  width: 36px; height: 36px; flex: none; border-radius: var(--radius-pill);
  display: grid; place-items: center; font-size: var(--fs-lg);
  background: color-mix(in oklab, var(--dot, var(--text-muted)) 16%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--dot, var(--text-muted)) 40%, transparent);
}
.tx-row .row__main { min-width: 0; }
.is-selecting .fab { display: none; }

/* ---- Import preview & inbox --------------------------------------------- */

.summary-list .row { min-height: var(--touch); }
.details .row__hint { white-space: pre-line; }
.callout {
  display: flex; flex-direction: column; gap: var(--s-1);
  padding: var(--s-2); border-radius: var(--radius-sm);
  background: var(--accent-soft);
}
.inbox-card__desc { font-size: var(--fs-lg); font-weight: var(--fw-medium); overflow-wrap: anywhere; }
.cat-btn { width: 100%; background: var(--surface); color: var(--text); cursor: pointer; text-align: left; }
.cat-btn:hover { border-color: var(--dot); background: color-mix(in oklab, var(--dot) 10%, transparent); }
.inbox-card__actions { display: flex; justify-content: space-between; }
.header-actions { display: flex; gap: var(--s-1); flex-wrap: wrap; justify-content: flex-end; }
.card--link { display: flex; color: inherit; text-decoration: none; }
.card--link:hover { border-color: var(--border-strong); }

/* ---- Overview ------------------------------------------------------------ */

.page-header .segmented { width: auto; min-width: 200px; }
@media (max-width: 520px) {
  .page-header:has(.segmented) { flex-direction: column; align-items: stretch; }
  .page-header .segmented { width: 100%; }
}
.stats { margin: 0; display: flex; flex-direction: column; gap: var(--s-half); }
.stat-row { display: flex; justify-content: space-between; gap: var(--s-2); font-size: var(--fs-sm); }
.stat-row dt, .stat-row dd { margin: 0; }
.stat-row dd { font-weight: var(--fw-medium); }
.tone-negative { color: var(--negative); }
.tone-positive { color: var(--positive); }

.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-2); }
.card-head a { text-decoration: none; }
.top-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.top-row {
  display: flex; align-items: center; gap: var(--s-2);
  min-height: calc(var(--touch) + var(--s-1)); padding: var(--s-1) 0;
  color: inherit; text-decoration: none;
}
.top-list li + li .top-row { border-top: var(--border-width) solid var(--border); }
.top-row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--s-half); }
.top-row__line { display: flex; justify-content: space-between; gap: var(--s-1); }

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

.chart-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-2);
  margin-bottom: var(--s-2);
}
.chart-controls .field { min-width: 180px; }
.chart-controls .segmented { width: auto; min-width: 200px; }
@media (max-width: 520px) {
  .chart-controls > * { flex: 1 1 100%; }
  .chart-controls .segmented { width: 100%; }
}
.chart-card { margin-bottom: var(--s-2); }
.chart-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.chart-box { position: relative; width: 100%; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-half) var(--s-2); font-size: var(--fs-sm); color: var(--text-muted); }
.legend li { display: inline-flex; align-items: center; gap: var(--s-1); }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--dot); flex: none; }
.legend__swatch--dashed { height: 0; width: 16px; border-radius: 0; background: none; border-top: 2px dashed var(--dot); }

.chip-row { display: flex; flex-wrap: wrap; gap: var(--s-1); }
.toggle-chip {
  display: inline-flex; align-items: center; gap: var(--s-1);
  min-height: 36px; padding: 0 var(--s-2); border-radius: var(--radius-pill);
  border: var(--border-width) solid var(--border); background: var(--surface); color: var(--text-muted);
  font-size: var(--fs-sm); cursor: pointer;
}
.toggle-chip[aria-pressed="true"] { color: var(--text); border-color: var(--dot); background: color-mix(in oklab, var(--dot) 10%, transparent); }
.toggle-chip[aria-pressed="false"] .legend__swatch { opacity: 0.35; }
@media (pointer: coarse) { .toggle-chip { min-height: var(--touch); } }

.multiples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-1); }
@media (min-width: 640px) { .multiples { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .multiples { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.multiple {
  display: flex; flex-direction: column; gap: var(--s-half);
  padding: var(--s-1) var(--s-1) var(--s-half);
  border: var(--border-width) solid var(--border); border-radius: var(--radius-sm);
  color: inherit; text-decoration: none; min-width: 0;
}
.multiple:hover { border-color: var(--border-strong); }
.multiple__head { display: flex; justify-content: space-between; gap: var(--s-1); align-items: baseline; }
.multiple__name { font-size: var(--fs-sm); font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.table-wrap { overflow-x: auto; }
.chart-table table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.chart-table th, .chart-table td { padding: var(--s-1); border-bottom: var(--border-width) solid var(--border); text-align: left; white-space: nowrap; }
.chart-table thead th { color: var(--text-muted); font-weight: var(--fw-medium); }
.chart-table .num { text-align: right; }
.chart-table tbody th { font-weight: var(--fw-regular); }
@media (max-width: 639px) {
  .multiple__head { flex-direction: column; align-items: flex-start; gap: 0; }
  .multiple__name { max-width: 100%; }
}

/* ---- Backup reminder ------------------------------------------------------ */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-1) var(--s-2);
  margin-bottom: var(--s-2); padding: var(--s-2);
  border: var(--border-width) solid color-mix(in oklab, var(--accent) 35%, var(--border));
  border-radius: var(--radius); background: var(--accent-soft);
}
.banner p { flex: 1 1 240px; }
.banner__actions { display: flex; gap: var(--s-1); }
