/* ============================================================================
   app.css — Expense Tracker · Forest design system
   ============================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Hanken+Grotesk:wght@400;500;600;700;800&family=Newsreader:opsz,wght@6..72,400;6..72,500;6..72,600&family=Spline+Sans+Mono:wght@400;500&display=swap');

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

/* The UA's `[hidden] { display: none }` is a plain type-less rule, so any class that sets
   display — .btn is inline-flex, for one — silently outranks it and the element stays on
   screen. Anything marked hidden must actually be hidden. */
[hidden] { display: none !important; }

/* ── Forest light (default) ────────────────────────────────────────────────── */
:root,
[data-theme="forest"] {
    --bg:          #e8efdf;
    --surface:     #fbfcf4;
    --soft:        #edf3e4;
    --track:       #dbe6cd;
    --hair:        #dde8d2;
    --ink:         #1b2a20;
    --ink2:        #52614e;
    --muted:       #5d6755;
    --muted2:      #7f8c6d;
    --accent:      #26845c;
    --accent2:     #15623f;
    --accent-soft: #d5e8d6;
    --on-accent:   #fbfcf4;
    --pos:         #bb8a24;
    --pos-soft:    #f3e9c8;
    --clay:        #c5824c;

    /* Text-safe siblings of the fill colours above. --accent/--pos/--clay are tuned to
       look right as *fills* (bars, dots, chips) and are too light to carry text at
       WCAG AA on our backgrounds; --*-ink is the same hue darkened until it passes.
       --accent-fill is the inverse case: a filled surface dark enough that --on-accent
       text sitting on it clears 4.5:1. */
    --accent-ink:  #15623f;
    --accent-fill: #237a56;
    --pos-ink:     #7d5f16;
    --clay-ink:    #8a5730;
    --danger-ink:  #b04a35;

    /* backward-compat aliases for existing class-based CSS */
    --color-primary:        var(--accent);
    --color-primary-hover:  var(--accent2);
    --color-primary-fg:     var(--on-accent);
    --color-primary-10:     rgba(38,132,92,0.10);
    --color-primary-20:     rgba(38,132,92,0.20);
    --color-primary-30:     rgba(38,132,92,0.30);
    --color-bg:             var(--bg);
    --color-surface:        var(--surface);
    --color-secondary:      var(--soft);
    --color-muted:          var(--track);
    --color-text:           var(--ink);
    --color-text-secondary: var(--ink2);
    --color-text-muted:     var(--muted);
    --color-border:         var(--hair);
    --color-ring:           var(--accent);
    --color-success:        #26845c;
    --color-warning:        #bb8a24;
    --color-danger:         #b04a35;
    --color-danger-hover:   #963d2c;
    --color-info:           #6b8cae;
    --color-warning-bg:     #f3e9c8;
    --color-warning-text:   #8a6a1a;
    --color-error-bg:       #ffe8e7;
    --color-error-text:     #a10128;

    --sidebar-w: 248px;

    /* Radius and padding scale. Card radii used to run 11/13/14/16/18/20px and paddings
       18/20/22/24px with no rule behind which was which. Three radius steps cover every
       real case: a card, a control, and a small square icon button — that last step is a
       deliberate third rung, because folding 8px icon buttons into the 12px control step
       makes a 26px button read as a circle. Legacy --radius/-sm/-lg are kept as aliases. */
    --radius-card:    18px;
    --radius-control: 12px;
    --radius-chip:     8px;
    --radius-pill:   999px;
    --pad-card:       20px;
    --pad-card-lg:    24px;

    --radius:    var(--radius-control);
    --radius-sm: var(--radius-control);
    --radius-lg: var(--radius-card);

    --shadow:    0 1px 2px rgba(43,37,33,.04);
    --shadow-md: 0 4px 8px -2px rgba(43,37,33,.08);
    --shadow-lg: 0 14px 30px -16px rgba(21,98,63,.4);

    --font:   'Hanken Grotesk', system-ui, sans-serif;
    --serif:  'Newsreader', Georgia, serif;
    --mono:   'Spline Sans Mono', ui-monospace, monospace;
}

/* ── Forest dark ────────────────────────────────────────────────────────────── */
[data-theme="forest-dark"] {
    --bg:          #10201a;
    --surface:     #17261e;
    --soft:        #1e2d24;
    --track:       #2a3a30;
    --hair:        #2a3930;
    --ink:         #e9f0e5;
    --ink2:        #aebcb0;
    --muted:       #96a397;
    --muted2:      #7d8c81;
    --accent:      #2f9e6b;
    --accent2:     #1f6f4c;
    --accent-soft: #1c3328;
    --on-accent:   #fbfcf4;
    --pos:         #d2a23a;
    --pos-soft:    #2f2a17;
    --clay:        #cf8a54;

    /* Dark flips which direction needs help: --pos/--clay already read fine on a dark
       surface, but the accent has to go *darker* to carry white text and *lighter* to
       be read as text itself, and --color-danger only clears AA once lightened. */
    --accent-ink:  #3fbc84;
    --accent-fill: #20835a;
    --pos-ink:     var(--pos);
    --clay-ink:    var(--clay);
    --danger-ink:  #e2816e;

    --color-primary:        var(--accent);
    --color-primary-hover:  var(--accent2);
    --color-primary-fg:     var(--on-accent);
    --color-primary-10:     rgba(47,158,107,0.15);
    --color-primary-20:     rgba(47,158,107,0.25);
    --color-primary-30:     rgba(47,158,107,0.35);
    --color-bg:             var(--bg);
    --color-surface:        var(--surface);
    --color-secondary:      var(--soft);
    --color-muted:          var(--track);
    --color-text:           var(--ink);
    --color-text-secondary: var(--ink2);
    --color-text-muted:     var(--muted);
    --color-border:         var(--hair);
    --color-error-bg:       rgba(176,74,53,0.15);
    --color-error-text:     #e2816e;
}

html { font-size: 16px; }

body {
    font-family: var(--font);
    background:  var(--bg);
    color:       var(--ink);
    line-height: 1.5;
    min-height:  100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background .25s ease, color .25s ease;
}

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

/* ── Type utilities ───────────────────────────────────────────────────────── */
.et-serif  { font-family: var(--serif); }
.et-mono   { font-family: var(--mono); }
.et-num    { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

/* ── Logo mark ─────────────────────────────────────────────────────────────── */
.logo {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    text-decoration: none;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.logo:hover { opacity: 0.85; text-decoration: none; }

.logo__leaf {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent-soft);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.logo__leaf-inner {
    width: 16px;
    height: 16px;
    background: linear-gradient(140deg, #2f9367, var(--accent2));
    border-radius: 1px 100% 1px 100%;
    transform: rotate(45deg);
    display: block;
}
.logo__wordmark {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.2px;
    color: var(--ink);
}
.logo__dot      { color: var(--accent-ink); }
.logo__secondary { font-weight: 500; color: var(--ink2); }

/* ── App shell & sidebar ───────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 22px 16px;
    background: var(--surface);
    border-right: 1px solid var(--hair);
    z-index: 30;
    transition: background .25s ease, border-color .25s ease;
}

.sidebar__logo {
    padding: 4px 8px 18px;
}

.sidebar__household {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 9px 11px;
    margin-bottom: 14px;
    background: var(--soft);
    border: 1px solid var(--hair);
    border-radius: var(--radius-control);
    text-align: left;
    text-decoration: none;
    color: var(--ink);
}
.sidebar__household:hover { text-decoration: none; border-color: var(--accent-soft); }
.sidebar__household-icon {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-chip);
    background: var(--surface);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex: 0 0 auto;
}
.sidebar__household-name {
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
.sidebar__household-chevron { color: var(--muted); font-size: 12px; flex: 0 0 auto; }

.sidebar__menu-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.8px;
    color: var(--muted);
    padding: 0 11px 7px;
    text-transform: uppercase;
}

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar__nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 11px;
    border-radius: var(--radius-control);
    font-size: 14.5px;
    font-weight: 500;
    color: var(--ink2);
    text-decoration: none;
    transition: background .15s, color .15s;
}
.sidebar__nav-link:hover { background: var(--soft); color: var(--ink); text-decoration: none; }
.sidebar__nav-link--active {
    color: var(--accent-ink);
    font-weight: 700;
    background: var(--accent-soft);
}

/* Pending-count pill on a nav link (SMS review queue). Pushed to the trailing edge so the
   label stays aligned with every other item's. */
.sidebar__nav-count {
    margin-left: auto;
    min-width: 20px;
    padding: 1px 6px;
    border-radius: var(--radius-pill);
    background: var(--accent-fill);
    color: var(--on-accent);
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1.5;
    text-align: center;
}
.sidebar__nav-link--active .sidebar__nav-count { background: var(--accent-fill); color: var(--on-accent); }

.sidebar__spacer { flex: 1; }

.sidebar__theme-toggle {
    display: flex;
    gap: 4px;
    background: var(--soft);
    border: 1px solid var(--hair);
    border-radius: var(--radius-control);
    padding: 4px;
    margin-top: 12px;
}
.sidebar__theme-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    border-radius: var(--radius-chip);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    border: none;
    transition: background .15s, color .15s, box-shadow .15s;
}
.sidebar__theme-btn--active {
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 1px 3px rgba(0,0,0,.14);
    font-weight: 700;
}

.sidebar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 8px 2px;
    margin-top: 10px;
    border-top: 1px solid var(--track);
}
.sidebar__user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex: 0 0 auto;
}
.sidebar__user-info { min-width: 0; line-height: 1.3; }
.sidebar__user-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-role { font-size: 12px; color: var(--muted); }

