/* ------------------------------------------------------------------ */
/* Variables                                                           */
/* ------------------------------------------------------------------ */

:root {
    --ink: #0a0a0a;
    --ink-soft: #2a2a2a;
    --ink-muted: #666666;
    --ink-faint: #999999;
    --paper: #f5f4f1;
    --paper-warm: #edeae2;
    --paper-card: #ffffff;
    --donut-dim: rgba(255, 255, 255, 0.68);
    --accent: #1a472a;
    --accent-hover: #15391f;
    --accent-light: #e6ede8;
    --accent-2: #b87320;
    --accent-2-light: #fdf0e0;
    --accent-3: #4a6fa5;
    --accent-4: #7b5ea7;
    --accent-5: #c0392b;
    --danger: #c0392b;
    --danger-light: #fdecea;
    --border: #e0ddd6;
    --border-soft: #eae7e0;
    --navbar-bg: rgba(245, 244, 241, 0.92);
    /* Chart tooltips sit on top of the bars they describe and are left fully
       clear — only the frame and the figures are drawn, and the column reads
       through them. */
    --chart-tip-bg: transparent;
    --footer-bg: #0a0a0a;
    --footer-text: #f5f4f1;
    --footer-muted: #999999;
    --row-hover: #f9f8f5;
    --sheet-footer-bg: #fafaf8;
    /* Week colours on the expenses sheet, shown on hover. Fixed to the week
       number, not to the month, so week 3 is the same shade all year. Pitched
       at about the weight of --row-hover: enough to name the week, not enough
       to read as a status. */
    --week-1: rgba(74, 111, 165, 0.11);
    --week-2: rgba(26, 71, 42, 0.10);
    --week-3: rgba(184, 115, 32, 0.12);
    --week-4: rgba(123, 94, 167, 0.11);
    color-scheme: light;

    --font: Helvetica, Arial, sans-serif;
    --font-display: Helvetica, Arial, sans-serif;
    --font-body: Helvetica, Arial, sans-serif;

    --max-width: 1200px;
    --auth-width: 420px;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;

    --shadow-sm: 0 1px 4px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 48px rgba(0,0,0,0.10), 0 4px 16px rgba(0,0,0,0.06);

    /* --- Category identity ---------------------------------------------
       One colour per category, used by every badge, bar, wedge and key.
       Hue is chosen for what the category *is* — orange for eating out,
       green for groceries, blue for transport, amber for utilities — with
       shades drawn from Color Hunt's palettes where it had a usable one and
       stepped at the same hue where it did not (it is thin on mid-lightness
       teals).

       Where categories share a colour family the hue cannot separate them, so
       the shade does: three blues at L 0.69 / 0.60 / 0.52 for Transport,
       Subscriptions and Insurance, two purples for Rent and Education, two
       reds for Shopping and Gifts, two pinks for Entertainment and Personal
       Care. Miscellaneous is held to a low chroma so the catch-all reads quiet
       rather than competing with real categories.

       Validated in both modes, not eyeballed: worst adjacent CVD ΔE 8.6 light
       / 8.1 dark against a floor of 8, normal-vision 15.2 / 15.6 against 15.
       Those margins are slim — pinning fifteen hues to their meanings spends
       most of the freedom a free palette would use for separation — so the
       secondary encoding matters: surface gaps between segments, values
       printed on each bar, and a legend and tooltip that name every category.
       Groceries and Miscellaneous sit under 3:1 on white, which is why the
       legend and tooltip always carry the category name and amount. */
    --cat-eating-out    : #d85700;
    --cat-groceries     : #41ca51;
    --cat-transport     : #37a1f9;
    --cat-rent          : #9929ea;
    --cat-utilities     : #c8900f;
    --cat-shopping      : #dc0e0e;
    --cat-entertainment : #df57b9;
    --cat-health        : #00a062;
    --cat-insurance     : #1b4ef5;
    --cat-education     : #9594ff;
    --cat-subscriptions : #0089cd;
    --cat-travel        : #00cdc0;
    --cat-personal-care : #b500b2;
    --cat-gifts         : #f35077;
    --cat-miscellaneous : #925900;
    --cat-other:          #8d8a83;   /* the folded tail, deliberately neutral */
}

[data-theme="dark"] {

    /* The same hues stepped for the dark surface, not a second palette. */
    --cat-eating-out    : #a84811;
    --cat-groceries     : #05a92e;
    --cat-transport     : #2196f3;
    --cat-rent          : #8c00ff;
    --cat-utilities     : #b37c00;
    --cat-shopping      : #bc0b20;
    --cat-entertainment : #d64fb1;
    --cat-health        : #009558;
    --cat-insurance     : #4379f9;
    --cat-education     : #8100d1;
    --cat-subscriptions : #137eb4;
    --cat-travel        : #00ab95;
    --cat-personal-care : #b500b2;
    --cat-gifts         : #ff0052;
    --cat-miscellaneous : #8a5100;
    --cat-other:          #8a8781;
    --ink: #eceae6;
    --ink-soft: #c9c7c2;
    --ink-muted: #98958e;
    --ink-faint: #6c6a64;
    --paper: #151412;
    --paper-warm: #211f1c;
    --paper-card: #1c1b18;
    --donut-dim: rgba(28, 27, 24, 0.7);
    --accent: #3f9d6a;
    --accent-hover: #4fb87f;
    --accent-light: #1d2c23;
    --accent-2: #d79544;
    --accent-2-light: #2d2315;
    --accent-3: #7c9fd0;
    --accent-4: #a48bd0;
    --accent-5: #d96455;
    --danger: #e0685a;
    --danger-light: #321f1c;
    --border: #2e2c28;
    --border-soft: #262521;
    --navbar-bg: rgba(21, 20, 18, 0.92);
    --chart-tip-bg: transparent;
    --footer-bg: #0d0d0c;
    --footer-text: #eceae6;
    --footer-muted: #8b8983;
    --row-hover: #21201d;
    --sheet-footer-bg: #191815;
    /* The same four hues, lifted to the lighter end of each so they register
       against a dark sheet at roughly the strength they have in light. */
    --week-1: rgba(124, 159, 208, 0.15);
    --week-2: rgba(63, 157, 106, 0.14);
    --week-3: rgba(215, 149, 68, 0.14);
    --week-4: rgba(164, 139, 208, 0.16);
    color-scheme: dark;

    --shadow-sm: 0 1px 4px rgba(0,0,0,0.35), 0 2px 8px rgba(0,0,0,0.25);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.30);
    --shadow-lg: 0 12px 48px rgba(0,0,0,0.55), 0 4px 16px rgba(0,0,0,0.35);
}

/* ------------------------------------------------------------------ */
/* Reset                                                               */
/* ------------------------------------------------------------------ */

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

html { font-size: 16px; scroll-behavior: smooth; }

/* The hidden attribute has to beat whatever display a component sets, or an
   element the script believes it has hidden stays on screen. The browser's own
   rule for it is the weakest kind there is, so any `display: flex` in a
   component's own styles quietly overrules it — which is exactly what kept
   "Add me" showing in the split editor after you were already in the split. */
[hidden] { display: none !important; }

/* Anchor targets land below the sticky navbar (64px) with breathing room */
[id] { scroll-margin-top: calc(64px + 2.5rem); }

body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ------------------------------------------------------------------ */
/* Navbar                                                              */
/* ------------------------------------------------------------------ */

.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--navbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
}

.nav-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    color: var(--ink);
    white-space: nowrap;
}

.brand-icon {
    color: var(--accent);
    font-size: 1.2rem;
}

/* The pixel-head mark in the navbar: 1px per grid unit, so it stays crisp. */
.brand-icon .brand-mark {
    display: block;
    width: 24px;
    height: 16px;
}
.nav-brand .brand-icon { display: inline-flex; align-items: center; }
.brand-mark-eyes { fill: var(--ink); }
/* The footer is dark in both themes, so --ink (near-black on light) would
   lose the eyes there: they take the footer's own light text colour. */
.footer .brand-mark-eyes { fill: var(--footer-text); }

.brand-name { color: var(--ink); }

/* Words in square pixels (pixel_text.py): one grid unit is about a tenth
   of the font size, rounded to whole pixels where the browser can, so the
   squares stay sharp. Capitals are 7 units tall, near the text's own. */
.pixel-word {
    --px: 0.1em;
    display: inline-block;
    width: calc(var(--px) * var(--w));
    height: calc(var(--px) * 9);
    vertical-align: calc(var(--px) * -2);
    overflow: visible;
}
.pixel-word + .pixel-word { margin-left: 0.12em; }
@supports (width: round(nearest, 1em, 1px)) {
    .pixel-word { --px: round(nearest, 0.1em, 1px); }
}
/* The blog masthead's "Dex", in Dex's green. */
.paper-wordmark-dex { color: var(--accent); }
/* "Dex" picked out (the home page hero, the story page title): green and
   bold, over a dotted underline of square pixels, echoing the pixel field. Each 5px tile is a whole 3px
   square and its 2px gap; `space` fits only whole tiles, spread evenly
   along the word, so no square is ever cut off at the end. */
.hero-dex {
    color: var(--accent);
    text-decoration: none;               /* also when it is a link */
    font-weight: 700;
    padding-bottom: 0.2em;
    background-image: linear-gradient(90deg, var(--accent) 3px, transparent 3px);
    background-size: 5px 3px;
    background-repeat: space no-repeat;
    background-position: 0 100%;
}

.wordmark { white-space: nowrap; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Regular nav links */
.nav-link {
    color: var(--ink-muted);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
    position: relative;
}
.nav-links a { color: var(--ink-muted); padding: 0.4rem 0.75rem; border-radius: var(--radius-sm); transition: color 0.15s, background 0.15s; }
.nav-links a:hover, .nav-link:hover { color: var(--ink); background: var(--paper-warm); }

/* Active nav link — green underline */
.nav-link--active {
    color: var(--ink) !important;
    font-weight: 700;
    background: transparent !important;
}
.nav-link--active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0.75rem;
    right: 0.75rem;
    height: 2px;
    background: var(--accent);
    border-radius: 999px;
}

/* Finances dropdown — a nav tab that opens Expenses / Wallet / Catalog */
.nav-group { position: relative; }
.nav-group-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: none;
    background: transparent;
    font: inherit;
    cursor: pointer;
}
.nav-group-btn svg { transition: transform 0.15s; }
.nav-group--open .nav-group-btn { color: var(--ink); background: var(--paper-warm); }
.nav-group--open .nav-group-btn svg { transform: rotate(180deg); }
.nav-group-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 170px;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 0.35rem;
    display: none;
    z-index: 200;
}
.nav-group--open .nav-group-panel { display: block; }
.nav-links .nav-group-panel a.nav-group-link { display: flex; align-items: center; gap: 0.6rem; }
.nav-group-link svg { flex-shrink: 0; color: var(--ink-muted); }
.nav-group-link:hover svg { color: var(--ink); }
.nav-group-panel .nav-group-link--active { color: var(--ink); font-weight: 600; background: var(--paper-warm); }
.nav-group-panel .nav-group-link--active svg { color: var(--accent); }

/* Three-dot menu */
.nav-dots-wrap { position: relative; }

.nav-dots-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.nav-dots-btn:hover { border-color: var(--ink-muted); color: var(--ink); background: var(--paper-warm); }
.nav-dots--open .nav-dots-btn { border-color: var(--accent); color: var(--accent); }

.nav-dots-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 240px;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 0.5rem;
    display: none;
    z-index: 200;
}
.nav-dots--open .nav-dots-panel { display: block; }

.nav-dots-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}
.nav-dots-item:hover { background: var(--paper-warm); }

.nav-dots-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    border: 1.5px solid var(--border);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent);
}
.nav-dots-avatar img { width: 100%; height: 100%; object-fit: cover; }
.nav-dots-avatar span { color: #fff; font-size: 0.85rem; font-weight: 700; }

.nav-dots-info { overflow: hidden; }
.nav-dots-name  { font-size: 0.875rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-dots-email { font-size: 0.75rem; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-dots-divider { height: 1px; background: var(--border-soft); margin: 0.35rem 0; }

.nav-dots-link {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--ink-soft);
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}
.nav-dots-link:hover { background: var(--paper-warm); color: var(--ink); }
/* Sign out — reads as leaving rather than another page. */
/* Scoped to the panel to outrank the bar's own .nav-links a colours. */
.nav-dots-panel .nav-dots-link--danger { color: var(--danger); }
.nav-dots-panel .nav-dots-link--danger:hover { background: var(--danger-light); color: var(--danger); }

.nav-cta {
    background: var(--ink) !important;
    color: var(--paper) !important;
    padding: 0.45rem 1.1rem !important;
    border-radius: var(--radius-sm) !important;
    transition: background 0.2s !important;
}
.nav-cta:hover { background: var(--accent) !important; color: var(--paper) !important; }

/* Public pages: see-through while at the top of the page (script adds
   .navbar--top), solid with its line once scrolled. */
.navbar--public { transition: background 0.2s, border-color 0.2s, backdrop-filter 0.2s; }
.navbar--public.navbar--top {
    background: transparent;
    border-bottom-color: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
.navbar--public .nav-links { gap: 0.15rem; white-space: nowrap; }

/* Sign in: an outlined button beside the solid Get started. */
.navbar--public .nav-links a.nav-signin {
    border: 1px solid var(--border);
    padding: 0.4rem 1rem;
    color: var(--ink);
    background: transparent;
}
.navbar--public .nav-links a.nav-signin:hover { border-color: var(--ink-muted); background: var(--paper-warm); }

/* Product / Resources dropdowns: icon, title and a one-line description. */
.nav-menu .nav-group-btn { color: var(--ink-muted); }
.nav-menu-panel {
    min-width: 320px;
    padding: 0.45rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
/* A bridge over the gap below the button, so a mouse can reach the panel. */
.nav-menu-panel::before { content: ''; position: absolute; left: 0; right: 0; top: -10px; height: 10px; }
@media (hover: hover) and (min-width: 601px) {
    .nav-menu:hover .nav-group-panel { display: block; }
    .nav-menu:hover .nav-group-btn svg { transform: rotate(180deg); }
}
.nav-links .nav-menu-panel a.nav-menu-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.6rem 0.7rem;
    border-radius: var(--radius-md);
    white-space: normal;
}
.nav-links .nav-menu-panel a.nav-menu-item:hover { background: var(--paper-warm); }
.nav-menu-icon {
    flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    border-radius: 9px;
    background: var(--accent-light);
    color: var(--accent);
}
.nav-menu-text { display: flex; flex-direction: column; gap: 0.1rem; }
.nav-menu-title { color: var(--ink); font-weight: 600; font-size: 0.9rem; }
.nav-menu-sub { color: var(--ink-faint); font-size: 0.78rem; font-weight: 400; }
.nav-mobile-iconlink { display: flex; align-items: center; gap: 0.6rem; }
.nav-mobile-iconlink svg { color: var(--accent); flex-shrink: 0; }

/* Tablets: Contact steps out of the bar (it's in the footer too). */
@media (max-width: 900px) and (min-width: 601px) {
    .navbar--public .nav-links > a.nav-link[href$="/contact"] { display: none; }
}
/* Features / Meet Dex links land below the sticky bar, not under it. */
#features, #dex, #faq { scroll-margin-top: 64px; }
.navbar--public .nav-signin { margin-left: 0.6rem; }
.navbar--public .nav-cta { margin-left: 0.35rem; }

/* Hamburger + mobile menu (shown ≤600px) */
.nav-hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.nav-hamburger:hover { border-color: var(--ink-muted); color: var(--ink); background: var(--paper-warm); }
.nav-hamburger .icon-close { display: none; }
.navbar.nav-open .nav-hamburger .icon-menu { display: none; }
.navbar.nav-open .nav-hamburger .icon-close { display: block; }

.nav-mobile-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 0.15rem;
    background: var(--paper-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    padding: 0.6rem 1rem 0.9rem;
    z-index: 150;
}

.nav-mobile-link {
    display: block;
    padding: 0.65rem 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink-soft);
    border-radius: var(--radius-sm);
    transition: background 0.12s, color 0.12s;
}
.nav-mobile-link:hover,
.nav-mobile-link--active { background: var(--paper-warm); color: var(--ink); }

/* Finances: a row that folds open to Expenses, Wallet and Catalog. */
.nav-mobile-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    list-style: none;
}
.nav-mobile-group-head::-webkit-details-marker { display: none; }
.nav-mobile-group-head svg { color: var(--ink-muted); transition: transform 0.15s; }
.nav-mobile-group[open] .nav-mobile-group-head svg { transform: rotate(180deg); }
.nav-mobile-group-items {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin: 0.15rem 0 0.15rem 0.75rem;
}
.nav-mobile-sublink {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 500;
}
.nav-mobile-sublink svg { flex-shrink: 0; color: var(--ink-muted); }
.nav-mobile-sublink.nav-mobile-link--active svg { color: var(--accent); }

.nav-mobile-divider { height: 1px; background: var(--border-soft); margin: 0.35rem 0.75rem; }
/* Sign out reads as leaving, same as in the desktop's three-dot menu. */
.nav-mobile-link--danger { color: var(--danger); }
.nav-mobile-link--danger:hover { background: var(--danger-light); color: var(--danger); }

/* "Get started" dropdown (logged-out navbar) */

/* ------------------------------------------------------------------ */
/* Main                                                                */
/* ------------------------------------------------------------------ */

.main-content { min-height: calc(100vh - 62px - 110px); }

/* ------------------------------------------------------------------ */
/* Hero                                                                */
/* ------------------------------------------------------------------ */

.hero {
    padding: 4.5rem 2rem 4rem;
    max-width: var(--max-width);
    margin: 0 auto;
}

.hero-inner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5rem;
    align-items: center;
}
/* Grid items default to min-width:auto and refuse to shrink below their
   content, blowing the whole page out past the viewport on small screens */
.hero-inner > * { min-width: 0; }

.hero-badge {
    display: inline-flex;
    align-items: center;
    color: var(--ink-faint);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin-bottom: 1.5rem;
}
/* A badge with no label still holds the gap above the title it used to sit on.
   A zero-width space gives the empty box the same text baseline real label text
   had, so the line box comes out identical instead of collapsing */
.hero-badge:empty::before { content: "\200B"; }

.hero-title {
    font-size: clamp(2.6rem, 5vw, 3.75rem);
    font-weight: 800;
    line-height: 1.08;
    letter-spacing: -0.035em;
    color: var(--ink);
    margin-bottom: 1.25rem;
}
.hero-title em { font-style: normal; color: var(--accent); }

.hero-subtitle {
    font-size: 1.05rem;
    color: var(--ink-muted);
    line-height: 1.75;
    max-width: 430px;
    margin-bottom: 2.25rem;
    font-weight: 400;
}

.hero-actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

/* ------------------------------------------------------------------ */
/* Mock card                                                           */
/* ------------------------------------------------------------------ */

.hero-visual { display: flex; justify-content: center; align-items: flex-start; }

.mock-card {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.mock-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-soft);
}

.mock-period {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
}
.mock-period svg { color: var(--ink-muted); }

.mock-header-stats { display: flex; align-items: flex-start; gap: 0.875rem; }

.mock-total-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 0.2rem;
    text-align: right;
}

.mock-total {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
    line-height: 1;
    text-align: right;
}

.mock-change {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius-sm);
    line-height: 1.2;
    white-space: nowrap;
}
.mock-change svg { margin-bottom: 1px; }
.mock-change-sub { font-size: 0.65rem; font-weight: 500; color: var(--ink-muted); }

/* Chart + bars layout */
.mock-chart-area {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

/* CSS donut chart */
.mock-donut-wrap { flex-shrink: 0; }

.mock-donut {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    /* Category colours from cat_icons.js; angles mirrored by the count-up
       script and the hover probe in landing.html */
    background: conic-gradient(
        #f39c12   0deg   148deg,
        #27ae60 148deg   231deg,
        #c0392b 231deg   278deg,
        #2980b9 278deg   321deg,
        #e74c3c 321deg   360deg
    );
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mock-donut::before {
    content: '';
    position: absolute;
    inset: 28px;
    background: var(--paper-card);
    border-radius: 50%;
    z-index: 2;
}

/* Hover dim overlay: fades the non-hovered segments toward the card colour.
   JS paints a conic-gradient here (transparent for the active segment,
   var(--donut-dim) for the rest); the radial mask keeps it on the ring only. */
.mock-donut-dim {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    -webkit-mask-image: radial-gradient(circle, transparent 0 56%, #000 57% 100%);
    mask-image: radial-gradient(circle, transparent 0 56%, #000 57% 100%);
}
.mock-donut-dim.is-active { opacity: 1; }

.mock-donut-inner {
    position: relative;
    z-index: 1;
    text-align: center;
}

/* The hovered segment's share, shown in the hole. z-index clears the ::before
   disc that forms the hole, which otherwise paints over anything in the middle. */
.mock-donut-probe {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}
.mock-donut.is-probing .mock-donut-probe { opacity: 1; }

.mock-donut-pct {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.mock-donut-probe-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    max-width: 90%;
}

.mock-donut-total {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.mock-donut-sub {
    font-size: 0.65rem;
    color: var(--ink-faint);
    font-weight: 500;
}

/* Bars */
.mock-bars { display: flex; flex-direction: column; gap: 0.6rem; flex: 1; min-width: 0; }

.mock-bar-row {
    display: grid;
    grid-template-columns: 14px 64px 1fr 44px 28px;
    align-items: center;
    gap: 0.5rem;
    cursor: default;
}

/* Legend marker: the category's own icon, inked in its slice colour */
.mock-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}
.mock-icon svg { width: 14px; height: 14px; }

.mock-cat {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--ink-soft);
    white-space: nowrap;
    transition: color 0.15s ease, font-weight 0.15s ease;
}
/* Highlight only the category name on hover / donut-segment sync */
.mock-bar-row:hover .mock-cat,
.mock-bar-row.is-active .mock-cat {
    color: var(--accent);
    font-weight: 700;
}

.mock-bar-track {
    height: 5px;
    background: var(--border-soft);
    border-radius: 999px;
    overflow: hidden;
}
.mock-bar {
    height: 100%;
    border-radius: 999px;
}

.mock-amt {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-muted);
    text-align: right;
    white-space: nowrap;
}

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

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--ink);
    color: var(--paper);
    padding: 0.7rem 1.5rem;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
    letter-spacing: -0.01em;
}
.btn-primary:hover { background: var(--accent); transform: translateY(-1px); }

/* A form that's already sending (behaviours.js): its buttons show the click
   landed and that more clicks won't do anything. */
form[data-submitting] button[type="submit"],
form[data-submitting] button:not([type]) {
    opacity: 0.7;
    cursor: progress;
    transform: none;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: transparent;
    color: var(--ink-soft);
    padding: 0.7rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    border: 1.5px solid var(--border);
    transition: all 0.2s;
    text-decoration: none;
    letter-spacing: -0.01em;
    /* Anchors carry the pointer themselves; the <button> ones — Save & add
       another among them — were falling back to the arrow without this. */
    cursor: pointer;
}
.btn-ghost:hover { border-color: var(--ink); color: var(--ink); background: var(--paper-warm); }

/* ------------------------------------------------------------------ */
/* Toasts (flash messages)                                             */
/* ------------------------------------------------------------------ */

.toast-stack {
    position: fixed;
    top: 80px;
    right: 1.25rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: min(360px, calc(100vw - 2rem));
    pointer-events: none;
}

.toast {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.85rem 2.2rem 0.9rem 0.9rem;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--toast-accent, var(--accent));
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    pointer-events: auto;
    animation: toast-in 0.35s cubic-bezier(.2, .9, .3, 1.3) both;
}

.toast--leaving {
    animation: toast-out 0.22s ease forwards;
}

@keyframes toast-in {
    from { transform: translateX(28px); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
    to { transform: translateX(28px); opacity: 0; }
}

.toast-icon {
    flex: none;
    display: flex;
    margin-top: 0.05rem;
    color: var(--toast-accent, var(--accent));
}

.toast-msg {
    font-size: 0.86rem;
    font-weight: 500;
    line-height: 1.4;
    color: var(--ink-soft);
}

.toast-close {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--ink-faint);
    cursor: pointer;
    border-radius: 5px;
    transition: background 0.15s, color 0.15s;
}

.toast-close:hover {
    background: var(--row-hover);
    color: var(--ink-soft);
}

.toast-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 2px;
    width: 100%;
    background: var(--toast-accent, var(--accent));
    opacity: 0.4;
    transform-origin: left;
    animation: toast-progress 5s linear forwards;
}

.toast:hover .toast-progress {
    animation-play-state: paused;
}

@keyframes toast-progress {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

.toast--success                { --toast-accent: var(--accent); }
.toast--info                   { --toast-accent: var(--accent-3); }
.toast--warning                { --toast-accent: var(--accent-2); }
.toast--error, .toast--danger  { --toast-accent: var(--danger); }

@media (max-width: 640px) {
    .toast-stack {
        left: 1rem;
        right: 1rem;
        top: 72px;
        width: auto;
    }
}

/* ------------------------------------------------------------------ */
/* Dashboard                                                           */
/* ------------------------------------------------------------------ */

.dashboard {
    padding: 3rem 2rem 5rem;
}

.dashboard-inner {
    max-width: var(--max-width);
    margin: 0 auto;
}

.dashboard-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    /* Without a gap the quote's attribution runs right up against the button —
       space-between leaves no room once a long quote has eaten the free space. */
    gap: 1.5rem;
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

/* On the dashboard the header holds only the dateline and greeting, so its
   rule comes in closer under them, and the Add expense + quote row follows
   just below it — a band of its own rather than straddling the rule, since
   the button sits level with the foot of the taller card and would run into
   the line. */
.dashboard-header:has(+ .dex-ask) {
    padding-bottom: 1.25rem;
    margin-bottom: 1.1rem;
}

/* Where a dateline follows the title, that block's own top hairline is the rule
   under it — two hairlines 2.5rem apart read as a mistake rather than a rhythm. */
.dashboard-header--flush {
    margin-bottom: 0;
    padding-bottom: 1.1rem;
    border-bottom: none;
}

/* The button is a flex child, so a long quote squeezes it until "+ Add expense"
   wraps onto two lines. It should hold its size and let the quote truncate. */
.dashboard-header > .btn-primary {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Today, then the month as week-grouped dots, then how far in that is. */
.cc-dateline {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-size: 0.78rem;
    color: var(--ink-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    margin-bottom: 0.45rem;
}

.cc-dateline-count {
    color: var(--ink-faint);
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0.01em;
}

/* One tick per day, in week groups, bottom-aligned so today can stand
   taller than the rest. Days to come are just a trace; days lived are filled
   in faintly, days with spending in full ink. A spent tick still in the
   future (a bill dated forward) stays a trace — it hasn't happened yet. */
.cc-ticks {
    display: inline-flex;
    align-items: flex-end;
    gap: 8px;                             /* between weeks */
    height: 15px;
}

.cc-tick-week {
    display: inline-flex;
    align-items: flex-end;
    gap: 3px;                             /* between days */
}

.cc-tick {
    width: 3px;
    height: 9px;
    border-radius: 1px;
    background: var(--border);
}

.cc-tick--past { background: var(--ink-faint); opacity: 0.45; }
.cc-tick--past.cc-tick--spent { background: var(--ink-soft); opacity: 1; }

.cc-tick--today {
    height: 15px;
    width: 4px;
    background: var(--accent);
}

/* A phone fits the whole month on one row only with the ticks drawn
   thinner; the count drops to its own line rather than pushing past the
   edge if it still doesn't fit. */
@media (max-width: 480px) {
    .cc-dateline { gap: 0.3rem 0.5rem; flex-wrap: wrap; }
    .cc-ticks { gap: 6px; }
    .cc-tick-week { gap: 2px; }
    .cc-tick { width: 2px; }
    .cc-tick--today { width: 3px; }
}

.dashboard-name {
    font-size: 2rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
}

.dashboard-name-greet {
    color: var(--ink-muted);
    font-weight: 500;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1.25rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem 1.75rem;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
    margin-bottom: 0.6rem;
}

.stat-value {
    position: relative;
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
}

.cc-stat-num { display: inline-block; }

.stat-card--owe  { border-top: 3px solid var(--danger); }
.stat-card--owed { border-top: 3px solid var(--accent); }
.stat-card--owe  .stat-value { color: var(--danger); }
.stat-card--owed .stat-value { color: var(--accent); }

/* Both standing-balance cards open the Balances tab — the page that breaks the
   figure down and lets it be settled. */
.stat-card--link {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.stat-card--link:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card-value-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.stat-card-chevron {
    flex-shrink: 0;
    color: var(--ink-faint);
    transition: transform 0.15s, color 0.15s;
}
.stat-card--owe:hover  .stat-card-chevron { color: var(--danger); transform: translateX(2px); }
.stat-card--owed:hover .stat-card-chevron { color: var(--accent); transform: translateX(2px); }

.stat-card--link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .stat-card--link { transition: none; }
    .stat-card--link:hover { transform: none; }
}

.dashboard-empty {
    background: var(--paper-card);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 4rem 2rem;
    text-align: center;
}

.empty-icon {
    font-size: 2.5rem;
    color: var(--ink-faint);
    margin-bottom: 1.25rem;
}

.empty-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.empty-body {
    font-size: 0.95rem;
    color: var(--ink-muted);
    margin-bottom: 1.75rem;
}

@media (max-width: 1100px) {
    .dashboard-stats { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
    .dashboard-stats { grid-template-columns: 1fr 1fr; }
    .dashboard-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
}

@media (max-width: 600px) {
    .dashboard-stats { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------ */
/* Auth pages                                                          */
/* ------------------------------------------------------------------ */

.auth-section {
    min-height: calc(100vh - 62px - 110px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    background: radial-gradient(ellipse at 50% 0%, var(--accent-light) 0%, transparent 65%);
}

.auth-container {
    width: 100%;
    max-width: var(--auth-width);
}

/* Register pairs its fields two to a row, which needs more width than the
   single-column sign-in card. */
.auth-container--wide { max-width: 600px; }

/* Live "n / 40" counter inside the name field, same rule and colour steps as
   the profile card's. Padding keeps typed text clear of the number. */
.input-wrap .form-input.has-count { padding-right: 3.6rem; }

.name-count {
    position: absolute;
    right: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.68rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--ink-muted);
    pointer-events: none;
}

.name-count--near { color: var(--accent-2); }
.name-count--full { color: var(--danger); }

/* Parked in the field's bottom-right corner instead of centred, and only while
   the field is being written in — an idle form shouldn't be counting at you. */
.name-count--corner {
    top: auto;
    bottom: 0.3rem;
    transform: none;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.input-wrap:focus-within .name-count--corner { opacity: 1; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 1rem;
    align-items: start;
}

@media (max-width: 560px) {
    .form-row { grid-template-columns: 1fr; }
}

.auth-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.auth-title {
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--ink);
    margin-bottom: 0.35rem;
    letter-spacing: -0.03em;
}

.auth-subtitle {
    font-size: 0.9rem;
    color: var(--ink-muted);
}

.auth-card {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 2.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-md);
}

/* "Forgot password?" sits on the password label's own line, pushed to the
   right, so it costs no vertical space in the form. The selector outweighs
   `.form-group :where(label)`, which would otherwise force display:block and
   leave the link sitting inline after the label text. */
.form-group label.label-with-link {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
}

.label-link {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
}

.label-link:hover { text-decoration: underline; }

/* Confirmation copy on the "check your inbox" step. */
.auth-sent-note {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.65;
    color: var(--ink-muted);
    text-align: center;
}

.auth-sent-note a {
    color: var(--accent);
    font-weight: 600;
}

.auth-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #f5c6c2;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 1.25rem;
}

.form-group { margin-bottom: 1.1rem; }

/* Field-label defaults. `:where` keeps this at .form-group's specificity so a
   label that is really a component — the split switch, a toggle button, the
   receipt Remove control — is styled by its own class instead of this. */
.form-group :where(label) {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--ink-soft);
    margin-bottom: 0.4rem;
    letter-spacing: 0.01em;
}

.form-input {
    width: 100%;
    padding: 0.65rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.95rem;
    color: var(--ink);
    background: var(--paper);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26, 71, 42, 0.1);
}

/* Amounts are typed, never nudged — no stepper arrows on number fields. The
   wheel and arrow keys are stopped in main.js for the same reason. */
.form-input.is-invalid { border-color: var(--danger); }

/* Formula mode on money fields (main.js): typing "=" turns the amount box into
   an equation box. The coloured text is a mirror laid over the input, whose own
   text goes transparent — the caret and selection underneath are still real. */
.money-field { position: relative; display: block; }
.money-fx,
.money-mirror,
.money-result { display: none; }

.money-field--formula .form-input {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.95rem;
    line-height: 1.4;
    letter-spacing: 0;
    color: transparent;
    caret-color: var(--ink);
    background: var(--accent-light);
    border-color: var(--accent);
    padding-left: 2.75rem;
    padding-right: 6.5rem;
}
.money-field--formula .form-input.is-invalid { border-color: var(--danger); }
.money-field--formula .money-mirror {
    display: flex;
    align-items: center;
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
    padding: 0.65rem 6.5rem 0.65rem 2.75rem;
    border: 1.5px solid transparent;   /* same box as the input's border */
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.95rem;
    line-height: 1.4;
    white-space: pre;
}
.money-mirror-clip {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}
.money-mirror-text { display: inline-block; flex: none; color: var(--ink); }
.money-mirror-text .fx-num   { color: var(--ink); }
.money-mirror-text .fx-op    { color: var(--accent); font-weight: 700; }
.money-mirror-text .fx-paren { color: var(--accent-2); font-weight: 700; }
.money-mirror-text .fx-eq    { color: var(--accent); font-weight: 700; }
.money-mirror-text .fx-other { color: var(--danger); }

.money-field--formula .money-fx {
    display: inline-flex;
    align-items: center;
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    padding: 0.1rem 0.4rem;
    font-size: 0.72rem;
    font-style: italic;
    font-weight: 700;
    color: #fff;
    background: var(--accent);
    border-radius: 5px;
    pointer-events: none;
}
.money-field--formula .money-result {
    display: block;
    position: absolute;
    right: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    max-width: 6rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
    pointer-events: none;
}
.money-field--formula .money-result--bad { color: var(--danger); }

/* The split editor's rows are too narrow for the full treatment: just the
   monospace and the tint, so it's still clear the row holds a formula. */
.money-input--formula {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: var(--accent-light);
    border-color: var(--accent);
}

input[type="number"] { appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.form-input::placeholder { color: var(--ink-faint); }

/* Date input wrapper */
.date-input-wrap {
    position: relative;
}
.date-input-wrap .date-icon {
    position: absolute;
    right: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--ink-faint);
}
input[type="date"].form-input {
    cursor: pointer;
    color-scheme: light;
    appearance: none;
    font-family: var(--font);
    font-size: 0.95rem;
    color: var(--ink);
    padding-right: 2.5rem; /* room for our icon */
}
input[type="date"].form-input::-webkit-calendar-picker-indicator {
    opacity: 0;
    position: absolute;
    right: 0;
    top: 0;
    width: 2.5rem;
    height: 100%;
    cursor: pointer;
}
input[type="date"].form-input::-webkit-datetime-edit-fields-wrapper { padding: 0; }
input[type="date"].form-input::-webkit-datetime-edit { color: var(--ink); }

/* ------------------------------------------------------------------ */
/* Date picker (static/js/datepicker.js)                               */
/* ------------------------------------------------------------------ */

/* The native input stays in the form for posting and validation, out of sight. */
.dp-native {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
    clip-path: inset(50%);
}
.dp, .dp-wrap { position: relative; display: block; }

.dp-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    text-align: left;
    cursor: pointer;
    padding-right: 2.5rem;
}
.dp-trigger:focus-visible,
.dp--open .dp-trigger {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26, 71, 42, 0.1);
}
.dp-trigger.is-invalid { border-color: var(--danger); }
.dp-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-value--empty { color: var(--ink-faint); }
.dp-trigger .dp-icon {
    position: absolute;
    right: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ink-faint);
}
.dp--open .date-icon,
.dp--open .dp-icon { color: var(--accent); }