/* ── Mobile top bar ─────────────────────────────────────────────────────────── */
.topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 25;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--hair);
    transition: background .25s ease;
}
.topbar__theme-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-chip);
    border: 1px solid var(--hair);
    background: var(--soft);
    color: var(--ink2);
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s;
}
.topbar__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex: 0 0 auto;
}

/* ── App content area ───────────────────────────────────────────────────────── */
.app-content {
    padding-left: var(--sidebar-w);
    min-height: 100vh;
}
.app-content__inner {
    max-width: 1140px;
    margin: 0 auto;
    padding: 30px 40px 70px;
}

/* ── Mobile bottom nav ──────────────────────────────────────────────────────── */
.bottomnav {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 25;
    align-items: center;
    justify-content: space-around;
    padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
    background: var(--surface);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--hair);
    transition: background .25s ease;
}
.bottomnav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    flex: 1;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    padding: 4px 0;
    transition: color .15s;
}
.bottomnav__item:hover { color: var(--ink2); text-decoration: none; }
.bottomnav__item--active { color: var(--accent-ink); }

/* ── Auth/guest layout (no sidebar) ────────────────────────────────────────── */
.main { padding: 1.5rem 1.5rem 3rem; }

@media (max-width: 900px) {
    .sidebar     { display: none; }
    .topbar      { display: flex; }
    .bottomnav   { display: flex; }
    .app-content { padding-left: 0; padding-bottom: 94px; }
    .app-content__inner { padding: 20px 16px 40px; }
}

/* ── Page auth layout ───────────────────────────────────────────────────────── */
.page--auth {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    padding: 1.5rem 1rem;
}
.auth { width: 100%; max-width: 420px; }
.auth__header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
    text-align: center;
}
.auth__card {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}
.auth__title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--ink);
    margin-bottom: 0.25rem;
}
.auth__subtitle { font-size: 0.9rem; color: var(--muted); line-height: 1.5; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    border: 1px solid transparent;
    line-height: 1.5;
}
.alert--error   { background: var(--color-error-bg);   color: var(--color-error-text);   border-color: #ffc3c2; }
.alert--success { background: #ddffdd;                 color: #004c00;                   border-color: #abe6ac; }
.alert--info    { background: #e2f8ff;                 color: #00397f;                   border-color: #add9ff; }
.alert--warning { background: var(--color-warning-bg); color: var(--color-warning-text); border-color: #f3d392; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form        { display: flex; flex-direction: column; gap: 1rem; }
.form__group { display: flex; flex-direction: column; gap: 0.375rem; }
.form__label { font-size: 0.875rem; font-weight: 500; color: var(--ink); }

.form__input,
.form__select,
.form__textarea {
    padding: 0.625rem 0.75rem;
    height: 2.75rem;
    border: 1.5px solid var(--hair);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9375rem;
    width: 100%;
    background: var(--soft);
    color: var(--ink);
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}
.form__textarea { height: auto; min-height: 6rem; }
.form__input::placeholder,
.form__select::placeholder,
.form__textarea::placeholder { color: var(--muted); }
.form__input:focus,
.form__select:focus,
.form__textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--color-primary-20);
}
.form__input[type="file"] { height: auto; padding: 0.5rem; }
.form__row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0 1rem;
    height: 2.25rem;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
    white-space: nowrap;
    line-height: 1;
    user-select: none;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--color-primary-30); }

.btn--primary       { background: var(--accent-fill); color: var(--on-accent); border-color: var(--accent-fill); }
.btn--primary:hover { background: var(--accent2); border-color: var(--accent2); text-decoration: none; color: var(--on-accent); }

.btn--danger        { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn--danger:hover  { background: var(--color-danger-hover); border-color: var(--color-danger-hover); text-decoration: none; color: #fff; }

.btn--ghost         { background: transparent; border-color: var(--hair); color: var(--ink); }
.btn--ghost:hover   { background: var(--soft); text-decoration: none; color: var(--ink); }

.btn--sm    { height: 1.875rem; padding: 0 0.625rem; font-size: 0.8125rem; }
.btn--full  { width: 100%; height: 2.75rem; font-size: 0.9375rem; }

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow);
    padding: var(--pad-card);
}
.card__title {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
    margin-bottom: 1rem;
}
/* D1: chart cards carry a metric title plus a quiet period subtitle. */
.chart-head { margin-bottom: 1rem; }
.chart-head .card__title { margin-bottom: 2px; }
.chart-head__sub { font-size: 12.5px; color: var(--muted); }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 0.75rem;
}

/* ── Category tag ─────────────────────────────────────────────────────────── */
/* The transactions list itself is styled by the windowed `.tx-*` block far below;
   this rule is only the pill used by the project-budget item table. */
.expense-item__cat    { font-size: 0.75rem; padding: 0.2rem 0.6rem; border-radius: var(--radius-pill); background: var(--soft); border: 1px solid var(--hair); white-space: nowrap; font-weight: 500; color: var(--ink2); }

/* ── Summary ──────────────────────────────────────────────────────────────── */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }
.summary__item {
    text-align: center;
    padding: 1.125rem 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--hair);
}
.summary__value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    color: var(--ink);
}
.summary__label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--muted);
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ── Loading / empty states ───────────────────────────────────────────────── */
.empty-state { text-align: center; color: var(--muted); padding: 2.5rem 1rem; font-size: 0.875rem; line-height: 1.6; }
.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid var(--hair); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 0.25rem;
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-lg);
    padding: 0.25rem;
    box-shadow: var(--shadow);
    /* Twelve tabs don't fit a phone, and this is a filter row, not a page: it scrolls
       inside itself rather than widening the document. */
    overflow-x: auto;
    max-width: 100%;
    scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-bar__btn {
    /* Sized by its label, not stretched to an equal share — "Last 30d" and "Jul" have
       nothing to gain from matching widths, and equal shares in a scrolling row would
       squeeze every label toward ellipsis. */
    flex: 0 0 auto;
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.filter-bar__btn:hover     { background: var(--soft); color: var(--ink); }
.filter-bar__btn--active   { background: var(--ink); color: var(--bg); }

/* ── Slide-over drawer (replaces native <dialog> modals app-wide) ───────────── */
body.drawer-scroll-lock { overflow: hidden; }

.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 61;
    width: min(500px, 100vw);
    max-width: 100vw;
    background: var(--surface);
    box-shadow: -12px 0 40px -12px rgba(42,37,33,.5);
    /* Column with a scrolling middle: the header and the Cancel/Save footer stay put while
       the fields scroll, so Save is reachable without scrolling a long form to the bottom —
       which on a phone, where the drawer is full-bleed, was the only way to reach it. */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(100%);
    visibility: hidden;
    transition: transform .28s cubic-bezier(.16,1,.3,1), visibility 0s linear .28s;
}
/* Drawers that still predate <form-drawer> keep the old single-scroll behaviour. */
.drawer:not(:has(> .drawer__body)) { display: block; overflow-y: auto; }
.drawer.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform .28s cubic-bezier(.16,1,.3,1), visibility 0s;
}
.drawer__inner { padding: var(--pad-card-lg); }

/* ── <form-drawer> chrome ─────────────────────────────────────────────────── */
.drawer__head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px var(--pad-card-lg);
    border-bottom: 1px solid var(--hair);
}
.drawer__title {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.2px;
    margin: 0;
}
.drawer__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--pad-card-lg);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.drawer__subtitle {
    font-size: 13.5px;
    color: var(--muted);
    margin: -4px 0 0;
}
.drawer__foot {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 14px var(--pad-card-lg) calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--hair);
    background: var(--soft);
}

/* Sits in <form-drawer>'s header. createDrawer() still injects one, absolutely positioned,
   for any drawer that has not been migrated to the shell yet — hence the position reset
   below for the header case. */
.drawer__close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 2;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-control);
    background: var(--soft);
    color: var(--ink2);
    cursor: pointer;
    padding: 0;
}
.drawer__close:hover { background: var(--track); color: var(--ink); }
.drawer__close:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--color-primary-30); }
.drawer__head .drawer__close { position: static; flex: 0 0 auto; }
/* Keep the drawer's own title clear of the dismiss control. */
.drawer__inner > .card__title:first-child { padding-right: 44px; }

/* ── Charts ───────────────────────────────────────────────────────────────── */
.charts-card { padding: 1.5rem; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.chart-section__title {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 0.75rem;
}
.chart-container--donut,
.chart-container--bar   { position: relative; height: 220px; }
.chart-empty            { text-align: center; color: var(--muted); font-size: 0.875rem; padding: 1rem 0; }

/* ── Expense list header ──────────────────────────────────────────────────── */
.expense-list-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 0.75rem;
}
.expense-list-count { font-size: 0.8rem; color: var(--muted); }

/* ── Section label ────────────────────────────────────────────────────────── */
.section-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 0.6rem;
}

/* ── Income bar ───────────────────────────────────────────────────────────── */
.income-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr;
    align-items: center;
    gap: 0.5rem;
    text-align: center;
}
.income-bar__tile { padding: 0.75rem 0.5rem; }
.income-bar__sep  { width: 1px; height: 2.5rem; background: var(--hair); }
.income-bar__value {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}
.income-bar__label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--muted);
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.income-bar__value--income   { color: var(--accent-ink); }
.income-bar__value--expense  { color: var(--danger-ink); }
.income-bar__value--positive { color: var(--accent-ink); }
.income-bar__value--negative { color: var(--danger-ink); }

/* ── Budget grid & progress bar ───────────────────────────────────────────── */
.budget-grid { display: flex; flex-direction: column; gap: 0.125rem; }

.budget-row {
    display: grid;
    grid-template-columns: 130px 1fr 160px 110px auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.375rem;
    border-bottom: 1px solid var(--hair);
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}
.budget-row:last-child { border-bottom: none; }
.budget-row:hover { background: var(--soft); }

.budget-row__cat              { font-weight: 500; font-size: 0.9rem; }
.budget-row__nums             { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 0.85rem; white-space: nowrap; }
.budget-row__nums--muted      { color: var(--muted); }
.budget-row__spent            { color: var(--ink); }
.budget-row__sep              { color: var(--muted); margin: 0 0.1rem; }
.budget-row__limit            { color: var(--muted); }
.budget-row__remaining        { font-size: 0.8rem; white-space: nowrap; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.budget-row__remaining--over  { color: var(--danger-ink); font-weight: 600; }
.budget-row__remaining--ok    { color: var(--accent-ink); }
.budget-row__actions          { display: flex; gap: 0.375rem; }

.budget-progress { height: 8px; background: var(--track); border-radius: var(--radius-pill); overflow: hidden; }
.budget-progress__bar         { height: 100%; border-radius: var(--radius-pill); transition: width 0.3s ease; }
.budget-progress__bar--ok     { background: var(--accent); }
.budget-progress__bar--warn   { background: var(--pos); }
.budget-progress__bar--over   { background: var(--color-danger); }
.budget-progress__bar--empty  { background: var(--hair); }

/* ── Project budget cards ─────────────────────────────────────────────────── */
.project-card {
    border: 1px solid var(--hair);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 0.75rem;
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.project-card:last-child { margin-bottom: 0; }
.project-card:hover { border-color: var(--accent-soft); box-shadow: var(--shadow); }

.project-card__header    { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.project-card__title-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.project-card__name      { font-weight: 600; font-size: 1rem; color: var(--ink); }
.project-card__actions   { display: flex; gap: 0.375rem; flex-shrink: 0; }
.project-card__metrics   { display: flex; gap: 1.5rem; margin-bottom: 0.5rem; }

.project-metric           { text-align: center; }
.project-metric__value    { display: block; font-weight: 700; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1rem; }
.project-metric__value--spent    { color: var(--danger-ink); }
.project-metric__value--upcoming { color: var(--pos-ink); }
.project-metric__value--over     { color: var(--danger-ink); }
.project-metric__label    { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }

/* ── Item table ───────────────────────────────────────────────────────────── */
.item-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; margin-top: 0.5rem; }
.item-table th {
    text-align: left;
    padding: 0.35rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--hair);
}
.item-table td                   { padding: 0.5rem; vertical-align: middle; }
.item-row + .item-row td         { border-top: 1px solid var(--hair); }
.item-row--paid .item-row__desc  { color: var(--muted); text-decoration: line-through; }
.item-row--cancelled             { opacity: 0.5; }
.item-row__amount  { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.item-row__date    { font-size: 0.8rem; color: var(--muted); white-space: nowrap; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.item-row__actions { display: flex; gap: 0.3rem; white-space: nowrap; }

/* ── Status badges ────────────────────────────────────────────────────────── */
.status-badge {
    display: inline-block;
    padding: 0.175rem 0.55rem;
    border-radius: var(--radius-pill);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.status-badge--active    { background: #d9ffd9; color: #005700; }
.status-badge--completed { background: #ddf9ff; color: #004288; }
.status-badge--cancelled { background: var(--track); color: var(--muted); }
.status-badge--planned   { background: #fff2c0; color: #814500; }
.status-badge--paid      { background: #d9ffd9; color: #005700; }

/* ── Income source rows ───────────────────────────────────────────────────── */
.income-source-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 0.375rem;
    border-bottom: 1px solid var(--hair);
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}
.income-source-row:last-of-type { border-bottom: none; }
.income-source-row:hover { background: var(--soft); }
.income-source-row__info    { display: flex; flex-direction: column; gap: 0.15rem; }
.income-source-row__name    { font-weight: 500; font-size: 0.9rem; }
.income-source-row__meta    { font-size: 0.8rem; color: var(--muted); }
.income-source-row__actions { display: flex; gap: 0.375rem; flex-shrink: 0; }

/* ── Income entry rows ────────────────────────────────────────────────────── */
.income-entry-row {
    display: grid;
    grid-template-columns: 90px 1fr auto auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.375rem;
    border-bottom: 1px solid var(--hair);
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}
.income-entry-row:last-of-type { border-bottom: none; }
.income-entry-row:hover { background: var(--soft); }
.income-entry-row__date   { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
/* Source and owner go on a second line rather than after the description: this card sits in a
   half-width column, and inline they either got ellipsised away or pushed into the amount. Same
   desc-over-meta stack as .activity-item__info. min-width:0 lets both lines ellipsise instead of
   widening the grid cell. */
.income-entry-row__desc   { font-size: 0.875rem; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.income-entry-row__desc-text,
.income-entry-row__desc-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.income-entry-row__desc-meta { font-size: 0.75rem; color: var(--muted); }
.income-entry-row__amount { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent-ink); white-space: nowrap; }
.income-entry-row__actions { display: flex; gap: 0.375rem; }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.text-muted { color: var(--muted); font-size: 0.875em; }
.container  { max-width: 1024px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.5rem; }

/* ── Avatar ───────────────────────────────────────────────────────────────── */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-weight: 600;
    user-select: none;
    border: 2px solid var(--surface);
    box-shadow: var(--shadow);
}
.avatar--xs { width: 1.5rem;  height: 1.5rem;  font-size: 0.65rem; }
.avatar--sm { width: 2rem;    height: 2rem;    font-size: 0.75rem; }
.avatar--lg { width: 4rem;    height: 4rem;    font-size: 1.4rem; }

/* ── Badge ────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--accent-fill);
    color: var(--on-accent);
    vertical-align: middle;
}
.badge--muted { background: var(--track); color: var(--muted); }
.badge--ai { background: var(--pos-soft); color: var(--pos-ink); border: 1px solid var(--pos-soft); }
.badge--ai-off { background: var(--soft); color: var(--muted); border: 1px solid var(--hair); }

/* ── Insight cards ────────────────────────────────────────────────────────── */
.insight-list { display: flex; flex-direction: column; gap: 12px; max-width: 720px; }
.insight-card {
    border-left: 4px solid transparent;
    border-radius: var(--radius-card);
    padding: var(--pad-card);
}
.insight-card--warn { background: var(--accent-soft); border-left-color: var(--accent); }
.insight-card--info { background: var(--surface); border: 1px solid var(--hair); border-left: 4px solid #6b8cae; }
.insight-card--good { background: var(--pos-soft); border-left-color: var(--pos); }
.insight-card__tag { font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; color: var(--muted); }
.insight-card__statement { font-size: 16.5px; font-weight: 600; line-height: 1.4; margin: 7px 0 5px; }
.insight-card__meta { font-size: 13.5px; color: var(--muted); }
.insight-card__actions { display: flex; gap: 8px; margin-top: 13px; }
.insight-footer-note {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 720px;
    margin-top: 16px;
    padding: 13px 16px;
    border: 1px dashed var(--muted2);
    border-radius: var(--radius-card);
    background: var(--soft);
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
}

/* ── Settings page ────────────────────────────────────────────────────────── */
.settings-section { margin-bottom: 0; }
.settings-flash   { margin-bottom: 1rem; }
.settings-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--hair);
}
/* The row's separator exists to divide it from whatever follows. On the Profile card the
   only thing that follows is the edit form, which starts collapsed — leaving a rule and
   24px of dead space dangling off the bottom of an otherwise finished card. */
.settings-profile:last-child,
.settings-profile:has(+ [hidden]) {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}
.settings-profile__name  { font-weight: 600; font-size: 1rem; }
.settings-profile__email { font-size: 0.875rem; color: var(--muted); margin-top: 0.125rem; }
.settings-hint { color: var(--muted); margin-bottom: 1rem; font-size: 0.9rem; line-height: 1.6; }
.settings-hint strong { color: var(--ink); }
.settings-form { max-width: 480px; }
/* `.form` is a column flex, so an inline variant has to put the direction back — without it
   the row collapsed into a right-aligned stack (field, then button on its own line) on the
   household, invite and base-currency forms. */
.settings-form--inline {
    display: flex;
    flex-direction: row;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
/* Fields carry `width: 100%`, which as a flex item resolves to a full-width flex basis and
   pushes the submit button onto its own line. Sizing them from flex instead keeps the row
   one line. */
.settings-form--inline > .form__input,
.settings-form--inline > .form__select { flex: 1; min-width: 180px; width: auto; }
.settings-form--inline > .form__group { flex: 1; min-width: 180px; }

/* Exchange rates: soft chips stacked in the Currency card, per the design. They used to
   borrow `.prefs-row`, whose borders belong to the Preferences card and left these sitting
   on bare background with nothing holding them together. */
.rate-list { display: flex; flex-direction: column; gap: 8px; }
.rate-list:empty { display: none; }
.rate-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--soft);
    border-radius: var(--radius-control);
    padding: 9px 13px;
}
.rate-row__code  { font-size: 14px; font-weight: 700; width: 48px; flex: 0 0 auto; }
.rate-row__name  { font-size: 13px; color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rate-row__value { font-size: 14px; color: var(--ink2); flex: 0 0 auto; }

/* ── Invite-link copy box ─────────────────────────────────────────────────── */
.invite-link-box { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.invite-link-box .form__input { font-family: var(--mono); font-size: 0.8rem; }

/* ── Family member list ───────────────────────────────────────────────────── */
.family-member-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.family-member-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    background: var(--soft);
    border: 1px solid var(--hair);
    border-radius: var(--radius);
    transition: border-color 0.15s;
}
.family-member-item:hover { border-color: var(--accent-soft); }
.family-member-item__name   { flex: 1; font-size: 0.9rem; }
.family-member-item__action { margin-left: auto; }

/* ── Expense list — attribution ───────────────────────────────────────────── */
.expense-item__attribution { display: inline-flex; align-items: center; margin-right: 0.25rem; }

/* ── Expense history panel ────────────────────────────────────────────────── */
.expense-history {
    margin-top: 1rem;
    border-top: 1px solid var(--hair);
    padding-top: 0.75rem;
}
.expense-history__toggle { cursor: pointer; font-size: 0.85rem; color: var(--muted); font-weight: 600; user-select: none; }
.expense-history__toggle:hover { color: var(--ink); }
.expense-history__list { list-style: none; margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.4rem; }
.expense-history__item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); flex-wrap: wrap; }
.expense-history__who  { display: inline-flex; align-items: center; gap: 0.3rem; font-weight: 600; color: var(--ink); }
.expense-history__when { font-size: 0.75rem; }
.expense-history__before { font-style: italic; }

/* ── Invite page ──────────────────────────────────────────────────────────── */
.main--centered {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    padding: 1.5rem 1rem;
}
.invite-card { width: 100%; max-width: 480px; }
.invite-card__logo-wrap { display: flex; justify-content: center; margin-bottom: 1.5rem; }
.invite-card__intro { margin-bottom: 1.5rem; color: var(--muted); line-height: 1.6; }
.invite-card__intro strong { color: var(--ink); }
.invite-card__login-hint { margin-top: 1.25rem; font-size: 0.875rem; color: var(--muted); line-height: 1.6; }
.invite-card__login-hint a { color: var(--accent-ink); }
.invite-card__login-hint a:hover { text-decoration: underline; }

/* ── Header (kept for backward compat, now replaced by sidebar) ───────────── */
.header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    padding: 0 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--hair);
    box-shadow: var(--shadow);
}
.header__nav  { display: flex; align-items: center; gap: 0.125rem; }
.header__user { color: var(--muted); font-size: 0.8125rem; padding: 0 0.625rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.header__logout-form { display: flex; }
.header__logout {
    display: inline-flex;
    align-items: center;
    font-size: 0.8125rem;
    font-family: var(--font);
    font-weight: 500;
    color: var(--muted);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
    white-space: nowrap;
    height: 2rem;
}
.header__logout:hover { color: var(--ink); background: var(--soft); text-decoration: none; }
.header__nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    padding: 0.375rem 0.875rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    height: 2rem;
}
.header__nav-link:hover { background: var(--soft); color: var(--ink); text-decoration: none; }
.header__nav-link--active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
/* ── Sidebar "Add expense" button ─────────────────────────────────────────── */
.sidebar__add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    background: var(--accent-fill);
    color: var(--on-accent);
    border-radius: var(--radius-control);
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 6px 16px -6px rgba(0,0,0,.2);
    transition: background .15s, box-shadow .15s;
    margin-bottom: 4px;
}
.sidebar__add-btn:hover { background: var(--accent2); color: var(--on-accent); text-decoration: none; box-shadow: 0 8px 20px -6px rgba(0,0,0,.28); }

/* ── Dashboard greeting ───────────────────────────────────────────────────── */
.dash-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}
.dash-header--simple { align-items: flex-start; }
.dash-eyebrow {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-ink);
    letter-spacing: 0.3px;
}
.dash-greeting {
    margin: 3px 0 0;
    font-size: 31px;
    font-weight: 500;
    letter-spacing: -0.3px;
    white-space: nowrap;
    line-height: 1.2;
}
.dash-note { font-size: 14px; color: var(--muted); margin: 4px 0 0; }