.dp-pop {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 300;
    width: 300px;
    max-width: calc(100vw - 2rem);
    padding: 0.75rem;
    background: var(--paper-card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    animation: dp-in 0.14s ease-out;
}
.dp--right .dp-pop { left: auto; right: 0; }
.dp--up .dp-pop { top: auto; bottom: calc(100% + 6px); }
@keyframes dp-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .dp-pop { animation: none; } }

.dp-head {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 0.5rem;
}
.dp-head .dp-title { margin-right: auto; }
/* Jump back to today and pick it — sits with the arrows rather than in a footer. */
.dp-today {
    margin-right: 4px;
    padding: 0.25rem 0.65rem;
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-light);
    border: none;
    border-radius: 999px;
    cursor: pointer;
}
.dp-today:hover:not(:disabled) { background: var(--accent); color: #fff; }
.dp-today:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.dp-today:disabled { opacity: 0.4; cursor: default; }
.dp-title,
.dp-nav,
.dp-day,
.dp-cell,
.dp-link {
    font-family: var(--font);
    border: none;
    background: none;
    color: var(--ink);
    cursor: pointer;
}
.dp-title {
    font-size: 0.9rem;
    font-weight: 700;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius-sm);
}
.dp-title:hover { background: var(--paper); }
.dp-pop[data-view="years"] .dp-title { cursor: default; pointer-events: none; }
.dp-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: var(--ink-muted);
}
.dp-nav:hover:not(:disabled) { background: var(--paper); color: var(--ink); }
.dp-nav:disabled { opacity: 0.3; cursor: default; }

.dp-dows,
.dp-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}
.dp-dows span {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--ink-faint);
    padding: 0.25rem 0;
}
.dp-day {
    aspect-ratio: 1;
    font-size: 0.85rem;
    border-radius: 50%;
    font-variant-numeric: tabular-nums;
}
.dp-day--outside { color: var(--ink-faint); }
.dp-day--today { font-weight: 700; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent-light); }

.dp-grid--wide { grid-template-columns: repeat(3, 1fr); gap: 4px; }
.dp-cell {
    padding: 0.7rem 0;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
}

.dp-day:hover:not(:disabled),
.dp-cell:hover:not(:disabled) { background: var(--paper); }
.dp-day:focus-visible,
.dp-cell:focus-visible,
.dp-title:focus-visible,
.dp-nav:focus-visible,
.dp-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.dp-day.dp-day--selected,
.dp-cell.dp-day--selected,
.dp-day.dp-day--selected:hover,
.dp-cell.dp-day--selected:hover {
    background: var(--accent);
    color: #fff;
    box-shadow: none;
}
.dp-day:disabled,
.dp-cell:disabled { opacity: 0.3; cursor: default; }

.dp-foot {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-soft);
}
.dp-link {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
}
.dp-link:hover { background: var(--accent-light); }
.dp-link--muted { color: var(--ink-muted); }
.dp-link--muted:hover { background: var(--paper); }

/* Paid-by toggle */
/* Toggle and payer/method input sit side by side, each under its own label. */
.paid-by-wrap {
    display: flex;
    /* Aligned at the top so the two labels share a line and the controls under
       them do too. Bottom alignment used to amount to the same thing, until the
       payment method grew a suggestion line underneath it — the bottom of that
       column stopped being the bottom of its input, and the toggle beside it
       sank to match. */
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}
.paid-by-col { flex-shrink: 0; }
.paid-by-col label,
.paid-payer-field label { white-space: nowrap; }
.paid-toggle-group {
    display: flex;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    /* Built from the same ingredients as the .form-input it sits beside — that
       field's vertical padding, its border, and a line box off its font size —
       so the two controls stand the same height and go on matching if any of
       those change. The buttons stretch to fill it. */
    min-height: calc(0.65rem * 2 + 1.5px * 2 + 0.95rem * 1.15);
}
.paid-toggle-btn {
    --pb-fill: var(--paper);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;                /* settle-up renders these as <label>s */
    padding: 0.6rem 1rem;
    background: var(--pb-fill);
    border: none;
    font-family: var(--font);
    font-size: 0.875rem;
    color: var(--ink-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border-right: 1.5px solid var(--border);
}
.paid-toggle-btn:last-child { border-right: none; }
.paid-toggle-btn:hover { --pb-fill: var(--paper-warm); color: var(--ink); }
.paid-toggle-btn--active {
    /* A light green tint with green text, not a solid block: the choice reads
       clearly without the toggle outweighing the fields around it. */
    --pb-fill: color-mix(in srgb, var(--accent) 14%, var(--paper-card));
    color: var(--accent);
    font-weight: 600;
}
/* Your avatar on the "You" side of the toggle — photo, or initial without one. */
.paid-avatar {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--accent);
    margin-block: -2px;   /* overhangs the line rather than heightening the button */
}
.paid-avatar span { color: #fff; font-size: 0.65rem; font-weight: 700; line-height: 1; }
.paid-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.paid-toggle-btn:not(.paid-toggle-btn--active) .paid-avatar { opacity: 0.7; }

/* "Someone else": the most frequent contacts as overlapping initials, most
   frequent in front, each in their own colour (.person-cN) and ringed in the
   button's fill so the overlaps read. */
.contact-stack {
    display: inline-flex;
    flex: none;
    margin-block: -2px;
}
.contact-stack-face {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 0 0 2px var(--pb-fill);
}
.contact-stack-face + .contact-stack-face { margin-left: -6px; }
.contact-stack-face:nth-child(1) { z-index: 3; }
.contact-stack-face:nth-child(2) { z-index: 2; }
.contact-stack-face:nth-child(3) { z-index: 1; }
.contact-stack { position: relative; isolation: isolate; }
/* No contacts yet: an empty dashed seat with a plus. */
.contact-stack--empty .contact-stack-face {
    background: transparent;
    color: var(--ink-muted);
    border: 1.5px dashed currentColor;
    box-shadow: none;
}
.paid-toggle-btn:not(.paid-toggle-btn--active) .contact-stack { opacity: 0.85; }

.paid-toggle-btn--active:hover {
    --pb-fill: color-mix(in srgb, var(--accent) 22%, var(--paper-card));
    color: var(--accent);
}
.paid-payer-field {
    flex: 1;
    min-width: 200px;
}
.paid-payer-field .form-input { margin: 0; }

/* Password show/hide wrapper */
.input-wrap {
    position: relative;
}

.input-wrap .form-input.has-toggle,
.input-wrap .form-input.has-tick {
    padding-right: 2.8rem;
}

/* Validity marks sitting inside the field on the right: a green tick once the
   address is complete, a red cross while it isn't. Both stay hidden on an
   empty field, so the form doesn't open already scolding you. */
.input-tick,
.input-cross {
    position: absolute;
    right: 0.85rem;
    top: 50%;
    transform: translateY(-50%) scale(0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.input-tick  { color: var(--accent); }
.input-cross { color: var(--danger); }

.input-wrap.is-valid .input-tick,
.input-wrap.is-invalid .input-cross {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}

.pw-toggle {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--ink-faint);
    display: flex;
    align-items: center;
    transition: color 0.15s;
}

.pw-toggle:hover { color: var(--ink-muted); }

/* Field hints (confirm password match) */
.field-hint {
    font-size: 0.78rem;
    margin-top: 0.35rem;
    min-height: 1.1em;
}

/* Google OAuth button */
.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--paper-card);
    color: var(--ink-soft);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    letter-spacing: -0.01em;
    margin-bottom: 1rem;
}
.btn-google:hover {
    border-color: #4285F4;
    background: #f8faff;
    box-shadow: 0 0 0 3px rgba(66,133,244,0.1);
}

/* Tapped: the Google trip is on its way (behaviours.js, data-busy-label). A
   spinner takes the logo's place and the button dims, so a slow phone
   connection never looks like a dead tap. */
.btn-google-spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: #4285F4;
    border-radius: 50%;
    animation: dex-spin 0.7s linear infinite;
}
.btn-google[aria-busy="true"] { cursor: progress; opacity: 0.75; }
.btn-google[aria-busy="true"] > svg { display: none; }
.btn-google[aria-busy="true"] .btn-google-spinner { display: inline-block; }
@media (prefers-reduced-motion: reduce) {
    .btn-google-spinner { animation-duration: 2s; }
}

/* Divider between OAuth and email form */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    color: var(--ink-faint);
    font-size: 0.78rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.btn-submit {
    width: 100%;
    padding: 0.75rem;
    background: var(--ink);
    color: var(--paper);
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    margin-top: 0.5rem;
    letter-spacing: -0.01em;
}

.btn-submit:hover {
    background: var(--accent);
    transform: translateY(-1px);
}

/* Gated submit — e.g. sign-in waits for a well-formed email. */
.btn-submit:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-submit:disabled:hover {
    background: var(--ink);
    transform: none;
}

.auth-switch {
    text-align: center;
    font-size: 0.875rem;
    color: var(--ink-muted);
}

.auth-switch a {
    color: var(--accent);
    font-weight: 700;
}

.auth-switch a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ */
/* Footer                                                              */
/* ------------------------------------------------------------------ */

.footer {
    background: var(--footer-bg);
    color: var(--footer-text);
    padding: 2.75rem 2rem 0;
}

.footer-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.footer-brand {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.footer-brand-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.footer .brand-icon { color: var(--accent); display: inline-flex; align-items: center; }

.footer-name {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.footer-links a svg { width: 13px; height: 13px; flex-shrink: 0; }

.footer-tagline {
    font-size: 0.8rem;
    color: var(--footer-muted);
    margin: 0;
}

.footer-nav {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.footer-nav-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--footer-muted);
    margin: 0;
}

/* ------------------------------------------------------------------ */
/* Footer links                                                        */
/* ------------------------------------------------------------------ */

.footer-links {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.footer-links a {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.82rem;
    color: var(--footer-muted);
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--footer-text);
}

/* ------------------------------------------------------------------ */
/* Footer bottom bar                                                   */
/* ------------------------------------------------------------------ */

.footer-bottom {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 0 2rem;
    gap: 1rem;
}

.footer-copy {
    font-size: 0.78rem;
    color: var(--footer-muted);
    margin: 0;
}

/* Sits beside the copyright as a quiet build marker — useful when someone
   reports a bug and you need to know which deploy they were on. */
.footer-version {
    margin-left: 0.5rem;
    padding-left: 0.5rem;
    border-left: 1px solid currentColor;
    font-variant-numeric: tabular-nums;
    opacity: 0.75;
}

.footer-credit {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--footer-muted);
    margin: 0;
}

.footer-creator-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--footer-text);
    font-weight: 500;
    transition: color 0.2s;
}

.footer-creator-link:hover {
    color: var(--accent-2);
}

/* ------------------------------------------------------------------ */
/* Legal pages (Terms & Privacy)                                       */
/* ------------------------------------------------------------------ */

.legal-page {
    padding: 3.5rem 2rem 6rem;
    max-width: 1060px;
    margin: 0 auto;
}

/* Header */
.legal-header {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 3rem;
}

.legal-header-icon {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: var(--radius-md);
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.legal-title {
    font-size: clamp(1.75rem, 3.5vw, 2.4rem);
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
    margin: 0 0 0.4rem;
    line-height: 1.1;
}

.legal-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink-muted);
    background: var(--paper-warm);
    border: 1px solid var(--border-soft);
    border-radius: 100px;
    padding: 0.2rem 0.75rem;
    letter-spacing: 0.01em;
}

/* Two-column layout */
.legal-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 3rem;
    align-items: start;
}

/* TOC sidebar */
.legal-toc {
    position: sticky;
    top: 5rem;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
}

.legal-toc-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    margin: 0 0 1rem;
}

.legal-toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    counter-reset: toc-counter;
}

.legal-toc-list li {
    counter-increment: toc-counter;
}

.legal-toc-list a {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--ink-muted);
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    line-height: 1.4;
}

.legal-toc-list a::before {
    content: counter(toc-counter, decimal-leading-zero);
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--ink-faint);
    flex-shrink: 0;
}

.legal-toc-list a:hover {
    background: var(--accent-light);
    color: var(--accent);
}

/* Main content */
.legal-body {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.legal-section {
    padding: 2rem 0;
    border-bottom: 1px solid var(--border-soft);
}

.legal-section:first-child { padding-top: 0; }

.legal-section-head {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-bottom: 0.9rem;
}

.legal-num {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: var(--accent);
    background: var(--accent-light);
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    flex-shrink: 0;
}

.legal-section h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
    letter-spacing: -0.01em;
}

.legal-section p {
    font-size: 0.95rem;
    color: var(--ink-muted);
    line-height: 1.8;
    margin: 0;
}

.legal-section p + p { margin-top: 0.75rem; }

.legal-section ul {
    margin-top: 0.75rem;
    padding-left: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.legal-section ul li {
    font-size: 0.95rem;
    color: var(--ink-muted);
    line-height: 1.7;
    padding-left: 1.2rem;
    position: relative;
}

.legal-section ul li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.65em;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.5;
}

.legal-section a {
    color: var(--accent);
    font-weight: 600;
}

.legal-section a:hover { text-decoration: underline; }

/* Contact card */
.legal-contact-card {
    margin-top: 2.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    background: var(--accent-light);
    border: 1px solid rgba(26,71,42,0.15);
    border-radius: var(--radius-md);
    padding: 1.5rem 1.75rem;
}

.legal-contact-icon {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Doubled selectors so these beat container rules like .dex-story-body p */
.legal-contact-card .legal-contact-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.4;
    margin: 0 0 0.2rem;
}

.legal-contact-card .legal-contact-body {
    font-size: 0.83rem;
    color: var(--ink-muted);
    line-height: 1.5;
    margin: 0;
}

.legal-contact-btn {
    margin-left: auto;
    flex-shrink: 0;
    background: var(--accent);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
    white-space: nowrap;
}

.legal-contact-btn:hover {
    background: var(--accent-hover);
    color: white;
}

/* ------------------------------------------------------------------ */
/* Contact form                                                        */
/* ------------------------------------------------------------------ */

/* Wears what the old "Email us" card wore — the tinted ground, the accent
   hairline, the circled icon — so the form reads as that card grown into
   something you can write in, rather than a second thing on the page. */
.contact-card {
    background: var(--accent-light);
    border: 1px solid rgba(26,71,42,0.15);
    border-radius: var(--radius-md);
    padding: 1.75rem;
}

.contact-card-head {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

/* Doubled selectors so these beat container rules like .dex-story-body p */
.contact-card .contact-card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.4;
    margin: 0 0 0.2rem;
}

.contact-card .contact-card-body {
    font-size: 0.83rem;
    color: var(--ink-muted);
    line-height: 1.5;
    margin: 0;
}
.contact-card .contact-card-body b { color: var(--accent); font-weight: 700; }

/* Nothing to fill in on the thank-you, so the head is the whole card. */
.contact-card--sent .contact-card-head { margin-bottom: 0; }

.contact-again {
    display: inline-block;
    margin: 1.1rem 0 0 calc(44px + 1.25rem);
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--accent);
}
.contact-again:hover { text-decoration: underline; }

/* The fields sit on the card's tint, so they need the page's own paper behind
   them to read as somewhere to type. */
.contact-card .form-input {
    background: var(--paper-card);
}

/* Dark drops the tint and goes neutral. The wash that reads as soft mint on
   paper reads as a green cast on ink — and worse, the fields inside it are the
   app's own card colour, which left a warm-grey box sitting in a green one.
   Same panel colours as every other card in the app, with the accent left to
   the icon. */
[data-theme="dark"] .contact-card {
    background: var(--paper-card);
    border-color: var(--border);
}
[data-theme="dark"] .contact-card .form-input {
    background: var(--paper);
}

/* Offered to bots, hidden from everyone else. Not display:none — some bots
   skip what the page has plainly hidden, and this one wants filling in. */
.contact-trap {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.contact-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Names read as names however they were typed. The server capitalises the same
   letters this does — word starts only, the rest left alone — so what was on
   screen is what lands in the inbox. */
.contact-name { text-transform: capitalize; }
.contact-name::placeholder { text-transform: none; }

.contact-textarea {
    resize: vertical;
    min-height: 8rem;
    line-height: 1.6;
    font-family: var(--font);
}

/* The message counter sits under the text rather than beside it (room at
   the bottom, not down the right side), and clear of the resize grip. */
.input-wrap .contact-textarea.has-count { padding-right: 1rem; padding-bottom: 1.6rem; }
.contact-textarea + .name-count--corner { right: 1.5rem; }

.contact-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.contact-submit {
    width: auto;
    /* Beats .btn-submit's own top margin — the row above already spaces this. */
    margin: 0 0 0 auto;
    padding-left: 2rem;
    padding-right: 2rem;
}

@media (max-width: 640px) {
    .contact-card { padding: 1.25rem; }
    .contact-card-head { align-items: flex-start; gap: 0.9rem; }
    .contact-again { margin-left: 0; }
    .contact-row { grid-template-columns: 1fr; }
    .contact-actions { flex-direction: column; align-items: stretch; }
    .contact-submit { width: 100%; margin-left: 0; }
}

/* ------------------------------------------------------------------ */
/* Expenses list page                                                  */
/* ------------------------------------------------------------------ */

.expenses-page { padding: 2.5rem 2rem 5rem; }

.expenses-inner {
    max-width: var(--max-width);
    margin: 0 auto;
}

.expenses-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
}

.expenses-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
}

/* Summary strip */
/* Three cards since the two split figures moved to Balances. Sized rather
   than stretched: at full width five columns' worth of space would leave each
   card mostly empty. */
/* Dateline — the month's figures set as a standfirst above the sheet.
   Deliberately not cards: hairlines top and bottom, no fill, no shadow. The
   numbers are the only ink that carries weight and the prose around them stays
   muted, so the block scans as statistics without being boxed into them. */
.dateline {
    /* Both rules are the same hairline the panels elsewhere are drawn with, so
       the block reads as part of the page rather than a masthead sitting on
       top of it — and it follows the theme into dark without a second colour. */
    position: relative;
    /* A column so the facts can be pushed to the foot of the block, down where
       the drawing has its shoreline, instead of trailing the total. */
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 1.1rem 0 1rem;
    margin-bottom: 1.5rem;
    min-height: 13rem;
    overflow: hidden;
}

/* The sketch. It draws in the accent, faded out towards the top so the peaks
   dissolve into the page rather than ending on an edge, and sits behind
   everything else in the block. */
.dateline-sketch {
    position: absolute;
    inset: 0;
    pointer-events: none;
    color: var(--accent);
    opacity: 0.26;
    -webkit-mask-image: linear-gradient(to bottom, transparent, #000 42%);
            mask-image: linear-gradient(to bottom, transparent, #000 42%);
}

.dateline-sketch svg { display: block; width: 100%; height: 100%; }

[data-theme="dark"] .dateline-sketch { opacity: 0.32; }

/* Everything else in the block stacks above the drawing. */
.dateline > p { position: relative; }

.dateline-scope {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-muted);
}

.dateline-total {
    font-family: var(--font-display);
    font-size: clamp(2.1rem, 5vw, 3rem);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.04em;
    color: var(--ink);
    margin-top: 0.3rem;
}

/* Total on the left, what qualifies it on the right, tops aligned. */
.dateline-head {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
}

.dateline-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
    gap: 0.3rem;
    padding-top: 0.15rem;
    font-size: 0.83rem;
    font-weight: 600;
}

/* Over usual is not a failure and under it is not a win — both read in ink,
   with only the arrow and a tint of the accent to carry the direction. */
.dl-delta--up   { color: var(--accent-2); }
.dl-delta--down { color: var(--accent); }
.dl-flat, .dl-pace { color: var(--ink-muted); font-weight: 500; }

/* One line across the full width. No max-width to hold it in — the clauses are
   short enough to sit on a single line once the meta moved off to the right,
   and it wraps rather than clips on the months wordy enough to overrun. */
.dateline-facts {
    position: relative;
    margin-top: auto;          /* sits at the foot of the block */
    /* Shrunk to its own text rather than left to fill the row: the haze below
       is sized off this box, and a full-width one would blur a stretch of
       drawing that has no words over it to protect. */
    align-self: flex-start;
    width: fit-content;
    max-width: 100%;
    padding-top: 0.9rem;
    font-size: 0.875rem;
    line-height: 1.7;
    color: var(--ink-muted);
}

/* Blurs the drawing behind the line and nothing else, faded off at the ends and
   along the top. Both gradients are intersected: a single one leaves the other
   axis with a hard edge, and a seam running across a hatched mountainside is
   more noticeable than the blur it was meant to hide. */
.dateline-facts-haze {
    position: absolute;
    inset: 0 -0.9rem -0.45rem;
    pointer-events: none;
    -webkit-backdrop-filter: blur(3.5px);
            backdrop-filter: blur(3.5px);
    -webkit-mask-image: linear-gradient(to right, transparent, #000 3.5%, #000 96.5%, transparent),
                        linear-gradient(to bottom, transparent, #000 60%);
            mask-image: linear-gradient(to right, transparent, #000 3.5%, #000 96.5%, transparent),
                        linear-gradient(to bottom, transparent, #000 60%);
    -webkit-mask-composite: source-in;
            mask-composite: intersect;
}

/* Positioned, so the clauses paint above the haze that precedes them. */
.dl-fact { white-space: nowrap; position: relative; }

.dateline-facts b {
    font-weight: 700;
    color: var(--ink);
}

/* Category named in prose: the sheet's icon and colour, without the pill.
   Deliberately not inline-flex — a flex box takes its baseline from its first
   item, and an icon span holding no text baselines on its bottom edge, which
   is what pushes the name off the line it is supposed to be sitting on. Plain
   inline flow instead, so the name shares the sentence's own baseline and only
   the icon is nudged, optically centred on the text rather than sat on it. */
.dl-cat { white-space: nowrap; }

.dl-cat .cat-icon-svg {
    display: inline-block;
    vertical-align: -0.15em;
    margin-right: 0.3rem;
    color: var(--cat-color, var(--ink-muted));
}
.dl-cat .cat-icon-svg svg { display: block; width: 13px; height: 13px; }

/* Name in the category's own colour, matching its icon and the sheet's badge.
   The share beside it stays in ink: two coloured values in one clause read as
   a highlight rather than a label. */
.dl-cat b { color: var(--cat-color, var(--ink)); }

/* The month's largest expense, coloured by the week it landed in — the same
   four hues the sheet lights its rows with. Those tints are near-transparent
   by design, so text borrows the opaque accents they were mixed from, which
   also means the theme swaps both at once. */
.dl-week b { color: var(--week-ink, var(--ink)); }
.dl-week[data-week="0"] { --week-ink: var(--accent-3); }
.dl-week[data-week="1"] { --week-ink: var(--accent); }
.dl-week[data-week="2"] { --week-ink: var(--accent-2); }
.dl-week[data-week="3"] { --week-ink: var(--accent-4); }

/* No-spend days, under the comparison. The one figure on the block that is
   unambiguously good news, so the one allowed to look pleased about itself. */
.dl-nospend { color: var(--accent); }
.dl-nospend b { color: var(--accent); font-weight: 700; }
.dl-nospend--none { color: var(--ink-muted); font-weight: 500; }
.dl-nospend--none b { color: var(--ink); }

.dl-spark { vertical-align: -2px; margin-right: 0.1rem; }

/* The separator is drawn between surviving clauses rather than printed with
   each one, so a month that can't state its heaviest week doesn't leave a
   dangling middot behind. */
.dl-fact + .dl-fact::before {
    content: '·';
    margin: 0 0.5rem;
    color: var(--ink-faint);
}

/* Filter bar */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

/* Native <select> with its own chevron — the browser's default glyph sits at
   an inconsistent distance from the edge across platforms, which reads as
   crowded or lopsided. appearance: none drops it in favour of one drawn
   ourselves, at a fixed, vertically-centred offset that matches every other
   icon-in-a-field on this page (.filter-search-icon, .date-input-wrap). */
.select-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.select-caret {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ink-faint);
    pointer-events: none;
    transition: color 0.15s;
}

.select-wrap:hover .select-caret,
.filter-select:focus + .select-caret {
    color: var(--ink-muted);
}

.filter-select {
    appearance: none;
    padding: 0.5rem 1.9rem 0.5rem 0.875rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink-soft);
    background: var(--paper-card);
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
}

.filter-select:focus { border-color: var(--accent); }

.filter-clear {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--ink-muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 1px;
    transition: color 0.15s;
}

.filter-clear:hover { color: var(--danger); }

.filter-search-wrap {
    margin-left: auto;
    position: relative;
    display: flex;
    align-items: center;
}

.filter-search-icon {
    position: absolute;
    left: 0.15rem;
    color: var(--ink-muted);
    pointer-events: none;
}

.filter-search {
    padding: 0.4rem 0.25rem 0.4rem 1.35rem;
    border: none;
    border-bottom: 1.5px solid transparent;
    border-radius: 0;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink);
    background: transparent;
    outline: none;
    width: 150px;
    transition: border-color 0.15s, width 0.15s;
}

.filter-search::placeholder { color: var(--ink-muted); font-weight: 400; }
.filter-search:focus { border-bottom-color: var(--accent); width: 190px; }

.filter-search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 0.25rem;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
    transition: opacity 0.12s, transform 0.12s, background 0.12s, color 0.12s;
}

.filter-search-clear--visible {
    opacity: 1;
    pointer-events: all;
    transform: scale(1);
}

.filter-search-clear:hover { background: var(--paper-warm); color: var(--ink); }

/* ------------------------------------------------------------------ */
/* Expenses table / weekly chart toggle                                */
/* ------------------------------------------------------------------ */

/* Icon-only — the label lived in the button before; the icon alone (the
   same short-tall-tall-medium bars the chart itself draws) is enough once
   there's only one control instead of a table/chart pair to choose
   between. Sits inline with the filters, right after payment method. */
.exp-chart-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--paper-card);
    color: var(--ink-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.exp-chart-toggle:hover { background: var(--paper-warm); color: var(--ink); }

.exp-chart-toggle[aria-expanded="true"] {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

/* Rises once from the baseline to its real height on load — the same
   --rise trick .cc-week-stack uses (see that rule's comment), just
   triggered on paint (the inline script right after this button) instead
   of on the chart panel opening, since the icon is visible immediately.
   Scaled from the bottom edge so the bars grow up from the axis rather
   than from their own centre. */
.exp-chart-toggle-bar {
    transform-box: fill-box;
    transform-origin: bottom;
    transform: scaleY(var(--rise, 1));
}

@media (prefers-reduced-motion: no-preference) {
    .exp-chart-toggle-bar { transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1); }
}

.exp-view-panel.is-hidden { display: none; }

/* Dropped in ahead of the table rather than replacing it, so it needs its
   own breathing room below before the sheet starts. */
#expViewChart.exp-view-panel { margin-bottom: 1.25rem; }

/* ------------------------------------------------------------------ */
/* Expenses table — clean, open design                                 */
/* ------------------------------------------------------------------ */

.sheet-wrap {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

/* The expenses sheet caps itself at eight rows and scrolls the rest inside the
   card, so the page keeps its shape however long the month ran. Rows carrying
   a description are the tall ones; the cap is measured off those, so a screen
   of short rows shows a few more rather than fewer. */
.sheet-wrap--capped {
    /* 40.8rem is header + 8 rows + the totals bar, with a few pixels of slack
       so a row that runs a line taller doesn't cost you the eighth. The
       viewport clamp only bites on a short window, where a full eight would
       push the pinned totals below the fold and undo the point of pinning. */
    max-height: min(40.8rem, calc(100vh - 6rem));
    overflow-y: auto;
}

/* The header rides along, since the columns are no longer readable from the
   top of the page once the body scrolls under it. Named through .sheet so the
   opaque background outranks `.sheet th`'s transparent one — otherwise the
   rows pass through the header on their way up.

   thead's own border scrolls away with the table box, so the sticky cells
   carry the line themselves. */
.sheet-wrap--capped .sheet th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--paper-card);
    box-shadow: inset 0 -1px 0 var(--border);
}
.sheet-wrap--capped .sheet thead tr { border-bottom: none; }

/* The totals ride the bottom edge the way the header rides the top, so the
   month's figures stay in view while the rows scroll between them. Same story
   with the background and the rule: they belong to the cells, since only the
   cells stay put. */
.sheet-wrap--capped .sheet tfoot td {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--sheet-footer-bg);
    box-shadow: inset 0 1px 0 var(--border);
}
.sheet-wrap--capped .sheet .sheet-footer { border-top: none; }

.sheet {
    width: 100%;
    /* Fixed, because auto layout treats a declared width as a suggestion and
       sizes columns to their contents — the title column kept taking about a
       third of the table however little was asked of it. Fixed makes the
       shares below the actual widths, and overlong text ends in an ellipsis
       rather than widening its column. */
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.875rem;
}

/* Header */
.sheet thead tr {
    border-bottom: 1px solid var(--border);
}

.sheet th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-faint);
    white-space: nowrap;
    background: transparent;
}

/* Rows */
.sheet-row {
    border-bottom: 1px solid var(--border-soft);
    transition: background 0.12s;
}
.sheet-row:last-child { border-bottom: none; }
/* The row sits plain until you point at it, then it lights up in its own
   category's colour, at the same weight the week tints were cut to: enough to
   name the category, not enough to shout. The week tint stays as the fallback
   for a row whose category never got painted. */
.sheet-row:hover { background: var(--cat-tint, var(--week-tint, var(--row-hover))); }

/* The tile is that same tint, so on a hovered row it would dissolve into the
   background. It goes solid instead and the glyph turns white — enough to keep
   it legible, without turning the row into a second thing to look at. */
.sheet-row:hover .cat-icon-badge--bare {
    background: var(--cat-color);
    color: #fff;
}

.sheet-row[data-week="0"] { --week-tint: var(--week-1); }
.sheet-row[data-week="1"] { --week-tint: var(--week-2); }
.sheet-row[data-week="2"] { --week-tint: var(--week-3); }
.sheet-row[data-week="3"] { --week-tint: var(--week-4); }

/* Where one week hands over to the next — the only week marking the sheet
   carries at rest, and faint enough to read as spacing rather than a divider. */
.sheet-row--weekbreak { border-top: 1px solid var(--border); }
.sheet-row:hover .icon-btn { opacity: 1; }

/* Rows that open the detail popup */
.sheet-row--clickable { cursor: pointer; }
.sheet-row--clickable:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.sheet td {
    padding: 0.9rem 1rem;
    color: var(--ink-soft);
    vertical-align: middle;
}

/* Cell helpers */
.cell-muted  { color: var(--ink-faint); font-size: 0.825rem; }
/* One line each, title and description alike: the column is sized for the
   sheet's rhythm, not for the longest title in the month, and anything past
   the edge trails off. The whole of both is in the detail popup. */