/* ── Quick-add card ───────────────────────────────────────────────────────── */
.quick-add { padding: 16px; }
.quick-add__row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.quick-add__amount-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--soft);
    border: 1.5px solid var(--hair);
    border-radius: var(--radius-control);
    padding: 0 14px;
    height: 52px;
    flex: 1 1 120px;
    transition: border-color .15s;
}
.quick-add__amount-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--color-primary-20); }
.quick-add__dollar {
    font-size: 22px;
    font-weight: 700;
    color: var(--muted);
    line-height: 1;
    flex: 0 0 auto;
}
.quick-add__amount-input {
    border: none;
    background: none;
    outline: none;
    font-size: 22px;
    font-weight: 700;
    width: 100%;
    min-width: 70px;
    color: var(--ink);
    font-family: var(--font);
}
.quick-add__amount-input::placeholder { color: var(--muted); }
.quick-add__currency {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    border-left: 1px solid var(--hair);
    background: none;
    outline: none;
    height: 100%;
    padding: 0 4px 0 12px;
    margin-left: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink2);
    font-family: var(--font);
    flex: 0 0 auto;
    max-width: 84px;
}
.quick-add__desc {
    border: 1.5px solid var(--hair);
    background: var(--soft);
    border-radius: var(--radius-control);
    padding: 0 16px;
    height: 52px;
    font-size: 15px;
    outline: none;
    flex: 2 1 200px;
    color: var(--ink);
    font-family: var(--font);
    transition: border-color .15s;
}
.quick-add__desc::placeholder { color: var(--muted); }
.quick-add__desc:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--color-primary-20); }
.quick-add__tag-select {
    height: 52px;
    max-width: 150px;
    min-width: 0;
    flex: 0 1 130px;
    border: 1.5px solid var(--hair);
    background: var(--soft);
    border-radius: var(--radius-control);
    padding: 0 12px;
    font-size: 14px;
    color: var(--ink);
    font-family: var(--font);
}
.quick-add__submit {
    height: 52px;
    padding: 0 26px;
    font-size: 15px;
    font-weight: 700;
    flex: 0 0 auto;
    border-radius: var(--radius-control);
    white-space: nowrap;
    box-shadow: 0 6px 16px -7px rgba(0,0,0,.2);
}
.quick-add__chips {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    margin-top: 12px;
}
.quick-add__chip {
    padding: 7px 13px;
    border-radius: var(--radius-pill);
    font-size: 13.5px;
    font-weight: 600;
    border: 1.5px solid var(--hair);
    background: var(--surface);
    color: var(--ink2);
    cursor: pointer;
    font-family: var(--font);
    transition: background .15s, color .15s, border-color .15s;
}
.quick-add__chip:hover { background: var(--soft); }
.quick-add__chip--active {
    background: var(--chip-bg, var(--accent-fill));
    /* --chip-fg is set alongside --chip-bg from the category colour's luminance; the
       category ramp spans light and dark tones, so a fixed light label is unreadable
       on half of it. */
    color: var(--chip-fg, var(--on-accent));
    border-color: var(--chip-bg, var(--accent-fill));
}
/* Opens the wider library — dashed, so it reads as "more of these" and not as another
   category sitting alongside them. */
.quick-add__chip--more {
    border-style: dashed;
    border-color: var(--muted2);
    background: transparent;
    color: var(--muted);
}

/* ── Category library picker ──────────────────────────────────────────────── */
.cat-picker {
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    background: var(--soft);
    padding: 12px;
    margin-top: 10px;
}
.cat-picker__search {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 12px;
    margin-bottom: 12px;
    background: var(--surface);
    border: 1.5px solid var(--hair);
    border-radius: var(--radius-control);
}
.cat-picker__search svg   { flex: 0 0 auto; }
.cat-picker__search input {
    flex: 1;
    min-width: 0;
    border: none;
    background: none;
    outline: none;
    font-family: var(--font);
    font-size: 14px;
    color: var(--ink);
}
.cat-picker__close {
    flex: 0 0 auto;
    border: none;
    background: none;
    color: var(--muted2);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
.cat-picker__scroll {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 260px;
    overflow-y: auto;
}
.cat-picker__group-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--muted2);
    margin-bottom: 8px;
}
.cat-picker__chips { display: flex; flex-wrap: wrap; gap: 7px; }
.cat-picker__chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    border: 1.5px solid var(--hair);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--ink2);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.cat-picker__chip:hover { border-color: var(--muted2); }
.cat-picker__chip--active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.cat-picker__chip-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.cat-picker__create {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--accent);
    border-radius: var(--radius-control);
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
}
.cat-picker__empty { font-size: 13px; color: var(--muted); margin: 4px 0; }