.cell-bold   {
    display: block;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* One line, always: a long description trails off in an ellipsis rather than
   wrapping and pushing its row taller than the rest of the sheet. The full
   text is a click away in the detail popup. The max-width caps what the
   column can claim; the column stays narrower than that on most screens, and
   the ellipsis lands wherever it actually runs out. */
/* The title cell leads with the category icon, then stacks the title over its
   description beside it. Centring the icon against the pair keeps it reading
   as one block rather than a glyph pinned to the first line. */
.title-cell {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
/* Without these the nowrap lines set a floor on the flex item, the column
   grows to the longest title in the month, and no ellipsis ever engages. */
.title-cell-text {
    min-width: 0;
    overflow: hidden;
}

.cell-desc   {
    display: block;
    font-size: 0.78rem;
    color: var(--ink-faint);
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cell-date   { font-size: 0.82rem; color: var(--ink-muted); white-space: nowrap; }
.cell-num    { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* Column widths, as shares rather than pixels. Fixed pixels left the table
   short of its own width, and the leftover is handed out in proportion to what
   each column already claimed — which quietly gave the widest column, the
   title, most of it again. Shares totalling 100% leave nothing to hand out, so
   each column ends up the width it was actually given. */
.col-date    { width: 10%; }
.col-title   { width: 23%; }
.col-payer   { width: 10%; }
/* Payment method carries labels like "Freedom Unlimited"; short of about 16%
   it wraps to two lines and that row alone stands taller than the rest. */
.col-mode    { width: 16%; }
.col-amount  { width: 10%; }
.col-split   { width: 10%; }
/* The figures are right-aligned by .cell-num; this puts their headings over
   the digits. Named through th because `.sheet th` sets the row's alignment
   and would otherwise out-rank a bare column class. */
.sheet th.col-amount,
.sheet th.col-split { text-align: right; }
.col-context { width: 13%; }
.col-actions { width: 8%; text-align: right; white-space: nowrap; }

/* Category icon badge (dashboard + expenses) */
.cat-icon-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.18rem 0.55rem 0.18rem 0.35rem;
    border-radius: 999px;
    border: 1px solid var(--cat-line, transparent);
    background: var(--cat-tint, transparent);
    color: var(--cat-color, var(--ink-muted));
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
}

.cat-icon-svg { display: inline-flex; align-items: center; line-height: 1; flex-shrink: 0; }
.cat-icon-svg svg { width: 13px; height: 13px; }
.cat-icon-label { font-size: 0.78rem; }

/* In the sheet the category is the icon alone. The colour and the shape are
   the category at a glance, and the name only matters when you stop to ask
   for it — so it arrives on hover rather than spending a column on it. The
   detail popup keeps the full pill, where there is room to spell things out. */
.cat-icon-badge--bare {
    position: relative;
    justify-content: center;
    flex-shrink: 0;
    width: 1.6rem;
    height: 1.6rem;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    cursor: default;
}
/* Same tile the dashboard's Recent rows use — see .cc-cat-mark. The tint is
   painted on, since it is the category's own colour. */
.cat-icon-badge--bare .cat-icon-svg svg { width: 14px; height: 14px; }

/* Hidden to the eye, still in the accessibility tree — the tooltip below is
   painted content, which a screen reader has no reliable way to reach. */
.cat-icon-badge--bare .cat-icon-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* The name opens upward, since to the right now sits the title it would
   cover. Rising from the icon's left edge it clears the row above without
   leaving the card, and it outranks the sticky header on the top row. */
.cat-icon-badge--bare::after {
    content: attr(data-category);
    position: absolute;
    bottom: calc(100% + 6px);
    left: -2px;
    padding: 0.35rem 0.55rem;
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: var(--paper);
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s;
    z-index: 10;
}
.cat-icon-badge--bare:hover::after { opacity: 1; }

/* Mode badge */
.mode-badge {
    display: inline-block;
    padding: 0.18rem 0.55rem;
    border-radius: 5px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--paper-warm);
    color: var(--ink-muted);
    letter-spacing: 0.01em;
}

/* Who fronted the cash. "Me" is the common case and gets the accent tint so a
   friend-paid row stands out by contrast rather than by reading the name. */
.payer-badge {
    display: inline-block;
    max-width: 100%;
    padding: 0.18rem 0.55rem;
    border-radius: 5px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--paper-warm);
    color: var(--ink-muted);
    letter-spacing: 0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.payer-badge--me {
    background: var(--accent-light);
    color: var(--accent);
}

/* On a row you paid, the sheet shows your face instead of the word "Me" — the
   one payer that never needs naming reads faster as a picture, and the rows a
   friend paid keep their name badge and stand out against it. */
.payer-me {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--accent);
    border: 1.5px solid var(--border);
    vertical-align: middle;
}
/* The initial is the floor and the photo covers it, so a Google URL that has
   gone stale — or that the browser declines to fetch — drops back to a letter
   instead of leaving a broken image on every row you paid for. */
.payer-me span { color: #fff; font-size: 0.72rem; font-weight: 700; }
.payer-me img  {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Owe / Owed pills */
.pill {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    /* One line: "You are owed" broke across two inside the narrow column,
       which made a pill read as a paragraph. */
    white-space: nowrap;
}
.pill--owe  { background: var(--danger-light); color: var(--danger); }
.pill--owed { background: var(--accent-light);  color: var(--accent); }

/* How many contacts share a split bill, beside its owe/owed pill. */
.split-count {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    margin-left: 0.3rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-faint);
    white-space: nowrap;
    vertical-align: middle;
}

/* The form's version sits on its own line above the participant rows. */
.split-count--form {
    display: flex;
    margin: 0.75rem 0 0.5rem;
    font-size: 0.78rem;
}
.split-count--form[hidden] { display: none; }
.split-count--form:not([hidden]) + .split-rows { margin-top: 0; }

/* Icon action buttons */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s, background 0.12s, color 0.12s;
    color: var(--ink-muted);
    text-decoration: none;
}
.icon-btn--edit:hover  { background: var(--accent-light); color: var(--accent); }
.icon-btn--delete:hover { background: var(--danger-light); color: var(--danger); }

/* Table footer */
.sheet-footer {
    background: var(--sheet-footer-bg);
    border-top: 1px solid var(--border);
}
.sheet tfoot td { padding: 0.75rem 1rem; }

.footer-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.footer-total {
    font-weight: 800;
    font-size: 0.9rem;
    color: var(--ink);
    text-align: right;
}

/* ------------------------------------------------------------------ */
/* Profile page                                                        */
/* ------------------------------------------------------------------ */

.profile-page { padding: 2.5rem 2rem 5rem; }

.profile-inner {
    max-width: 680px;
    margin: 0 auto;
}

.profile-header { margin-bottom: 2rem; }

.profile-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
}

/* Hero block — one box: identity on top, gender/DOB below */
.profile-hero {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.75rem;
}

.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--border);
    flex-shrink: 0;
}

.profile-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar-initials {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    font-size: 1.6rem;
    font-weight: 800;
}

.profile-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 0.2rem;
}

.profile-email {
    font-size: 0.875rem;
    color: var(--ink-muted);
}

/* Email and the connection badges share a line */
.profile-contact {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

/* Google-linked accounts are marked by the G alone, ahead of the address */
.profile-google-mark {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    margin-right: -0.15rem;
}

.profile-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.profile-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;          /* the icon sits flush against the label without this */
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}

.profile-badge--pw {
    background: var(--accent-light);
    color: var(--accent);
}

.profile-badge--unverified {
    background: #fdecea;
    color: #c0392b;
}

/* No pill — sits beside the address as a note rather than a status chip.
   Declared after the colour variants so it wins on background. */
.profile-badge--bare {
    padding: 0;
    background: transparent;
}

.profile-badge--muted {
    background: var(--paper-warm);
    color: var(--ink-muted);
}

/* Avatar upload — the hero's circle doubles as the upload trigger */
.profile-hero-top {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

/* Gender/DOB sit under a divider */
.profile-details {
    margin-top: 1.35rem;
    padding-top: 1.35rem;
    border-top: 1px solid var(--border-soft);
}

/* Editing swaps each value for an input where it already sits, so the box
   never reflows. One class on the hero flips every field at once. */
.profile-hero .profile-edit-field { display: none; }
/* The date picker wraps the date-of-birth input in a span of its own. The
   input inside is hidden, but the empty wrapper stayed as a third flex item,
   and space-between pushed the value into the middle of the row. */
.profile-hero:not(.profile-hero--editing) .profile-detail-row > .dp-wrap { display: none; }
.profile-hero--editing .profile-view-field { display: none; }
.profile-hero--editing .profile-edit-field { display: block; }
.profile-hero--editing .profile-edit-actions.profile-edit-field { display: flex; }
.profile-hero--editing .profile-detail-row { align-items: center; }

/* Anchors the character counter to the input's corner */
.profile-name-field {
    position: relative;
    max-width: 340px;
    margin-bottom: 0.4rem;
}

.profile-name-input {
    width: 100%;
    /* Right padding keeps typed text from running under the counter */
    padding: 0.4rem 4.2rem 0.4rem 0.7rem;
    font-size: 1.05rem;
    font-weight: 700;
}

.profile-name-count {
    position: absolute;
    right: 0.6rem;
    bottom: 0.35rem;
    font-size: 0.68rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--ink-muted);
    pointer-events: none;
}

/* Last few characters — warn before the input stops accepting them */
.profile-name-count--near {
    color: var(--accent-2);
}

.profile-name-count--full {
    color: var(--danger);
}

/* Password form: stacked fields on the left, the live rule checklist beside
   them. min-width:0 on the field column lets the inputs shrink; without it they
   hold their intrinsic width and push the checklist out of the card. */
.pw-layout {
    display: flex;
    align-items: flex-start;
    gap: 1.8rem;
}

.pw-fields {
    flex: 1 1 0;
    min-width: 0;
}

.pw-rules {
    flex: 0 0 auto;
    width: 190px;
    margin: 1.55rem 0 0;   /* clears the first field's label */
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.pw-rule {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    color: var(--ink-muted);
    transition: color 0.15s;
}

/* Hollow ring until the rule is satisfied, then a filled tick */
.pw-rule-mark {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid var(--border);
    border-radius: 50%;
    color: transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

/* The match line reuses .pw-rule's mark and met state, but sits under the
   confirm field instead of in the checklist column */
.pw-match {
    margin: 0.45rem 0 0;
}

/* ── Devices + archived contacts ──────────────────────────────────── */

.dev-list {
    margin: 1.1rem 0 0;
    padding: 0;
    list-style: none;
}

.dev-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-soft);
}

.dev-row:last-child { border-bottom: none; }

.dev-info { min-width: 0; }   /* lets long user agents ellipsize, not overflow */

.dev-name {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--ink);
}

.dev-current {
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.66rem;
    font-weight: 700;
}

.dev-meta {
    margin: 0.15rem 0 0;
    font-size: 0.76rem;
    color: var(--ink-muted);
    overflow-wrap: anywhere;
}

.dev-signout {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-soft);
    font-family: var(--font);
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.dev-signout:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* Restoring is not destructive, so it shouldn't hover red like a sign-out */
.dev-signout--restore:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.dev-all { margin-top: 1rem; }

/* Connect-an-app consent (oauth_consent.html) */
.consent-lead {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--ink-soft);
}

.consent-scopes {
    margin: 0 0 1rem;
    padding-left: 1.2rem;
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--ink);
}

.consent-actions {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin: 1.25rem 0 0.75rem;
}

.consent-actions .btn-submit { margin-top: 0; }
.consent-deny { justify-content: center; width: 100%; }

.dev-empty {
    margin: 1rem 0 0;
    font-size: 0.82rem;
    color: var(--ink-muted);
}

/* ── Delete account, behind "More options" ─────────────────────────── */

/* Folded away under the import action rather than sharing its row: a
   destructive control next to a routine one is how people click the wrong
   thing. Opened, it explains first and offers the button underneath. */
.more-options {
    margin-top: 1.5rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--border-soft);
}
.more-options-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    list-style: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-muted);
}
.more-options-toggle::-webkit-details-marker { display: none; }
.more-options-toggle:hover { color: var(--ink); }
.more-options-chevron { transition: transform 0.15s ease; }
.more-options[open] .more-options-chevron { transform: rotate(180deg); }
.more-options-body { margin-top: 1rem; }
.more-options-body .wipe-btn { margin-top: 0.9rem; }
.wipe-btn--icon { display: inline-flex; align-items: center; gap: 0.45rem; }

.wipe-row-title {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--ink);
}

.wipe-row-sub {
    margin: 0.15rem 0 0;
    font-size: 0.8rem;
    color: var(--ink-muted);
}

.wipe-btn {
    flex: 0 0 auto;
    padding: 0.5rem 1rem;
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--danger);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.wipe-btn:hover:not(:disabled) {
    background: var(--danger);
    color: #fff;
}

.wipe-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.wipe-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 500;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.wipe-overlay--open { display: flex; }

.wipe-modal {
    width: 100%;
    max-width: 420px;
    padding: 1.75rem;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.wipe-title {
    margin: 0 0 0.6rem;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--ink);
}

.wipe-text {
    margin: 0 0 1.25rem;
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--ink-muted);
}

.wipe-text strong { color: var(--danger); }

/* Retention notice — set apart so it reads as a disclosure, not fine print */
.wipe-note {
    margin: 0 0 1.25rem;
    padding: 0.7rem 0.85rem;
    border-left: 2px solid var(--border);
    background: var(--paper-warm);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    line-height: 1.5;
    color: var(--ink-soft);
}

.wipe-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.6rem;
}

.wipe-cancel {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-soft);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.wipe-cancel:hover { background: var(--row-hover); }

.pw-rule--met { color: var(--ink); }

.pw-rule--met .pw-rule-mark {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Under the card's comfortable width the checklist goes below the fields */
@media (max-width: 620px) {
    .pw-layout { display: block; }
    .pw-rules {
        width: auto;
        margin-top: 0.2rem;
        margin-bottom: 1.1rem;
    }
}

/* Sized to the widest content — "Prefer not to say" and a mm/dd/yyyy date
   with its native picker — rather than filling the row. */
.profile-detail-input {
    flex: 0 0 auto;
    width: 180px;
    padding: 0.45rem 0.7rem;
    font-size: 0.875rem;
}

@media (max-width: 480px) {
    .profile-hero-top { align-items: flex-start; }
    .profile-detail-input { width: 150px; }
}

/* A phone: the usual 16px gutter, tighter cards, and the identity allowed to
   shrink so the edit button stays inside the box. */
/* Scoped under .profile-page so these win over the base rules further down. */
@media (max-width: 600px) {
    .profile-page { padding: 1.5rem 1rem 3rem; }
    .profile-page .profile-header { margin-bottom: 1.25rem; }
    .profile-page .profile-hero,
    .profile-page .profile-card { padding: 1.15rem; }
    .profile-page .profile-hero-top { gap: 0.9rem; }
    .profile-page .profile-avatar { width: 56px; height: 56px; }
    .profile-page .profile-avatar-initials { font-size: 1.3rem; }
    .profile-page .profile-identity { flex: 1 1 auto; min-width: 0; }
    /* The edit button floats in the corner instead of taking a column, so
       the G and the address have the row's full width to share. */
    .profile-page .profile-hero { position: relative; }
    .profile-page .profile-edit-btn--corner { position: absolute; top: 1.15rem; right: 1.15rem; }
    .profile-page .profile-name { padding-right: 2.5rem; }
    .profile-page .profile-email { font-size: 0.82rem; }
    /* The G and the address share a line at the address's own width, so the
       badges wrap beneath it; only an address too long for the line breaks. */
    .profile-page .profile-email { flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }
    /* Joined and Dex usage drop to rows like Gender and Date of birth above:
       label left, value right. */
    .profile-page .profile-meta-row { flex-direction: column; align-items: stretch; gap: 0.85rem; }
    .profile-page .profile-meta-item { justify-content: space-between; }
}

/* Personal info — read-only values with an Edit toggle */
.profile-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.7rem;
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink-soft);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.profile-edit-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Edit sits in the box's top-right corner, not beside the identity text.
   Icon only — a label there would compete with the name for attention. */
.profile-edit-btn--corner {
    margin-left: auto;
    align-self: flex-start;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    color: var(--ink);
}

.profile-details { display: grid; gap: 0.85rem; }

.profile-detail-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
}

.profile-detail-label {
    font-size: 0.85rem;
    color: var(--ink-muted);
}

.profile-detail-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ink);
    text-align: right;
}

/* Joined and Dex usage share one line — both are short, read-only facts */
.profile-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
    flex-wrap: wrap;
}

.profile-meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Dex allowance left, as a share. The tip (data-tip) shows on hover or focus. */
.dex-left { position: relative; cursor: default; }
.dex-left--ok  { background: var(--accent-light);   color: var(--accent); }
.dex-left--low { background: var(--accent-2-light); color: var(--accent-2); }
.dex-left--out { background: var(--danger-light);   color: var(--danger); }
.dex-left:focus { outline: none; }
.dex-left:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.dex-left::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    padding: 0.35rem 0.55rem;
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: var(--paper);
    font-size: 0.72rem;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translateY(3px);
    transition: opacity 0.12s, transform 0.12s;
    z-index: 5;
}
.dex-left:hover::after,
.dex-left:focus::after { opacity: 1; transform: none; }

.profile-edit-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.25rem;
}

.profile-edit-cancel {
    background: none;
    border: none;
    padding: 0;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ink-muted);
    cursor: pointer;
}

.profile-edit-cancel:hover { color: var(--accent); }

/* Separates Settings from the Profile identity above it on the same page */
.profile-section-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 2.5rem 0 1.25rem;
}

.profile-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-muted);
    white-space: nowrap;
}

.profile-section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-soft);
}

/* Section cards */
.profile-sections {
    display: grid;
    /* minmax(0, …) so one card's wide content (the theme switch, a long
       device line) can't stretch the column past the page's edge. */
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
}

.profile-card {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
}

.profile-card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 1.1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-soft);
}

.profile-card-hint {
    font-size: 0.85rem;
    color: var(--ink-muted);
    margin-bottom: 1.1rem;
    line-height: 1.5;
}

.btn-submit-sm {
    padding: 0.55rem 1.25rem;
    background: var(--ink);
    color: var(--paper);
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 0.25rem;
}

.btn-submit-sm:hover { background: var(--accent); }

.profile-ie-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.profile-ie-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 1.1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ink-soft);
    background: var(--paper-warm);
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.profile-ie-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* ------------------------------------------------------------------ */
/* Add Expense form page                                               */
/* ------------------------------------------------------------------ */

.form-page { padding: 2.5rem 2rem 5rem; }

.form-page-inner {
    max-width: 720px;
    margin: 0 auto;
}

.form-page-breadcrumb {
    font-size: 0.82rem;
    color: var(--ink-muted);
    margin-bottom: 0.25rem;
}

.form-page-breadcrumb a {
    color: var(--accent);
    font-weight: 600;
}

.form-page-breadcrumb a:hover { text-decoration: underline; }

.form-page-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
    margin-bottom: 2rem;
}

/* Form card wrapper */
.expense-form-card {
    position: relative;   /* the mark tag hangs off its top edge */
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-md);
}

/* ------------------------------------------------------------------ */
/* Custom select dropdown (cselect)                                    */
/* ------------------------------------------------------------------ */

.cselect { position: relative; }

.cselect-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    background: var(--paper-card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.9rem;
    text-align: left;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.cselect-trigger:focus,
.cselect-combo:focus-within,
.cselect--open .cselect-trigger {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26, 71, 42, 0.1);
    outline: none;
}

.cselect-preview-icon {
    color: var(--accent);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.cselect-preview-icon:empty { display: none; }

/* The trigger is a search field itself: icon, what's typed (or chosen), chevron.
   Boxed exactly like .form-input — same fill, type size and height — so it sits
   level with the Amount field beside it. */
.cselect-combo {
    cursor: text;
    background: var(--paper);
    font-size: 0.95rem;
    line-height: normal;
}
.cselect-input {
    flex: 1;
    min-width: 0;
    height: auto;
    margin: 0;
    padding: 0;
    border: none;
    outline: none;
    background: transparent;
    font: inherit;
    line-height: inherit;
    color: var(--ink);
}
/* The colour tile overhangs the text line rather than heightening the field. */
.cselect-combo .cselect-preview-icon.cat-tile {
    width: 24px;
    height: 24px;
    margin-block: -4px;
}
.cselect-input::placeholder { color: var(--ink-faint); }
.cselect--open .cselect-input::placeholder { color: var(--ink-muted); }
.cselect-combo .cselect-chevron { cursor: pointer; }

.cselect-chevron {
    color: var(--ink-faint);
    flex-shrink: 0;
    transition: transform 0.2s;
}
.cselect--open .cselect-chevron { transform: rotate(180deg); }

/* Dropdown panel */
.cselect-panel {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--paper-card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 300;
    overflow: hidden;
}
.cselect--open .cselect-panel { display: block; }

.cselect-list {
    list-style: none;
    max-height: 220px;
    overflow-y: auto;
    padding: 0.35rem 0;
}

.cselect-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--ink-soft);
    transition: background 0.1s;
}
.cselect-option:hover { background: var(--paper-warm); color: var(--ink); }
.cselect-option--active { background: var(--paper-warm); color: var(--ink); }
.cselect-option[hidden] { display: none; }
.cselect-none {
    display: none;
    margin: 0;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    color: var(--ink-faint);
}
.cselect--empty .cselect-none { display: block; }
.cselect-option--selected { color: var(--accent); font-weight: 600; }
.cselect-option--selected .cselect-option-check { opacity: 1; }

.cselect-option-icon {
    color: var(--accent);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    opacity: 0.8;
}
.cselect-option:hover .cselect-option-icon { opacity: 1; }

/* Category icons in the picker and its trigger, painted in the category's own
   colour on a pale tile of it (add/edit expense, paintCatIcon). */
.cselect-option-icon.cat-tile,
.cselect-preview-icon.cat-tile {
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 7px;
    opacity: 1;
}

.cselect-option-label { flex: 1; }

.cselect-option-check {
    opacity: 0;
    color: var(--accent);
    flex-shrink: 0;
    transition: opacity 0.1s;
}

.expense-form-grid {
    display: grid;
    /* minmax(0, …) rather than a bare 1fr: a plain 1fr track can't shrink below
       its content's min-content width, so one long header chip was widening its
       column and starving the other. The columns stay even whatever they hold. */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0 1.5rem;
}

.form-group--full { grid-column: 1 / -1; }

/* Required-field marker — red dot + "Required" beside the field label. */
.req {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-left: 0.45rem;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-muted);
    vertical-align: middle;
    position: relative;
    top: -1px;
}

.req::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--danger);
}

/* Optional-field counterpart to .req — same type, no dot. */
.opt {
    margin-left: 0.4rem;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-faint);
    vertical-align: middle;
}

.split-hint {
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
    color: var(--ink-faint);
}

.split-hint--owe  { color: var(--danger); }

/* Smart fill: what the form filled in for you, and why. Sits under the field
   it explains and disappears the moment that field is changed. */
.suggest-chip {
    display: block;
    margin-top: 0.35rem;
    /* Holds its line whether or not there is anything to say. A chip that
       appears and disappears with the field's contents was shoving everything
       below it down mid-typing, and knocking the two form columns out of step
       whenever only one of them had a suggestion. */
    /* Stated rather than inherited, and the reservation matched to it exactly —
       an inherited line-height made the empty box shorter than the filled one,
       which left a few pixels of shift still in play. */
    line-height: 1.5;
    min-height: 1.5em;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--accent);
}

/* Space kept, ink withdrawn — and visibility takes it out of the accessibility
   tree the same as display:none would, so the attribute still means what it
   says. Overrides the global [hidden] rule for this one case. */
.suggest-chip[hidden] { display: block !important; visibility: hidden; }

/* Label on the left, suggestion on the right, both on the field's header line.
   The chip sits above the box it describes rather than under it, which also
   means it no longer needs a reserved line of its own — the label sets the row
   height, so a chip appearing can't shift anything below. */
.field-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
}

/* The label keeps its line whole — without this the chip squeezes it until
   "Required" drops to a second row and the two columns fall out of step. */
.field-head label { white-space: nowrap; }

/* Whatever width is left over is the chip's, and anything too long for it is
   clipped rather than allowed to wrap the row taller. */
.field-head .suggest-chip {
    margin-top: 0;
    min-height: 0;
    min-width: 0;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.expense-form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.5rem;   /* the last field's own bottom margin already spaces it */
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-soft);
}

/* One height for every button here — the fields' 40px, so the row lines up
   with the form above it. Widths follow the label; rank is shown by style:
   solid for Save, outlined for the second save, plain text for Cancel. */
.expense-form-actions .btn-primary,
.expense-form-actions .btn-ghost {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2.5rem;
    padding-top: 0;
    padding-bottom: 0;
    line-height: 1;
}
.expense-form-actions .expense-form-cancel {
    border-color: transparent;
    background: none;
    color: var(--ink-muted);
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    margin-left: -0.5rem;   /* the text lines up with the form's left edge */
}
.expense-form-actions .expense-form-cancel:hover {
    background: var(--paper-warm);
    border-color: transparent;
    color: var(--ink);
}

.expense-form-submit-group {
    display: flex;
    gap: 0.75rem;
}

/* Dashboard section header (month title + link) */
.dashboard-section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin: 2rem 0 0.875rem;
}

.dashboard-section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.02em;
}

.dashboard-section-link {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent);
}
.dashboard-section-link:hover { text-decoration: underline; }

/* Analytics chart section */
.analytics-section {
    margin-bottom: 3rem;
}

/* Header row: title + stats pill */
.analytics-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.875rem;
}

.analytics-header-stats {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.analytics-hstat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.analytics-hstat-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-faint);
    line-height: 1;
    margin-bottom: 0.15rem;
}

.analytics-hstat-value {
    font-size: 1rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.02em;
}

.analytics-hstat-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    flex-shrink: 0;
}

.analytics-change {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}
.analytics-change--up   { background: #e6ede8; color: var(--accent); }
.analytics-change--down { background: var(--danger-light); color: var(--danger); }

.analytics-change-arrow { font-size: 0.85rem; }
.analytics-change-pct   { letter-spacing: -0.01em; }
.analytics-change-label { font-weight: 500; color: inherit; opacity: 0.75; font-size: 0.75rem; }

/* Card */
.analytics-card {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem 1.75rem;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.analytics-empty {
    text-align: center;
    color: var(--ink-muted);
    font-size: 0.95rem;
    padding: 2.5rem 0;
    margin: 0;
}

/* Legend bar */
.analytics-legend-bar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.analytics-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.5rem;
    align-items: center;
    flex: 1;
}

/* Clickable legend chips */
.analytics-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.28rem 0.6rem 0.28rem 0.45rem;
    border-radius: 999px;
    border: 1.5px solid var(--border);
    background: var(--paper-card);
    cursor: pointer;
    user-select: none;
    transition: opacity 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap;
}
.analytics-legend-item--on  { color: var(--ink-soft); border-color: var(--border); }
.analytics-legend-item--off { color: var(--ink-faint); background: var(--paper-warm); border-color: transparent; opacity: 0.55; }
.analytics-legend-item:hover { border-color: var(--ink-muted); opacity: 1; }

.analytics-legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* All / None buttons */
.analytics-legend-controls {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
}

.analytics-ctrl-btn {
    background: transparent;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.28rem 0.65rem;
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-muted);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.analytics-ctrl-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Footer strip */
.analytics-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-soft);
    flex-wrap: wrap;
}

.analytics-footer-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
}

.analytics-footer-value {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.02em;
}

.analytics-footer-note {
    font-size: 0.78rem;
    color: var(--ink-muted);
    margin-left: 0.1rem;
}

/* Filter bar period selectors */
.filter-select--period {
    font-weight: 700;
    color: var(--ink);
}

.filter-divider {
    display: inline-block;
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 0.25rem;
    vertical-align: middle;
}

/* ------------------------------------------------------------------ */
/* Breakdown / Charts section                                          */
/* ------------------------------------------------------------------ */

.breakdown-section {
    margin-top: 2.5rem;
}

.breakdown-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
}

.breakdown-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1.25rem;
}

.breakdown-card {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.5rem 1.5rem;
}

.breakdown-card-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-faint);
    margin-bottom: 1rem;
}

.chart-wrap {
    width: 100%;
    max-width: 180px;
    margin: 0 auto 1rem;
    aspect-ratio: 1;
}

/* Chart legend — capped rather than left to grow with the category (or
   payment method) count, so a month with a dozen-plus of either doesn't
   stretch its card past its neighbours in the Snapshot row. */
.breakdown-legend {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-top: 0.5rem;
    max-height: 180px;
    overflow-y: auto;
    padding-right: 2px; /* clears the thumb so it doesn't sit on the figures */
}
.breakdown-legend::-webkit-scrollbar { width: 4px; }
.breakdown-legend::-webkit-scrollbar-track { background: transparent; }
.breakdown-legend::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--ink-soft);
}

.legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-label { flex: 1; }

.legend-value {
    font-weight: 600;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.legend-pct {
    font-size: 0.72rem;
    color: var(--ink-faint);
    min-width: 36px;
    text-align: right;
}

/* Split summary card */
.breakdown-card--split { display: flex; flex-direction: column; }

.split-stat { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 0.5rem; }

.split-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}

.split-stat-row--toggle {
    width: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0;
    font-family: inherit;
    color: inherit;
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}
.split-stat-row--toggle:hover { background: var(--paper-warm); }

.split-stat-row-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.split-stat-chevron {
    color: var(--ink-muted);
    transition: transform 0.18s;
}
.split-stat-row--toggle[aria-expanded="true"] .split-stat-chevron { transform: rotate(180deg); }

/* Capped the same way the Snapshot legends are — a heavy month's "you owe"
   or "you are owed" list can run long, and it's already tucked behind a
   toggle, not a reason to let the card underneath it drift. */
.split-stat-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin: -0.25rem 0 0;
    padding: 0.1rem 2px 0.35rem 0.1rem;
    max-height: 160px;
    overflow-y: auto;
}
.split-stat-list[hidden] { display: none; }
.split-stat-list::-webkit-scrollbar { width: 4px; }
.split-stat-list::-webkit-scrollbar-track { background: transparent; }
.split-stat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.split-stat-list-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.split-item-title {
    color: var(--ink);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.split-item-date { color: var(--ink-faint); flex-shrink: 0; }

.split-item-amount {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.split-stat-list-empty {
    font-size: 0.8rem;
    color: var(--ink-faint);
    padding: 0.15rem 0 0.35rem;
}

.split-stat-label { color: var(--ink-muted); font-weight: 500; }

.split-stat-value {
    font-weight: 700;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}
.split-stat-value--owe  { color: var(--danger); }
.split-stat-value--owed { color: var(--accent); }

.split-stat-bar {
    display: flex;
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--paper-warm);
}
.split-stat-bar-owe  { background: var(--danger); transition: width 0.4s; }
.split-stat-bar-owed { background: var(--accent);  transition: width 0.4s; }

.split-stat-empty {
    font-size: 0.82rem;
    color: var(--ink-faint);
    text-align: center;
    margin-top: 1rem;
}

/* ------------------------------------------------------------------ */
/* Responsive — expenses                                               */
/* ------------------------------------------------------------------ */

@media (max-width: 700px) {
    .dateline-facts { font-size: 0.85rem; line-height: 1.7; }
    /* No room for two columns — the meta drops under the total and back to the
       left, and the clauses are allowed to break rather than overrun. */
    .dateline-head { flex-direction: column; gap: 0.5rem; }
    .dateline-meta { align-items: flex-start; text-align: left; }
    .dl-fact { white-space: normal; }
    .sheet-wrap { overflow-x: auto; }
    .expense-form-grid { grid-template-columns: 1fr; }
    .form-group--full { grid-column: 1; }
    .expense-form-actions { flex-direction: column; gap: 1rem; align-items: stretch; }
    /* Stacked: the save goes first, under the thumb; Cancel goes last. */
    .expense-form-actions .expense-form-cancel { margin-left: 0; order: 2; }
    .expense-form-submit-group { flex-direction: column; }
    .breakdown-grid { grid-template-columns: 1fr; }
}

/* A phone: the page pared down to what's used there — the month's total and
   how it compares, a month / year / category pick and search, and the
   expenses as a plain list. Each row is its title and date beside your share,
   with the split pill under it; tapping a row opens the detail popup, which
   has edit and delete. Paid by, payment method, the full amount, the row
   icons, the dateline's extra facts, the weekly chart and the Snapshot all
   stay on the wider layouts. Scoped under .expenses-page so it outranks the
   base rules wherever they sit. */
@media (max-width: 600px) {
    .expenses-page { padding: 1.5rem 1rem 3rem; }
    .expenses-page .expenses-header { margin-bottom: 1.1rem; }
    .expenses-page .expenses-title { font-size: 1.5rem; }
    .expenses-page .expenses-header .btn-primary { padding: 0.55rem 0.9rem; font-size: 0.85rem; }

    /* Dateline: the month, the total and the comparison only. */
    /* Its height was set for the sketch, which is gone here. */
    .expenses-page .dateline { min-height: 0; margin-bottom: 1.1rem; }
    .expenses-page .dateline-sketch,
    .expenses-page .dateline-facts,
    .expenses-page .dl-pace,
    .expenses-page .dl-nospend { display: none; }

    /* Filters: month, year and category share a row; search goes under it. */
    .expenses-page .filter-bar { flex-wrap: wrap; gap: 0.5rem; }
    .expenses-page .filter-bar > .select-wrap { flex: 1 1 0; min-width: 0; }
    .expenses-page .select-wrap:has(> select[name="year"]) { flex: 0 0 auto; }
    .expenses-page .select-wrap:has(> select[name="mode"]),
    .expenses-page .filter-divider,
    .expenses-page .exp-chart-toggle,
    .expenses-page #expViewChart { display: none; }
    .expenses-page .filter-select { width: 100%; min-width: 0; text-overflow: ellipsis; font-size: 0.82rem; }
    .expenses-page .filter-clear { order: 5; }
    .expenses-page .filter-search-wrap { flex: 1 1 100%; margin-left: 0; order: 6; }
    .expenses-page .filter-search { width: 100%; }

    /* The sheet becomes a list, the whole length of the page rather than a
       capped box scrolling inside it. */
    .expenses-page .sheet-wrap--capped { max-height: none; overflow: visible; }
    .expenses-page .sheet-wrap { overflow-x: visible; }
    .expenses-page .sheet,
    .expenses-page .sheet tbody,
    .expenses-page .sheet tfoot { display: block; }
    .expenses-page .sheet thead { display: none; }
    .expenses-page .sheet tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "title share" "date context";
        column-gap: 0.75rem;
        align-items: center;
        padding: 0.7rem 0.9rem;
    }
    .expenses-page .sheet td { display: block; width: auto; padding: 0; }
    .expenses-page .sheet .col-payer,
    .expenses-page .sheet .col-mode,
    .expenses-page .sheet .col-amount,
    .expenses-page .sheet .col-actions { display: none; }
    .expenses-page .sheet .col-title   { grid-area: title; min-width: 0; }
    .expenses-page .sheet .col-split   { grid-area: share; color: var(--ink); font-size: 0.92rem; }
    /* Under the title, lined up with its text rather than the icon. */
    .expenses-page .sheet .col-date    { grid-area: date; padding-left: calc(26px + 0.6rem); font-size: 0.74rem; }
    .expenses-page .sheet .col-context {
        grid-area: context;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 0.35rem;
    }
    .expenses-page .sheet .col-context .cell-muted { display: none; }
    .expenses-page .sheet .cell-desc { display: none; }

    /* Totals: the count and your share of it. */
    .expenses-page .sheet .sheet-footer {
        grid-template-areas: "label share";
        padding: 0.75rem 0.9rem;
    }
    .expenses-page .sheet .sheet-footer td:empty { display: none; }
    .expenses-page .sheet .sheet-footer .footer-label { grid-area: label; }

    .expenses-page .breakdown-section { display: none; }
}

/* ------------------------------------------------------------------ */
/* Video Modal                                                         */
/* ------------------------------------------------------------------ */

.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.modal-backdrop.is-open { display: flex; }

.modal-box {
    position: relative;
    width: 100%;
    max-width: 820px;
    background: var(--ink);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 32px 100px rgba(0, 0, 0, 0.6);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 10;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 50%;
    width: 2.1rem;
    height: 2.1rem;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover { background: rgba(255, 255, 255, 0.25); }

.modal-video-wrap {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
}

.modal-video-wrap iframe,
.modal-video-wrap video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* The recording is 16:9, same as the wrapper — contain guards against any
   future clip with a different aspect getting cropped. */
.modal-video-wrap video {
    background: #000;
    object-fit: contain;
    display: block;
}

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

/* Tablet landscape / small desktop */
@media (max-width: 1024px) {
    .hero { padding: 3.5rem 2rem 3rem; }
    .hero-inner { gap: 3rem; }
    .mock-card { max-width: 360px; }

}

/* Tablet portrait */
@media (max-width: 900px) {
    .hero { padding: 3rem 2rem 2.5rem; }
    .hero-inner {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 2.5rem;
    }
    .hero-subtitle { max-width: 100%; }
    .hero-actions { justify-content: center; }


    /* Brand block on its own row, link columns share the next one */
    .footer-inner { flex-wrap: wrap; row-gap: 1.75rem; }
    .footer-brand { flex-basis: 100%; }
}

/* Mobile */
@media (max-width: 600px) {
    .nav-link, .nav-group { display: none; }
    /* The calculator opens from the hamburger menu's own row instead. */
    .nav-links .nav-icon-btn[data-calc-open] { display: none; }
    /* Profile/sign-out live in the hamburger menu on mobile */
    .nav-dots-wrap { display: none; }
    .nav-cta { display: inline-flex; white-space: nowrap; padding: 0.4rem 0.8rem !important; font-size: 0.8rem; }
    .nav-hamburger { display: flex; }
    .navbar.nav-open .nav-mobile-menu { display: flex; }
    .nav-inner { height: 58px; }
    .nav-left { gap: 0.5rem; }
    .navbar { padding: 0 1.25rem; }

    .hero { padding: 2.5rem 1.25rem 2rem; }
    .hero-title { font-size: 2.4rem; }
    .hero-actions { flex-direction: column; align-items: stretch; }
    .hero-actions .btn-primary,
    .hero-actions .btn-ghost { justify-content: center; }
    .mock-card { padding: 1.25rem; }
    .mock-header-stats { flex-wrap: wrap; }
    .mock-chart-area { gap: 1rem; }
    .mock-donut { width: 110px; height: 110px; }
    .mock-donut::before { inset: 24px; }
    /* Drop the unused 5th (pct) column so the card fits narrow screens */
    .mock-bar-row { grid-template-columns: 14px 64px 1fr 44px; }


    .dex-intro { padding: 2.5rem 1.25rem; }
    .dex-intro-inner { gap: 3rem; }

    .legal-layout { grid-template-columns: 1fr; }
    .legal-toc { position: static; }
    .legal-contact-card { flex-wrap: wrap; }
    .legal-contact-btn { margin-left: 0; }

    /* Footer: brand full width, link columns in two-up grid */
    .footer-inner { display: grid; grid-template-columns: 1fr 1fr; gap: 1.75rem; }
    .footer-brand { grid-column: 1 / -1; }
    .footer-bottom { flex-direction: column; align-items: center; text-align: center; gap: 0.5rem; }
}

/* Very narrow phones: the navbar theme toggle doesn't fit next to a long
   CTA like "Go to Dashboard"; the footer still has a toggle */
@media (max-width: 380px) {
    .nav-left .theme-toggle { display: none; }
}

/* ------------------------------------------------------------------ */
/* Import / Export page + Normalize modal                             */
/* ------------------------------------------------------------------ */

.ie-page { padding: 3rem 2rem 5rem; }

.ie-inner {
    max-width: var(--max-width);
    margin: 0 auto;
}

.ie-header {
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.ie-eyebrow {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
    margin-bottom: 0.2rem;
}

.ie-title {
    font-size: 2rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
}

.ie-inner--single {
    max-width: 620px;
}

.ie-back {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink-muted);
    transition: color 0.15s;
}
.ie-back:hover { color: var(--accent); }
/* Import page, laid out like Profile settings */
.ie-crumb { margin: 0 0 0.35rem; }
.ie-template-actions { align-items: center; }
/* The Template card folds: its title is the toggle, and while closed it
   drops the rule and gap that sit under an open card's title. */
.ie-fold-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    list-style: none;
    cursor: pointer;
}
.ie-fold-toggle::-webkit-details-marker { display: none; }
.ie-fold:not([open]) .ie-fold-toggle { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.ie-fold-chevron { color: var(--ink-muted); transition: transform 0.15s ease; }
.ie-fold-toggle:hover .ie-fold-chevron { color: var(--accent); }
.ie-fold[open] .ie-fold-chevron { transform: rotate(180deg); }
/* A round "i" that shows its data-tip on hover, focus or tap, in the same
   dark bubble as the Dex allowance tip; aria-label carries the same words. */
.info-tip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--ink-muted);
    cursor: help;
}
.info-tip:hover, .info-tip:focus-visible { color: var(--accent); }
.info-tip:focus { outline: none; }
.info-tip:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.info-tip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    width: max-content;
    max-width: min(280px, 70vw);
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: var(--paper);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.45;
    text-align: left;
    white-space: normal;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, 3px);
    transition: opacity 0.12s, transform 0.12s;
    z-index: 5;
}
.info-tip:hover::after,
.info-tip:focus::after { opacity: 1; transform: translate(-50%, 0); }
.profile-card.ie-form { gap: 1.1rem; }
.profile-card.ie-form .profile-card-title { margin-bottom: 0; }
.btn-submit-sm:disabled { opacity: 0.45; cursor: not-allowed; background: var(--ink); }

.ie-card--full {
    width: 100%;
}

.ie-card {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 2rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.ie-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}
.ie-card-icon--import { background: #e8edf5; color: var(--accent-3); }

.ie-card-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.02em;
    margin-top: -0.25rem;
}

.ie-card-desc {
    font-size: 0.9rem;
    color: var(--ink-muted);
    line-height: 1.55;
    margin-top: -0.5rem;
}
.ie-card-desc code {
    background: var(--paper-warm);
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--ink-soft);
}

/* Form */
.ie-form { display: flex; flex-direction: column; gap: 1.25rem; }

.ie-form-row { display: flex; flex-direction: column; gap: 0.45rem; }

.ie-label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-soft);
}

/* Month actions */

.ie-text-btn {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.ie-text-btn:hover { text-decoration: underline; }
.ie-text-btn--browse {
    font-size: 0.85rem;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 600;
}

/* Buttons */
.ie-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.7rem 1.5rem;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.2s, transform 0.1s, opacity 0.2s;
    letter-spacing: -0.01em;
    width: 100%;
    justify-content: center;
}
.ie-btn--primary { background: var(--ink); color: var(--paper); }
.ie-btn--primary:hover { background: var(--accent); transform: translateY(-1px); }
.ie-btn--secondary { background: var(--paper-warm); color: var(--ink-muted); border: 1.5px solid var(--border); }
.ie-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; }

/* Template download row */
.ie-template-row {
    background: var(--paper-warm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.ie-template-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--accent-3);
    transition: color 0.15s;
}
.ie-template-link:hover { color: var(--ink); text-decoration: underline; }

.ie-template-hint {
    font-size: 0.78rem;
    color: var(--ink-muted);
}

/* Dropzone */
.ie-dropzone {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 2rem 1rem;
    text-align: center;
    transition: border-color 0.15s, background 0.15s;
    cursor: pointer;
}
.ie-dropzone:hover,
.ie-dropzone--hover { border-color: var(--accent-3); background: #f0f4fb; }
.ie-dropzone--has-file { border-color: var(--accent); background: var(--accent-light); }
.ie-dropzone--has-file .ie-dropzone-body svg { color: var(--accent); }

.ie-dropzone-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 1;
}

.ie-dropzone-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    color: var(--ink-faint);
}
.ie-dropzone-body svg { color: var(--ink-faint); }
.ie-dropzone-body code {
    background: var(--paper-warm);
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--ink-soft);
    pointer-events: none;
}

.ie-dropzone-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--ink-soft);
}

.ie-dropzone-or {
    font-size: 0.78rem;
    color: var(--ink-faint);
}

.ie-dropzone-body .ie-text-btn--browse {
    pointer-events: auto;
    color: var(--accent-3);
}

/* Import mode selector */
.import-mode-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    margin-top: 0.35rem;
}

.import-mode-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: var(--paper-card);
}
.import-mode-card input[type="radio"] { display: none; }
.import-mode-card:hover { border-color: var(--ink-muted); }
.import-mode-card--selected { border-color: var(--accent); background: var(--accent-light); }

.import-mode-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-top: 1px;
}
/* Just the mark, no tile behind it: the title's own colour, green on hover
   and on the chosen option. */
.import-mode-icon { color: var(--ink); }
.import-mode-icon { transition: color 0.15s; }
.import-mode-card:hover .import-mode-icon,
.import-mode-card--selected .import-mode-icon { color: var(--accent); }

.import-mode-title {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 0.15rem;
}

.import-mode-desc {
    font-size: 0.78rem;
    color: var(--ink-muted);
    line-height: 1.4;
}

@media (max-width: 540px) {
    .import-mode-group { grid-template-columns: 1fr; }
}

/* ── Normalize modal ───────────────────────────────────── */

.norm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 500;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.norm-overlay--open { display: flex; }

.norm-modal {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.norm-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.75rem 2rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.norm-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.02em;
}

.norm-subtitle {
    font-size: 0.85rem;
    color: var(--ink-muted);
    margin-top: 0.2rem;
}

.norm-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s;
}
.norm-close:hover { border-color: var(--ink-muted); color: var(--ink); }

.norm-form { display: flex; flex-direction: column; overflow: hidden; flex: 1; }

.norm-body {
    overflow-y: auto;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.norm-section {}

.norm-section-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
    margin-bottom: 0.3rem;
}

.norm-section-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--paper-warm);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--ink-muted);
    padding: 0 0.45rem;
    height: 18px;
    margin-left: 0.1rem;
}

.norm-section-hint {
    font-size: 0.8rem;
    color: var(--ink-muted);
    margin-bottom: 0.75rem;
}

.norm-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.norm-row {
    display: grid;
    grid-template-columns: 1fr 20px 1fr;
    align-items: center;
    gap: 0.5rem;
}

.norm-original {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink-soft);
    background: var(--paper-warm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.norm-arrow { color: var(--ink-faint); justify-self: center; flex-shrink: 0; }

.norm-input,
.norm-select {
    width: 100%;
    padding: 0.45rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.85rem;
    color: var(--ink);
    background: var(--paper-card);
    transition: border-color 0.15s;
}
.norm-input:focus,
.norm-select:focus { outline: none; border-color: var(--accent); }

.norm-select { cursor: pointer; }

.norm-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.25rem 2rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.norm-btn-skip  { width: auto; }
.norm-btn-apply { width: auto; }

@media (max-width: 600px) {
    .norm-modal { max-height: 92vh; border-radius: var(--radius-md); }
    .norm-header { padding: 1.25rem 1.25rem 1rem; }
    .norm-body { padding: 1.25rem; }
    .norm-footer { padding: 1rem 1.25rem; }
    .norm-row { grid-template-columns: 1fr 16px 1fr; gap: 0.3rem; }
}

/* ── Expense detail popup ──────────────────────────────── */

.xd-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.xd-overlay[hidden] { display: none; }

.xd-modal {
    position: relative;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.xd-modal:focus { outline: none; }

.xd-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 1;
}

.xd-body {
    overflow-y: auto;
    padding: 1.75rem 2rem 1.5rem;
}

.xd-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    /* Clear of the close button */
    padding-right: 2.5rem;
    margin-bottom: 0.35rem;
}

.xd-eyebrow {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

/* The two things you opened the popup to read, so they carry the weight the
   fields below them don't. */
.xd-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin-top: 0.2rem;
}

.xd-amount {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    /* Clears the eyebrow above the title, so the two sit on one line. */
    margin-top: 1.35rem;
}

.xd-desc {
    font-size: 0.85rem;
    color: var(--ink-muted);
    line-height: 1.5;
    margin-top: 0.5rem;
}

.xd-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem 1.25rem;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-soft);
}

.xd-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-faint);
    margin-bottom: 0.3rem;
}

.xd-value {
    font-size: 0.875rem;
    color: var(--ink-soft);
}
.xd-value--num {
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.xd-section {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-soft);
}

.xd-section-title {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-faint);
    margin-bottom: 0.6rem;
}

.xd-section-note {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
    font-size: 0.78rem;
    color: var(--ink-muted);
}

.xd-shares {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.xd-share {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: var(--paper-warm);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.xd-share-who { display: inline-flex; align-items: center; gap: 0.4rem; }

.xd-share-tag {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-faint);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0 0.35rem;
}

.xd-share-amount { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

.xd-receipt {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
    color: var(--accent);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.7rem;
    max-width: 100%;
}
.xd-receipt:hover { border-color: var(--accent); }
.xd-receipt-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xd-receipt-size { color: var(--ink-faint); flex-shrink: 0; }

.xd-meta {
    font-size: 0.75rem;
    color: var(--ink-faint);
    margin-top: 1.25rem;
}

/* Receipt photo, shown at a size you can actually read a total off; the link
   under it still opens the original full size. */
.xd-receipt-shot {
    display: block;
    margin-bottom: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--paper-warm);
    line-height: 0;
}
.xd-receipt-shot img {
    display: block;
    width: 100%;
    max-height: 300px;
    /* Contained, not cropped — a receipt cropped to fill is a receipt with its
       total cut off. */
    object-fit: contain;
}
.xd-receipt-shot:hover { border-color: var(--ink-faint); }

.xd-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-soft);
}
.xd-edit { width: auto; display: inline-flex; white-space: nowrap; }

/* Pushed to the far end, quiet until you go for it: it reads as text next to
   the primary button and only takes the danger colour on approach. */
.xd-delete {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.7rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-muted);
    cursor: pointer;
    transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.xd-delete:hover,
.xd-delete:focus-visible {
    color: var(--danger);
    background: var(--danger-light);
    border-color: var(--danger);
}

@media (max-width: 600px) {
    .xd-modal { max-height: 92vh; border-radius: var(--radius-md); }
    .xd-body { padding: 1.5rem 1.25rem 1.25rem; }
    .xd-grid { grid-template-columns: 1fr; gap: 0.8rem; }
}

/* ------------------------------------------------------------------ */
/* Import review page                                                  */
/* ------------------------------------------------------------------ */

.review-summary {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.review-summary-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
    background: var(--accent-light);
    color: var(--accent);
    border: 1px solid rgba(26,71,42,0.15);
}

.review-summary-pill--warn {
    background: var(--accent-2-light);
    color: var(--accent-2);
    border-color: rgba(184,115,32,0.2);
}

.review-summary-pill--alert {
    background: var(--danger-light);
    color: var(--danger);
    border-color: rgba(192,57,43,0.2);
}

.review-table {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 1.75rem;
}

.review-table-head,
.review-table-row {
    display: grid;
    grid-template-columns: 1fr 3.5rem 1fr;
    gap: 0;
    align-items: center;
}

.review-table-head {
    background: var(--paper-warm);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-muted);
}

.review-table-row {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-soft);
}

.review-table-row:last-child { border-bottom: none; }

.review-table-row:nth-child(even) { background: rgba(245,244,241,0.5); }

.review-raw-cat {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.review-count {
    font-size: 0.8rem;
    color: var(--ink-muted);
    text-align: center;
}

.review-select {
    width: 100%;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--ink);
    background: var(--paper-card);
    cursor: pointer;
    transition: border-color 0.15s;
}

.review-select:focus { outline: none; border-color: var(--accent); }

.review-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

@media (max-width: 600px) {
    .review-table-head,
    .review-table-row { grid-template-columns: 1fr 2.5rem 1fr; padding: 0.6rem 0.75rem; }
    .review-actions { flex-direction: column-reverse; }
    .review-actions .ie-btn { width: 100%; }
}

/* ------------------------------------------------------------------ */
/* Dex AI Companion                                                    */
/* ------------------------------------------------------------------ */

.dex-fab {
    position: fixed;
    bottom: 1.75rem;
    right: 1.75rem;
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1rem 0.55rem 0.55rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(26,71,42,0.30);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 600;
    transition: transform 0.15s, box-shadow 0.15s;
}

.dex-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(26,71,42,0.38);
}

.dex-fab-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.dex-fab-label { letter-spacing: 0.01em; }

.dex-modal {
    position: fixed;
    bottom: 5.25rem;
    right: 1.75rem;
    z-index: 901;
    width: 340px;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(12px) scale(0.97);
    pointer-events: none;
    transform-origin: bottom right;
    transition: opacity 0.18s, transform 0.18s;
}

.dex-modal--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.dex-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-soft);
}

.dex-modal-title {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.dex-modal-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 700;
    flex-shrink: 0;
}

.dex-modal-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.2;
}

.dex-modal-sub {
    font-size: 0.75rem;
    color: var(--ink-muted);
}

.dex-modal-close {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--ink-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
}

.dex-modal-close:hover { background: var(--paper-warm); color: var(--ink); }

/* ------------------------------------------------------------------ */
/* Dex chat UI                                                         */
/* ------------------------------------------------------------------ */

.dex-chat-messages {
    height: 320px;
    overflow-y: auto;
    padding: 0.875rem 0.875rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    scroll-behavior: smooth;
}

.dex-chat-messages::-webkit-scrollbar { width: 4px; }
.dex-chat-messages::-webkit-scrollbar-track { background: transparent; }
.dex-chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.dex-msg {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    max-width: 100%;
}

.dex-msg--user {
    flex-direction: row-reverse;
}

.dex-msg-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.dex-msg-bubble {
    max-width: calc(100% - 38px);
    padding: 0.5rem 0.75rem;
    border-radius: 14px;
    font-size: 0.825rem;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.dex-msg--ai .dex-msg-bubble {
    background: var(--paper-warm, #f5f4f0);
    color: var(--ink);
    border-bottom-left-radius: 4px;
}

.dex-msg--user .dex-msg-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Starter prompt chips */
.dex-starters {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    margin: 0.125rem 0 0 34px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.dex-starters--hidden {
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    height: 0;
    overflow: hidden;
    margin: 0 0 0 34px;
}

.dex-starter-chip {
    font-family: inherit;
    font-size: 0.78rem;
    line-height: 1.4;
    text-align: left;
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.dex-starter-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--paper-warm, #f5f4f0);
}

.dex-starter-chip--skeleton {
    width: 132px;
    height: 30px;
    border-color: transparent;
    background: linear-gradient(90deg, var(--paper-warm, #f5f4f0) 25%, var(--border) 50%, var(--paper-warm, #f5f4f0) 75%);
    background-size: 200% 100%;
    animation: dex-skeleton-shimmer 1.4s ease-in-out infinite;
    cursor: default;
}
.dex-starter-chip--skeleton:nth-child(2) { width: 168px; }
.dex-starter-chip--skeleton:nth-child(3) { width: 104px; }

@keyframes dex-skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Typing indicator */
.dex-msg--typing .dex-msg-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.55rem 0.875rem;
}

.dex-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink-muted);
    animation: dex-bounce 1.2s infinite ease-in-out;
}
.dex-dot:nth-child(2) { animation-delay: 0.18s; }
.dex-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes dex-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%            { transform: translateY(-5px); opacity: 1; }
}

/* "What Dex is doing" activity pills */
.dex-activity {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
    margin: 0.1rem 0 0.1rem 34px;
}

.dex-activity-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: var(--accent);
    background: var(--accent-light);
    border-radius: 12px;
    padding: 0.25rem 0.6rem;
    transition: opacity 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.dex-activity-spin {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    animation: dex-spin 0.7s linear infinite;
    flex-shrink: 0;
}

/* Once Dex replies, the running pills settle into a quiet "done" state */
.dex-activity-item--done {
    color: var(--ink-muted);
    background: var(--paper-warm, #f5f4f0);
}

.dex-activity-item--done .dex-activity-spin {
    border: none;
    animation: none;
    position: relative;
}

.dex-activity-item--done .dex-activity-spin::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0;
    width: 3px;
    height: 7px;
    border: solid var(--accent);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Finished, but Dex needs an answer from the user before it can go on —
   a still dot in the warm accent rather than a tick. */
.dex-activity-item--waiting { color: var(--accent-2); background: var(--accent-2-light); }
.dex-activity-item--waiting .dex-activity-spin {
    width: 7px;
    height: 7px;
    margin: 0 2px;
    border: none;
    background: var(--accent-2);
    animation: none;
}

@keyframes dex-spin {
    to { transform: rotate(360deg); }
}

/* Input area */
.dex-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 0.875rem;
    border-top: 1px solid var(--border-soft);
}

.dex-chat-input {
    flex: 1;
    background: var(--paper-warm, #f5f4f0);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    font-size: 0.825rem;
    font-family: inherit;
    color: var(--ink);
    resize: none;
    line-height: 1.45;
    outline: none;
    transition: border-color 0.15s;
    max-height: 120px;
    overflow-y: auto;
}

.dex-chat-input:focus { border-color: var(--accent); }
.dex-chat-input::placeholder { color: var(--ink-muted); }

.dex-chat-send {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}

.dex-chat-send:hover { background: var(--accent-hover, var(--accent)); filter: brightness(1.08); }
.dex-chat-send:active { transform: scale(0.92); }
.dex-chat-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ------------------------------------------------------------------ */
/* Dashboard: top Dex ask bar (replaces the floating fab on this page) */
/* ------------------------------------------------------------------ */

.dex-top-bar {
    position: relative;              /* anchors the perched fox */
    display: flex;
    align-items: center;
    gap: 0.65rem;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    /* The 38px send button now sets the bar's height, so the padding is
       trimmed to keep it at the ~64px established above. */
    padding: 0.72rem 0.7rem 0.72rem 0.9rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.75rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

/* Dex standing on the top-right edge of the ask bar. Sized so his feet land
   just inside the border; pointer-events off so he never eats a click. */
.dex-top-bar-pet {
    position: absolute;
    right: 18px;
    /* Sunk by one leg height (rows 10-12 of the 12-row sprite ≈ 9.6px at this
       width) so the body sits on the bar's top edge and the legs cross over it. */
    bottom: calc(100% - 9.6px);
    width: 86px;   /* matches .dex-pet in the chat popup */
    z-index: 2;
    pointer-events: none;
    filter: drop-shadow(0 3px 4px rgba(14, 59, 39, 0.22));
}

.dex-top-bar-pet svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.dex-ask { position: relative; }

/* Messages opens straight on the bar — no header. Its top padding is the
   perched fox's headroom. */
.messages-top { padding-top: 1rem; }

/* The live chat: the thread sits above the bar, which becomes its reply box. */
.convo-thread--live { margin-bottom: 1.25rem; }
.convo-thread--live + .messages-top { padding-top: 2.5rem; }
.convo-activity { margin: 0 0 0 calc(36px + 0.55rem); }
.convo-msg--typing .convo-bubble { display: flex; align-items: center; gap: 4px; }
.convo-msg--error .convo-bubble { color: var(--danger); }
.convo-note a { color: var(--accent); font-weight: 500; text-decoration: none; }
.convo-note a:hover { text-decoration: underline; }

/* Add expense on the left, the quote card pushed right beside Dex. Bottoms
   aligned, so the button sits level with the foot of the card. */
.dex-ask-head {
    display: flex;
    align-items: flex-end;
    gap: 1.5rem;
}

.dex-ask-head > .btn-primary {
    flex-shrink: 0;
    white-space: nowrap;
    margin-bottom: 56px;                  /* the card's own lift above the bar */
}

.dex-ask-head > .dex-quote { min-width: 0; }

/* Dex saying the day's quote: a card sitting just above the bar, left of
   him, with a trail of thought-bubble dots stepping down to his face. It's
   in the flow rather than floated over the gap, so the space it takes is
   exactly its own height — a one-line quote leaves a one-line gap. Hidden
   until the reveal script adds --in, and it steps aside while the bar is
   being typed into. */
.dex-quote {
    position: relative;                   /* anchors the dots */
    width: fit-content;
    max-width: min(560px, calc(100% - 150px));
    /* Right-aligned clear of the 86px fox, and lifted so its bottom-right
       corner sits just above his ears — the thought rises off his head into
       the card rather than the card standing beside him. */
    margin: 0 122px 56px auto;
    padding: 0.6rem 0.95rem;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-size: 0.8rem;
    line-height: 1.5;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.dex-quote--in { opacity: 1; transform: none; }
.dex-ask:focus-within .dex-quote { opacity: 0; transform: translateY(4px); }

/* Dex at work: while the ask bar's answer needs tools, the cloud swaps the
   quote for those steps (dex_ask_bar.js) and stays up while you type. */
.dex-quote-steps { display: none; margin: 0; }
.dex-quote--steps .dex-quote-text,
.dex-quote--steps .dex-quote-author { display: none; }
.dex-quote--steps .dex-quote-steps { display: flex; }
.dex-ask .dex-quote.dex-quote--steps {
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* One line tall whether it holds the dots or a step, so it fits what it
       shows and doesn't change size between them (dex_ask_bar.js). */
    min-height: 2.6rem;
    opacity: 1;
    transform: none;
}
/* While a tool runs the cloud shows only the dots; when it finishes, only
   the step it came to (dex_ask_bar.js keeps just the latest). */
.dex-quote-dots { display: none; gap: 4px; padding: 0.45rem 0; }
.dex-quote--working .dex-quote-dots { display: flex; }
.dex-quote--working .dex-quote-steps { display: none; }
.dex-quote-dots .dex-dot { width: 5px; height: 5px; }

/* Plain lines in the card rather than pills — the card is the bubble — and
   no tick in front: the dots before it already said it was running. */
.dex-quote-steps .dex-activity-item {
    padding: 0;
    background: none;
    font-size: 0.78rem;
}
.dex-quote-steps .dex-activity-spin { display: none; }

/* The trail: two small rounds in the card's own fill and outline, stepping
   up from beside the fox's ears to the card's corner — smallest by his head,
   the way a thought bubble grows out of whoever's thinking it. */
.dex-quote::before,
.dex-quote::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    background: var(--paper-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.dex-quote::before {
    width: 9px;
    height: 9px;
    right: -9px;
    bottom: -13px;
}

.dex-quote::after {
    width: 5px;
    height: 5px;
    right: -17px;
    bottom: -23px;
}

/* Quote and attribution each on their own line. Run together, the pair
   almost always overran one line, and the attribution wrapping onto the next
   left the card at its full max-width with a gap after the quote — a box
   sizes to its unwrapped content, not to the lines it ends up drawing. The
   script in dashboard.html trims what's left when the quote itself wraps. */
.dex-quote-text {
    margin: 0;
    font-style: italic;
    color: var(--ink-soft);
    text-wrap: pretty;
}

.dex-quote-author {
    display: block;
    white-space: nowrap;
    margin-top: 0.1rem;
    color: var(--ink-faint);
    font-size: 0.72rem;
}

/* On a phone there's no room beside Dex, so the card spans the width above
   the bar with room beneath for him to stand, the dots trailing down to him. */
@media (max-width: 600px) {
    .dex-quote {
        width: fit-content;
        max-width: 100%;
        margin: 0 0 66px;
        font-size: 0.78rem;
    }
    .dex-ask-head { flex-direction: column; align-items: flex-start; gap: 1rem; }
    .dex-ask-head > .btn-primary { display: none; }
    .dex-ask-head > .dex-quote.dex-quote--steps {
        align-self: flex-end;
        --trail-right: 84px !important;
    }
    .dex-quote::before { right: var(--trail-right, 84px); bottom: -17px; }
    .dex-quote::after  { right: calc(var(--trail-right, 84px) - 6px); bottom: -29px; }
    .dex-quote.dex-quote--short:not(.dex-quote--steps)::before { right: -9px;  bottom: -15px; }
    .dex-quote.dex-quote--short:not(.dex-quote--steps)::after  { right: -19px; bottom: -27px; }
}

@media (prefers-reduced-motion: reduce) {
    .dex-quote { transition: none; transform: none; }
}
.dex-top-bar:focus-within { border-color: var(--accent); box-shadow: var(--shadow-md); }

.dex-top-bar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dex-top-bar-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 0.9rem;
    outline: none;
    min-width: 0;
}
.dex-top-bar-input::placeholder { color: var(--ink-faint); }

.dex-top-bar-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.18s, transform 0.18s, box-shadow 0.18s;
}

/* Hover: the button lifts a touch with a soft accent halo, and the paper
   plane inside edges up and to the right as if about to take off. Pressing
   squashes it back down. */
.dex-top-bar-send svg { transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1); }
.dex-top-bar-send:hover,
.dex-top-bar-send:focus-visible {
    background: var(--accent-hover);
    transform: scale(1.07);
    box-shadow: 0 0 0 4px var(--accent-light), 0 4px 12px rgba(26, 71, 42, 0.25);
}
.dex-top-bar-send:hover svg,
.dex-top-bar-send:focus-visible svg { transform: translate(2px, -2px) rotate(-8deg); }
.dex-top-bar-send:focus-visible { outline: none; }
.dex-top-bar-send:active { transform: scale(0.92); box-shadow: 0 0 0 2px var(--accent-light); }
.dex-top-bar-send:active svg { transform: translate(3px, -3px) rotate(-8deg); }

@media (prefers-reduced-motion: reduce) {
    .dex-top-bar-send,
    .dex-top-bar-send svg { transition: background 0.18s, box-shadow 0.18s; }
    .dex-top-bar-send:hover,
    .dex-top-bar-send:active,
    .dex-top-bar-send:hover svg,
    .dex-top-bar-send:active svg { transform: none; }
}

/* "123 / 500" on a Dex input — appears once something's typed, warms to
   amber near the limit and red at it. */
.dex-count {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink-faint);
    white-space: nowrap;
    align-self: center;
}
.dex-count[hidden] { display: none; }
.dex-count--near { color: var(--accent-2); }
.dex-count--full { color: var(--danger); font-weight: 600; }

/* Voice input, beside send: a quiet outline until it's listening, then
   filled in the danger red with a slow pulse, the usual "recording" signal. */
.dex-top-bar-mic {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--ink-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.dex-top-bar-mic[hidden] { display: none; }
.dex-top-bar-mic:hover,
.dex-top-bar-mic:focus-visible { color: var(--accent); border-color: var(--accent); outline: none; }
.dex-top-bar-mic--on,
.dex-top-bar-mic--on:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    animation: dex-mic-pulse 1.4s ease-in-out infinite;
}
@keyframes dex-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); }
    50%      { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
    .dex-top-bar-mic--on { animation: none; }
}

/* Reaching for send gets Dex excited — same wild tail as hovering the chat pet.
   Matched on the bar because the fox sits before the button in the DOM. */
.dex-top-bar:has(.dex-top-bar-send:hover) .dex-top-bar-pet .fox-tail,
.dex-top-bar:has(.dex-top-bar-send:active) .dex-top-bar-pet .fox-tail {
    animation-duration: 0.6s;
}

/* ------------------------------------------------------------------ */
/* Dashboard tour — spotlight highlight + floating tooltip callout     */
/* ------------------------------------------------------------------ */

/* Only a fallback shape, at plain specificity: a target that defines its own
   radius (the round help button, the panels) keeps it, and the ring follows. */
.dtour-spotlight { border-radius: var(--radius-md); }

/* Class doubled deliberately. The ring and the page dimming are one box-shadow,
   and every card on the dashboard sets box-shadow itself at the same
   specificity — .cc-panel is declared later in this file and was silently
   winning, so the Contacts step lit nothing at all. Doubling wins on
   specificity instead of on source order, which no later rule can undo.
   Note: `position` is deliberately not set here — the tour script adds it
   inline only to static targets, so the fixed help button keeps its corner. */
.dtour-spotlight.dtour-spotlight {
    z-index: 950;
    box-shadow: 0 0 0 4px var(--accent), 0 0 0 9999px rgba(10,20,15,0.55);
    transition: box-shadow 0.2s ease;
}

.dtour-tooltip {
    position: fixed;
    z-index: 951;
    width: min(300px, 90vw);
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 1.1rem 1.2rem;
}

.dtour-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 0.4rem;
}

.dtour-body {
    font-size: 0.85rem;
    color: var(--ink-muted);
    line-height: 1.55;
    margin-bottom: 1rem;
}

.dtour-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.dtour-dots {
    display: flex;
    gap: 0.3rem;
}
.dtour-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border);
}
.dtour-dot--active { background: var(--accent); }

.dtour-actions { display: flex; align-items: center; gap: 0.6rem; }

.dtour-skip {
    background: none;
    border: none;
    color: var(--ink-faint);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0;
}
.dtour-skip:hover { color: var(--ink-muted); }

.dtour-next {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.4rem 0.9rem;
    cursor: pointer;
}
.dtour-next:hover { filter: brightness(1.08); }

/* ------------------------------------------------------------------ */
/* Dex the fox — peeking pet                                            */
/* ------------------------------------------------------------------ */

/* Every fox wears the same drop-shadow to sit it on the surface it perches on.
   In dark mode that shadow has nothing to fall on: it just smudges a dark
   halo around a dark outline. Worse, the filter rasterises the sprite, which
   softens the very pixel edges shape-rendering="crispEdges" exists to keep —
   so on dark the fox goes shadowless and renders as clean vector pixels. */
[data-theme="dark"] .dex-pet,
[data-theme="dark"] .dex-top-bar-pet,
[data-theme="dark"] .dex-mock-pet,
[data-theme="dark"] .dex-story-fox { filter: none; }

.dex-pet {
    position: absolute;
    top: -46px;
    right: 14px;
    width: 86px;
    height: auto;
    z-index: 3;
    cursor: pointer;
    filter: drop-shadow(0 3px 4px rgba(14,59,39,0.22));
    -webkit-tap-highlight-color: transparent;
}

.dex-pet-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Entrance: pops up whenever the chat opens */
.dex-modal--open .dex-pet { animation: foxPop 0.5s cubic-bezier(.34,1.56,.64,1) both; }