/* ── Hero card ────────────────────────────────────────────────────────────── */
.hero-card {
    background: linear-gradient(135deg, var(--accent-fill), var(--accent2));
    color: var(--on-accent);
    border-radius: var(--radius-card);
    padding: var(--pad-card-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    box-shadow: 0 14px 30px -16px rgba(0,0,0,.2);
    margin-bottom: 14px;
}
.hero-card__period {
    font-size: 13px;
    font-weight: 600;
    opacity: .85;
}
.hero-card__spend {
    font-size: 46px;
    font-weight: 500;
    letter-spacing: -0.5px;
    margin: 2px 0 6px;
    line-height: 1.1;
}
.hero-card__budget-note { font-size: 13.5px; opacity: .85; }
.hero-card__right { text-align: right; min-width: 120px; }
.hero-card__left-label { font-size: 13px; font-weight: 600; opacity: .85; }
.hero-card__left-amount { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
/* Caption under the daily average — "across 30 days" — shown in place of the budget bar
   when the window isn't a calendar month. */
.hero-card__right-note { font-size: 12px; opacity: .75; margin-top: 4px; }
.hero-card__bar-track {
    width: 130px;
    height: 8px;
    background: rgba(255,255,255,.28);
    border-radius: var(--radius-pill);
    margin: 9px 0 0 auto;
    overflow: hidden;
    display: flex;
}
.hero-card__bar { height: 100%; background: var(--on-accent); transition: width .4s ease; }
/* The share of spending the budget does *not* cover — only ever non-zero once over. */
.hero-card__bar-over { height: 100%; background: #f2c9a8; transition: width .4s ease; }

/* QW1: over budget is the one moment this card has to be loud. Same layout, clay frame,
   and the right column states the overage rather than a clamped "Left to spend $0.00". */
.hero-card--over { background: linear-gradient(135deg, #a8623a, #7d4e2a); }

/* ── Stat tiles ───────────────────────────────────────────────────────────── */
.stat-tiles {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px;
}
.stat-tile {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    padding: var(--pad-card);
}
.stat-tile__label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}
.stat-tile__value {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-top: 3px;
}
.stat-tile__value--pos { color: var(--pos-ink); }
.stat-tile__sublabel {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 2px;
}
/* QW6 verdict — must come after the base rule, which sets the muted colour. */
.stat-tile__sublabel--over  { color: var(--clay-ink); font-weight: 600; }
.stat-tile__sublabel--under { color: var(--accent-ink); font-weight: 600; }

/* ── Charts row ───────────────────────────────────────────────────────────── */
.charts-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}
.chart-card { flex: 1 1 290px; padding: 20px; }

/* ── CSS Donut chart ──────────────────────────────────────────────────────── */
.donut-row {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.donut-chart {
    width: 124px;
    height: 124px;
    border-radius: 50%;
    flex: 0 0 auto;
    position: relative;
}
.donut-inner {
    position: absolute;
    inset: 26px;
    background: var(--surface);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}
.donut-inner__label { font-size: 11px; color: var(--muted); font-weight: 600; }
.donut-inner__value { font-size: 16px; font-weight: 800; }
.donut-legend { flex: 1 1 130px; display: flex; flex-direction: column; gap: 9px; }
.donut-legend-item { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.donut-legend-item__swatch { width: 11px; height: 11px; border-radius: 4px; flex: 0 0 auto; }
.donut-legend-item__name { flex: 1; color: var(--ink2); }
.donut-legend-item__pct { color: var(--muted); font-weight: 600; }

/* ── CSS Bar chart ────────────────────────────────────────────────────────── */
.bar-chart-wrap { margin-top: 8px; }
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    height: 130px;
}
.bar-chart__group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    height: 100%;
    justify-content: flex-end;
}
.bar-chart__bar {
    width: 100%;
    min-height: 6px;
    border-radius: 7px 7px 0 0;
    transition: height .4s ease;
}
.bar-chart__label { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ── Month-over-month list ────────────────────────────────────────────────── */
.mom-card { margin-top: 14px; padding: 20px; }
.mom-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.mom-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--hair);
}
.mom-row:last-child { border-bottom: none; padding-bottom: 0; }
.mom-row__swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.mom-row__name { flex: 1; font-size: 14px; color: var(--ink2); font-weight: 600; min-width: 0; }
/* QW7: the money columns wandered mid-row because each was sized by its own content, so
   the eye had nothing straight to scan. Fixed columns, right-aligned, tabular figures. */
.mom-row__amounts {
    font-size: 13.5px;
    color: var(--ink);
    white-space: nowrap;
    text-align: right;
    min-width: 168px;
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum';
}
.mom-row__prev { color: var(--muted); font-weight: 500; }
.mom-row__delta {
    font-size: 13.5px;
    font-weight: 700;
    white-space: nowrap;
    text-align: right;
    min-width: 118px;
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum';
}
.mom-row__delta--up { color: var(--danger-ink); }
.mom-row__delta--down { color: var(--color-success); }
.mom-row__pct { font-weight: 600; opacity: .85; }

/* ── Analysis disclosure (dashboard) ──────────────────────────────────────── */
.analysis { margin-top: 14px; }
.analysis__toggle {
    display: flex;
    align-items: baseline;
    gap: 10px;
    cursor: pointer;
    list-style: none;
    padding: 12px 4px;
    border-top: 1px solid var(--hair);
}
.analysis__toggle::-webkit-details-marker { display: none; }
.analysis__title { font-size: 16px; font-weight: 700; }
.analysis__hint { font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
.analysis__chevron {
    color: var(--muted);
    flex: 0 0 auto;
    align-self: center;
    transition: transform .2s ease;
}
.analysis[open] .analysis__chevron { transform: rotate(180deg); }
.analysis__toggle:hover .analysis__title { color: var(--accent-ink); }
.analysis__toggle:focus-visible {
    outline: none;
    border-radius: var(--radius-control);
    box-shadow: 0 0 0 3px var(--color-primary-30);
}
@media (max-width: 640px) {
    .analysis__hint { display: none; }
}

/* ── Transactions panel (windowed) ─────────────────────────────────────────── */
.tx-panel { padding: 18px 20px 14px; border-radius: var(--radius-card); }
.tx-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.tx-header__title { font-size: 15px; font-weight: 700; }
/* margin-right reserves space for the always-visible ⋮ export button (top-right). */
.tx-header__count { font-size: 13px; color: var(--muted); font-weight: 600; margin-right: 40px; }
.tx-header__sum   { color: var(--accent-ink); }

/* Search + category dropdown. */
.tx-searchrow { display: flex; gap: 8px; margin-bottom: 11px; position: relative; }
.tx-search {
    flex: 1 1 auto;
    /* Without this the automatic minimum size keeps the field at the input's intrinsic
       width, so it never shrinks and shoves the fixed-width category trigger past the
       card edge — 59px of horizontal page scroll at 375px. */
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    background: var(--soft);
    border: 1.5px solid var(--hair);
    border-radius: var(--radius-control);
    padding: 0 14px;
    height: 42px;
}
.tx-search svg { flex: 0 0 auto; }
.tx-search input {
    border: none;
    background: none;
    outline: none;
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--ink);
    font-family: inherit;
}
.tx-search input::placeholder { color: var(--muted); }
/* The input itself is borderless and outline:none, and the wrapper had no focus rule at
   all — tabbing into the transaction search gave no indication whatsoever. Matches the
   treatment every other field in the app uses. */
.tx-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--color-primary-20); }
.tx-search__clear {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: var(--hair);
    color: var(--ink2);
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.tx-catmenu { position: relative; flex: 0 0 auto; }
.tx-catmenu__trigger {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    width: 150px;
    height: 42px;
    padding: 0 13px;
    border-radius: var(--radius-control);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    background: var(--soft);
    border: 1.5px solid var(--hair);
    color: var(--ink2);
}
.tx-catmenu__trigger.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.tx-catmenu__dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.tx-catmenu__label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-catmenu__chevron { color: var(--muted); flex: 0 0 auto; font-size: 10px; }
.tx-catmenu__catcher { position: fixed; inset: 0; z-index: 20; }
.tx-catmenu__popover {
    position: absolute;
    top: 50px;
    right: 0;
    z-index: 21;
    width: 244px;
    max-height: 344px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    padding: 6px;
    box-shadow: 0 18px 44px -14px rgba(0,0,0,.34);
}
.tx-catmenu__row {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 8px 11px;
    border-radius: var(--radius-chip);
    border: none;
    background: transparent;
    color: var(--ink);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
}
.tx-catmenu__row.is-active { background: var(--soft); font-weight: 700; }
.tx-catmenu__row-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.tx-catmenu__row-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-catmenu__row-count { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.tx-catmenu__row-check { color: var(--accent-ink); width: 12px; flex: 0 0 auto; }

.tx-empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 14px; }

/* Windowed scroller: fixed 60px rows, top/bottom spacers keep the scrollbar honest.
   The scrollbar itself is left alone on purpose. A restyled thumb (`scrollbar-width: thin`
   + a painted `::-webkit-scrollbar-thumb`) opts this element out of the platform's overlay
   scrollbars, so a permanent dark bar sat over the last column of every row instead of the
   one that fades in while you scroll. Native is what the design shows. */
.tx-scroll {
    max-height: 520px;
    overflow-y: auto;
    overflow-x: hidden;
    margin: 0 -8px;
    padding-right: 2px;
}
.tx-spacer { flex-shrink: 0; }

.expense-item {
    height: 60px;
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 0 8px;
    box-sizing: border-box;
    border-radius: var(--radius-control);
    background: transparent;
    transition: background .12s ease;
}
.expense-item:hover { background: var(--soft); }
.tx-dot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }

.activity-item__info { flex: 1; min-width: 0; }
.activity-item__desc {
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.activity-item__meta {
    font-size: 12px;
    color: var(--muted);
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.activity-item__amount { font-size: 15px; font-weight: 700; white-space: nowrap; flex: 0 0 auto; }

/* Ghost actions — hidden until row hover (kept faintly visible on touch). */
.expense-item__actions {
    display: flex;
    gap: 2px;
    flex: 0 0 auto;
    width: 56px;
    justify-content: flex-end;
    opacity: 0;
    transition: opacity .12s ease;
}
.expense-item:hover .expense-item__actions { opacity: 1; }
.tx-ghost {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-chip);
    border: none;
    background: transparent;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.tx-ghost:hover { color: var(--ink); background: var(--track); }
@media (hover: none) {
    .expense-item__actions { opacity: .55; }
}

/* Ghost icon-buttons for card/row Edit·Delete pairs elsewhere (accounts, loans, income,
   project budgets, category limits) — same visual language as .tx-ghost, always visible
   since these aren't dense scrolling lists. */
.icon-btn {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-chip);
    border: none;
    background: transparent;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
    padding: 0;
}
.icon-btn:hover { color: var(--ink); background: var(--track); }

/* ── Share / export (⋮ menu → Download PNG / PDF) ─────────────────────────── */
.share-host { position: relative; }
.share-bar {
    position: absolute;
    top: 14px;
    right: 16px;
    z-index: 7;
}
.share-dot {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-chip);
    border: 1px solid var(--hair);
    background: var(--surface);
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px -2px rgba(0,0,0,.2);
}
.share-dot:hover { color: var(--ink); }
.share-dot svg { flex: 0 0 auto; }
/* Full-screen click-away catcher; sits under the menu, over the page. */
.share-catcher { position: fixed; inset: 0; z-index: 7; }
.share-menu {
    position: absolute;
    top: 36px;
    right: 0;
    z-index: 8;
    min-width: 168px;
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-control);
    padding: 5px;
    box-shadow: 0 14px 34px -12px rgba(0,0,0,.34);
}
.share-menu__item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 9px 11px;
    border: none;
    background: none;
    border-radius: var(--radius-chip);
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    text-align: left;
}
.share-menu__item:hover { background: var(--soft); }
.share-menu__item svg { flex: 0 0 auto; color: var(--muted); }