@keyframes foxPop {
    0%   { transform: translateY(36px) scale(0.6); opacity: 0; }
    60%  { transform: translateY(-4px) scale(1.05); opacity: 1; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* Idle life — shared by the chat pet and the ask-bar fox */
.dex-pet .fox,
.dex-top-bar-pet .fox      { transform-box: fill-box; transform-origin: 50% 92%; }
.dex-pet .fox-eyes,
.dex-top-bar-pet .fox-eyes { transform-box: fill-box; transform-origin: center;
                             animation: foxBlink 4.5s ease-in-out infinite; }
.dex-pet .fox-ear-r,
.dex-top-bar-pet .fox-ear-r{ transform-box: fill-box; transform-origin: 50% 100%;
                             animation: foxEarTwitch 6s ease-in-out infinite; }
.dex-pet .fox-tail,
.dex-top-bar-pet .fox-tail { transform-box: fill-box; transform-origin: 0% 100%;
                             animation: foxTailWag 2.8s ease-in-out infinite; }

@keyframes foxBob       { 0%,100% { transform: translateY(0); }   50% { transform: translateY(-2.5px); } }
@keyframes foxBlink     { 0%,92%,100% { transform: scaleY(1); }   95% { transform: scaleY(0.12); } }
@keyframes foxEarTwitch { 0%,88%,100% { transform: rotate(0); }   92% { transform: rotate(-10deg); } 96% { transform: rotate(5deg); } }
@keyframes foxTailWag   { 0%,100% { transform: rotate(-6deg); }   50% { transform: rotate(9deg); } }

/* Hover — tail goes wild */
.dex-pet:hover .fox-tail { animation-duration: 0.6s; }

/* Reaction: happy wiggle (responses, saved changes) */
.dex-pet--happy .fox { animation: foxHappy 0.65s ease; }
@keyframes foxHappy {
    0%,100% { transform: translateY(0) rotate(0); }
    25%     { transform: translateY(-7px) rotate(-5deg); }
    50%     { transform: translateY(0) rotate(0); }
    75%     { transform: translateY(-5px) rotate(5deg); }
}

/* Reaction: thinking head-tilt while Dex works */
.dex-pet--think .fox { animation: foxThink 1.1s ease-in-out infinite; }
@keyframes foxThink { 0%,100% { transform: rotate(0); } 50% { transform: rotate(-7deg); } }

/* Reaction: oops shake on errors */
.dex-pet--oops .fox { animation: foxShake 0.5s ease; }
@keyframes foxShake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

/* Reaction: wink when poked */
.dex-pet--wink .fox-eye-r { transform-box: fill-box; transform-origin: center; animation: foxWink 0.5s ease; }
@keyframes foxWink { 0%,100% { transform: scaleY(1); } 40%,60% { transform: scaleY(0.1); } }

@media (prefers-reduced-motion: reduce) {
    .dex-pet, .dex-pet .fox, .dex-pet .fox-eyes, .dex-pet .fox-ear-r,
    .dex-pet .fox-tail, .dex-pet--happy .fox, .dex-pet--think .fox,
    .dex-pet--oops .fox, .dex-pet--wink .fox-eye-r { animation: none; }
}

/* ------------------------------------------------------------------ */
/* Chart year navigation                                               */
/* ------------------------------------------------------------------ */

.analytics-year-nav {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.chart-year-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--paper-card);
    color: var(--ink-muted);
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s, opacity 0.12s;
    flex-shrink: 0;
}

.chart-year-btn:hover:not(:disabled) {
    background: var(--paper-warm);
    color: var(--ink);
    border-color: var(--border);
}

.chart-year-btn:disabled {
    cursor: default;
    pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* Theme toggle                                                        */
/* ------------------------------------------------------------------ */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: none;
    color: var(--ink-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.theme-toggle:hover {
    border-color: var(--ink-muted);
    color: var(--ink);
    background: var(--paper-warm);
}

/* Icon reflects the current preference: sun = light, moon = dark, monitor = system */
.theme-toggle .icon-sun,
.theme-toggle .icon-moon,
.theme-toggle .icon-system { display: none; }
[data-theme-pref="light"] .theme-toggle .icon-sun { display: block; }
[data-theme-pref="dark"] .theme-toggle .icon-moon { display: block; }
[data-theme-pref="system"] .theme-toggle .icon-system { display: block; }

/* Footer variant sits on the always-dark footer in both themes */
.footer .theme-toggle {
    border-color: rgba(255, 255, 255, 0.18);
    color: var(--footer-muted);
}

.footer .theme-toggle:hover {
    border-color: rgba(255, 255, 255, 0.35);
    color: var(--footer-text);
    background: rgba(255, 255, 255, 0.08);
}

/* ------------------------------------------------------------------ */
/* Dark-theme one-off overrides                                        */
/* ------------------------------------------------------------------ */

[data-theme="dark"] .btn-google:hover {
    background: #1a2231;
}

[data-theme="dark"] .review-table-row:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

/* Theme preference segmented control (profile page) */
.theme-seg {
    display: inline-flex;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.theme-seg-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 1.1rem;
    border: none;
    background: none;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.theme-seg-btn + .theme-seg-btn {
    border-left: 1.5px solid var(--border);
}

.theme-seg-btn:hover {
    background: var(--paper-warm);
    color: var(--ink);
}

.theme-seg-btn--active {
    background: var(--accent-light);
    color: var(--accent);
}

/* ------------------------------------------------------------------ */
/* Landing: Meet Dex section                                           */
/* ------------------------------------------------------------------ */

/* Full-bleed like the hero, with the same pixel field behind it. */
.dex-intro {
    position: relative;
    padding: 4.5rem 2rem;
    overflow: hidden;
    isolation: isolate;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.dex-intro-inner {
    max-width: var(--max-width);
    margin: 0 auto;
}

.dex-intro-title {
    font-size: clamp(2rem, 4vw, 2.75rem);
    font-weight: 800;
    line-height: 1.12;
    letter-spacing: -0.03em;
    color: var(--ink);
    margin-bottom: 1.25rem;
}
.dex-intro-title em { font-style: normal; color: var(--accent); }

.dex-intro-body {
    font-size: 1rem;
    color: var(--ink-muted);
    line-height: 1.75;
    max-width: 460px;
    margin-bottom: 1.75rem;
}


.dex-intro-visual { display: flex; justify-content: center; }

/* Sits so the body rests on the card edge and the legs hang over it,
   matching how the pet perches on the real Dex chat modal */
.dex-mock-pet {
    position: absolute;
    top: -40px;
    right: 26px;
    width: 72px;
    cursor: pointer;
    filter: drop-shadow(0 3px 4px rgba(14,59,39,0.22));
    -webkit-tap-highlight-color: transparent;
}

.dex-mock-pet svg,
.dex-story-fox svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Idle life + poke reaction — same keyframes as the chat pet */
.dex-mock-pet .fox,       .dex-story-fox .fox       { transform-box: fill-box; transform-origin: 50% 92%; }
.dex-mock-pet .fox-eyes,  .dex-story-fox .fox-eyes  { transform-box: fill-box; transform-origin: center;
                                                      animation: foxBlink 4.5s ease-in-out infinite; }
.dex-mock-pet .fox-ear-r, .dex-story-fox .fox-ear-r { transform-box: fill-box; transform-origin: 50% 100%;
                                                      animation: foxEarTwitch 6s ease-in-out infinite; }
.dex-mock-pet .fox-tail,  .dex-story-fox .fox-tail  { transform-box: fill-box; transform-origin: 0% 100%;
                                                      animation: foxTailWag 2.8s ease-in-out infinite; }
.dex-mock-pet:hover .fox-tail, .dex-story-fox:hover .fox-tail { animation-duration: 0.6s; }

.fox-winking .fox-eye-r { transform-box: fill-box; transform-origin: center; animation: foxWink 0.5s ease; }

@media (prefers-reduced-motion: reduce) {
    .dex-mock-pet .fox-eyes,  .dex-story-fox .fox-eyes,
    .dex-mock-pet .fox-ear-r, .dex-story-fox .fox-ear-r,
    .dex-mock-pet .fox-tail,  .dex-story-fox .fox-tail,
    .dex-top-bar-pet .fox-eyes, .dex-top-bar-pet .fox-ear-r,
    .dex-top-bar-pet .fox-tail,
    .fox-winking .fox-eye-r { animation: none; }
}

.dex-story-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 1.75rem;
    font-size: 0.925rem;
    font-weight: 600;
    color: var(--accent);
    transition: gap 0.15s, color 0.15s;
}
.dex-story-link:hover { color: var(--accent-hover); gap: 0.7rem; }

@media (max-width: 900px) {
    .dex-intro { padding: 3rem 2rem; }
}

/* ------------------------------------------------------------------ */
/* Dex story page                                                      */
/* ------------------------------------------------------------------ */

.dex-story-page {
    max-width: 680px;
    margin: 0 auto;
    padding: 4rem 2rem 5rem;
    text-align: center;
}

.dex-story-fox {
    width: 144px;
    margin: 0 auto 1.75rem;
    cursor: pointer;
    filter: drop-shadow(0 3px 4px rgba(14,59,39,0.22));
    -webkit-tap-highlight-color: transparent;
}

.dex-story-title {
    font-size: clamp(2.2rem, 4.5vw, 3rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--ink);
    margin-bottom: 0.9rem;
}

.dex-story-sub {
    font-size: 1.05rem;
    color: var(--ink-muted);
    line-height: 1.7;
    margin: 0 auto;
    max-width: 480px;
}

.dex-story-body {
    margin-top: 3rem;
    text-align: left;
    font-size: 1rem;
    line-height: 1.85;
    color: var(--ink-soft);
}
.dex-story-body p { margin-bottom: 1.25rem; }

/* Curly brackets around the About page's rhetorical question. Drawn as
   pseudo-elements so the braces stay decorative — screen readers get the
   question on its own — and kept light so they frame without shouting. */
/* The question itself sits one step lighter than the body's --ink-soft,
   with the braces lighter again, so the aside recedes as a unit. */
.about-brace { color: var(--ink-muted); }

.about-brace::before,
.about-brace::after {
    color: var(--ink-faint);
    font-weight: 300;
    font-size: 1.9em;
    line-height: 0;
    vertical-align: -0.22em;
}

.about-brace::before { content: "{"; margin-right: 0.1em; }
.about-brace::after  { content: "}"; margin-left: 0.1em; }

.dex-story-placeholder {
    text-align: center;
    color: var(--ink-faint);
    background: var(--paper-warm);
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 2.5rem 1.5rem;
}

/* ------------------------------------------------------------------ */
/* Blog index, set as a broadsheet.                                     */
/*                                                                      */
/* The money pages of a newspaper rather than a card grid: rules do the  */
/* dividing, headlines run in a serif the rest of the app never uses,    */
/* and anything that is data — datelines, bylines, the jump link — is    */
/* set in tracked agate caps. Colour stays on the shared tokens, so the  */
/* night edition comes for free.                                         */
/* ------------------------------------------------------------------ */

.paper {
    --paper-serif: Georgia, 'Times New Roman', Times, serif;
    max-width: 1080px;
    margin: 0 auto;
    padding: 3.25rem 2rem 4.5rem;
}

/* --- Masthead --- */

.paper-masthead { text-align: center; }

/* Three true facts, set the width of the page the way a folio line is. */
.paper-dateline {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.55rem 0;
    border-top: 1px solid var(--ink);
    border-bottom: 1px solid var(--border);
    font-family: var(--font);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.paper-dateline-mid { color: var(--ink-faint); }

/* Sized to set on one line at the full measure — a masthead that wraps reads
   as a headline instead. Below ~900px it wraps, which is the point at which a
   single line would be too small to carry the page anyway. */
.paper-wordmark {
    font-family: var(--paper-serif);
    font-weight: 700;
    font-size: clamp(2.4rem, 7vw, 5.3rem);
    line-height: 0.98;
    letter-spacing: -0.03em;
    color: var(--ink);
    margin: 1.5rem 0 1.3rem;
}

/* Thick over hairline: two borders on a 6px-tall element leave the gap. */
.paper-double-rule {
    height: 6px;
    border-top: 3px solid var(--ink);
    border-bottom: 1px solid var(--ink);
}

.paper-strapline {
    font-family: var(--paper-serif);
    font-style: italic;
    font-size: 1.05rem;
    line-height: 1.5;
    color: var(--ink-muted);
    max-width: 40rem;
    margin: 1rem auto 0;
    text-wrap: balance;
}

/* --- Stories --- */

.paper-story {
    padding: 2.25rem 0;
    border-bottom: 1px solid var(--border);
}

.paper-story--lead {
    margin-top: 2.5rem;
    border-top: 1px solid var(--ink);
}

.paper-story-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.paper-byline {
    font-family: var(--font);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-bottom: 0.7rem;
}

.paper-headline {
    font-family: var(--paper-serif);
    font-weight: 700;
    font-size: 1.45rem;
    line-height: 1.18;
    letter-spacing: -0.015em;
    color: var(--ink);
    margin-bottom: 0.7rem;
}

.paper-story--lead .paper-headline {
    font-size: clamp(1.8rem, 4.2vw, 2.9rem);
    max-width: 22ch;
}

.paper-excerpt {
    font-family: var(--paper-serif);
    font-size: 1rem;
    line-height: 1.62;
    color: var(--ink-muted);
    margin-bottom: 1rem;
}

.paper-jump {
    display: inline-block;
    font-family: var(--font);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
    border-bottom: 1px solid currentColor;
    padding-bottom: 2px;
}

.paper-story-link:hover .paper-headline {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}

.paper-story-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 6px;
}

/* Briefs run two up, divided by the column rule that separates newspaper
   columns. Every second one starts a row, so it opens without a rule. */
.paper-briefs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 2.75rem;
}

.paper-briefs .paper-story {
    border-left: 1px solid var(--border);
    padding-left: 2.75rem;
}

.paper-briefs .paper-story:nth-child(2n+1) {
    border-left: none;
    padding-left: 0;
}

.paper-empty {
    font-family: var(--paper-serif);
    font-style: italic;
    font-size: 1.05rem;
    color: var(--ink-muted);
    text-align: center;
    padding: 4rem 0;
    border-top: 1px solid var(--ink);
    border-bottom: 1px solid var(--border);
    margin-top: 2.5rem;
}

/* The one control on the page, squared off and set in agate to keep the pill
   shape of the app's ghost button out of the broadsheet. */
.paper-folio {
    margin-top: 3rem;
    text-align: center;
}

.paper-folio .btn-ghost {
    border-radius: 0;
    border-color: var(--ink);
    font-family: var(--font);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

/* --- The post itself: an inside page --- */

/* One column at reading measure, ranged left — inside pages centre nothing
   but the folio. */
.paper--article {
    max-width: 44rem;
    text-align: left;
}

/* The running head a paper prints above an inside page, doubling as the way
   back to the index. */
.paper-runninghead {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.55rem 0;
    border-top: 1px solid var(--ink);
    border-bottom: 1px solid var(--border);
    font-family: var(--font);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.paper-runninghead-link {
    color: var(--ink-muted);
    text-decoration: none;
}

.paper-runninghead-link:hover { color: var(--accent); }

.paper-article-title {
    font-family: var(--paper-serif);
    font-weight: 700;
    font-size: clamp(2rem, 5.5vw, 3.2rem);
    line-height: 1.1;
    letter-spacing: -0.025em;
    color: var(--ink);
    margin: 2rem 0 0.9rem;
}

.paper-article-byline {
    font-family: var(--font);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-faint);
    padding-bottom: 1.4rem;
    border-bottom: 1px solid var(--ink);
}

.paper-article-body {
    font-family: var(--paper-serif);
    font-size: 1.06rem;
    line-height: 1.72;
    color: var(--ink-soft);
    margin-top: 2rem;
}

.paper-article-body p { margin-bottom: 1.3rem; }

/* Drop cap on the opening paragraph only, and only when the piece actually
   opens with one — a pull quote first would leave it stranded mid-article. */
.paper-article-body > p:first-child::first-letter {
    float: left;
    font-size: 3.6em;
    line-height: 0.8;
    font-weight: 700;
    color: var(--accent);
    padding: 0.02em 0.09em 0 0;
}

/* ------------------------------------------------------------------ */
/* Article figures — cut in like a newspaper's, rule under the caption  */
/* ------------------------------------------------------------------ */

.paper-figure { margin: 2.25rem 0; }

.paper-figure figcaption {
    margin-top: 0.7rem;
    padding-top: 0.55rem;
    border-top: 1px solid var(--border);
    font-family: var(--font);
    font-size: 0.72rem;
    line-height: 1.5;
    color: var(--ink-muted);
}

/* --- Books ------------------------------------------------------- */

.bookshelf {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

/* The cover, then its details beside it — a shelf entry rather than a card.
   The art carries the recognition, so it leads. */
.bookcover {
    flex: 1 1 15rem;
    display: flex;
    align-items: flex-start;
    gap: 0.9rem;
    text-decoration: none;
    transition: transform 0.15s;
}
.bookcover:hover { transform: translateY(-2px); }

.bookcover-art {
    flex-shrink: 0;
    width: 5.6rem;
    height: auto;
    border-radius: 2px;
    /* The spine edge: a cover floating on paper looks pasted on. */
    box-shadow: var(--shadow-sm), -1px 0 0 rgba(0, 0, 0, 0.16) inset;
    transition: box-shadow 0.15s;
}
/* The <picture> around the cover (AVIF/WebP sources) is the flex item now. */
.bookcover picture { flex-shrink: 0; display: block; line-height: 0; }
.bookcover:hover .bookcover-art { box-shadow: var(--shadow-md), -1px 0 0 rgba(0, 0, 0, 0.16) inset; }

.bookcover-meta {
    display: flex;
    flex-direction: column;
    padding-top: 0.15rem;
    min-width: 0;
}

.bookcover-title {
    font-family: var(--paper-serif);
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--ink);
}

.bookcover-author {
    margin-top: 0.3rem;
    font-family: var(--font);
    font-size: 0.75rem;
    color: var(--ink-muted);
}

.bookcover-source {
    margin-top: 0.7rem;
    font-family: var(--font);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent);
}

/* --- The spreadsheet template ------------------------------------ */

.sheetshot {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--paper-card);
    overflow: hidden;
    text-decoration: none;
    transition: border-color 0.15s;
}
.sheetshot:hover { border-color: var(--ink-faint); }

.sheetshot-tabs {
    display: flex;
    align-items: flex-end;
    gap: 0.2rem;
    padding: 0.6rem 0.6rem 0;
}

.sheetshot-tab {
    padding: 0.22rem 0.7rem;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    background: var(--paper-warm);
    font-family: var(--font);
    font-size: 0.66rem;
    font-weight: 700;
    color: var(--ink-faint);
}

/* The month on show sits forward of the ones behind it. */
.sheetshot-tab--on {
    background: var(--paper-card);
    color: var(--ink);
    padding-bottom: 0.32rem;
    margin-bottom: -1px;
}

.sheetshot-grid {
    display: grid;
    /* One track per column, weighted the way the sheet is: the description gets
       the room, the date and amount need little. Sized to fit the article
       column on a desktop — a sheet with its last column sliced off reads as
       broken rather than as scrollable — and it scrolls below that. */
    grid-template-columns: minmax(5rem, 0.8fr) minmax(6rem, 1fr) minmax(9rem, 1.9fr) minmax(5rem, 0.8fr);
    border-top: 1px solid var(--border);
    overflow-x: auto;
}

.sheetshot-cell {
    padding: 0.45rem 0.6rem;
    border-right: 1px solid var(--border-soft);
    border-bottom: 1px solid var(--border-soft);
    font-family: var(--font);
    font-size: 0.72rem;
    color: var(--ink-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sheetshot-cell--head {
    background: var(--paper-warm);
    font-weight: 700;
    color: var(--ink);
}

/* --- Dex --------------------------------------------------------- */

.paper-figure--dex { text-align: center; }

.dex-portrait {
    display: inline-block;
    width: 8.5rem;
}
.dex-portrait svg { display: block; width: 100%; height: auto; }
/* A hat widens the drawing by one column (19 wide, not 18); widen the
   portrait to match so Dex himself stays the same size. */
.dex-portrait--hat { width: calc(8.5rem * 19 / 18); }

/* The chat pet's idle life, minus the tail — a wag reads as a reaction, and
   in the middle of an article there is nothing for him to be reacting to. He
   blinks and twitches an ear and otherwise sits still. */
.dex-portrait .fox      { transform-box: fill-box; transform-origin: 50% 92%; }
.dex-portrait .fox-eyes { transform-box: fill-box; transform-origin: center;
                          animation: foxBlink 4.5s ease-in-out infinite; }
.dex-portrait .fox-ear-r{ transform-box: fill-box; transform-origin: 50% 100%;
                          animation: foxEarTwitch 6s ease-in-out infinite; }

@media (max-width: 600px) {
    .bookcover { flex-basis: 100%; }
}

/* Rules above and below, nothing else: the newspaper pull quote. */
.paper-pullquote {
    margin: 2.25rem 0;
    padding: 1.4rem 1rem;
    border-top: 1px solid var(--ink);
    border-bottom: 1px solid var(--ink);
    font-size: 1.3rem;
    font-style: italic;
    line-height: 1.45;
    text-align: center;
    color: var(--ink);
}

.paper-pullquote cite {
    display: block;
    margin-top: 0.8rem;
    font-family: var(--font);
    font-size: 0.62rem;
    font-style: normal;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.paper-article-end {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--ink);
}

/* Squared off to match the folio button on the index. */
.paper-article-end .btn-primary,
.paper-article-end .btn-ghost {
    border-radius: 0;
    font-family: var(--font);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.paper-article-end .btn-ghost { border-color: var(--ink); }

@media (max-width: 760px) {
    .paper { padding: 2.5rem 1.25rem 3.5rem; }
    /* The archive count is the one dateline item a phone can spare. */
    .paper-dateline-mid { display: none; }
    .paper-dateline { font-size: 0.55rem; letter-spacing: 0.14em; }
    .paper-briefs { grid-template-columns: 1fr; }
    .paper-briefs .paper-story { border-left: none; padding-left: 0; }
    .paper-runninghead { font-size: 0.55rem; letter-spacing: 0.12em; }
    .paper-pullquote { font-size: 1.12rem; }
}

.dex-story-back {
    margin-top: 3rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ------------------------------------------------------------------ */
/* 404 / error page                                                    */
/* ------------------------------------------------------------------ */

.error-page {
    min-height: 64vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 1.5rem 5rem;
}

.error-inner { max-width: 540px; }

.error-glyph {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: clamp(5rem, 17vw, 8.5rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
    color: var(--ink);
    margin-bottom: 1.75rem;
}

.error-diamond {
    width: 0.74em;
    height: 0.74em;
    color: var(--accent);
    /* nudge the diamond onto the numeral baseline */
    transform: translateY(0.02em);
}

.error-title {
    font-size: clamp(1.55rem, 4vw, 2.15rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: var(--ink);
    margin-bottom: 1rem;
}
.error-title em { font-style: normal; color: var(--accent); }

.error-sub {
    font-size: 1rem;
    color: var(--ink-muted);
    line-height: 1.6;
    margin-bottom: 2rem;
}

.error-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ------------------------------------------------------------------ */
/* Admin — access gate                                                 */
/* ------------------------------------------------------------------ */

.admin-gate-page {
    min-height: 66vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 1.5rem 5rem;
}

.admin-gate-card {
    width: 100%;
    max-width: 420px;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 2.5rem 2.25rem;
    text-align: center;
}

.admin-gate-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
}

.admin-gate-title {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin-bottom: 0.6rem;
}

.admin-gate-sub {
    font-size: 0.92rem;
    color: var(--ink-muted);
    line-height: 1.6;
    margin-bottom: 1.75rem;
}
.admin-gate-sub strong { color: var(--ink); font-weight: 600; }

.admin-gate-form { margin-bottom: 0.5rem; }

.admin-gate-input {
    width: 100%;
    text-align: center;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.4em;
    padding: 0.75rem 0.5rem;
    margin-bottom: 1rem;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.admin-gate-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}
.admin-gate-input::placeholder { color: var(--ink-faint); letter-spacing: 0.4em; }

.admin-gate-btn { width: 100%; justify-content: center; }

.admin-gate-resend { margin-top: 1rem; }
.admin-gate-link {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.25rem;
}
.admin-gate-link:hover { text-decoration: underline; }

.admin-gate-back {
    display: inline-block;
    margin-top: 1.5rem;
    font-size: 0.85rem;
    color: var(--ink-muted);
    text-decoration: none;
}
.admin-gate-back:hover { color: var(--ink); }

/* ------------------------------------------------------------------ */
/* Admin — panel                                                       */
/* ------------------------------------------------------------------ */

.admin-eyebrow {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    margin-bottom: 0.3rem;
}

.admin-panel .dashboard-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--ink);
}

/* Tabs carry different numbers of cards (six on the overview, four on Dex),
   so the grid flows instead of pinning a column count. */
.admin-stats {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.admin-stats .stat-card { padding: 1.25rem 1.35rem; }

.admin-subtitle {
    margin: 0.4rem 0 0;
    font-size: 0.875rem;
    color: var(--ink-muted);
}

/* The overview's headline is a count, not a sum, so it needs the noun after it
   to mean anything. Set well down from the figure and in the muted ink, so the
   number still carries the block on its own. */
.dateline-unit {
    margin-left: 0.4rem;
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--ink-muted);
    vertical-align: 0.55em;
}

.admin-table-wrap {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 720px;
}

.admin-table thead th {
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-muted);
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.admin-table tbody td {
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--border-soft);
    color: var(--ink-soft);
    white-space: nowrap;
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--accent-light); }

/* Sortable column headers. The whole header is the link, so the click target
   matches what it looks like. */
.admin-table thead th.admin-th-sort { padding: 0; }

.admin-sort {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.9rem 0.7rem;
    color: inherit;
    font: inherit;
    text-decoration: none;
    white-space: nowrap;
}
.admin-sort:hover { color: var(--ink); background: var(--paper-warm); }
.admin-sort.is-active { color: var(--accent); }

/* Right- and centre-aligned columns keep their label next to their numbers */
.admin-col-right  .admin-sort { justify-content: flex-end; }
.admin-col-center .admin-sort { justify-content: center; }

.admin-sort-arrow {
    font-size: 0.6rem;
    line-height: 1;
    /* The inactive hint is there to say "this sorts" without competing with
       the column that's actually sorted. */
    opacity: 0.25;
}
.admin-sort:hover .admin-sort-arrow  { opacity: 0.6; }
.admin-sort.is-active .admin-sort-arrow { opacity: 1; }

.admin-cell-strong { font-weight: 600; color: var(--ink); }
.admin-cell-muted  { color: var(--ink-muted); }
.admin-col-center  { text-align: center; }
.admin-col-right   { text-align: right; font-variant-numeric: tabular-nums; }

/* Users tab: per-account Dex cap, edited in place. The input reads as plain
   text until hovered or focused, so the table doesn't turn into a form. */
.admin-dex-limit {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
}
.admin-dex-used { color: var(--ink-muted); }
.admin-dex-limit.is-capped .admin-dex-used { color: var(--danger); font-weight: 600; }
.admin-dex-input {
    width: 4.5rem;
    padding: 0.2rem 0.4rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-variant-numeric: tabular-nums;
    text-align: right;
    -moz-appearance: textfield;
}
.admin-dex-input::-webkit-outer-spin-button,
.admin-dex-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.admin-dex-input::placeholder { color: var(--ink-soft); }
.admin-dex-input:hover { border-color: var(--border); }
.admin-dex-input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--paper);
}
.admin-dex-save {
    padding: 0.2rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--paper);
    color: var(--ink-soft);
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    /* Faded in only while editing (Enter saves too). Opacity rather than
       visibility so it stays clickable as the input blurs on mousedown. */
    opacity: 0;
    transition: opacity 0.15s;
}
.admin-dex-limit:focus-within .admin-dex-save,
.admin-table tbody tr:hover .admin-dex-save { opacity: 1; }
.admin-dex-save:hover { color: var(--ink); border-color: var(--ink); }

.admin-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    border: 1px solid transparent;
}
.admin-badge--google {
    color: var(--accent-3);
    background: rgba(74, 111, 165, 0.12);
}
.admin-badge--email {
    color: var(--ink-muted);
    background: var(--paper-warm);
}

.admin-badge--admin {
    color: var(--accent);
    background: var(--accent-light);
    border-color: var(--accent);
}

.admin-check { color: var(--accent); font-weight: 700; }
.admin-dash  { color: var(--ink-faint); }

.admin-empty {
    text-align: center;
    color: var(--ink-muted);
    padding: 2rem !important;
}

/* The Users tab carries ten columns. Tighter gutters so the whole row fits a
   desktop window; below that the wrapper still scrolls. */
.admin-table--wide { min-width: 1040px; font-size: 0.82rem; }
.admin-table--wide thead th,
.admin-table--wide tbody td {
    padding-left: 0.7rem;
    padding-right: 0.7rem;
}

/* Secondary line inside a cell: the time under a date, the start date under a
   subscription length. */
.admin-cell-sub {
    display: block;
    font-size: 0.75rem;
    color: var(--ink-faint);
}

/* ---- Overview: plots, links and the make-up of the accounts ---- */

/* The plots take the width; the panels beside them are read one line at a
   time and don't want it. */
.admin-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 1rem;
    align-items: start;
}

.admin-side {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.admin-plots {
    display: flex;
    flex-direction: column;
}

.admin-plot + .admin-plot {
    margin-top: 1.15rem;
    padding-top: 1.15rem;
    border-top: 1px solid var(--border-soft);
}

.admin-plot-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.7rem;
}

.admin-plot-peak {
    font-size: 0.75rem;
    color: var(--ink-faint);
    font-variant-numeric: tabular-nums;
}

.admin-plot-bars {
    display: flex;
    align-items: flex-end;
    gap: 0.35rem;
}

.admin-plot-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.admin-plot-value {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
    /* Fixed rather than min-height: the body's line-height makes a column with
       a figure in it taller than an empty one, and a few pixels of that pushes
       that column's bar below its neighbours' baseline. */
    height: 1.05rem;
    line-height: 1.05rem;
}

.admin-plot-track {
    width: 100%;
    height: 96px;
    display: flex;
    align-items: flex-end;
}

.admin-plot-bar {
    width: 100%;
    min-height: 3px;
    background: var(--accent);
    border-radius: 3px 3px 0 0;
    opacity: 0.75;
    transition: opacity 0.15s;
}
.admin-plot-col:hover .admin-plot-bar { opacity: 1; }

/* A month with nothing in it: a rule on the baseline rather than a bar of no
   height, which would read as a rendering fault. */
.admin-plot-zero {
    width: 100%;
    height: 2px;
    background: var(--border);
    border-radius: 2px;
}

.admin-plot-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--ink-faint);
    white-space: nowrap;
}

/* The month being filled in — marked on the label rather than the bar, which
   is a part figure and shouldn't be dressed up as a record. */
.admin-plot-col--current .admin-plot-label { color: var(--accent); }

/* ---- Jump-to links ---- */

.admin-links {
    list-style: none;
    margin: 0;
    padding: 0;
}

.admin-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.6rem;
    margin: 0 -0.6rem;
    border-radius: var(--radius-sm);
    color: var(--ink);
    transition: background 0.12s, color 0.12s;
}
.admin-link:hover { background: var(--paper-warm); }

.admin-link--out {
    margin-top: 0.5rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border-soft);
    border-radius: 0;
}
.admin-link--out:hover { background: transparent; color: var(--accent); }

.admin-link-main {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.admin-link-name {
    font-size: 0.875rem;
    font-weight: 600;
}

.admin-link-hint {
    font-size: 0.75rem;
    color: var(--ink-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-link-chevron {
    flex-shrink: 0;
    color: var(--ink-faint);
    transition: transform 0.15s, color 0.15s;
}
.admin-link:hover .admin-link-chevron { color: var(--accent); transform: translateX(2px); }

/* ---- Make-up of the accounts ---- */

.admin-mix {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
}

.admin-mix-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.6rem;
    margin-bottom: 0.35rem;
    font-size: 0.8rem;
}

.admin-mix-label { font-weight: 600; color: var(--ink); }

.admin-mix-count {
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
}
.admin-mix-count b { color: var(--ink); }

.admin-mix-track {
    height: 6px;
    background: var(--paper-warm);
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    overflow: hidden;
}

.admin-mix-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
}

.admin-feed-empty {
    padding: 2rem 1.1rem;
    text-align: center;
    color: var(--ink-muted);
    font-size: 0.875rem;
}

/* ---- Dex tab: conversations and transcripts ---- */

.admin-convos {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.admin-convo {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.admin-convo-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.1rem;
    cursor: pointer;
    list-style: none;
    font-size: 0.875rem;
}
.admin-convo-head::-webkit-details-marker { display: none; }
.admin-convo-head:hover { background: var(--accent-light); }

.admin-convo-title {
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-convo-meta {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    flex-shrink: 0;
    font-size: 0.8rem;
}

.admin-convo-count {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-light);
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    white-space: nowrap;
}

.admin-convo-body {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    padding: 1.1rem;
    border-top: 1px solid var(--border-soft);
    max-height: 26rem;
    overflow-y: auto;
}

.admin-turn {
    display: grid;
    grid-template-columns: 52px 1fr;
    gap: 0.75rem;
    align-items: start;
}

.admin-turn-role {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
    padding-top: 0.15rem;
}
.admin-turn--assistant .admin-turn-role { color: var(--accent); }

.admin-turn-text {
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--ink-soft);
    /* Transcripts are raw text — keep the author's newlines, and don't let a
       long unbroken string stretch the panel. */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (max-width: 860px) {
    /* The side panels drop under the plots rather than squeezing them — a
       12-column chart is the first thing a narrow column ruins. */
    .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .admin-stats { grid-template-columns: repeat(2, 1fr); }
    /* Twelve labelled columns don't fit a phone: the bars stay, the months
       under them go, and the title on each column keeps the figures. */
    .admin-plot-label { display: none; }
    .admin-plot-value { font-size: 0.62rem; }
    .admin-plot-bars { gap: 0.2rem; }
    .admin-convo-head { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .admin-convo-meta { flex-wrap: wrap; gap: 0.6rem; }
}

/* ------------------------------------------------------------------ */
/* Admin — standalone shell (app navbar, no marketing footer)          */
/* ------------------------------------------------------------------ */

/* The panel wears the same navbar as the app; only the identity-only
   account card is its own. */

/* Not a link — no hover lift, so it doesn't invite a click */
.nav-dots-item--static:hover { background: transparent; }

.admin-main {
    min-height: calc(100vh - 64px);
}

/* ------------------------------------------------------------------ */
/*  Placeholder panels for tabs that aren't built out yet              */
/* ------------------------------------------------------------------ */

.tab-stub-sub {
    margin: 0.35rem 0 0;
    color: var(--ink-muted);
    font-size: 0.92rem;
}

.tab-stub {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    padding: 3.5rem 2rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 14px;
}

.tab-stub-icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin-bottom: 0.25rem;
    color: var(--accent);
    background: var(--accent-light);
    border-radius: 50%;
}

.tab-stub-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ink);
}

.tab-stub-text {
    margin: 0;
    max-width: 46ch;
    color: var(--ink-muted);
    font-size: 0.92rem;
    line-height: 1.65;
}

.tab-stub .btn-ghost { margin-top: 0.75rem; }

@media (max-width: 640px) {
    .tab-stub { padding: 2.5rem 1.25rem; }
}

/* ------------------------------------------------------------------ */
/*  AI sparkle on the Analysis tab                                     */
/* ------------------------------------------------------------------ */

.nav-link-ai {
    position: absolute;
    top: 0.05rem;
    right: 0.02rem;
    display: block;
    line-height: 0;
    color: var(--accent);
    pointer-events: none;
}

/* The AI mark pops in: big star, then the small one, each overshooting a
   little. Plays on every page load in the nav, and once per Dex row in the
   calculator history (.ai-spark--intro, see calculator.js). */
@keyframes aiSparkPop {
    0%   { transform: scale(0) rotate(-60deg); opacity: 0; }
    60%  { transform: scale(1.35) rotate(12deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}
.nav-link-ai path,
.ai-spark--intro path {
    transform-box: fill-box;
    transform-origin: center;
    animation: aiSparkPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}
.nav-link-ai path:nth-child(2),
.ai-spark--intro path:nth-child(2) { animation-delay: 0.4s; }
@media (prefers-reduced-motion: reduce) {
    .nav-link-ai path,
    .ai-spark--intro path { animation: none; }
}

/* Mobile menu rows are full-width, so the mark sits inline after the label */
.nav-link-ai--inline {
    position: static;
    display: inline-block;
    margin-left: 0.4rem;
    vertical-align: 1px;
}

/* ------------------------------------------------------------------ */
/*  Overview "command centre" — three-column dashboard                 */
/* ------------------------------------------------------------------ */

.cc-grid {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) 300px;
    gap: 1rem;
    align-items: stretch;
    margin-top: 1.25rem;
}

/* No column stretches to match another. The centre used to, which meant the
   side column's stacked panels decided how tall the weekly chart was: three
   full panels there pulled the chart to roughly twice its readable height. */
.cc-rail,
.cc-main,
.cc-side { align-self: start; }

/* Instead the rail and the month card share one height, so the chart ends level
   with the donut panel next to it. The value is the rail's own content height
   (balances pair + donut panel); tying both to the same custom property is what
   keeps them flush if either one is edited later.

   Desktop only — under 1100px the side column moves below and the columns
   reflow, so a fixed height would just clip. */
@media (min-width: 1101px) {
    .cc-grid { --cc-row-h: 34.25rem; }
    .cc-rail,
    .cc-month,
    .cc-side { height: var(--cc-row-h); }
    /* Takes up the slack under the balances pair, so the rail ends level with
       the month card beside it — the trend chart simply gets taller. */
    .cc-trend-panel { flex: 1 1 auto; }

    /* The side panels split that height between them and let their lists do
       the scrolling. Three panels never fitted: headers, padding and notes
       alone ate most of the row, leaving about a row and a half each. Contacts
       moved to the full-width strip below so the other two get real room. */
    .cc-side > .cc-panel {
        display: flex;
        flex-direction: column;
        flex: 1 1 0;
        min-height: 0;
    }
    .cc-side .cc-list {
        flex: 1 1 auto;
        max-height: none;   /* the panel is the cap now */
    }
}

/* The strip splits on the same tracks as the columns above rather than on a
   grid of its own, so outstanding balances sit under the centre and what has
   been cleared lands under the side column, flush with it. */
.cc-panel--strip-main { grid-column: 1 / 3; }
.cc-panel--strip-side { grid-column: 3 / -1; }

/* One card for the month: the headline figure and the breakdown of that same
   figure, divided rather than detached. */
.cc-month {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
}
.cc-month-split {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    margin-top: 1.15rem;
    padding-top: 1.15rem;
    border-top: 1px solid var(--border-soft);
}

.cc-rail,
.cc-rail-balances,
.cc-main,
.cc-side {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

/* Sits under the owe/owed pair as their summary, so it is deliberately quieter
   than either card — a rule, not a third card. */
/* The result of the two cards either side, so it is drawn as a pill between
   them rather than as loose text: coloured by direction, labelled, and tied to
   the pair by a rule in the same colour. A bare figure floating between two
   cards did not say what it was. */
/* The gap between the two cards and the pill, and the length of the rules that
   bridge it — one value, so they cannot drift apart. */
.cc-rail-balances {
    --net-gap: 0.5rem;
    gap: var(--net-gap);
}

.cc-net {
    position: relative;
    align-self: center;
    display: inline-flex;
    align-items: baseline;
    gap: 0.4rem;
    margin: 0;
    padding: 0.22rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--net-tone, var(--border));
    background: var(--paper-card);
    font-size: 0.74rem;
    line-height: 1;
    color: var(--ink-muted);
    z-index: 1;
}

/* Joined to the card above and below by a short rule each, so the three read as
   one figure derived from two. Each rule takes the colour of the card it meets
   — red up to what you owe, green down to what you are owed — rather than the
   pill's own, which says only which way the difference fell. */
.cc-net::before,
.cc-net::after {
    content: '';
    position: absolute;
    left: 50%;
    width: 1px;
    /* Exactly the gap, so each rule meets the card it points at. */
    height: var(--net-gap);
}
.cc-net::before { bottom: 100%; background: var(--danger); }
.cc-net::after  { top: 100%;    background: var(--accent); }

.cc-net-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-faint);
}

.cc-net strong {
    position: relative;
    display: inline-block;
    font-weight: 800;
    font-size: 0.92rem;
    font-variant-numeric: tabular-nums;
    color: var(--net-tone, var(--ink));
}

.cc-net--up   { --net-tone: var(--accent); }
.cc-net--down { --net-tone: var(--danger); }

.cc-panel {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem 1.35rem;
}

/* Stands in for the category icon the expense rows carry, so settlement rows
   line up with them in the same column. */
.cc-settle-mark {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    flex: 0 0 auto;
    margin: 0 0.35rem;
}

.cc-settle-mark--in  { background: var(--accent); }
.cc-settle-mark--out { background: var(--danger); }

.cc-panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
}

.cc-panel-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--ink-muted);
}

.cc-panel-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.cc-panel-link {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
}
.cc-panel-link:hover { text-decoration: underline; }

.cc-empty-note {
    font-size: 0.85rem;
    color: var(--ink-muted);
    line-height: 1.55;
}

.cc-note {
    margin-top: 0.75rem;
    font-size: 0.72rem;
    color: var(--ink-faint);
    line-height: 1.5;
}

/* --- Dex suggestion chips in the ask bar --- */

/* One suggestion, on the input's row, just left of send — close at hand
   without adding a row to the bar. A single chip has the room to show its
   question in full; it only ellipsizes on a bar too narrow for it. */
.cc-chips {
    display: flex;
    flex-shrink: 1;
    min-width: 0;
    max-width: 55%;
}
.cc-chips:empty { display: none; }

.cc-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 500;
    line-height: 1.3;
    color: var(--ink-soft);
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.32rem 0.8rem;
    cursor: pointer;
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

/* The question in its own span so it can ellipsize while the arrow after it
   stays put. */
.cc-chip-text { overflow: hidden; text-overflow: ellipsis; }

/* A small arrow that says "send this", in the accent, nudged on hover. */
.cc-chip:not(.cc-chip--skeleton)::after {
    content: "\2197";
    font-size: 0.72rem;
    color: var(--accent);
    opacity: 0.6;
    transition: transform 0.15s, opacity 0.15s;
}

.cc-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}
.cc-chip:hover::after { opacity: 1; transform: translate(1px, -1px); }
.cc-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* On a phone the input needs the whole bar. */
@media (max-width: 600px) {
    .cc-chips { display: none; }
}

/* Shimmering placeholders while the starter fetch is in flight — same
   treatment as the Dex modal's own starter skeleton and the greeting/quote
   above. Swapped for real chips (or removed outright on failure) once the
   fetch settles. */
.cc-chip--skeleton {
    width: 240px;
    height: 1.7rem;
    border-color: transparent;
    background: linear-gradient(90deg, var(--paper-warm, #f5f4f0) 25%, var(--border) 50%, var(--paper-warm, #f5f4f0) 75%);
    background-size: 200% 100%;
    animation: dex-skeleton-shimmer 1.4s ease-in-out infinite;
    cursor: default;
}

/* --- Insight strip --- */

.cc-insight {
    position: relative;
    overflow: hidden;               /* clips the loading sliver to the corners */
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin-top: 0.9rem;
    padding: 0.8rem 1rem;
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
}

/* Nothing to say yet — Dex's line may still arrive and un-hide it. */
.cc-insight--empty { display: none; }

.cc-insight-mark { color: var(--accent); line-height: 0; padding-top: 2px; }

/* While Dex is working the sparkle comes alive: the big star turns and
   breathes, the small one twinkles half a beat behind it. Both start and end
   each cycle at rest, so it settles rather than snaps when the work is done. */
.cc-insight-mark path { transform-box: fill-box; transform-origin: center; }
.cc-insight--loading .cc-spark-big,
.cc-insight--fetching .cc-spark-big { animation: ccSparkTurn 1.6s ease-in-out infinite; }
.cc-insight--loading .cc-spark-small,
.cc-insight--fetching .cc-spark-small { animation: ccSparkTwinkle 1.6s ease-in-out 0.4s infinite; }
.cc-insight--loading .cc-insight-mark svg,
.cc-insight--fetching .cc-insight-mark svg {
    filter: drop-shadow(0 0 3px color-mix(in srgb, var(--accent) 45%, transparent));
}

@keyframes ccSparkTurn {
    0%, 100% { transform: rotate(0deg) scale(1); }
    50%      { transform: rotate(90deg) scale(1.25); }
}

@keyframes ccSparkTwinkle {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(0.45); opacity: 0.35; }
}

.cc-insight-main { flex: 1; min-width: 0; }

/* One line on wider screens, two on a phone (--cc-lines). The strip only
   shows what fits (dashboard.html skips cards that don't, and the ask bar
   moves longer answers to Messages); the clamp is the backstop. */
.cc-insight { --cc-lines: 1; }
@media (max-width: 600px) { .cc-insight { --cc-lines: 2; } }
.cc-insight-line {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: var(--cc-lines);
    line-clamp: var(--cc-lines);
    overflow: hidden;
    white-space: normal;
}

.cc-insight-text {
    position: relative;
    font-size: 0.9rem;
    color: var(--ink-soft);
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The strip's shimmering bar, shown while it answers the ask bar
   (--loading, below). Its own tint rather than the default grey shimmer —
   the strip's background is already accent-tinted, and a neutral grey bar
   read as a mismatched patch sitting on top of it. Compound selector: a
   plain .cc-insight-skel rule is the same specificity as .cc-skel-line's
   own background and loses to it on source order, so this needs the extra
   class to actually win. */
.cc-insight-skel.cc-skel-line {
    width: 72%;
    background: linear-gradient(90deg,
        color-mix(in srgb, var(--accent) 14%, var(--accent-light)) 25%,
        color-mix(in srgb, var(--accent) 32%, var(--accent-light)) 50%,
        color-mix(in srgb, var(--accent) 14%, var(--accent-light)) 75%);
    background-size: 200% 100%;
}
#ccInsightText { transition: opacity 0.35s ease; }

/* --- The same strip while it's answering the ask bar --- */

/* Held to the same line(s) as a daily card — anything longer has already
   gone to Messages. */
.cc-insight--answer .cc-insight-text { color: var(--ink); }
.cc-insight--error  .cc-insight-text { color: var(--danger, #c0392b); }

/* While Dex works, the line holds the current step (the chat modal's
   spinner-to-tick pill) and then the insight's shimmering bar — set inline
   here rather than laid over text, since there's no text under it yet. */
.cc-insight-step:empty { display: none; }
/* No pill of its own on the strip, which is already tinted. */
.cc-insight-step .dex-activity-item {
    margin-right: 0.75rem;
    padding: 0;
    background: none;
    font-size: 0.8rem;
    vertical-align: middle;
}
.cc-insight--loading .cc-insight-skel.cc-skel-line {
    display: inline-block;
    position: static;
    width: min(55%, 360px);
    vertical-align: middle;
}

/* The answer arrives whole and settles in. */
.cc-insight--reveal #ccInsightText { animation: ccReveal 0.4s ease both; }
@keyframes ccReveal {
    from { opacity: 0; transform: translateY(3px); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .cc-insight--reveal #ccInsightText { animation: none; }
    .cc-insight-mark path { animation: none !important; }
}

/* --- Headline spend --- */

.cc-spend-value {
    font-size: 2.9rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.04em;
    line-height: 1.05;
    margin: 0.35rem 0 0.5rem;
    font-variant-numeric: tabular-nums;
}

.cc-spend-meta {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
    font-size: 0.82rem;
}

.cc-delta { font-weight: 600; }
.cc-delta--down { color: var(--accent); }
.cc-delta--up   { color: var(--danger); }

.cc-spend-count { color: var(--ink-muted); }

/* Pace line: secondary to the headline, so it sits at note size rather than
   competing with the delta chip above it. */
.cc-pace {
    margin: 0.55rem 0 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--ink-muted);
}

.cc-pace strong {
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

/* --- Weekly stacked bars --- */

/* Takes whatever height the month card was stretched to by the taller rail
   beside it, so a short legend leaves no dead space under the chart. */
.cc-weeks {
    display: flex;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
    position: relative;      /* the tooltip positions against the chart */
}

/* --- Week tooltip --- */

.cc-week-tip {
    position: absolute;
    z-index: 5;
    /* Sized by its widest line, which is the change sentence. The rows under it
       are a glyph and a figure, so a fixed floor only left a gulf between
       them. */
    min-width: 0;
    white-space: nowrap;
    padding: 0.65rem 0.85rem;
    /* Solid, not glass. Both charts clamp their box inside the plot, so it sits
       over the bars rather than in the margin above them — and a column running
       through the sentence made the figures hard to pick out. Opaque fill and a
       shadow to lift it off the chart; no blur, no glyph halo, neither of which
       has anything left to do. */
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 0.75rem;
    line-height: 1.5;
    pointer-events: none;    /* never steals the hover it was opened by */
    transform: translateX(-50%);   /* top is set outright, so it can be clamped */
}

.cc-week-tip-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.9rem;
    margin-bottom: 0.3rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border-soft);
    color: var(--ink-muted);
}

/* The trend tooltip has no category list under it, so it is cut tighter than
   the week tooltip its padding is set for. */
#ccTrendTip {
    min-width: 0;
    padding: 0.4rem 0.6rem;
    line-height: 1.35;
}

/* Month on the left, figure hard right — the pair reads as one line. */
#ccTrendTip .cc-week-tip-head { gap: 1.1rem; }

.cc-trend-tip-title,
.cc-week-tip-title {
    color: var(--ink-muted);
    font-weight: 600;
}

/* The change spelled out, coloured the way the column labels are: a rise in
   spending is the unwelcome direction. Shared by both charts' tooltips — the
   sentence is the same sentence, only the period it compares differs. */
.cc-trend-tip-change,
.cc-week-tip-change {
    margin: 0;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.cc-trend-tip-change.is-up,    .cc-week-tip-change.is-up    { color: var(--danger); }
.cc-trend-tip-change.is-down,  .cc-week-tip-change.is-down  { color: var(--accent); }
.cc-trend-tip-change.is-level, .cc-week-tip-change.is-level { color: var(--ink-soft); }

/* The part-run period's caveat — quieter than the figure it qualifies. */
.cc-trend-tip-note,
.cc-week-tip-note {
    margin: 0.1rem 0 0;
    color: var(--ink-muted);
    font-size: 0.7rem;
}

/* The split is a list, and the sentence above it is prose: the gap between them
   is what separates the two, since a second rule inside a box this small would
   cut it into thirds. */
.cc-week-tip-change + .cc-week-tip-rows,
.cc-week-tip-note + .cc-week-tip-rows { margin-top: 0.45rem; }

/* Only the hovered week's own figure stands down — the tooltip opens exactly
   where it sits. The other weeks keep theirs: unlike the trend chart's
   percentages, these are the totals the bars are read by, and blanking them
   would empty the chart around the one column being pointed at. */
.cc-week--active .cc-week-amount { visibility: hidden; }

/* Every printed change stands down while the tooltip is up. The hovered
   column's label would sit under the box, and the other five are percentages
   competing with the one the box is spelling out. Hidden rather than removed,
   so the space above each bar is the same either way. */
.cc-trend--tipped .cc-trend-delta { visibility: hidden; }

/* A week still to come has no categories under it, so the head's rule would
   hang across an empty box with nothing to divide. */
.cc-week-tip-head--alone {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: 0;
}

/* The figure half of the head, set hard right against the week's own label. */
.cc-week-tip-total {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

/* Mark on the left, figure hard right — with the name gone there is no middle
   column left to carry. Two side by side once there is more than one
   category — see the tooltip builder for --tip-cols. */
.cc-week-tip-rows {
    display: grid;
    grid-template-columns: repeat(var(--tip-cols, 1), auto);
    column-gap: 1.1rem;
    row-gap: 0.4rem;
}

.cc-week-tip-row {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 0.6rem;
    color: var(--ink-soft);
}

/* Same tinted tile as the Recent rows and the legend, cut down slightly to
   fit the tooltip's tighter rows. */
.cc-cat-mark--tip {
    width: 1.3rem;
    height: 1.3rem;
}
.cc-cat-mark--tip svg { width: 13px; height: 13px; }

.cc-week-tip-amt {
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    text-align: right;
}

/* The column under the pointer lifts slightly out of the row. */
.cc-week--active .cc-week-stack { filter: brightness(1.06); }
.cc-week:focus-visible { outline: none; }
.cc-week:focus-visible .cc-week-stack {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* No gap between columns: the tracks butt up against each other so their
   bottom borders join into one baseline under the bars, with the labels below
   it. The bars are spaced by their own max-width inside a centred track. */
.cc-week {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}

/* Sits on the cap of its own bar rather than in a shared row at the top of the
   chart, where every week's figure read at the same height whatever the bar
   was doing. Positioned off the track's bottom edge by the same percentage the
   stack is tall, so it rides the cap exactly. */
.cc-week-amount {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    pointer-events: none;
}

/* Every track is the same box — they share the row height — and the stack
   inside it is a percentage of the biggest week. It grows past its floor when
   the card has spare height to give. */
.cc-week-track {
    position: relative;     /* the cap figure positions against this */
    width: 100%;
    flex: 1 1 auto;
    min-height: 122px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    border-bottom: 1px solid var(--border);
}

/* The dashboard's version sits in a card with a header and total above it,
   so its track ends up flexed well past the shared floor. The expenses
   page's chart tab has no header eating height above the chart, so it reads
   short next to the dashboard's at the same floor — given a taller one here
   rather than raising the shared minimum every other user of this component
   would inherit. Left alone below the point .cc-week-amount already drops,
   where the compact mobile chart is deliberate. */
@media (min-width: 541px) {
    #expViewChart .cc-week-track { min-height: 260px; }
}

/* Capped rather than filling the track, so the leftover reads as air — but
   wide enough that a thin category segment is still a band and not a line. */
.cc-week-stack {
    width: 100%;
    max-width: 2.9rem;
    min-height: 4px;
    display: flex;
    flex-direction: column-reverse;   /* largest category at the base */
    /* Segments square off now that they touch, so the rounded data-end belongs
       to the stack as a whole. */
    border-radius: 4px 4px 0 0;
    overflow: hidden;
    /* Rises from the baseline on first paint — see animateBarsRise(), which
       drives --rise rather than the height property: several of these boxes
       size themselves as a percentage of a flex or absolutely-positioned
       ancestor, and rewriting that percentage after the fact doesn't
       reliably re-resolve. A custom property composes with each element's
       own transform (the projection outline also centres itself with one)
       without either clobbering the other. */
    transform: scaleY(var(--rise, 1));
    transform-origin: bottom;
    transition: transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Segments are solid in the category's colour, ringed on all four sides by the
   pale wash of that colour.

   They touch, so the stack reads as one column: two adjacent rings are what
   divide one segment from the next. Nothing is taken out of the bar for a gap,
   so each item's height stays exactly proportional — a flex gap would lengthen
   a six-category week and leave a one-category week untouched, and the columns
   would stop being comparable. */
.cc-week-seg {
    position: relative;
    display: block;
    min-height: 6px;
    transition: opacity 0.15s;
}

.cc-week-seg::before {
    content: '';
    position: absolute;
    inset: 0;
    background-color: var(--seg);
}

/* Hovering a legend entry singles its category out across every week — the
   rest fade rather than disappear, so the stack's overall shape stays
   visible while the one segment being asked about stands out. */
.cc-weeks--dim .cc-week-seg { opacity: 0.2; }
.cc-weeks--dim .cc-week-seg--hl { opacity: 1; }

/* A week that has come and gone with nothing in it — flat on the baseline,
   which is a real answer, unlike the dashed outline of a week not yet had. */
.cc-week-zero {
    width: 100%;
    max-width: 2.9rem;    /* matches the bars, so an empty week isn't wider */
    height: 2px;
    background: var(--border);
    border-radius: 2px;
}

/* A week that hasn't happened and can't be projected either — no pace to read,
   because nothing has been spent this month yet. The box is kept for the
   column's height and as the hover target that opens "Still to come". */
.cc-week-ghost {
    width: 100%;
    max-width: 2.9rem;    /* matches the bars, so a ghost isn't wider */
    height: 22%;
}

/* The projection: the week's shape at the month's pace, outlined rather than
   filled so it never reads as money already spent. Absolute, so the running
   week's real stack sits inside it and the gap between the two is the part of
   the week still to be had. Open at the foot, where the track's own baseline
   already closes it — the same outline the six-month chart draws over its
   running month. */
.cc-week-proj {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 100%;
    max-width: 2.9rem;
    border: 1px dashed var(--border);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    background: none;
    pointer-events: none;
    /* Centring and the first-paint rise share one transform — see the note
       on .cc-week-stack. */
    transform: translateX(-50%) scaleY(var(--rise, 1));
    transform-origin: bottom;
    transition: transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.cc-week-label {
    font-size: 0.7rem;
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.cc-week-label--future { color: var(--ink-faint); }

/* --- Weekly chart key --- */

.cc-week-key {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.1rem;
    margin-top: 0.9rem;
}

.cc-week-key-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--ink-soft);
    cursor: default;
}

/* The category's own icon, tinted, boxed the same way the Recent and
   upcoming rows tag their category — so the legend reads as the same mark
   used everywhere else rather than a bare glyph of its own. */
.cc-key-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: var(--radius-sm);
}

.cc-key-dot svg { width: 14px; height: 14px; }

.cc-key-amount {
    font-weight: 600;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

/* --- Six-month trend (rail) --- */

.cc-trend-panel { display: flex; flex-direction: column; }

.cc-trend {
    position: relative;      /* the tooltip positions against this */
    display: flex;
    align-items: stretch;
    gap: 5px;
    flex: 1 1 auto;
    min-height: 94px;
    margin-top: 0.85rem;
}

.cc-trend-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
    border-radius: var(--radius-sm);
}

.cc-trend-col:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cc-trend-track {
    position: relative;
    flex: 1 1 auto;
    border-bottom: 1px solid var(--border);
}

/* One series, so one colour — a per-month hue would encode nothing the height
   does not already say. */
.cc-trend-bar,
.cc-trend-ghost {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transform: scaleY(var(--rise, 1));
    transform-origin: bottom;
}

.cc-trend-bar { background: var(--accent); }

/* The running month is part-finished; its projection is an outline so it never
   reads as money already spent. */
.cc-trend-ghost {
    border: 1px dashed var(--border);
    border-bottom: none;
    background: none;
}

.cc-trend-col.is-current .cc-trend-bar { background: var(--accent); opacity: 0.55; }

/* The column under the cursor lifts a shade, so it's clear which figure the
   tooltip is quoting. Brightness rather than a second colour: it lands the same
   way on the running month's faded bar and on the accent at full strength.
   Rises from the baseline on first paint — see animateBarsRise(). */
.cc-trend-bar,
.cc-trend-ghost {
    transition: filter 0.12s ease, border-color 0.12s ease,
                transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.cc-trend-col--tipped .cc-trend-bar { filter: brightness(1.45); }
.cc-trend-col--tipped .cc-trend-ghost { border-color: var(--accent); }

.cc-trend-col:hover .cc-trend-bar,
.cc-trend-col:focus-visible .cc-trend-bar { opacity: 1; filter: brightness(1.08); }

.cc-trend-label {
    font-size: 0.62rem;
    text-align: center;
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
}

.cc-trend-col.is-current .cc-trend-label { color: var(--ink-soft); font-weight: 600; }

/* Whole-percent change against the month before, sitting on the bar's own cap
   rather than in a row underneath — at a glance the figure belongs to the
   column it labels. Positioned off the baseline by the same percentage the bar
   is tall. */
.cc-trend-delta {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.56rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    pointer-events: none;
}

.cc-trend-delta.is-up   { color: var(--danger); }
.cc-trend-delta.is-down { color: var(--accent); }

.cc-trend-note {
    margin: 0.7rem 0 0;
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--ink-muted);
}

.cc-trend-note strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* --- Top-category donut --- */

.cc-donut-panel { text-align: center; }

.cc-donut {
    display: block;
    width: 128px;
    height: 128px;
    margin: 0.9rem auto 0.75rem;
}

.cc-donut-track { fill: none; stroke: var(--border-soft); stroke-width: 16; }

.cc-donut-slice {
    fill: none;
    stroke-width: 16;
    cursor: pointer;
    transition: stroke-width 0.15s ease, opacity 0.15s ease;
}
.cc-donut-slice:focus { outline: none; }

/* Probing a wedge fades the rest, so the figures below can only be read as
   belonging to the one under the cursor. */
.cc-donut.is-probing .cc-donut-slice { opacity: 0.3; }
.cc-donut.is-probing .cc-donut-slice.is-active { opacity: 1; stroke-width: 19; }

.cc-donut-caption {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    font-size: 0.88rem;
    min-height: 2.6em;      /* reserved, so the panel doesn't twitch on hover */
}
.cc-donut-cat {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.3;
}

/* Inherits the category's own colour, set by the script; the label beside it
   stays ink so the pair doesn't read as a coloured heading. */
.cc-donut-icon { display: inline-flex; align-items: center; line-height: 1; }
.cc-donut-icon svg { width: 15px; height: 15px; }
.cc-donut-meta {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
}

/* Category mark for the Recent and upcoming rows: the icon carries the
   category on its own, so a narrow panel spends its width on the title and
   amount instead of a repeated word. */
.cc-cat-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: center;      /* the rows are baseline-aligned; this isn't text */
    flex-shrink: 0;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: var(--radius-sm);
}

.cc-cat-mark svg { width: 14px; height: 14px; }

/* --- Recent / upcoming lists --- */

.cc-list { display: flex; flex-direction: column; }

/* A panel is as tall as its list, so a busy month used to stretch the side
   column past 1000px. Cap it instead and scroll the rest. The first row has no
   top padding, hence the odd-looking sums: 53px + n x 62px. */
.cc-side .cc-list,
.cc-list--scroll {
    max-height: 17rem;              /* ~4.5 rows */
    overflow-y: auto;
    overscroll-behavior: contain;
}
/* Three rows. Sized for the 62px row: Recent's first row is shorter (no top
   padding), so it clears three and shows a sliver of the fourth as the cue. */
.cc-panel--list3 .cc-list { max-height: 11.65rem; }

/* Contacts, three rows. Its rows hang their padding on the settle button, so
   there is no short first row to borrow from the way Recent has — three full
   62px rows, plus a sliver of the fourth as the cue that it scrolls. */
.cc-contacts-list { max-height: 12.4rem; }

.cc-list-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--border-soft);
}
.cc-list-row:last-child { border-bottom: none; }
.cc-list-row:first-child { padding-top: 0; }

/* Rows that are a link to the prefilled add form. The padding moves onto the
   anchor so the whole row, not just the text, is the hit area. */
.cc-list-row--action { padding: 0; }

/* Rows that open the expense detail popup. The negative margin lets the hover
   tint bleed past the text without moving the row. */
.cc-list-row--clickable {
    cursor: pointer;
    padding-left: 0.4rem;
    padding-right: 0.4rem;
    margin-left: -0.4rem;
    margin-right: -0.4rem;
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}
.cc-list-row--clickable:hover { background: var(--row-hover); }
.cc-list-row--clickable:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* --- One-click settle rows (Contacts panel) --- */

.cc-settle-form { width: 100%; }

/* Laid out like .cc-list-link, but it submits rather than navigates. */
.cc-settle-btn {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    padding: 0.55rem 0.4rem;
    margin: 0 -0.4rem;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.cc-settle-btn:hover,
.cc-settle-btn:focus-visible { background: var(--accent-light); }
.cc-settle-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Both states occupy the same grid cell so the swap can't reflow the row —
   the cell is as wide as the longer of the two from the start. */
.cc-settle-state { display: grid; }
.cc-settle-state > span {
    grid-area: 1 / 1;
    transition: opacity 0.15s ease;
}

.cc-settle-state-hover {
    opacity: 0;
    color: var(--accent);
    font-weight: 600;
    white-space: nowrap;
}

.cc-settle-btn:hover .cc-settle-state-rest,
.cc-settle-btn:focus-visible .cc-settle-state-rest { opacity: 0; }
.cc-settle-btn:hover .cc-settle-state-hover,
.cc-settle-btn:focus-visible .cc-settle-state-hover { opacity: 1; }

.cc-list-link {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    padding: 0.55rem 0.4rem;
    margin: 0 -0.4rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}

.cc-list-link:hover { background: var(--paper-warm); }
.cc-list-link:hover .cc-list-title { color: var(--accent); }
.cc-list-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Takes the free space so the leading category mark stays tucked against the
   title rather than being pushed away by space-between. */
.cc-list-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; flex: 1 1 auto; }

.cc-list-title {
    font-size: 0.87rem;
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cc-list-sub { font-size: 0.74rem; color: var(--ink-muted); }

.cc-list-amount {
    font-size: 0.87rem;
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* --- Footer quote --- */

/* Sits under the name in the dashboard header, so it stays a quiet second
   line rather than the page-closing footnote it used to be.

   Shown in full — no ellipsis. This used to be a nowrap flex row that clipped
   the text, which cut quotes off mid-word. The curated pool tops out at ~150
   characters, so normal inline flow fits on one line at desktop widths and
   wraps to a second when the window is narrow. max-width keeps the measure
   readable instead of letting it stretch the full page. */
/* Skeleton bar, hidden until a state shows it. Used by the insight strip
   while it's answering the ask bar (.cc-insight--loading). */
.cc-skel-line {
    display: none;
    position: absolute;
    inset: 0;
    height: 0.8em;
    margin: auto 0;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--paper-warm, #f5f4f0) 25%, var(--border) 50%, var(--paper-warm, #f5f4f0) 75%);
    background-size: 200% 100%;
    animation: dex-skeleton-shimmer 1.4s ease-in-out infinite;
}

/* The header is a flex row; without this the text column refuses to shrink
   and the quote pushes the Add expense button off to the right. */
.dashboard-header > div { min-width: 0; }

/* --- Responsive --- */

@media (max-width: 1100px) {
    /* Side column drops under the main pair */
    .cc-grid { grid-template-columns: 220px minmax(0, 1fr); }
    .cc-side { grid-column: 1 / -1; flex-direction: row; }
    .cc-side > .cc-panel { flex: 1 1 0; min-width: 0; }
    /* Two tracks now, and the narrow one is 220px — too tight for a list of
       names and figures, so the strip stacks instead of splitting. */
    .cc-panel--strip-main,
    .cc-panel--strip-side { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
    .cc-grid { grid-template-columns: minmax(0, 1fr); }
    .cc-rail { flex-direction: row; flex-wrap: wrap; }
    /* The pair turns into a row of two alongside the donut below it. */
    .cc-rail-balances { flex: 1 1 100%; flex-direction: row; flex-wrap: wrap; }
    .cc-rail-balances > .stat-card { flex: 1 1 8rem; }
    /* The pair turn into a row, so the summary that sits between them on
       desktop drops to a line of its own underneath. */
    .cc-rail-balances > .cc-net { flex: 1 1 100%; order: 3; }
    .cc-side { flex-direction: column; }
    .cc-spend-value { font-size: 2.4rem; }
}

@media (max-width: 540px) {
    /* Five columns of "$1,234.56" don't fit — the labels and the key carry it,
       and each bar keeps its figure on hover. */
    .cc-week-amount { display: none; }
    .cc-week-track { height: 96px; }
    .cc-week-label { font-size: 0.62rem; }
}

/* ------------------------------------------------------------------ */
/* Calculator — a popover off the nav icon, not a page                 */
/* ------------------------------------------------------------------ */

.nav-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--ink-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.nav-icon-btn:hover { background: var(--paper-warm); color: var(--ink); }
.nav-icon-btn[aria-expanded="true"] { background: var(--accent-light); color: var(--accent); }

.calc-pop { position: fixed; inset: 0; z-index: 900; }
.calc-pop[hidden] { display: none; }

/* Catches the click-outside; stays see-through so the page underneath is
   still readable while you're punching numbers about it. */
.calc-pop-backdrop { position: absolute; inset: 0; }

.calc-pop-panel {
    position: absolute;
    top: 72px;
    right: 1.5rem;
    width: min(496px, calc(100vw - 3rem));
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    padding: 0.7rem 0.85rem 0.85rem;
    /* Clear glass: a light tint, no blur, so the page reads through untouched. */
    background: color-mix(in srgb, var(--paper) 15%, transparent);
    border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
    border-radius: var(--radius-lg);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.14);
    animation: calcPopIn 0.14s ease-out;
}

.calc-pop-panel:focus { outline: none; }

@keyframes calcPopIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: none; }
}

.calc-pop-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.7rem;
}

.calc-pop-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.calc-pop-close {
    display: inline-flex;
    width: 26px;
    height: 26px;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--ink-faint);
    cursor: pointer;
}