/* ── Date range popover ───────────────────────────────────────────────────── */
/* The bar scrolls inside itself rather than widening the page (twelve period tabs are
   wider than a phone), which needs the whole chain down from the flex item capped:
   a flex item defaults to min-width:auto and grows to its max-content width, so
   max-width:100% further in would only ever resolve against that grown width. */
expense-filters { display: block; min-width: 0; max-width: 100%; }
.filter-wrap { position: relative; max-width: 100%; }
.date-range-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 30;
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    padding: 15px;
    box-shadow: 0 16px 38px -14px rgba(0,0,0,.34);
    width: 272px;
}
.date-range-popover__title { font-size: 13.5px; font-weight: 700; margin-bottom: 11px; }
.date-range-popover__fields { display: flex; flex-direction: column; gap: 9px; }
.date-range-popover__label { font-size: 12px; color: var(--muted); font-weight: 600; display: block; }
.date-range-popover__actions { display: flex; gap: 8px; margin-top: 13px; }
.date-range-popover__actions .btn--primary { flex: 1; }

/* ── Budget / flow chart ──────────────────────────────────────────────────── */
.budget-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 13px;
}
.budget-section-title { font-size: 16px; font-weight: 700; }

/* ── <list-section> ───────────────────────────────────────────────────────── */
.list-section { display: block; margin-bottom: 26px; }
.list-section__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 13px;
}
.list-section__titlewrap { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.list-section__title { font-size: 16px; font-weight: 700; }
.list-section__count { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.list-section__note { font-size: 0.9rem; color: var(--muted); line-height: 1.6; margin: -4px 0 12px; }

/* QW2: one empty-state pattern — a quiet icon, one line, and the action inline, replacing
   a bare centred sentence whose only way out was the button up in the section header. */
.list-empty {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    padding: 26px var(--pad-card);
    text-align: center;
}
.list-empty__icon {
    display: inline-flex;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-control);
    background: var(--soft);
    color: var(--accent-ink);
    align-items: center;
    justify-content: center;
    margin-bottom: 11px;
}
.list-empty__title { font-size: 14.5px; font-weight: 600; color: var(--ink); }
.list-empty__body { font-size: 13px; color: var(--muted); margin: 4px auto 14px; max-width: 42ch; }
.list-empty__action { margin: 0 auto; }

.flow-chart { padding: 20px; }
.flow-chart__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 18px;
}
.flow-chart__title { font-size: 15px; font-weight: 700; }
/* margin-right reserves space for the always-visible ⋮ export button (top-right). */
.flow-chart__saved-label { font-size: 14px; font-weight: 700; margin-right: 40px; }
.flow-chart__bars {
    display: flex;
    align-items: flex-end;
    gap: 28px;
    height: 150px;
}
.flow-chart__group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
    height: 100%;
    justify-content: flex-end;
}
.flow-chart__amt { font-size: 14px; font-weight: 700; }
.flow-chart__bar-wrap { flex: 1; display: flex; align-items: flex-end; }
.flow-chart__bar {
    width: 46px;
    border-radius: 8px 8px 0 0;
    transition: height .5s ease;
    min-height: 8px;
}
.flow-chart__bar--in    { background: var(--accent); }
.flow-chart__bar--out   { background: var(--clay); }
.flow-chart__bar--saved { background: var(--pos); }
.flow-chart__lbl { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ── Envelope cards ───────────────────────────────────────────────────────── */
.envelope-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
}
/* Loan cards carry a longer meta line (kind · lender · APR · original) than a budget card. */
.envelope-grid--loans { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.envelope-card {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    padding: var(--pad-card);
    transition: border-color .15s, box-shadow .15s;
}
.envelope-card:hover { border-color: var(--accent-soft); box-shadow: var(--shadow); }
.envelope-card--empty { opacity: 0.7; }
.envelope-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 11px;
}
.envelope-card__name-row { display: flex; align-items: center; gap: 9px; }
.envelope-swatch { width: 11px; height: 11px; border-radius: 4px; flex: 0 0 auto; }
.envelope-card__name { font-size: 15px; font-weight: 700; }
.envelope-card__nums { font-size: 13.5px; color: var(--muted); }
/* Loans lead with the outstanding balance; a budget card leads with "spent / limit", where
   neither half should shout. */
.envelope-card__nums--strong { font-size: 17px; font-weight: 800; color: var(--ink); }
.envelope-card__header--tight { margin-bottom: 4px; }
.envelope-card__meta { font-size: 12.5px; color: var(--muted); margin-bottom: 11px; }
.envelope-progress {
    height: 9px;
    background: var(--track);
    border-radius: var(--radius-pill);
    overflow: hidden;
}
.envelope-progress__fill {
    height: 100%;
    border-radius: var(--radius-pill);
    transition: width .5s ease;
}
.envelope-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}
.envelope-card__pct { font-size: 12px; font-weight: 600; }
.envelope-card__actions { display: flex; gap: .3rem; }

/* Collapsed "paid off / closed" loans section on the Accounts & loans page. */
.loan-closed { margin-top: 20px; border-top: 1px solid var(--hair); padding-top: 16px; }
.loan-closed__toggle {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 600;
    user-select: none;
    list-style: none;
    margin-bottom: 12px;
}
.loan-closed__toggle::-webkit-details-marker { display: none; }
.loan-closed__toggle::before { content: '▸ '; }
.loan-closed[open] > .loan-closed__toggle::before { content: '▾ '; }
.loan-closed__toggle:hover { color: var(--ink); }

/* ── Income two-column layout ─────────────────────────────────────────────── */
.income-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

/* ── Accounts & loans summary tiles ───────────────────────────────────────── */
.acct-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 26px;
}
.acct-summary__tile {
    border-radius: var(--radius-card);
    padding: var(--pad-card);
}
.acct-summary__tile--cash {
    background: linear-gradient(135deg, var(--accent-fill), var(--accent2));
    color: var(--on-accent);
}
.acct-summary__tile--debt {
    background: var(--surface);
    border: 1px solid var(--hair);
}
.acct-summary__tile--networth {
    background: var(--surface);
    border: 1.5px solid var(--hair);
}
.acct-summary__label {
    font-size: 13px;
    font-weight: 600;
}
.acct-summary__tile--cash .acct-summary__label { opacity: .85; }
.acct-summary__tile--debt .acct-summary__label,
.acct-summary__tile--networth .acct-summary__label { color: var(--muted); }
.acct-summary__value {
    font-size: 34px;
    font-weight: 500;
    margin-top: 2px;
}
.acct-summary__tile--debt .acct-summary__value {
    font-size: 30px;
    font-weight: 800;
    color: var(--clay-ink);
}
.acct-summary__tile--networth .acct-summary__value {
    font-size: 30px;
    font-weight: 800;
}
.acct-summary__tile--networth .acct-summary__value--pos { color: var(--accent-ink); }
.acct-summary__tile--networth .acct-summary__value--neg { color: var(--clay-ink); }
.acct-summary__note {
    font-size: 12.5px;
    opacity: .8;
    margin-top: 2px;
}
.acct-summary__tile--networth .acct-summary__note { color: var(--muted); opacity: 1; }
/* Payoff progress on the "Total owed" tile — the same bar the loan cards carry, summed. */
.acct-summary__progress {
    height: 8px;
    background: var(--track);
    border-radius: var(--radius-pill);
    overflow: hidden;
    margin-top: 11px;
}
.acct-summary__progress-fill {
    height: 100%;
    width: 0;
    background: var(--accent);
    border-radius: var(--radius-pill);
    transition: width .5s ease;
}
.acct-summary__payoff {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 7px;
    font-size: 12px;
    color: var(--muted);
}
.acct-summary__payoff-pct { font-weight: 700; color: var(--accent-ink); }
.acct-summary__breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    margin-top: 8px;
    line-height: 1.3;
}
.acct-summary__breakdown span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.acct-summary__breakdown b { color: var(--ink2); }

/* ── Account rows ─────────────────────────────────────────────────────────── */
.account-list {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    overflow: hidden;
    margin-bottom: 26px;
}
/* Every list that uses this shell renders its rows into it and shows a separate empty
   state alongside — so with no rows the shell collapses to its own 2px of border and
   leaves a stray rule floating under the "nothing here yet" copy. */
.account-list:empty { display: none; }
/* <list-section> already owns the gap to whatever section comes next; stacking this one on
   top of it doubled the space under Accounts and left 26px of dead card under both Settings
   rule lists. */