.calc-pop-close:hover { background: var(--paper-warm); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
    .calc-pop-panel { animation: none; }
}

@media (max-width: 700px) {
    .calc-pop-panel {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 88vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
    /* A sheet from the bottom wants a dimmed page behind it. */
    .calc-pop-backdrop { background: rgba(0, 0, 0, 0.35); }
}

/* Calculator + its side history laid out together */
.calc-workspace {
    display: flex;
    gap: 0.75rem;
    align-items: stretch;
    flex-wrap: wrap;
}
.calc-workspace .calc-card {
    flex: 1 1 210px;
    max-width: 252px;
    margin: 0;
}
.calc-workspace .calc-history {
    flex: 1 1 175px;
    min-width: 0;
}

/* Standard calculator */
.calc-card {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1rem;
    max-width: 282px;
}

.calc-display {
    position: relative;
    background: var(--paper);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    /* Left padding clears the copy button parked in the gutter. */
    padding: 0.65rem 0.8rem 0.65rem 2.35rem;
    margin-bottom: 0.7rem;
    text-align: right;
    overflow: hidden;
}

/* Copy the answer out. Bottom-left, level with the big figure rather than the
   expression line, because the figure is what it copies. */
.calc-copy {
    position: absolute;
    left: 0.45rem;
    bottom: 0.5rem;
    display: inline-flex;
    width: 26px;
    height: 26px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--ink-faint);
    cursor: pointer;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.calc-copy:hover { color: var(--ink); background: var(--paper-warm); border-color: var(--border); }
.calc-copy:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.calc-copy-tick { display: none; }
.calc-copy.is-copied { color: var(--accent); }
.calc-copy.is-copied .calc-copy-icon { display: none; }
.calc-copy.is-copied .calc-copy-tick { display: block; }

/* Nothing to copy (a bare 0, or an error) — kept in place so the display
   doesn't shift, just unreachable. */
.calc-copy[disabled] { opacity: 0.35; cursor: default; }
.calc-copy[disabled]:hover { color: var(--ink-faint); background: none; border-color: transparent; }

.calc-sr-live {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.calc-display-prev {
    font-size: 0.78rem;
    color: var(--ink-faint);
    min-height: 1.2em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-display-main {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-pad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.38rem;
}

.calc-btn {
    aspect-ratio: 1;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.calc-btn:hover { background: var(--paper-warm); border-color: var(--ink-muted); }
.calc-btn:active { transform: scale(0.95); }

.calc-btn--op { color: var(--ink-muted); background: var(--paper-warm); }

.calc-btn--accent { color: var(--accent); background: var(--accent-light); border-color: transparent; }
.calc-btn--accent:hover { background: var(--accent-light); border-color: var(--accent); }

.calc-btn--equals { background: var(--accent); color: #fff; border-color: transparent; }
.calc-btn--equals:hover { background: var(--accent-hover); }

/* Equals runs along the bottom row beside backspace, so it drops the square
   aspect ratio and stretches to the height its row-mate sets. */
.calc-btn--wide { grid-column: span 3; aspect-ratio: auto; }

/* History panel — sits beside the calculator */
.calc-history {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
}
.calc-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.7rem;
}
.calc-history-title {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-muted);
}
.calc-history-clear {
    background: none;
    border: none;
    color: var(--ink-faint);
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.2rem 0.35rem;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}
.calc-history-clear:hover { color: var(--danger); background: var(--danger-light); }

/* min-height: 0 is what makes the overflow bite — without it the list takes its
   content height, stretching the whole popover instead of scrolling. The cap
   keeps the column shorter than the keypad beside it, so a long history never
   leaves dead space under the pad. */
.calc-history-list {
    display: flex;
    flex-direction: column;
    gap: 0.42rem;
    flex: 1 1 auto;
    min-height: 0;
    max-height: min(360px, calc(100vh - 260px));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.calc-history-empty { font-size: 0.82rem; color: var(--ink-faint); line-height: 1.5; }

.calc-history-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    background: var(--paper);
    font-family: var(--font);
}
.calc-history-item--calc { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.calc-history-item--calc:hover { border-color: var(--accent); background: var(--accent-light); }

.calc-hist-expr {
    font-size: 0.78rem;
    color: var(--ink-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.calc-hist-expr-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* Where a row came from: ƒx for an amount-field formula, the AI mark for Dex. */
.calc-hist-tag {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    line-height: 0;
}
.calc-hist-tag--fx {
    font-size: 0.68rem;
    font-weight: 700;
    font-style: italic;
    line-height: 1;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    color: var(--accent);
    background: var(--accent-light);
}
.calc-hist-tag--dex { color: var(--accent); }

.calc-hist-result {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 680px) {
    .calc-workspace .calc-card,
    .calc-workspace .calc-history { flex: 1 1 100%; max-width: 100%; }
    .calc-history-list { max-height: 260px; }
}

@media (max-width: 640px) {
    .calc-card { max-width: 100%; }
}

/* ------------------------------------------------------------------ */
/* Messages — past Dex conversations (read-only)                       */
/* ------------------------------------------------------------------ */

.convo-list {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.convo-item + .convo-item { border-top: 1px solid var(--border-soft); }

.convo-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.95rem 1.1rem;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}
.convo-link:hover { background: var(--accent-light); }

.convo-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }

.convo-title {
    font-weight: 600;
    color: var(--ink);
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.convo-meta  { font-size: 0.8rem; color: var(--ink-faint); }
.convo-date  { font-size: 0.82rem; color: var(--ink-faint); flex-shrink: 0; }

.convo-note {
    margin-top: 1rem;
    font-size: 0.83rem;
    color: var(--ink-faint);
    line-height: 1.6;
}

.convo-back {
    display: inline-block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: var(--ink-muted);
    text-decoration: none;
}
.convo-back:hover { color: var(--accent); }

/* Transcript — mirrors the live chat bubbles, without the input */
.convo-thread {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.2rem;
}

.convo-msg { display: flex; gap: 0.55rem; align-items: flex-start; }
.convo-msg--user { justify-content: flex-end; }

.convo-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Bubble with its time underneath; the pair hugs its own side. */
.convo-msg-body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    max-width: 78%;
    min-width: 0;
}
.convo-msg--user .convo-msg-body { align-items: flex-end; }

.convo-time {
    font-size: 0.7rem;
    color: var(--ink-faint);
    padding: 0 0.2rem;
}

/* You, on the right: your photo, else your initial on a quiet disc so it
   doesn't read as a second Dex. */
.convo-msg-avatar--user {
    overflow: hidden;
    background: var(--paper-warm, #f5f4f0);
    color: var(--ink-soft);
    border: 1px solid var(--border);
}
.convo-msg-avatar--user img { width: 100%; height: 100%; object-fit: cover; }

/* The foot of a past chat: a dashed rule either side of "Chat ended". */
.convo-end {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.6rem 0 0;
    font-size: 0.75rem;
    color: var(--ink-faint);
    white-space: nowrap;
}
.convo-end::before,
.convo-end::after {
    content: "";
    flex: 1;
    border-top: 1px dashed var(--border);
}

.convo-bubble {
    max-width: 100%;
    padding: 0.65rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.convo-msg--ai   .convo-bubble { background: var(--paper-warm, #f5f4f0); color: var(--ink);
                                 border-bottom-left-radius: 4px; }
.convo-msg--user .convo-bubble { background: var(--accent); color: #fff;
                                 border-bottom-right-radius: 4px; }

/* A phone: smaller faces, so the bubbles get the width. The step pills'
   indent shrinks with them, so they still line up with Dex's bubble. */
@media (max-width: 600px) {
    .convo-msg { gap: 0.45rem; }
    .convo-msg-avatar { width: 26px; height: 26px; font-size: 0.72rem; }
    .convo-msg-body { max-width: 84%; }
    .convo-activity { margin-left: calc(26px + 0.45rem); }
}

/* ------------------------------------------------------------------ */
/* Friends & balances                                                  */
/* ------------------------------------------------------------------ */

.friends-page { padding: 2.5rem 0 4rem; }

.friends-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 2rem;
}

.friends-inner--narrow { max-width: 820px; }
.friends-inner--form   { max-width: 520px; }

.friends-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.75rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.friends-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--ink);
}

.friends-sub {
    margin-top: 0.3rem;
    font-size: 0.9rem;
    color: var(--ink-muted);
}

.friend-add-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 1.75rem;
}

.friend-add-form .form-input { flex: 1 1 180px; margin: 0; }

/* --- The list --- */

.friend-list {
    list-style: none;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.friend-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--border-soft);
}

.friend-row:last-child { border-bottom: none; }
.friend-row:hover { background: var(--row-hover); }

.friend-row-main {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex: 1 1 auto;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}

.friend-avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
}

.friend-avatar--muted { background: var(--ink-faint); }

.friend-avatar--lg {
    width: 52px;
    height: 52px;
    font-size: 1.25rem;
}

.friend-row-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }

.friend-row-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.friend-row-state {
    font-size: 0.75rem;
    color: var(--ink-muted);
    text-transform: lowercase;
}

.friend-row-amount {
    font-size: 1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.friend-row-amount--owe      { color: var(--danger); }
.friend-row-amount--owed     { color: var(--accent); }
.friend-row-amount--settled  { color: var(--ink-faint); font-weight: 600; }

.friend-row-spacer { width: 84px; flex-shrink: 0; }

.btn-ghost--sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.78rem;
    flex-shrink: 0;
}

.friends-empty {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 2.5rem 1.5rem;
    text-align: center;
}

.friends-empty-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 0.35rem;
}

.friends-archived { margin-top: 2rem; }
.friend-list--archived { margin-top: 0.6rem; opacity: 0.75; }

/* --- Legacy rows that never recorded who owed --- */

.friend-unassigned {
    background: var(--accent-2-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.75rem;
}

.friend-unassigned-head {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
}

.friend-unassigned-note {
    margin-top: 0.25rem;
    font-size: 0.82rem;
    color: var(--ink-muted);
    line-height: 1.5;
}

.friend-unassigned-list {
    list-style: none;
    margin-top: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.friend-unassigned-list li {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    font-size: 0.85rem;
}

.friend-unassigned-list a { color: var(--ink); font-weight: 600; }
.friend-unassigned-date   { color: var(--ink-muted); font-size: 0.78rem; }
.friend-unassigned-amount { margin-left: auto; font-weight: 700; color: var(--accent); }

/* --- Friend detail --- */

.friend-back {
    display: inline-block;
    margin-bottom: 1.25rem;
    font-size: 0.85rem;
    color: var(--ink-muted);
    text-decoration: none;
}

.friend-back:hover { color: var(--ink); }

.friend-hero {
    display: flex;
    align-items: center;
    gap: 1.1rem;
    padding-bottom: 1.5rem;
    margin-bottom: 1.75rem;
    border-bottom: 1px solid var(--border);
}

.friend-hero-text { flex: 1 1 auto; min-width: 0; }

.friend-hero-net {
    margin-top: 0.4rem;
    font-size: 1.05rem;
    font-weight: 700;
}

.friend-entry-undo {
    background: none;
    border: none;
    padding: 0 0 0 0.75rem;
    font-family: var(--font);
    font-size: 0.75rem;
    color: var(--ink-faint);
    cursor: pointer;
}

.friend-entry-undo:hover { color: var(--danger); text-decoration: underline; }

.friend-manage { margin-top: 1.5rem; }
.friend-manage .friend-add-form { margin-bottom: 0.9rem; }

.friend-remove {
    background: none;
    border: none;
    padding: 0;
    font-family: var(--font);
    font-size: 0.82rem;
    color: var(--danger);
    cursor: pointer;
}

.friend-remove:hover { text-decoration: underline; }

/* --- Settle up --- */

.settle-card {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.75rem;
}

.settle-form { margin-top: 1.5rem; }

.settle-form .paid-toggle-group { width: 100%; }

.settle-form .paid-toggle-btn {
    flex: 1 1 0;
    justify-content: center;
    text-align: center;
}

.settle-form .paid-toggle-btn input { position: absolute; opacity: 0; pointer-events: none; }

.settle-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}
/* Labels stay on one line ("Start from scratch", "Record payment"); on a
   phone the pair shares the row rather than each wrapping in a narrow box. */
.settle-actions > * { white-space: nowrap; }

@media (max-width: 700px) {
    .friends-inner { padding: 0 1.25rem; }
    .friends-header { flex-direction: column; align-items: flex-start; }
    .friend-row { flex-wrap: wrap; }
    .friend-row-spacer { display: none; }
}

/* ------------------------------------------------------------------ */
/* Split editor (add / edit expense)                                   */
/* ------------------------------------------------------------------ */

/* One box around the whole split, switch included: compact while off — a
   field's height — and growing to hold the details once on. It's always
   boxed, so switching on never shifts the switch. Field corners. */
.split-editor {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.45rem 1rem;   /* with the switch, a field's height while off */
    background: var(--paper);
}

/* The on/off switch on its own line: name beside it, centred, no subtitle. */
/* A flex line of its own (not inline), so no text-line slack under it. */
.split-switch.split-switch--compact { align-items: center; display: flex; width: fit-content; }
.split-switch--compact .split-switch-text { font-size: 0.875rem; }

.split-switch {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    cursor: pointer;
    margin: 0;
}

.split-switch input { position: absolute; opacity: 0; pointer-events: none; }

.split-switch-track {
    position: relative;
    flex-shrink: 0;
    width: 38px;
    height: 22px;
    margin-top: 1px;
    border-radius: 11px;
    background: var(--border);
    transition: background 0.18s;
}

.split-switch-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.18s;
}

.split-switch input:checked + .split-switch-track { background: var(--accent); }
.split-switch input:checked + .split-switch-track .split-switch-knob { transform: translateX(16px); }
.split-switch input:focus-visible + .split-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.split-switch-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ink);
    text-transform: none;
    letter-spacing: 0;
}

.split-switch-sub {
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--ink-muted);
}

.split-body { margin-top: 0.75rem; padding-bottom: 0.55rem; }

/* --- "I'll settle this myself" --- */

/* .split-switch is display:flex, which outranks the UA [hidden] rule, so the
   toggle needs to be told to disappear explicitly. */
.split-switch--cover[hidden] { display: none; }

.split-switch--cover {
    padding-bottom: 1.1rem;
    margin-bottom: 1.1rem;
    border-bottom: 1px solid var(--border-soft);
}

.split-cover-note {
    margin: 0.4rem 0 0;
    font-size: 0.82rem;
    color: var(--ink-muted);
}

/* --- Mode tabs --- */

.split-modes {
    /* Four equal segments across the box, a field's height. The dividers are
       the container's own colour showing through 1.5px gaps, so they stay
       right when a narrow screen wraps the four into two rows. */
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--border);
}

.split-mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(2.5rem - 3px);   /* 40px with the container's border */
    padding: 0 0.5rem;
    background: var(--paper-card);
    border: none;
    font-family: var(--font);
    font-size: 0.82rem;
    color: var(--ink-muted);
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.split-mode-btn:hover { background: var(--paper-warm); color: var(--ink); }

/* Selected: the light green the Paid by toggle uses, not a solid block. */
.split-mode-btn--active,
.split-mode-btn--active:hover {
    background: color-mix(in srgb, var(--accent) 14%, var(--paper-card));
    color: var(--accent);
    font-weight: 600;
}

/* --- Participant rows --- */

.split-rows {
    list-style: none;
    margin: 0.75rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--paper-card);
}

.split-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border-soft);
}

.split-row:last-child { border-bottom: none; }

/* touch-action so a drag on the handle moves the row instead of scrolling. */
.split-row-handle {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 24px;
    padding: 0;
    border: none;
    background: none;
    color: var(--ink-faint);
    cursor: grab;
    touch-action: none;
}

.split-row-handle:hover  { color: var(--ink-muted); }
.split-row-handle:active { cursor: grabbing; }

/* Rows glide to the gap they are making; the one in hand tracks the pointer
   exactly, so it must not be animated. */
.split-rows--dragging .split-row { transition: transform 0.16s ease; }
.split-rows--dragging { cursor: grabbing; user-select: none; }

.split-row--dragging {
    position: relative;
    z-index: 2;
    transition: none !important;
    background: var(--paper-card);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-sm);
    border-bottom-color: transparent;
}

/* "They're already here" — a single pulse on the row you tried to duplicate. */
.split-row--nudge { animation: splitRowNudge 0.5s ease; }
@keyframes splitRowNudge {
    0%, 100% { background: transparent; }
    25%      { background: var(--accent-light); }
}
@media (prefers-reduced-motion: reduce) {
    .split-row--nudge { animation-duration: 0.01s; }
    .split-rows--dragging .split-row { transition: none; }
}

.split-row-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.split-row-input {
    width: 96px;
    flex-shrink: 0;
    padding: 0.4rem 0.55rem;
    font-size: 0.85rem;
    margin: 0;
}

.split-row-amount {
    width: 88px;
    flex-shrink: 0;
    text-align: right;
    font-size: 0.9rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.split-row-remove {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    border-radius: 50%;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--ink-faint);
    cursor: pointer;
}

.split-row-remove:hover { background: var(--danger-light); color: var(--danger); }

/* --- Add someone / running total --- */

.split-add { display: flex; gap: 0.6rem; }
.split-add .cselect { flex: 1 1 auto; min-width: 0; }
/* On the split box's paper tone, the picker lifts to the card like the rows. */
.split-add .cselect-combo { background: var(--paper-card); }
.split-add-input { flex: 1 1 auto; margin: 0; }

.split-remaining {
    margin: 0.75rem 0 0;
    font-size: 0.8rem;
    font-weight: 600;
}

.split-remaining--ok  { color: var(--ink-muted); }
.split-remaining--bad { color: var(--danger); }

@media (max-width: 600px) {
    .split-row { flex-wrap: wrap; }
    /* Leaves the handle beside the name rather than alone on the first line. */
    .split-row-name { flex: 1 1 calc(100% - 2rem); }
    .split-row-amount { margin-left: auto; }
    .split-modes { grid-template-columns: repeat(2, 1fr); }
}

/* ------------------------------------------------------------------ */
/* Receipts                                                            */
/* ------------------------------------------------------------------ */

/* The form's receipt is a paperclip clipped onto the card's left edge beside
   the split switch — the counterpart of the mark tag on the card's top edge —
   with what's attached as a chip under the box (_receipt_field.html). With
   nothing attached the field takes no room at all: it tucks into the split
   box's bottom margin. */
.receipt-field { margin-top: -1.1rem; }

/* Out of sight but still focusable, so Tab reaches the picker. */
.receipt-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    clip-path: inset(50%);
}

.receipt-attach-row {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
}

.form-group .receipt-attach {
    display: inline-flex;
    align-items: flex-start;
    gap: 0.35rem;
    margin: 0;
    color: var(--ink-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}
/* The clip itself straddles the card's left border, tilted the way a real one
   sits. Absolute with no `top`, so it stays level with the row it belongs to;
   the card (.expense-form-card, position: relative) is what `left` measures
   from. A classic two-loop paperclip, upright and centred on the edge so the
   card passes between its loops (see the SVG in _receipt_field.html). */
.receipt-attach-icon {
    position: absolute;
    left: -12px;          /* measured inside the card's 1px border: centres on its outer edge */
    margin-top: -47px;    /* up beside the split switch */
    width: 22px;
    height: 54px;
    color: var(--ink-faint);
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.12));
    /* Same spring as the mark tag. Vertical only, so the inner loop stays cut
       exactly at the card's edge. */
    transition: color 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
/* Hover lifts it, as if about to be pushed on; attaching snaps it down onto
   the card (the tag's drop, in reverse direction). */
.receipt-attach:hover .receipt-attach-icon { transform: translateY(-4px); }
/* --snap is added by receipt_preview.js only when something gets attached, so a
   receipt that was already saved doesn't replay it on page load. */
.receipt-attach--snap .receipt-attach-icon { animation: receipt-clip-on 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
.receipt-attach--on:hover .receipt-attach-icon { transform: translateY(-2px); }
@keyframes receipt-clip-on {
    0%   { transform: translateY(-10px); }
    60%  { transform: translateY(2px); }
    100% { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    .receipt-attach-icon { transition: color 0.2s ease; animation: none !important; }
    .receipt-attach:hover .receipt-attach-icon,
    .receipt-attach--on:hover .receipt-attach-icon { transform: none; }
}
/* The inner loop is the half behind the card, so it reads a touch fainter. */
.receipt-attach-back { opacity: 0.75; }
/* No visible label, like the tag: the clip is the control. The text stays for
   screen readers; the tooltip says it to everyone else. */
.receipt-attach-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
.receipt-attach--on,
.receipt-attach--on .receipt-attach-icon { color: var(--accent); }
.receipt-field:has(.receipt-input:focus-visible) .receipt-attach {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
}

/* What's attached: thumbnail, name, size, ×. */
.receipt-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 100%;
    margin-top: 0.65rem;   /* the gap under the split box, only once there's a chip */
    padding: 0.25rem 0.35rem 0.25rem 0.25rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--paper);
    font-size: 0.78rem;
}
.receipt-chip[hidden] { display: none; }
.receipt-chip-thumb {
    flex: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border);
    display: block;
}
.receipt-chip-thumb--file {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--ink-muted);
    background: var(--paper-warm);
    text-decoration: none;
}
.receipt-chip-name {
    min-width: 0;
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
    font-weight: 600;
}
.receipt-chip-size { color: var(--ink-faint); flex: none; }
.receipt-chip-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 20px;
    height: 20px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--ink-muted);
    cursor: pointer;
}
.receipt-chip-x:hover { background: var(--paper-warm); color: var(--danger); }
.receipt-chip-x input { position: absolute; opacity: 0; pointer-events: none; }
.receipt-chip-x:has(input:focus-visible),
.receipt-chip-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Marked for removal: struck through until the form is saved (× again undoes). */
.receipt-chip--removed { opacity: 0.55; }
.receipt-chip--removed .receipt-chip-name { text-decoration: line-through; }

.receipt-error {
    margin: 0.5rem 0 0;
    font-size: 0.8rem;
    color: var(--danger);
}

.receipt-clip {
    display: inline-flex;
    margin-left: 0.3rem;
    color: var(--ink-faint);
    vertical-align: -1px;
}

.receipt-clip:hover { color: var(--accent); }

.expense-mark {
    display: inline-flex;
    margin-left: 0.3rem;
    color: var(--accent);
    vertical-align: -1px;
}

/* Mark tag on the add/edit expense card — a bookmark ribbon hanging off the
   top edge. Unmarked it is short and muted; marked it drops further down in
   red. The checkbox underneath is what actually posts. */
.mark-tag {
    position: absolute;
    top: -1px;            /* sits over the card's top border */
    right: 2.5rem;
    width: 28px;
    height: 60px;
    cursor: pointer;
    z-index: 1;
    border-radius: 4px;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.12));
}
.mark-tag-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}
.mark-tag-ribbon {
    position: absolute;
    top: 0;
    left: 0;
    width: 28px;
    height: 32px;
    background: color-mix(in srgb, var(--ink-faint) 40%, var(--paper-card));
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - 9px), 0 100%);
    transition: height 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease;
}
/* The eyelet. */
.mark-tag-ribbon::before {
    content: '';
    position: absolute;
    top: 9px;
    left: 50%;
    width: 7px;
    height: 7px;
    margin-left: -3.5px;
    border-radius: 50%;
    background: var(--paper-card);
    box-shadow: inset 0 0 0 1.5px rgba(0, 0, 0, 0.15);
}
.mark-tag:hover .mark-tag-ribbon { height: 38px; }

.mark-tag-input:checked ~ .mark-tag-ribbon {
    height: 54px;
    background: var(--accent-5);
}

.mark-tag:has(.mark-tag-input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
    .mark-tag-ribbon { transition: none; }
}

/* Left-aligned inside a centred card: a list of features reads as a list,
   not as prose. */

/* ------------------------------------------------------------------ */
/*  Balances — the two directions as tabs over their own lines          */
/* ------------------------------------------------------------------ */

/* The old summary cards, now selectable. They keep the card look so the page
   reads the same at a glance; the active one loses its bottom edge to join the
   panel below it. */
.bal-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin: 1.25rem 0 0;
}

.bal-tab {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 1.1rem 1.3rem;
    text-align: left;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-top-width: 3px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-family: var(--font);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.bal-tab:hover { box-shadow: var(--shadow-md); }
.bal-tab:active { transform: translateY(1px); }
.bal-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bal-tab--owe  { border-top-color: var(--danger); }
.bal-tab--owed { border-top-color: var(--accent); }

/* Unselected sits back: paper, no shadow, muted figure. Only the chosen side
   looks like a live card, so the page always says which list you're reading. */
.bal-tab:not(.is-active) {
    background: var(--paper);
    box-shadow: none;
    border-top-color: var(--border);
}
.bal-tab:not(.is-active) .bal-tab-value { color: var(--ink-faint); }

.bal-tab-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
}

.bal-tab-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
}

.bal-tab-count { font-size: 0.78rem; color: var(--ink-faint); }

.bal-panel {
    margin-top: 1rem;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.bal-panel.is-hidden { display: none; }

/* The contact list reuses .friend-list's row markup, but it's nested inside
   a .bal-panel that already carries the border/background — drop its own so
   the two don't double up. */
.bal-contacts {
    background: none;
    border: none;
    border-radius: 0;
}

.bal-panel-foot {
    margin: 0;
    padding: 0.8rem 1.25rem;
    border-top: 1px solid var(--border-soft);
    background: var(--paper);
    font-size: 0.8rem;
    color: var(--ink-faint);
}

/* ------------------------------------------------------------------ */
/* Catalog — every uploaded receipt image, browsable by category       */
/* ------------------------------------------------------------------ */

.catalog-page { padding: 2.5rem 2rem 5rem; }

.catalog-inner {
    max-width: var(--max-width);
    margin: 0 auto;
}

.catalog-header { margin-bottom: 1.5rem; }

.catalog-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
}

.catalog-subtitle {
    margin-top: 0.3rem;
    color: var(--ink-muted);
    font-size: 0.92rem;
}

/* Filter chips double as a category legend: each carries its own colour via
   --cat-color/--cat-tint/--cat-line (set in catalog.html, same variables
   .cat-icon-badge already reads), so the filter row and the tiles below it
   read as one system rather than two. */
.catalog-chip {
    border: 1px solid var(--cat-line, var(--border));
    background: var(--cat-tint, var(--paper-card));
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.catalog-chip:hover { box-shadow: var(--shadow-sm); }

.catalog-chip--active {
    background: var(--cat-color, var(--accent));
    border-color: var(--cat-color, var(--accent));
    color: #fff;
}

.catalog-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.catalog-empty-filter {
    color: var(--ink-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* True masonry with no JS: CSS columns let each receipt keep its own aspect
   ratio, so a tall bill and a wide storefront photo naturally sit at
   different heights instead of being cropped to match. */
.catalog-grid {
    column-count: 2;
    column-gap: 1rem;
}

@media (min-width: 640px)  { .catalog-grid { column-count: 3; } }
@media (min-width: 960px)  { .catalog-grid { column-count: 4; } }
@media (min-width: 1280px) { .catalog-grid { column-count: 5; } }

.catalog-tile {
    display: block;
    position: relative;
    break-inside: avoid;
    margin-bottom: 1rem;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--paper-card);
    box-shadow: var(--shadow-sm);
    /* The category colour as a top accent bar — the "pattern" that ties every
       tile back to the filter chip it belongs to, at a glance, before a
       single word is read. */
    border-top: 4px solid var(--cat-color, var(--border));
    transition: box-shadow 0.15s, transform 0.15s;
}

.catalog-tile:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.catalog-tile-img {
    display: block;
    width: 100%;
    height: auto;
}

.catalog-tile-badge {
    position: absolute;
    top: 0.6rem;
    left: 0.6rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: rgba(20, 18, 14, 0.62);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    backdrop-filter: blur(2px);
}

.catalog-tile-badge .cat-icon-svg svg { width: 12px; height: 12px; }

.catalog-tile-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem 0.65rem;
}

.catalog-tile-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.catalog-tile-date {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--ink-faint);
}

@media (max-width: 640px) {
    .bal-tabs { grid-template-columns: 1fr; gap: 0.6rem; }
}

/* A phone: the title with a quiet link to All contacts beside it, and the
   two sides back next to each other as compact tabs, so the list itself
   starts on the first screen. */
@media (max-width: 600px) {
    /* Every page on this layout (balances, contacts, a contact, settle up,
       the Wallet's pages): the 16px gutter and a lighter back link. */
    .friends-page { padding-top: 1.5rem; }
    .friends-page .friends-inner { padding: 0 1rem; }
    .friends-page .friend-back { margin-bottom: 0.75rem; }

    /* Contacts: the title with a compact Add beside it; the count goes. */
    .friends-page--contacts .friends-header {
        flex-direction: row;
        align-items: flex-end;            /* level with the title, under the back link */
        margin-bottom: 1rem;
        padding-bottom: 1rem;
    }
    .friends-page--contacts .friends-title { font-size: 1.5rem; }
    .friends-page--contacts .friends-header .friends-sub { display: none; }
    .friends-page--contacts .friends-header .btn-primary {
        padding: 0.45rem 0.8rem;
        font-size: 0.82rem;
        white-space: nowrap;
    }

    /* A contact: smaller face and name, and Settle up on a row of its own
       under them rather than squeezed beside the name. */
    .friends-page .friend-hero { flex-wrap: wrap; gap: 0.85rem; padding-bottom: 1.1rem; margin-bottom: 1.25rem; }
    .friends-page .friend-hero .friend-avatar--lg { width: 44px; height: 44px; font-size: 1.05rem; }
    .friends-page .friend-hero .friends-title { font-size: 1.5rem; }
    .friends-page .friend-hero-net { margin-top: 0.2rem; font-size: 0.95rem; }
    .friends-page .friend-hero > .btn-primary { flex: 1 1 100%; justify-content: center; text-align: center; white-space: nowrap; }

    .friends-page--balances { padding-top: 1.5rem; }
    .friends-page--balances .friends-inner { padding: 0 1rem; }
    .friends-page--balances .friends-header {
        flex-direction: row;
        align-items: center;
        margin-bottom: 1rem;
        padding-bottom: 1rem;
    }
    .friends-page--balances .friends-title { font-size: 1.5rem; }
    .friends-page--balances .friends-sub { display: none; }
    .friends-page--balances .friends-header .btn-primary {
        padding: 0;
        background: none;
        border: none;
        color: var(--accent);
        font-size: 0.85rem;
        font-weight: 600;
        box-shadow: none;
    }
    .friends-page--balances .bal-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; margin-top: 0; }
    .friends-page--balances .bal-tab { padding: 0.75rem 0.85rem; }
    .friends-page--balances .bal-tab-label { font-size: 0.62rem; }
    .friends-page--balances .bal-tab-value { font-size: 1.2rem; }
    .friends-page--balances .bal-tab-count { font-size: 0.72rem; }
}

/* ------------------------------------------------------------------ */
/* Contact colours — utils.person_color() / combobox.js personColor()  */
/* ------------------------------------------------------------------ */

/* Contacts have no photos, so each wears one of these, picked by a hash of the
   name: different people look different, the same person looks the same
   everywhere. Mid-tones that carry white initials on either theme. */