.list-section > .account-list:last-child { margin-bottom: 0; }
.account-row {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 14px 18px;
    border-top: 1px solid var(--hair);
}
.account-row:first-child { border-top: none; }
.account-row__dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex: 0 0 auto;
    background: var(--accent);
}
.account-row__dot--neg { background: var(--clay); }
.account-row__info { flex: 1; min-width: 0; }
.account-row__name { font-size: 15px; font-weight: 600; }
.account-row__meta { font-size: 12.5px; color: var(--muted); }
.account-row__balance { font-size: 16px; font-weight: 700; }
.account-row__balance--neg { color: var(--clay-ink); }

/* ── <rule-list> ──────────────────────────────────────────────────────────── */
/* D4: both rule lists read as one sentence per rule. Priority shows as the rank it
   actually is rather than as "priority 30" buried in a meta line. */
/* Custom elements default to `display: inline`. Left inline, the block `.rule-row`
   children split the host's inline box in two and the leftovers rendered as a stray
   vertical hairline above and below the rules — visible on both Settings rule lists. */
.rule-list { display: block; }
.rule-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 13px 18px;
    border-top: 1px solid var(--hair);
}
.rule-row:first-child { border-top: none; }
.rule-row--off { opacity: .6; }
.rule-row__rank {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: var(--radius-chip);
    background: var(--soft);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-variant-numeric: tabular-nums;
}
.rule-row__body { flex: 1; min-width: 0; }
.rule-row__sentence { font-size: 14px; line-height: 1.5; color: var(--ink2); }
.rule-row__strong { font-weight: 700; color: var(--ink); }
.rule-row__dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 2px;
}
.rule-row__off { font-size: 12px; color: var(--muted); }

/* D5: transfers read as movement, not spending — a glyph where other rows carry a
   category or balance dot, and no category colour anywhere on the row. */
.transfer-glyph {
    flex: 0 0 auto;
    width: 22px;
    text-align: center;
    font-size: 15px;
    line-height: 1;
    color: var(--muted);
}
.transfer-arrow { color: var(--muted); font-weight: 400; }

/* N5: reconciliation status as a chip rather than another clause in the meta line. */
.recon-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}
.recon-chip--ok  { background: var(--accent-soft); color: var(--accent-ink); }
.recon-chip--off { background: #f6e3d6; color: var(--clay-ink); }
[data-theme="forest-dark"] .recon-chip--off { background: #3a2a1f; }
.account-row__actions { display: flex; gap: .3rem; flex: 0 0 auto; }

/* ── Category color list (Settings) ──────────────────────────────────────── */
.category-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 18px;
    border-top: 1px solid var(--hair);
}
.category-row:first-child { border-top: none; }
.category-row__swatch {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-chip);
    border: 1px solid var(--hair);
    flex: 0 0 auto;
    cursor: pointer;
    padding: 0;
}
.category-row__name { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; }
.category-palette-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 5px;
    max-height: 260px;
    overflow-y: auto;
    padding: 2px;
}
.category-palette-grid__swatch {
    width: 100%;
    padding-bottom: 100%;
    border-radius: var(--radius-chip);
    border: 2px solid var(--hair);
    cursor: pointer;
    position: relative;
}
.category-palette-grid__swatch--active { border-color: var(--ink); }

/* ── Savings goal cards ───────────────────────────────────────────────────── */
.goal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 12px;
}
.goal-card {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    padding: var(--pad-card);
    display: flex;
    align-items: center;
    gap: 16px;
}
.goal-ring {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}
.goal-ring__inner {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
}
.goal-card__info { flex: 1; min-width: 0; }
.goal-card__name { font-size: 16px; font-weight: 700; line-height: 1.25; }
.goal-card__nums { font-size: 14px; color: var(--ink2); margin-top: 2px; }
.goal-card__due { font-size: 12.5px; color: var(--muted); margin-top: 3px; font-weight: 600; }
.goal-card__actions { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.goal-card__add-funds { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.goal-card__add-funds input {
    width: 80px;
    border: 1px solid var(--hair);
    background: var(--soft);
    border-radius: var(--radius-chip);
    padding: 5px 8px;
    font-size: 13px;
    color: var(--ink);
}

/* ── Settings: section labels ─────────────────────────────────────────────── */
.settings-section-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.6px;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 10px;
}

/* ── Settings: household member rows ─────────────────────────────────────── */
.household-member {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 14px 16px;
    border-top: 1px solid var(--hair);
}
.household-member:first-child { border-top: none; }
.household-member__info { flex: 1; min-width: 0; }
.household-member__name-row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.household-member__name { font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.household-member__bar-track {
    height: 6px;
    background: var(--track);
    border-radius: var(--radius-pill);
    overflow: hidden;
    max-width: 220px;
}
.household-member__bar { height: 100%; border-radius: var(--radius-pill); transition: width .5s ease; }

/* ── Settings: preferences card rows ─────────────────────────────────────── */
.prefs-card .prefs-row { border-top: 1px solid var(--hair); }
.prefs-card .prefs-row:first-child { border-top: none; }
.prefs-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    gap: 12px;
}
.prefs-row__label { font-size: 15px; font-weight: 600; }
.prefs-row__value { font-size: 14px; color: var(--muted); }

/* ── Tags + split expense editor ─────────────────────────────────────────── */
.tag-input {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    border: 1.5px solid var(--hair);
    background: var(--soft);
    border-radius: var(--radius-control);
    padding: 6px 10px;
    min-height: 44px;
}
.tag-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--color-primary-20); }
.tag-input__field {
    flex: 1 1 100px;
    min-width: 100px;
    border: none;
    background: none;
    outline: none;
    font-size: 14px;
    color: var(--ink);
    font-family: var(--font);
    padding: 4px 2px;
}
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 12.5px;
    font-weight: 600;
    background: var(--track);
    color: var(--muted);
    white-space: nowrap;
}
.tag-chip__remove {
    border: none;
    background: none;
    color: inherit;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 2px 4px;
    opacity: .7;
}
.tag-chip__remove:hover { opacity: 1; }

.split-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--ink2);
    margin-top: 10px;
    cursor: pointer;
    user-select: none;
}
.split-toggle input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

.split-editor { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.split-row {
    display: grid;
    grid-template-columns: 1fr 120px auto;
    gap: 8px;
    align-items: center;
}
.split-row__remove {
    border: none;
    background: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 4px 8px;
}
.split-row__remove:hover { color: var(--danger-ink); }
.split-editor__hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.split-editor__hint--bad { color: var(--danger-ink); font-weight: 600; }
.split-editor__hint--ok { color: var(--accent-ink); font-weight: 600; }

/* ── Section head (title + note on the left, a figure or chip on the right) ── */
/* <list-section> covers "titled list + add button"; this is the same header shape for the
   read-only sections that have nothing to add — the payoff plan, the commitment calendar. */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 13px;
}
.section-head__title { font-size: 16px; font-weight: 700; }
.section-head__note  { font-size: 13px; color: var(--muted); }

/* ── Payoff plan ──────────────────────────────────────────────────────────── */
.payoff-chip {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--accent-ink);
    background: var(--accent-soft);
    border-radius: var(--radius-pill);
    padding: 5px 12px;
    white-space: nowrap;
}
.payoff-list {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    overflow: hidden;
}
.payoff-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
}
.payoff-row + .payoff-row { border-top: 1px solid var(--hair); }
.payoff-row__marker {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    background: var(--soft);
    color: var(--muted);
}
.payoff-row__marker--target { background: var(--accent-fill); color: var(--on-accent); }
.payoff-row__info    { flex: 1; min-width: 0; }
.payoff-row__title   { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.payoff-row__name    { font-size: 14.5px; font-weight: 700; }
.payoff-row__meta    { font-size: 12px; color: var(--muted); }
.payoff-row__figures { text-align: right; flex: 0 0 auto; }
.payoff-row__balance { font-size: 14.5px; font-weight: 700; }
.payoff-row__date    { font-size: 12px; color: var(--muted); }
.payoff-badge {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .4px;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    white-space: nowrap;
}
.payoff-badge--target { background: var(--accent-soft); color: var(--accent-ink); }
.payoff-badge--expire { background: var(--soft); color: var(--muted); }
.payoff-note {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    background: var(--accent-soft);
    border-radius: var(--radius-control);
    padding: 12px 14px;
    margin-top: 12px;
    font-size: 13.5px;
    line-height: 1.5;
    /* --accent-ink, not --accent2: the dark palette's --accent2 is a *darker* green than the
       --accent-soft it would sit on, so the note read as unlit text there. --accent-ink is the
       token that stays legible against soft fills in both themes. */
    color: var(--accent-ink);
}
.payoff-note__arrow { color: var(--accent-ink); font-weight: 800; flex: 0 0 auto; }

/* ── Committed ahead (12-month calendar) ──────────────────────────────────── */
.commit-now             { text-align: right; }
.commit-now__value      { font-size: 17px; font-weight: 800; }
.commit-now__share      { font-size: 12px; color: var(--clay-ink); font-weight: 600; }
.commit-card            { padding: 18px 20px; }
.commit-bars            { display: flex; align-items: flex-end; gap: 6px; height: 110px; }
.commit-bars__slot      { flex: 1; display: flex; align-items: flex-end; height: 100%; }
.commit-bars__bar {
    width: 100%;
    background: var(--accent);
    border-radius: 6px 6px 0 0;
    transition: height .4s ease;
}
.commit-bars__bar--heavy { background: var(--clay); }
.commit-bars__labels     { display: flex; gap: 6px; margin-top: 6px; }
.commit-bars__labels span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); }
.commit-card__caption    { font-size: 12.5px; color: var(--muted); margin: 12px 0 0; line-height: 1.5; }

/* ── Reserves ─────────────────────────────────────────────────────────────── */
.reserve-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}
.reserve-card {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    padding: var(--pad-card);
}
.reserve-card__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}
.reserve-card__name  { font-size: 15px; font-weight: 700; }
.reserve-card__nums  { font-size: 14px; color: var(--muted); white-space: nowrap; }
.reserve-card__meta  { font-size: 12px; color: var(--muted); margin: 3px 0 11px; }
.reserve-progress {
    height: 9px;
    background: var(--track);
    border-radius: var(--radius-pill);
    overflow: hidden;
}
.reserve-progress__bar {
    height: 100%;
    background: var(--pos);
    border-radius: var(--radius-pill);
    transition: width .4s ease;
}
.reserve-progress__bar--behind { background: var(--clay); }
.reserve-card__foot {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--muted);
    margin-top: 7px;
    font-weight: 600;
}
.reserve-card__behind  { color: var(--clay-ink); }
.reserve-card__actions { display: flex; align-items: center; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.reserve-card__actions input {
    width: 80px;
    border: 1px solid var(--hair);
    background: var(--soft);
    border-radius: var(--radius-chip);
    padding: 5px 8px;
    font-size: 13px;
    color: var(--ink);
}

/* ── Guaranteed vs variable income ────────────────────────────────────────── */
.income-split {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}
.income-split__card  { padding: var(--pad-card); }
.income-split__label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 12px;
}
.income-split__bars      { display: flex; flex-direction: column; gap: 13px; }
.income-split__row-head  { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.income-split__row-label { font-size: 14.5px; font-weight: 700; }
.income-split__row-value { font-size: 15px; font-weight: 700; }
.income-split__track {
    height: 8px;
    background: var(--track);
    border-radius: var(--radius-pill);
    overflow: hidden;
    margin: 7px 0 5px;
}
.income-split__fill        { height: 100%; border-radius: var(--radius-pill); transition: width .4s ease; }
.income-split__fill--accent { background: var(--accent); }
.income-split__fill--pos    { background: var(--pos); }
.income-split__row-foot {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    color: var(--muted);
}
.income-split__headline { display: flex; align-items: baseline; gap: 8px; }
.income-split__pct      { font-size: 32px; font-weight: 500; }
.income-split__pct-note { font-size: 13px; color: var(--muted); }
.income-split__empty    { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0; }

/* ── Budget limits: category-name mismatch warning ────────────────────────── */
.budget-mismatch {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    background: var(--pos-soft);
    border-radius: var(--radius-control);
    padding: 11px 14px;
    margin-bottom: 13px;
}
.budget-mismatch__mark { color: var(--clay-ink); font-weight: 800; flex: 0 0 auto; }
.budget-mismatch__text { font-size: 13px; line-height: 1.5; color: var(--ink2); }
.budget-mismatch__fix {
    border: none;
    background: none;
    color: var(--accent-ink);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    padding: 0 0 0 6px;
}
.budget-mismatch__fix:hover { text-decoration: underline; }

/* ── Settings: data quality flags ─────────────────────────────────────────── */
.data-flags {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--radius-card);
    overflow: hidden;
}
.data-flag {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
}
.data-flag + .data-flag { border-top: 1px solid var(--hair); }
.data-flag__chip {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .4px;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: var(--radius-chip);
    white-space: nowrap;
    background: var(--surface);
    border: 1px solid var(--hair);
    color: var(--ink2);
    flex: 0 0 auto;
}
.data-flag--warn .data-flag__chip { border-color: var(--clay); color: var(--clay-ink); }
.data-flag__body { flex: 1; min-width: 0; }
.data-flag__text { font-size: 14px; font-weight: 600; line-height: 1.4; }
.data-flag__meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.data-flag__action {
    border: none;
    background: none;
    color: var(--accent-ink);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    flex: 0 0 auto;
    white-space: nowrap;
    text-decoration: none;
}
.data-flag__action:hover { text-decoration: underline; }
.data-flag__action[disabled] { color: var(--muted); cursor: default; text-decoration: none; }
.data-flags__clear {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 14px 16px;
    font-size: 13.5px;
    color: var(--muted);
}
.data-flags__count { font-size: 12px; color: var(--clay-ink); font-weight: 700; }

/* ── Responsive additions ─────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .header           { padding: 0 1rem; height: 56px; }
    .header__user     { display: none; }
    .main             { padding: 1rem 1rem 2rem; }
    .form__row        { grid-template-columns: 1fr; }
    .charts-grid      { grid-template-columns: 1fr; }
    .chart-container--donut,
    .chart-container--bar { height: 200px; }
    .income-bar { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
    .income-bar__sep { display: none; }
    .budget-row {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto;
    }
    .budget-row > .budget-progress { grid-column: 1 / -1; }
    .budget-row__remaining { display: none; }
    .project-card__metrics { flex-wrap: wrap; gap: 0.75rem; }
    .income-entry-row { grid-template-columns: 68px 1fr auto auto; gap: 0.5rem; }
    .income-columns { grid-template-columns: 1fr; }

    /* New component mobile overrides */
    .dash-greeting { font-size: 24px; }
    .stat-tiles    { grid-template-columns: 1fr 1fr; }
    .hero-card     { flex-direction: column; gap: 12px; }
    .hero-card__right { text-align: left; }
    .hero-card__bar-track { margin-left: 0; }
    .quick-add__row { flex-direction: column; align-items: stretch; }
    .quick-add__amount-wrap { flex: none; }
    /* flex-basis is the *main* axis, so the px bases in this row — written as widths —
       became heights the moment the rule above flipped it to a column: a 200px tall
       description box and two 130px tall selects, eating most of the fold on a phone.
       Reset them to their own 52px heights. */
    .quick-add__desc,
    .quick-add__tag-select { flex: 0 0 auto; max-width: none; }
    .split-row { grid-template-columns: 1fr; }
    .charts-row    { flex-direction: column; }
    .activity-item__desc { font-size: 14px; }
    .mom-row       { flex-wrap: wrap; }
    .mom-row__amounts, .mom-row__delta { min-width: 0; }

    /* Search and the category filter each get a full row — side by side they leave the
       search field ~60px wide on a phone. */
    .tx-searchrow          { flex-wrap: wrap; }
    .tx-searchrow .tx-search { flex: 1 1 100%; }
    .tx-catmenu            { flex: 1 1 100%; }
    .tx-catmenu__trigger   { width: 100%; }
}

/* ── Tablet (641-900px) ───────────────────────────────────────────────────────
   The shell switches to the mobile pattern at 900px (sidebar out, top bar and bottom
   nav in) but the content grids above only reflow at 640px, so 641-900px got a phone
   chrome wrapped around desktop-width grids. These close that gap. */
@media (max-width: 900px) {
    /* Five fixed columns squeezed each tile to ~135px at 768. auto-fit gives 5 across on
       a laptop, 3+2 on a tablet, and the 640px rule still pins phones to two. */
    .stat-tiles { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

    /* Tap targets. Dense controls sit at 26-33px, well under the ~44px guideline, and
       this is exactly the range where the app is being used by thumb. */
    .btn                { height: 2.75rem; }
    .btn--sm            { height: 2.5rem; }
    .filter-bar__btn    { min-height: 44px; }
    .sidebar__theme-btn { min-height: 44px; }
    .quick-add__chip    { min-height: 40px; }
    .cat-picker__chip   { min-height: 40px; }
    .topbar__theme-btn,
    .topbar__avatar     { width: 40px; height: 40px; }
    .tx-search__clear   { width: 32px; height: 32px; }
    .share-dot          { width: 40px; height: 40px; }
    /* 40px rather than 44: Edit and Delete sit 6px apart, and padding each out to 44
       would leave their hit areas overlapping right next to a destructive action. */
    .icon-btn { width: 40px; height: 40px; flex: 0 0 auto; }
    /* Transaction rows are the one place a 40px-wide button does not fit: the row is 315px
       at 375px wide and already spends it on dot + description + amount. .expense-item__actions
       is a hard 56px, which squeezed the two ghosts to 27px each. Widen it just enough for a
       36x40 target and pay for it by tightening the row gap, so the description barely moves. */
    .expense-item          { gap: 8px; }
    .expense-item__actions { width: 76px; }
    .tx-ghost              { width: 36px; height: 40px; flex: 0 0 auto; }

    /* N1: the row opens the editor on tap below 640px, so the inline Edit button is
       redundant here and its width goes to the merchant name — the column was down to
       ~144px and clipping real names. Delete stays inline: it is the one action a tap
       on the row must never do. */
    .expense-item__actions [data-action="edit"] { display: none; }
    .expense-item__actions { width: 40px; }
    .expense-item--editable { cursor: pointer; }
    .goal-card__add-funds input { min-height: 40px; }
    .category-row__swatch { width: 32px; height: 32px; }
    .split-toggle input[type="checkbox"] { width: 20px; height: 20px; }
    .logo { min-height: 44px; }
    /* <summary> disclosures are only as tall as their text; give the row some body. */
    .settings-hint, .expense-history__toggle { padding-top: 10px; padding-bottom: 10px; }

    /* These inputs sit inside a taller styled wrapper that *looks* like the control, so
       tapping the wrapper's padding did nothing. Stretch them to fill it. */
    .quick-add__amount-input,
    .tx-search input { align-self: stretch; }
}

/* Tablet only. .quick-add__row still lays out as a row here and wraps, orphaning "Add it"
   on its own line against a lot of dead space; letting it claim the full line makes the
   wrap read as intentional. Kept above 640px because below that the row switches to
   flex-direction: column, where flex-basis would size the button's *height*. */
@media (min-width: 641px) and (max-width: 900px) {
    .quick-add__submit { flex: 1 1 100%; }
}