.person-c0 { background: #2e7d5b; }
.person-c1 { background: #2f6fd1; }
.person-c2 { background: #8a4fd8; }
.person-c3 { background: #d0543c; }
.person-c4 { background: #b9770e; }
.person-c5 { background: #0e8a94; }
.person-c6 { background: #c2407a; }
.person-c7 { background: #5b6b80; }
[data-theme="dark"] .person-c0 { background: #3a9a70; }
[data-theme="dark"] .person-c1 { background: #4a86e0; }
[data-theme="dark"] .person-c2 { background: #9d68e2; }
[data-theme="dark"] .person-c3 { background: #dc6a52; }
[data-theme="dark"] .person-c4 { background: #c98a22; }
[data-theme="dark"] .person-c5 { background: #1fa2ac; }
[data-theme="dark"] .person-c6 { background: #d35a8f; }
[data-theme="dark"] .person-c7 { background: #71839a; }

/* ------------------------------------------------------------------ */
/* Free pickers: Payment method and Who paid (combobox.js)             */
/* ------------------------------------------------------------------ */

/* Option and field icons: 24/26px, like the category tiles. */
.cselect-option-icon.pm-tile,
.cselect-option-icon.person-face,
.cselect-option-icon.cselect-add-icon { justify-content: center; width: 26px; height: 26px; opacity: 1; }
.cselect-combo .cselect-preview-icon.pm-tile,
.cselect-combo .cselect-preview-icon.person-face {
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-block: -4px;   /* overhangs the line rather than heightening the field */
}

/* Payment methods: the mark in its kind's colour on a pale tile of it. */
.pm-tile { border-radius: 7px; color: var(--pm); background: color-mix(in srgb, var(--pm) 16%, var(--paper-card)); }
.pm-tile--cash   { --pm: #2e9d5b; }
.pm-tile--credit { --pm: #2f6fd1; }
.pm-tile--debit  { --pm: #0e8a94; }
.pm-tile--card   { --pm: #2f6fd1; }
.pm-tile--app    { --pm: #8a4fd8; }
.pm-tile--bank   { --pm: #b9770e; }
.pm-tile--cheque { --pm: #c2407a; }
.pm-tile--other  { --pm: #6b7280; }

/* People: their initial on their colour. */
.person-face {
    border-radius: 50%;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

/* "Add …": a dashed empty seat with a plus, like the no-contacts stack. */
.cselect-add-icon {
    border-radius: 50%;
    border: 1.5px dashed currentColor;
    color: var(--ink-muted);
}
.cselect-add .cselect-option-label b { font-weight: 700; color: var(--ink); }

/* ------------------------------------------------------------------ */
/* Dashboard bell — top right of the header                            */
/* ------------------------------------------------------------------ */

/* The panel opens inside the header's own band, to the left of the bell.
   Three rows is what fits there, so rows past the third (--extra) wait for a
   phone, where the panel has the greeting's whole block — no scroll, and
   nothing spills over the cards below the rule. */
.notif-item--extra { display: none; }
@media (max-width: 600px) {
    .notif-item--extra { display: list-item; }
}
.dashboard-header { position: relative; }

.notif {
    flex-shrink: 0;
    align-self: flex-start;
}

.notif-btn { position: relative; }

.notif-badge {
    position: absolute;
    top: 3px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 600;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--paper);
}

.notif-panel {
    position: absolute;
    top: 0;
    right: calc(34px + 0.75rem);
    z-index: 5;
    width: min(460px, calc(100% - 34px - 0.75rem));
    overflow: hidden;
}

.notif-empty {
    margin: 0;
    padding: 0.6rem 0.9rem;
    color: var(--ink-faint);
    font-size: 0.85rem;
}

.notif-list { margin: 0; padding: 0; list-style: none; }

.notif-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    height: 1.5rem;
    padding: 0 0.9rem 0 0.75rem;
    color: var(--ink-muted);
    font-size: 0.8rem;
    text-decoration: none;
}

a.notif-row { border-radius: var(--radius-sm); }
a.notif-row:hover { background: var(--paper-warm); color: var(--ink); }

/* Unread: a dot where the read rows have a blank, and full-strength ink. */
.notif-dot {
    flex-shrink: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
}
.notif-item--unread .notif-dot { background: var(--accent); }
.notif-item--unread .notif-row { color: var(--ink); }

.notif-tag {
    flex-shrink: 0;
    width: 3.1rem;
    color: var(--ink-faint);
    font-size: 0.64rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.notif-item--limit .notif-tag { color: var(--accent-2); }
.notif-item--release .notif-tag { color: var(--accent-3); }
.notif-item--wallet .notif-tag { color: var(--danger); }

.notif-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A clipped message slides left on hover until its end shows, at reading
   pace. The bell's script measures the overflow (--notif-shift) and sets the
   duration from it (--notif-scroll), so long and short ones move alike. The
   inner span stays inline at rest so the ellipsis still shows. */
@media (prefers-reduced-motion: no-preference) {
    .notif-row:hover .notif-text--clipped,
    .notif-row:focus-visible .notif-text--clipped { text-overflow: clip; }
    .notif-row:hover .notif-text--clipped .notif-text-inner,
    .notif-row:focus-visible .notif-text--clipped .notif-text-inner {
        display: inline-block;
        transform: translateX(calc(-1 * var(--notif-shift, 0px)));
        transition: transform var(--notif-scroll, 2s) ease-in-out 0.3s;
    }
}

.notif-when {
    flex-shrink: 0;
    color: var(--ink-faint);
    font-size: 0.72rem;
}

/* The header stacks into a column here: the bell stays top right, and the
   panel takes the band beside it, over the greeting, while it's open. */
@media (max-width: 900px) {
    .dashboard-header > div:first-child { padding-right: 2.75rem; }
    /* The button is what's pinned, not .notif: the panel has to measure
       against the whole header, and a positioned .notif would box it into
       the bell's own 34px. */
    .notif-btn { position: absolute; top: 0; right: 0; }
    .notif-panel { left: 0; width: auto; }
    /* No box behind the rows, so the greeting steps aside while they show. */
    .dashboard-header.notif-open > div:first-child { visibility: hidden; }
    .notif-when { display: none; }
}

/* ------------------------------------------------------------------ */
/* Wallet                                                              */
/* ------------------------------------------------------------------ */

/* What's left in an account, beside its name in the payment-method picker. */
.cselect-option-hint {
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
}

.wallet-totals {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.wallet-total {
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.wallet-total-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-muted);
}
.wallet-total-value {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}
.wallet-total--net .wallet-total-value { color: var(--accent); }

.wallet-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.75rem 1.25rem;
}
.wallet-tile {
    display: block;
    color: inherit;
    text-decoration: none;
}
.wallet-tile .wcard { transition: transform 0.25s cubic-bezier(.22,.8,.24,1); }
.wallet-tile:hover .wcard,
.wallet-tile:focus-visible .wcard { transform: translateY(-4px); }
.wallet-tile:focus-visible { outline: none; }
.wallet-tile:focus-visible .wcard-face { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--accent); }
.wallet-tile-caption {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-top: 0.65rem;
}
.wallet-tile-name { font-weight: 600; font-size: 0.92rem; }
.wallet-tile-meta { font-size: 0.78rem; color: var(--ink-muted); }

/* --- The card itself: static/css/cards.css --- */

/* --- Sections: My cards, then Recommended --- */

.wallet-section-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 0.85rem; }
.wallet-rec { margin-top: 2.75rem; }
.wallet-rec-list { list-style: none; margin: 1rem 0 0; padding: 0; }
.wallet-rec-row {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr) auto;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 0;
    border-top: 1px solid var(--border-soft);
}
.wallet-cash { margin-bottom: 1.25rem; border-bottom: 1px solid var(--border-soft); color: inherit; text-decoration: none; }
.wallet-cash-figure { font-weight: 700; font-variant-numeric: tabular-nums; }
.wallet-rec-info { display: grid; gap: 0.2rem; min-width: 0; }
.wallet-rec-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wallet-rec-used { font-size: 0.78rem; color: var(--ink-muted); }

.wallet-empty {
    text-align: center;
    padding: 3.5rem 1rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
}
.wallet-empty-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.35rem; }
.wallet-empty .btn-primary { margin-top: 1.25rem; display: inline-block; }

/* --- New / edit account --- */

.wallet-form-inner { max-width: 940px; }
.wallet-form-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 2rem;
    align-items: start;
}
.wallet-form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.wallet-form-row > [hidden] { display: none; }
.wallet-form-note { margin: -0.4rem 0 1rem; font-size: 0.78rem; color: var(--ink-muted); }
.wallet-kind .paid-toggle-btn { padding-left: 0.6rem; padding-right: 0.6rem; font-size: 0.82rem; }
.wallet-color { height: 2.6rem; padding: 0.25rem; cursor: pointer; }
.wallet-archive-form {
    display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.25rem 0.75rem;
    margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border-soft);
}
.wallet-archive-form .wallet-form-note { margin: 0; }
.wallet-preview { position: sticky; top: 6rem; }
.wallet-preview-label {
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--ink-muted); margin-bottom: 0.75rem;
}
.wallet-preview-via { margin-top: 0.75rem; font-size: 0.8rem; color: var(--ink-muted); line-height: 1.45; }

@media (max-width: 820px) {
    .wallet-form-layout { grid-template-columns: minmax(0, 1fr); }
    /* The preview leads on a phone: you see the card change as you type below it. */
    .wallet-preview { position: static; order: -1; max-width: 320px; }
}
@media (max-width: 600px) {
    .wallet-totals { grid-template-columns: minmax(0, 1fr); gap: 0.6rem; }
    .wallet-total { flex-direction: row; justify-content: space-between; align-items: baseline; }
    .wallet-total-value { font-size: 1.2rem; }
    .wallet-rec-row { grid-template-columns: 72px minmax(0, 1fr) auto; gap: 0.75rem; }
    .wallet-form-row { grid-template-columns: minmax(0, 1fr); }
    .wallet-kind { flex-wrap: wrap; }
    .wallet-kind .paid-toggle-btn { flex: 1 1 45%; justify-content: center; }
}

/* --- One account: its card, what you can do, and its history --- */

.wallet-account-head {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 1.75rem;
    align-items: center;
    padding-bottom: 1.75rem;
    margin-bottom: 1.75rem;
    border-bottom: 1px solid var(--border);
}
.wallet-account-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.1rem; }
.wallet-section-title {
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--ink-muted); margin-bottom: 0.5rem;
}
.wallet-history { list-style: none; margin: 0; padding: 0; }
.wallet-history-row {
    display: grid;
    grid-template-columns: 3.5rem minmax(0, 1fr) auto 7rem 4.5rem;
    align-items: center;
    gap: 0.9rem;
    padding: 0.75rem 0;
    border-top: 1px solid var(--border-soft);
    font-size: 0.9rem;
}
.wallet-history-date { color: var(--ink-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.wallet-history-main { display: flex; flex-direction: column; min-width: 0; }
.wallet-history-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallet-history-sub { font-size: 0.78rem; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallet-history-change { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.wallet-history-change.is-in { color: var(--accent); }
.wallet-history-after { text-align: right; color: var(--ink-muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.wallet-history-act { text-align: right; }
.wallet-history-row--opening { color: var(--ink-muted); }
.wallet-history-row--opening .wallet-history-title { font-weight: 500; }
.wallet-link {
    background: none; border: none; padding: 0; cursor: pointer;
    font-family: var(--font); font-size: 0.8rem; font-weight: 600;
    color: var(--accent); text-decoration: none;
}
.wallet-link:hover { text-decoration: underline; }
.wallet-link--quiet { color: var(--ink-muted); font-weight: 500; }
.wallet-link--quiet:hover { color: var(--danger); }
.wallet-empty-note { color: var(--ink-muted); font-size: 0.9rem; padding: 1rem 0; }

/* --- Moving money: the modes as tabs over one small form --- */

.wallet-modes {
    display: flex; flex-wrap: wrap; gap: 0.35rem;
    margin: -0.25rem 0 1.25rem;
}
.wallet-mode {
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--ink-muted);
    text-decoration: none;
}
.wallet-mode:hover { color: var(--ink); border-color: var(--ink-faint); }
.wallet-mode.is-active {
    background: color-mix(in srgb, var(--accent) 14%, var(--paper-card));
    border-color: transparent;
    color: var(--accent);
    font-weight: 600;
}

/* Under the payment method on the expense form. A note, not an error: the
   expense still saves. */
.wallet-warn {
    margin-top: 0.45rem;
    font-size: 0.8rem;
    color: var(--accent-2);
    line-height: 1.4;
}

/* Edit and Refund sit together on the left of the expense popup's footer. */
.xd-actions-main { display: inline-flex; align-items: center; gap: 0.5rem; }

@media (max-width: 720px) {
    .wallet-account-head { grid-template-columns: minmax(0, 1fr); }
    .wallet-account-card { max-width: 320px; }
    .wallet-history-row { grid-template-columns: 3rem minmax(0, 1fr) auto; row-gap: 0.15rem; }
    .wallet-history-after { grid-column: 2; text-align: left; font-size: 0.75rem; }
    .wallet-history-act { grid-column: 3; }
}

/* A card's statement cycle, above its history. */
.wallet-statement {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.75rem;
}
.wallet-statement-cell {
    display: flex; flex-direction: column; gap: 0.2rem;
    padding: 0.85rem 1rem;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}
.wallet-statement-label {
    font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted);
}
.wallet-statement-value { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.wallet-statement-sub { font-size: 0.78rem; color: var(--ink-muted); }
.wallet-statement-cell.is-soon { border-color: var(--danger); }
.wallet-statement-cell.is-soon .wallet-statement-value { color: var(--danger); }

/* --- Dashboard: the Wallet in the right column (_dash_wallet.html) --- */

.dw-panel {
    /* The same surface as every other dashboard panel, in either theme; the
       stitching, the pressed lettering and the pocket's edge do the rest. */
    --dw-back-c: var(--paper-card);
    --dw-front-c: var(--paper-card);
    --dw-text: var(--ink);
    --dw-text-soft: var(--ink-muted);
    --dw-stitch: color-mix(in srgb, var(--ink) 16%, transparent);
    --dw-mark: color-mix(in srgb, var(--ink) 32%, transparent);
    --dw-mark-hover: color-mix(in srgb, var(--ink) 55%, transparent);
    --dw-mark-edge: 0 1px 0 rgba(255, 255, 255, .9);
    --dw-pocket-shadow: 0 -4px 12px rgba(0, 0, 0, .07);
    --dw-ease: cubic-bezier(.22, .8, .24, 1);
    --dw-pop: cubic-bezier(.34, 1.36, .64, 1);
    position: relative;
    z-index: 2;               /* above the panels around it when notes rise out */
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-md);
    color: var(--dw-text);
    /* The leather: the panel itself is the back of the open wallet, with a
       soft light from the top and stitching just inside the edge. */
    background: var(--dw-back-c);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.dw-panel::before {
    content: ""; position: absolute; inset: 6px; z-index: 0; pointer-events: none;
    border: 1px dashed var(--dw-stitch); border-radius: calc(var(--radius-md) - 4px);
}
[data-theme="dark"] .dw-panel {
    --dw-stitch: color-mix(in srgb, var(--ink) 18%, transparent);
    --dw-mark: color-mix(in srgb, var(--ink) 38%, transparent);
    --dw-mark-hover: color-mix(in srgb, var(--ink) 62%, transparent);
    --dw-mark-edge: 0 -1px 0 rgba(0, 0, 0, .5);
    --dw-pocket-shadow: 0 -6px 14px rgba(0, 0, 0, .35);
}
/* "Wallet" pressed into the pocket's leather, like a maker's mark: a faint
   letter with an edge that catches the light (below it on a light panel,
   above it on a dark one), rather than a heading. */
.dw-stamp {
    position: absolute; top: 17px; right: 20px;
    font-size: 10px; font-weight: 700; letter-spacing: .24em; text-transform: uppercase;
    color: var(--dw-mark);
    text-shadow: var(--dw-mark-edge);
    pointer-events: none;
}
.dw {
    position: relative;
    width: 100%;
    /* Clipped at the bottom, where cards slide down into the pocket, but open
       above and at the sides so the cash can rise out of the wallet. The
       bottom corners follow the panel's. */
    clip-path: inset(-90px -40px 0 -40px round 0 0 var(--radius-md) var(--radius-md));
    perspective: 900px;
    -webkit-tap-highlight-color: transparent;
}
.dw.dw--no-tx * { transition: none !important; }
.dw-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Before the script places them (or without it), the cards sit in a plain
   column of strips so nothing overlaps unreadably. */
.dw:not(.dw--ready):not(.dw--empty) { display: grid; gap: 0.5rem; padding: 0.5rem; }
.dw:not(.dw--ready) .dw-card { position: relative; aspect-ratio: 1.586; }
.dw:not(.dw--ready) .dw-card[data-cash],
.dw:not(.dw--ready) .dw-notes { display: none; }
.dw:not(.dw--ready) .dw-pocket { position: relative; height: auto; }
.dw:not(.dw--ready) .dw-pocket-face { position: relative; padding-bottom: 0.9rem; }

.dw-notes { position: absolute; left: 0; top: 0; width: 100%; z-index: 1; cursor: pointer; transition: transform .55s var(--dw-ease); }
.dw-notes:focus-visible { outline: none; }
.dw-notes:focus-visible .dw-note:last-child { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.dw-note {
    position: absolute;
    border-radius: 4px;
    transform-origin: 50% 100%;
    transition: transform .4s var(--dw-ease);
    background:
        repeating-radial-gradient(circle at 20% 120%, transparent 0 6px, rgba(47, 93, 58, .10) 6px 7px),
        repeating-radial-gradient(circle at 85% -30%, transparent 0 5px, rgba(47, 93, 58, .08) 5px 6px),
        linear-gradient(180deg, #e7eedf, #d5e0cb);
    box-shadow: 0 -1px 0 rgba(255,255,255,.5) inset, 0 1px 3px rgba(0,0,0,.18);
}
.dw-note::before { content: ""; position: absolute; inset: 4px; border: 1px solid rgba(47, 93, 58, .28); border-radius: 2px; }
@media (hover: hover) {
    /* Pulled up out of the wallet, past its top edge, fanned like a hand of notes. */
    .dw:not(.has-pulled) .dw-notes:hover .dw-note:nth-child(1) { transform: rotate(-8deg) translateY(-26px); }
    .dw:not(.has-pulled) .dw-notes:hover .dw-note:nth-child(2) { transform: rotate(1.5deg) translateY(-36px); }
    .dw:not(.has-pulled) .dw-notes:hover .dw-note:nth-child(3) { transform: rotate(8deg) translateY(-26px); }
}

.dw-card {
    position: absolute; left: 0; top: 0;
    container-type: inline-size;
    transition: transform .55s var(--dw-ease);
    cursor: pointer;
    outline: none;
}
.dw.dw--opening .dw-card,
.dw.dw--opening .dw-notes { transition-timing-function: var(--dw-pop); transition-duration: .7s; }
.dw-bob { width: 100%; height: 100%; transition: transform .25s var(--dw-ease); }
.dw-flip { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .6s var(--dw-ease); }
.dw-card.is-flipped .dw-flip { transform: rotateY(180deg); }
@media (hover: hover) { .dw:not(.has-pulled) .dw-card:hover .dw-bob { transform: translateY(-9px); } }
.dw:not(.has-pulled) .dw-card:focus-visible .dw-bob { transform: translateY(-9px); }
.dw-card:focus-visible .dw-face { box-shadow: 0 0 0 2px var(--paper-card), 0 0 0 4px var(--accent-2); }

.dw-face { position: absolute; inset: 0; border-radius: 4.2cqw; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.dw-card.is-pulled .dw-face.wcard-face { box-shadow: 0 -1px 0 rgba(255,255,255,.14) inset, 0 10px 30px rgba(0,0,0,.32), 0 2px 6px rgba(0,0,0,.2); }
.dw-face--warn.wcard-face { box-shadow: 0 0 0 1.5px var(--accent-2) inset, 0 1px 2px rgba(0,0,0,.22), 0 6px 16px rgba(0,0,0,.14); }
@media (hover: hover) { .dw:not(.has-pulled) .dw-card:hover .wcard-face::after { background-position: -30% 0; } }
.dw-card.is-pulled .wcard-face::after { background-position: -30% 0; }

/* The strip that shows while a card sits in its slot. */
.dw-top.wcard-top { right: 36cqw; }
/* One line in the stack, where only the strip shows: "freedom RISE". */
.dw-top .wcard-wordmark { flex-direction: row; align-items: baseline; gap: 1.6cqw; font-size: 6.4cqw; }
.dw-top .wcard-wordmark small { font-size: 2.8cqw; }
.dw-sfig {
    position: absolute; right: 5.5cqw; top: 4.6cqw;
    font-size: 4.8cqw; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
    opacity: 0;
    transition: opacity .3s var(--dw-ease);
}
/* Hidden until asked for: hovered, or reached with the keyboard. */
@media (hover: hover) { .dw:not(.has-pulled) .dw-card:hover .dw-sfig { opacity: 1; } }
.dw:not(.has-pulled) .dw-card:focus-visible .dw-sfig { opacity: 1; }
.dw-sfig small { font-size: 3.6cqw; font-weight: 500; color: var(--wc-soft); margin-left: .2em; }
.dw-card.is-pulled .dw-sfig { opacity: 0; }
.dw-face--warn .wcard-bar i { background: var(--accent-2); }
/* The full figure only once the card is out. */
.dw-big { opacity: 0; transform: translateY(4px); transition: opacity .35s var(--dw-ease) .1s, transform .35s var(--dw-ease) .1s; }
.dw-card.is-pulled .dw-big { opacity: 1; transform: none; }

/* The back: magnetic stripe, then the account's last three movements. */
.dw-back { transform: rotateY(180deg); background: linear-gradient(rgba(0,0,0,.28), rgba(0,0,0,.28)), var(--dw-back); color: var(--wc-ink); }
.dw-back.wcard-tone-light { background: linear-gradient(rgba(255,255,255,.2), rgba(255,255,255,.2)), var(--dw-back); }
.dw-mag { position: absolute; left: 0; right: 0; top: 5cqw; height: 10cqw; background: #15161a; }
.dw-back-body { position: absolute; left: 5cqw; right: 5cqw; top: 17.5cqw; bottom: 3.8cqw; display: flex; flex-direction: column; }
.dw-back-body--account { top: 5cqw; }
.dw-back-title { margin: 0 0 1cqw; font-size: 3.8cqw; text-transform: uppercase; letter-spacing: .1em; color: var(--wc-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dw-back-list { list-style: none; margin: 0; padding: 0; display: grid; }
.dw-back-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 2.5cqw; font-size: 4.4cqw; line-height: 8cqw; }
.dw-back-t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dw-back-d { color: var(--wc-soft); }
.dw-back-a { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.dw-back-empty { font-size: 4.4cqw; color: var(--wc-soft); margin: 1cqw 0 0; }
.dw-back-link { margin-top: auto; align-self: flex-end; font-size: 4.2cqw; font-weight: 700; color: var(--wc-ink); text-decoration: none; }
.dw-back-link:hover { text-decoration: underline; }

/* The front pocket, with the net on it. */
.dw-pocket { position: absolute; left: 0; right: 0; top: 0; z-index: 20; transition: transform .55s var(--dw-ease); }
.dw-pocket-face {
    position: absolute; inset: 0;
    background: linear-gradient(180deg, var(--dw-front-c), var(--dw-back-c) 140%);
    /* Rounded on top; the bottom corners are the panel's own. */
    border-radius: 18px 18px var(--radius-md) var(--radius-md);
    box-shadow: var(--dw-pocket-shadow);
    transform-origin: 50% 100%;
    color: var(--dw-text);
    padding: 15px 18px 0;
}
.dw-pocket-face::before {
    content: ""; position: absolute; left: 9px; right: 9px; top: 7px; bottom: 9px;
    border: 1px dashed var(--dw-stitch); border-bottom: 0; border-radius: 12px 12px 0 0;
    pointer-events: none;
}
.dw-total { display: flex; align-items: baseline; gap: .45rem; }
.dw-total-num { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.dw-total-label { font-size: 11px; color: var(--dw-text-soft); }
.dw-total-sub { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 0; font-size: 10.5px; color: var(--dw-text-soft); font-variant-numeric: tabular-nums; }
.dw--empty .dw-total-sub { display: block; }

/* The total's two halves: the amount itself carries the colour, green for
   what's in the accounts and red for what the cards are owed, the same pair
   the balances use. The words after it stay plain. */
.dw-tag {
    font-size: 10.5px; font-weight: 600; line-height: 1.3; white-space: nowrap;
    color: var(--dw-text-soft);
}
.dw-tag b { font-weight: 700; }
.dw-tag--in b   { color: var(--accent); }
.dw-tag--owed b { color: var(--danger); }
.dw-total-sub { column-gap: 12px; }
/* Same lettering as the "Wallet" mark, on its own line under the figures. */
.dw-more {
    display: inline-block; margin-top: 10px;
    font-size: 10px; font-weight: 700; letter-spacing: .24em; text-transform: uppercase;
    color: var(--dw-mark);
    text-shadow: var(--dw-mark-edge);
    text-decoration: none;
}
.dw-more:hover { color: var(--dw-mark-hover); }
.dw-more:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* What changed since your last visit, floating off the card it changed. */
.dw-chip {
    position: absolute; z-index: 40; pointer-events: none;
    font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
    padding: .15rem .45rem; border-radius: 999px;
    background: var(--paper-card); color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.dw-chip.is-in { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
    .dw-card, .dw-notes, .dw-pocket, .dw-bob, .dw-note, .dw-flip, .dw-big { transition: opacity .2s linear !important; }
    .dw-bob, .dw-note { transform: none !important; }
    .dw-flip { transform: none !important; }
    .dw-back { transform: none; opacity: 0; transition: opacity .2s linear; }
    .dw-card.is-flipped .dw-back { opacity: 1; }
    .dw-card.is-flipped .dw-face.wcard-face { opacity: 0; }
    .wcard-face::after { transition: none; }
}

/* An empty wallet: open slots above a flat pocket. */
.dw--empty { display: flex; flex-direction: column; }
.dw-slots { display: grid; gap: 0; padding: 1.4rem 1rem 0; }
.dw-slots span {
    display: block; height: 30px;
    border: 1px dashed var(--dw-stitch); border-bottom: 0;
    border-radius: 10px 10px 0 0;
}
.dw-slots span + span { margin-top: -6px; }
.dw--empty .dw-pocket { position: relative; height: auto; margin-top: -8px; }
.dw--empty .dw-pocket-face { position: relative; padding-bottom: 1.1rem; }
.dw--empty .dw-total-num { font-size: 18px; }

/* The Wallet keeps its own height; Likely upcoming takes what's left. */
@media (min-width: 1101px) {
    .cc-side > .dw-panel { flex: 0 0 auto; }
}
@media (max-width: 1100px) {
    .cc-side > .dw-panel { flex: 1 1 0; min-width: 0; }
}

/* A phone gets one column in its own order: this month's spend, the Wallet,
   what you owe and are owed, Likely upcoming, then Contacts. The rail and
   side columns dissolve (display: contents) so their cards can be ordered
   one by one. The weekly breakdown, Last 6 months and Recently settled stay
   on the wider layouts. */
@media (max-width: 600px) {
    .cc-rail,
    .cc-side { display: contents; }
    .cc-main                      { order: 1; }
    .cc-side > .dw-panel          { order: 2; }
    /* Back to the desktop's column — owe, the net pill, owed — rather than
       the side-by-side pair the 720px layout makes, so the pill sits between
       the two cards it's worked out from, joined to each by its rule. */
    .cc-rail-balances             { order: 3; flex-direction: column; flex-wrap: nowrap; }
    .cc-rail-balances > .stat-card { flex: none; }
    .cc-rail-balances > .cc-net    { flex: none; order: 0; }
    .cc-side > .cc-panel--list3   { order: 4; }
    .cc-panel--strip-main         { order: 5; }
    .cc-month-split,
    .cc-trend-panel,
    .cc-panel--strip-side         { display: none; }
}

/* --- Analysis: the Wallet section --- */
.an-wallet { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1rem; }
.an-bars { list-style: none; margin: 0.9rem 0 0; padding: 0; display: grid; gap: 0.65rem; }
.an-bar-row { display: grid; grid-template-columns: minmax(0, 9rem) minmax(0, 1fr) auto; align-items: center; gap: 0.75rem; font-size: 0.86rem; }
.an-bar-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.an-bar-track { height: 8px; border-radius: 4px; background: var(--border-soft); overflow: hidden; }
.an-bar-track i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.an-bar-row--quiet .an-bar-track i { background: var(--ink-faint); }
.an-bar-row--quiet .an-bar-name { color: var(--ink-muted); }
.an-bar-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.an-note { margin-top: 0.9rem; font-size: 0.76rem; color: var(--ink-muted); }
.an-lag { margin-top: 1rem; }
.an-lag-headline { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0 0; }
.an-lag-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.an-lag-sub { font-size: 0.86rem; color: var(--ink-muted); }
.an-usage { list-style: none; margin: 0.9rem 0 0; padding: 0; display: grid; gap: 1rem; }
.an-usage-row { display: grid; grid-template-columns: minmax(0, 9rem) minmax(0, 1fr); align-items: end; gap: 0.75rem; }
.an-usage-name { font-size: 0.86rem; font-weight: 600; display: flex; flex-direction: column; min-width: 0; }
.an-usage-name small { font-weight: 400; font-size: 0.72rem; color: var(--ink-muted); }
.an-usage-cols { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.4rem; }
.an-usage-col { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }
.an-usage-bar { width: 100%; max-width: 22px; height: 44px; border-radius: 4px; background: var(--border-soft); display: flex; align-items: flex-end; overflow: hidden; }
.an-usage-bar i { display: block; width: 100%; background: var(--accent-3); border-radius: 4px 4px 0 0; }
.an-usage-col.is-high .an-usage-bar i { background: var(--accent-2); }
.an-usage-col.is-empty .an-usage-bar { background: repeating-linear-gradient(135deg, var(--border-soft) 0 3px, transparent 3px 6px); }
.an-usage-month { font-size: 0.68rem; color: var(--ink-muted); }
@media (max-width: 820px) { .an-wallet { grid-template-columns: minmax(0, 1fr); } }

/* Admin: the AI accounts tab (/admin/ai) */
.admin-badge--ok     { color: var(--accent); background: var(--accent-light); }
.admin-badge--bad    { color: var(--danger); background: var(--danger-light); }
.admin-badge--muted  { color: var(--ink-muted); background: var(--paper-warm); }
.admin-ai-actions    { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1.5rem; }
.admin-ai-actions form { margin: 0; }
.admin-ai-note       { color: var(--ink-muted); font-size: 0.85rem; margin: 0 0 1rem; }
.admin-ai-prompt     { font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.8rem;
                       white-space: pre-wrap; word-break: break-word; }
.admin-ai-detail     { font-size: 0.8rem; color: var(--ink-muted); white-space: pre-wrap;
                       word-break: break-word; margin: 0.35rem 0 0; }
.admin-ai-row--bad td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

/* Two-factor sign-in card (profile.html #two-factor) */
.twofa-qr { display: block; margin: 0.75rem 0; background: #fff; border-radius: 8px; padding: 6px; }
.twofa-key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.06em; word-break: break-all; }
.twofa-form { margin-top: 1rem; }
.twofa-codes { margin-bottom: 1rem; padding: 0.9rem 1rem; border: 1.5px solid var(--accent); border-radius: 10px; background: var(--accent-light); }
.twofa-code-list { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 0.35rem 1rem; }
.twofa-code-list code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.95rem; }

/* --- Newer / older under a paged history (templates/_pager.html) --- */
.history-pager {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    gap: 0.75rem; margin-top: 0.85rem; font-size: 0.8rem;
}
.history-pager-link {
    font-weight: 600; color: var(--accent); text-decoration: none;
}
.history-pager-link:hover { text-decoration: underline; }
.history-pager-link[rel="next"] { justify-self: end; }
.history-pager-where { color: var(--ink-muted); }

/* --- The disclosure on anything a model wrote (Dex's strip line and answers,
   Dex's take): for screen readers only, no written "AI" chip on screen. The
   sparkle beside it carries the same words as a tooltip. --- */
.ai-label {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.cc-insight--empty .ai-label,
.cc-insight--app:not(.cc-insight--answer) .ai-label { display: none; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.auth-legal { margin-top: 0.85rem; font-size: 0.78rem; color: var(--ink-muted); text-align: center; line-height: 1.5; }
.auth-legal a { color: var(--accent); }

/* --- Profile → Data → Download your data --- */

/* --- Landing: FAQ --- */
.faq-section { padding: 4rem 1.5rem; }
.faq-inner { max-width: 760px; margin: 0 auto; }
.faq-title { font-size: 1.9rem; letter-spacing: -0.02em; margin: 0 0 1.25rem; }
.faq-item { border-bottom: 1px solid var(--border); }
.faq-item > summary {
    cursor: pointer; list-style: none; padding: 1.05rem 2rem 1.05rem 0; position: relative;
    font-weight: 600; font-size: 1rem; color: var(--ink);
}
.faq-item > summary::-webkit-details-marker { display: none; }
.faq-item > summary:hover { color: var(--accent); }
.faq-item > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* A plus whose upright turns flat into a minus. --open is set by
   static/js/landing_faq.js as an item starts opening and taken off as it
   starts closing, so the icon moves with the answer; [open] covers no JS. */
.faq-icon {
    position: absolute; right: 0.25rem; top: 50%;
    width: 14px; height: 14px; margin-top: -7px;
    color: var(--ink-muted);
    transition: color 0.2s ease;
}
.faq-icon::before,
.faq-icon::after {
    content: ''; position: absolute; left: 0; top: 6px;
    width: 14px; height: 2px; border-radius: 1px; background: currentColor;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.faq-icon::after { transform: rotate(90deg); }
.faq-item[open]:not(.faq-item--closing) .faq-icon::after,
.faq-item.faq-item--open .faq-icon::after { transform: rotate(0deg); }
.faq-item[open]:not(.faq-item--closing) .faq-icon,
.faq-item.faq-item--open .faq-icon { color: var(--accent); }
.faq-item > summary:hover .faq-icon { color: var(--accent); }

.faq-answer { overflow: hidden; }
.faq-answer > p { margin: 0 0 1.1rem; color: var(--ink-muted); line-height: 1.7; font-size: 0.95rem; }

@media (prefers-reduced-motion: reduce) {
    .faq-icon, .faq-icon::before, .faq-icon::after { transition: none; }
}

/* --- Landing: sticky sign-up bar, phones only --- */
.sticky-cta { display: none; }
@media (max-width: 640px) {
    .sticky-cta {
        display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
        padding: 0.7rem 1rem calc(0.7rem + env(safe-area-inset-bottom));
        background: var(--paper-card); border-top: 1px solid var(--border);
        box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.06);
        transform: translateY(110%); transition: transform 0.25s ease;
    }
    .sticky-cta--on { transform: translateY(0); }
    .sticky-cta-text { font-size: 0.85rem; color: var(--ink-muted); }
    .sticky-cta-btn { padding: 0.6rem 1.1rem; }
}
@media (max-width: 640px) and (prefers-reduced-motion: reduce) {
    .sticky-cta { transition: none; }
}
.paper-crumbs { display: inline-flex; gap: 0.4rem; align-items: baseline; }
.paper-article-more { max-width: 42rem; margin: 2.5rem auto 0; color: var(--ink-muted); line-height: 1.7; }
.paper-article-more a { color: var(--accent); }

/* --- Cookie choice (only when analytics is configured; consent.py) --- */
.consent-banner {
    position: fixed; left: 1rem; right: 1rem; bottom: 1rem; z-index: 60; margin: 0 auto;
    max-width: 640px; display: flex; gap: 1rem; align-items: center; justify-content: space-between;
    padding: 0.9rem 1rem; background: var(--paper-card); color: var(--ink);
    border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.12);
}
.consent-text { margin: 0; font-size: 0.85rem; line-height: 1.5; color: var(--ink-muted); }
.consent-text a { color: var(--accent); }
.consent-actions { display: flex; gap: 0.5rem; flex: none; }
/* Same size, same weight, same colour: neither answer is the easy one. */
.consent-btn {
    min-width: 6rem; padding: 0.55rem 0.9rem; border-radius: 8px; cursor: pointer;
    font: 600 0.85rem var(--font); color: var(--ink);
    background: transparent; border: 1px solid var(--ink);
}
.consent-btn:hover { background: var(--accent-light); }
@media (max-width: 560px) {
    .consent-banner { flex-direction: column; align-items: stretch; }
    .consent-actions > * { flex: 1; }
}

.nav-brand:active { opacity: 0.6; }
