/* TripTrek — visual language inherited from BookTrek/MoneyTrek: neutral
   page canvas, white cards, one restrained accent. TripTrek's accent is an
   ocean blue (departure boards and clear skies) so the three apps read as
   siblings, not the same app. */

:root {
    color-scheme: light;
    --bg: #f8f9fa;
    --bg-gradient: none;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --border-soft: #f1f5f9;
    --accent: #0369a1;
    --accent-dark: #075985;
    --accent-soft: #e0f2fe;
    --sub: #475569;

    --ok-bg: #d1fae5;      --ok-fg: #047857;
    --warn-bg: #fef3c7;    --warn-fg: #b45309;
    --danger-fg: #b3261e;

    --up: #047857;
    --down: #b3261e;

    /* Chart series: 1 = pensions, 2 = savings & shares */
    --series-1: #0369a1;
    --series-2: #b45309;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.06);

    --content-max: 1080px;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #151719;
        --bg-gradient: radial-gradient(circle at 15% 0%, #1d2427 0%, #151719 40%);
        --card: #22282b;
        --text: #edf1ef;
        --muted: #93a09b;
        --border: #3b4649;
        --border-soft: #2b3336;
        --accent: #38bdf8;
        --accent-dark: #7dd3fc;
        --accent-soft: #0c3149;
        --sub: #b4c0bb;
        --ok-bg: #064e3b;   --ok-fg: #6ee7b7;
        --warn-bg: #4a3208; --warn-fg: #fcd34d;
        --danger-fg: #f2a8a2;
        --up: #6ee7b7;
        --down: #f2a8a2;
        --series-1: #38bdf8;
        --series-2: #e8a04c;
        --shadow-sm: none;
        --shadow-md: none;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    background-image: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

main {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: calc(3.6rem + env(safe-area-inset-top)) 1rem calc(5.5rem + env(safe-area-inset-bottom));
}

h1 { font-size: 1.45rem; font-weight: 800; letter-spacing: -0.02em; margin: 0.8rem 0 0.15rem; }
h2 { font-size: 1.02rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 0.6rem; }

.page-sub { color: var(--sub); font-size: 0.92rem; margin: 0 0 1.1rem; }

/* ---------------------------------------------------------------- topbar */

.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 30;
    background: var(--card);
    border-bottom: 1px solid var(--border-soft);
    padding-top: env(safe-area-inset-top);
}
.topbar-inner {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0.55rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.wordmark-btn { background: none; border: 0; padding: 0; cursor: pointer; }
.wordmark {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    font-family: inherit;
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
}
.wordmark-trek { color: var(--accent); }
.wordmark-cairn {
    height: 1.1em; width: 1.1em;
    margin-left: 0.22rem;
    fill: var(--accent);
    opacity: 0.9;
}
.topbar-signout {
    background: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.3rem 0.8rem;
    cursor: pointer;
}
.topbar-signout:hover { color: var(--text); border-color: var(--muted); }

/* ---------------------------------------------------------------- tab nav */

.tab-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 30;
    display: flex;
    justify-content: space-around;
    max-width: var(--content-max);
    margin: 0 auto;
    background: var(--card);
    border-top: 1px solid var(--border-soft);
    padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom));
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    flex: 1;
    padding: 0.25rem 0;
    text-decoration: none;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 600;
}
.nav-item .nav-ic svg { width: 1.35rem; height: 1.35rem; display: block; }
.nav-item.on { color: var(--accent); }

/* ---------------------------------------------------------------- cards */

.card {
    background: var(--card);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.1rem;
    margin-bottom: 0.9rem;
}

.card-footnote { color: var(--muted); font-size: 0.82rem; margin: 0.7rem 0 0; line-height: 1.5; }
.card-footnote a { color: var(--accent); font-weight: 600; text-decoration: none; }

/* ---------------------------------------------------------------- dashboard */

.stat-hero { display: flex; flex-direction: column; gap: 0.15rem; }
.stat-label {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.stat-value { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; }
.stat-delta { font-size: 0.85rem; font-weight: 600; }
.stat-delta.up { color: var(--up); }
.stat-delta.down { color: var(--down); }

.stat-row, .summary-strip {
    display: grid;
    /* minmax(0,1fr): a wide figure can't force its column wider and shove
       the last tile off-screen */
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
    margin-bottom: 0.9rem;
}
.stat-mini { min-width: 0; }
.stat-mini {
    margin: 0;
    padding: 0.75rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    /* centred content keeps the three tiles reading as a matched set */
    align-items: center;
    text-align: center;
}
/* Bottom-pinned so the figures stay on one line with each other even when
   a neighbour's label wraps on a narrow screen. */
.stat-mini-value { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; margin-top: auto; }
.stat-mini-next { color: var(--muted); font-size: 0.7rem; font-weight: 600; }
.stat-mini-next.neg { color: var(--danger-fg); }
.stat-mini-value.neg, .amount.neg { color: var(--danger-fg); }

.iht-note { color: var(--muted); font-weight: 500; font-size: 0.78em; }
.iht-hero { margin: 0.7rem 0 0.2rem; }
.iht-hero-value { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; color: var(--danger-fg); line-height: 1.1; }
.iht-bar-block { margin-top: 1rem; }
.iht-bar-title { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0 0.6rem; color: var(--sub); font-size: 0.8rem; font-weight: 650; margin-bottom: 0.35rem; }
.iht-bar-title strong { color: var(--text); }
.iht-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--border-soft); }
.iht-bar span { height: 100%; }
.seg-pension { background: var(--series-1); }
.seg-savings { background: #e8a04c; }
.seg-house { background: #5aa9d6; }
.seg-free { background: #2e7d5b; }
.seg-taxed { background: #b3564e; }
.iht-legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; margin-top: 0.45rem; }
.iht-chip { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--sub); font-size: 0.78rem; font-weight: 600; }
.iht-chip strong { color: var(--text); font-weight: 700; }
.iht-dot { width: 0.65rem; height: 0.65rem; border-radius: 3px; display: inline-block; }
.iht-allow { color: var(--muted); font-size: 0.78rem; margin-top: 0.5rem; line-height: 1.5; }
.iht-allow strong { color: var(--sub); }
.iht-trend { margin-top: 1.1rem; border-top: 1px solid var(--border-soft); padding-top: 0.8rem; }
.iht-trend-title { color: var(--muted); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.3rem; }
/* Falling IHT is the win condition — down reads green here */
.iht-change { font-weight: 700; font-size: 0.9rem; margin-top: 0.55rem; }
.iht-change.good { color: var(--up); }
.iht-change.bad { color: var(--down); }
.iht-card { scroll-margin-top: 3.6rem; }

/* ⓘ info popup (CSS-only modal: the open summary's ::before is a fixed
   backdrop, so tapping anywhere outside closes it) */
.group-title { display: flex; align-items: center; gap: 0.35rem; }
.group-title h2 { margin: 0; }
.info-pop > summary {
    list-style: none;
    cursor: pointer;
    color: var(--muted);
    font-size: 0.95rem;
    padding: 0 0.25rem;
}
.info-pop > summary::-webkit-details-marker { display: none; }
.info-pop[open] > summary::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 40;
}
.info-pop-card {
    position: fixed;
    z-index: 50;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 680px);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-md);
}
.info-pop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; }
.info-pop-close {
    background: none;
    border: 0;
    color: var(--muted);
    font: inherit;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
}

.goal-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 0.6rem; }
.goal-edit[open] { flex-basis: 100%; }
.goal-edit summary {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}
.goal-edit summary::-webkit-details-marker { display: none; }
.goal-bar {
    height: 12px;
    border-radius: 999px;
    background: var(--border-soft);
    overflow: hidden;
    margin: 0.55rem 0 0.6rem;
}
.goal-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), var(--accent-dark));
    min-width: 6px;
}
.goal-figures {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.1rem;
    color: var(--sub);
    font-size: 0.86rem;
}
.goal-figures strong { color: var(--text); }
.goal-reached { color: var(--ok-fg); font-weight: 700; }

.chart-card h2 { margin-bottom: 0.3rem; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; margin-bottom: 0.4rem; }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--sub); font-weight: 600; }
.legend-swatch { width: 0.85rem; height: 0.3rem; border-radius: 2px; display: inline-block; }
.legend-1 .legend-swatch { background: var(--series-1); }
.legend-2 .legend-swatch { background: var(--series-2); }
.chart-scroll { overflow-x: auto; }
.trend-chart { width: 100%; min-width: 480px; height: auto; display: block; }
.grid-line { stroke: var(--border-soft); stroke-width: 1; }
.axis-line { stroke: var(--border); stroke-width: 1; }
.axis-label { fill: var(--muted); font-size: 11px; font-family: inherit; }
.trend-line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.trend-line.trend-1 { stroke: var(--series-1); }
.trend-line.trend-2 { stroke: var(--series-2); }
.trend-dot.trend-1 { fill: var(--series-1); }
.trend-dot.trend-2 { fill: var(--series-2); }

.left-rows { display: flex; flex-direction: column; }
.left-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.95rem;
}
.left-row:last-child { border-bottom: 0; }
.left-total { font-weight: 700; }
.left-row .amount { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------------------------------------------------------------- accounts */

.total-strip {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.8rem 1.1rem;
    font-size: 0.95rem;
}
.total-strip span { font-weight: 700; }
.share-strip {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.65rem 1.1rem;
    font-size: 0.85rem;
    color: var(--sub);
}
.share-strip strong { color: var(--text); font-size: 0.95rem; }
.share-strip-val { display: flex; align-items: baseline; gap: 0.5rem; }
.total-strip strong { font-size: 1.15rem; letter-spacing: -0.01em; }

/* Top margin keeps the group heading clear of the All-accounts strip
   above (sibling margins collapse, so group-to-group gaps stay 1.4rem). */
.account-group { margin-top: 1.3rem; margin-bottom: 1.4rem; }
.group-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0 0.2rem;
    margin-bottom: 0.5rem;
}
.group-head h2 { margin: 0; }
.group-total { color: var(--sub); font-weight: 700; font-size: 0.92rem; font-variant-numeric: tabular-nums; }

.subgroup-head {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0.6rem 0.2rem 0.45rem;
}
.account-card { padding: 0.85rem 1rem; margin-bottom: 0.55rem; }
.account-main { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; }
.account-names { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.account-name { font-weight: 650; font-size: 0.95rem; }
.account-meta { color: var(--muted); font-size: 0.78rem; }
.account-balance { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.account-balances { display: flex; flex-direction: column; align-items: flex-end; gap: 0.05rem; }
.account-delta { font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.account-delta.up { color: var(--up); }
.account-delta.down { color: var(--down); }
/* Tap the account card to log a balance (the monthly habit); editing the
   account's details is a second, quieter step inside. */
details.account-card { display: block; }
.account-card.row-tap[open] > summary .account-name { color: var(--accent); }
.edit-more { margin-top: 0.3rem; }
.edit-more > summary { font-size: 0.8rem; }
.move-row { display: flex; gap: 0.5rem; margin: 0.5rem 0 0.2rem; }

/* ---------------------------------------------------------------- bills */

/* Gentle nudge banners */
.nudge-card { border-left: 3px solid var(--warn-fg); padding: 0.8rem 1rem; }
.nudge-title {
    color: var(--warn-fg);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}
.nudge-text { color: var(--sub); font-size: 0.85rem; margin: 0; line-height: 1.5; }
.nudge-text strong { color: var(--text); font-weight: 650; }
/* Compact one-per-line: name (ellipsized) · source tag · date pinned right */
.nudge-line { display: flex; align-items: center; gap: 0.45rem; padding: 0.18rem 0; }
.nudge-name {
    color: var(--text);
    font-weight: 650;
    font-size: 0.85rem;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nudge-tag {
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: var(--border-soft);
    color: var(--muted);
    white-space: nowrap;
}
.nudge-tag.bank { background: var(--warn-bg); color: var(--warn-fg); }
.nudge-tag.in { background: var(--ok-bg); color: var(--ok-fg); }
.nudge-when {
    margin-left: auto;
    color: var(--sub);
    font-size: 0.8rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.nudge-line.overdue .nudge-name, .nudge-line.overdue .nudge-when { color: var(--danger-fg); }

.section-label {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 1.4rem 0.2rem 0.6rem;
}

.due-badge {
    background: var(--border-soft);
    color: var(--sub);
    font-size: 0.72rem;
    font-weight: 650;
    padding: 0.18rem 0.55rem;
    border-radius: 999px;
    white-space: nowrap;
}
.due-badge.soon { background: var(--warn-bg); color: var(--warn-fg); }
.due-badge.overdue { background: var(--warn-bg); color: var(--danger-fg); }
.offer-star { color: #d9a441; font-size: 0.85em; }

.bill-group { padding-bottom: 0.55rem; scroll-margin-top: 3.6rem; /* anchored sort links land clear of the fixed topbar */ }
/* Post-save redirects anchor back to the row that was edited. */
.row-tap, .income-card, .goal-card { scroll-margin-top: 3.6rem; }
/* Card payment rows: hero due-amount, then the due chip, then a muted
   liability line — cash-out-now and total-debt no longer compete. */
.pay-row { padding: 0.6rem 0; border-top: 1px solid var(--border-soft); }
.pay-row:first-of-type { border-top: 0; }
.pay-top { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.6rem; }
.pay-name { flex: 1 1 auto; min-width: 8rem; font-weight: 650; font-size: 0.95rem; }
.pay-due { font-weight: 750; font-size: 1.08rem; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.pay-liability { color: var(--muted); font-size: 0.76rem; }
div.pay-liability { margin-top: 0.15rem; }
.pay-liability strong { color: var(--sub); font-weight: 600; }

/* Outflow vs liability vs forecast, as three aligned figures */
.stat-footer {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    border-top: 1px solid var(--border-soft);
    margin-top: 0.7rem;
    padding-top: 0.7rem;
}
.stat-footer div { display: flex; flex-direction: column; gap: 0.1rem; }
/* Anchor the outer columns to the card edges (amounts above are
   right-aligned, so the last column meets them) and centre the middle. */
.stat-footer div:nth-child(2) { align-items: center; text-align: center; }
.stat-footer div:nth-child(3) { align-items: flex-end; text-align: right; }
.sf-label {
    color: var(--muted);
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.sf-value { font-size: 0.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.provider-head {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0.55rem;
}
.provider-head + .line-row { border-top: 0; }
.provider-head { scroll-margin-top: 3.6rem; }
/* Subgroup heading and its sort picker share one line */
.subhead-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0 0.6rem;
    scroll-margin-top: 3.6rem;
}
.subhead-row .provider-head { margin-top: 0.55rem; }
/* A subgroup that follows rows starts a NEW list — draw the boundary */
details.line-row + .subhead-row, details.pay-row + .subhead-row {
    border-top: 2px solid var(--border);
    margin-top: 0.9rem;
    padding-top: 0.35rem;
}
.subhead-row .sort-row { margin: 0.55rem 0 0.3rem; }
.sort-row + .line-row { border-top: 0; }
.bill-group .group-head { margin-bottom: 0.2rem; padding: 0; }
.income-card .line-row:first-of-type { border-top: 0; }

/* Two-line rows: name + amount on top, meta + due badge underneath.
   The one-flex-row-with-everything version crushed the name column into a
   sliver on phones. */
.line-row {
    padding: 0.55rem 0;
    border-top: 1px solid var(--border-soft);
}
.line-top { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem; }
.line-top .line-name { flex: 1 1 auto; min-width: 8rem; }
.line-sub {
    display: flex;
    /* top-aligned: when a row carries two chips (due + offer), the meta
       stays snug under the name instead of being centred down the row */
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.25rem 0.6rem;
    margin-top: 0.15rem;
}
.line-sub .line-meta, .line-sub .pay-liability { flex: 1 1 auto; }
/* Due chips sit on the RIGHT in every section — dates line up under the
   amounts (and stay right-aligned even when a long meta line wraps). */
.line-sub .due-badge { margin-left: auto; }
/* Due chip in its usual spot; the offer chip stacks beneath it,
   right-aligned — consistent with every other row's chip position. */
.badge-group {
    margin-left: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}
.badge-group .due-badge { margin-left: 0; }
/* An open edit expander takes the full width UNDER the row instead of
   squeezing into the top line. */
.line-edit[open] { flex-basis: 100%; }
.line-name { font-weight: 600; font-size: 0.92rem; }
.line-meta { color: var(--muted); font-size: 0.76rem; }
.line-amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.line-amount small { color: var(--muted); font-weight: 500; }

/* Whole-row tap targets: the row itself is the <summary>, tapping it opens
   the edit form beneath (replaced the little ✎ pencils, which were fiddly
   on a phone). */
details.line-row, details.pay-row { display: block; }
.row-tap > summary { list-style: none; cursor: pointer; position: relative; padding-left: 0.75rem; }
/* Colour bar per item: category-coded for bills, section-coded elsewhere. */
.row-tap > summary::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.35rem;
    bottom: 0.35rem;
    width: 3px;
    border-radius: 3px;
    background: var(--bar, var(--border));
}
.bar-income { --bar: var(--accent); }
.bar-card { --bar: #e58a1a; }
.bar-instalment { --bar: #9c6bce; }
.bar-bnpl { --bar: #d9679e; }
.bar-housing { --bar: #2e7dbb; }
.bar-entertainment { --bar: #8a7cc4; }
.bar-health { --bar: #3f9d68; }
.bar-insurance { --bar: #d9a441; }
.bar-phone-internet { --bar: #c4694f; }
.bar-loan { --bar: #b3261e; }
.bar-pension { --bar: var(--accent); }
.bar-cash { --bar: #3f9d68; }
.bar-business { --bar: #8a8378; }
.bar-invest { --bar: #e58a1a; }
.bar-cash_isa { --bar: #2e7dbb; }
.bar-shares { --bar: #e58a1a; }
.bar-isa { --bar: #8a7cc4; }
.row-tap > summary::-webkit-details-marker { display: none; }
.row-tap > summary:active { opacity: 0.7; }
.row-tap[open] > summary .line-name,
.row-tap[open] > summary .pay-name { color: var(--accent); }

/* ---------------------------------------------------------------- forms */

.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: flex-end;
    padding: 0.7rem 0 0.3rem;
}
.inline-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}
.inline-form input, .inline-form select,
.auth-card input {
    font: inherit;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.45rem 0.6rem;
    min-width: 0;
}
.inline-form input { width: 9.5rem; }

/* Money inputs show a £ inside the box — display only, you just type the
   number (the backend strips a typed £ anyway). */
.money { position: relative; display: inline-block; }
.money::before {
    content: '£';
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.9rem;
    pointer-events: none;
}
.money input { padding-left: 1.45rem; width: 100%; }
.inline-form .money { width: 9.5rem; }

/* Same iOS quirk BookTrek hit: a native date input keeps its own much
   taller intrinsic rendering (and centres its text) until appearance is
   stripped — then the explicit height matches its sibling fields. */
.inline-form input[type="date"], .auth-card input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
    height: 2.35rem;
    line-height: 2.35rem;
    padding-top: 0;
    padding-bottom: 0;
    text-align: left;
    overflow: hidden;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; }

.sort-row {
    text-align: right;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    margin: -0.1rem 0 0.3rem;
}
.sort-row a { color: var(--muted); text-decoration: none; font-weight: 700; padding: 0.15rem; }
.sort-row a.on { color: var(--accent); }
.inline-form input:focus, .inline-form select:focus, .auth-card input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
    border-color: transparent;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 10px;
    font: inherit;
    font-weight: 700;
    padding: 0.55rem 1.2rem;
    cursor: pointer;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.85rem; }
.btn-ghost {
    display: inline-block;
    color: var(--accent);
    font-size: 0.84rem;
    font-weight: 650;
    cursor: pointer;
    list-style: none;
    padding: 0.2rem 0;
}
.btn-ghost::-webkit-details-marker { display: none; }
.btn-cancel {
    background: none;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--muted);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.45rem 0.9rem;
    cursor: pointer;
}
.btn-cancel:hover { color: var(--text); border-color: var(--muted); }
.btn-danger-ghost {
    background: none;
    border: 0;
    color: var(--danger-fg);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.3rem 0;
    cursor: pointer;
}
.add-card details > summary { text-align: center; }
.add-inline { margin-top: 0.4rem; }

/* ---------------------------------------------------------------- auth */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.auth-card { width: 100%; max-width: 26rem; }
.auth-card label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--muted); margin: 0.8rem 0 0.25rem; }
.auth-card input { width: 100%; }
.auth-title { margin-bottom: 0.3rem; }
.auth-title .wordmark { font-size: 1.4rem; }
.auth-subtitle { color: var(--muted); font-size: 0.9rem; margin: 0 0 1rem; }
.auth-subtitle.small { font-size: 0.8rem; margin: 0.4rem 0 0; line-height: 1.45; }
.auth-error {
    background: #fdecea;
    color: #b3261e;
    border: 1px solid #f4c7c3;
    border-radius: 9px;
    padding: 0.65rem 0.9rem;
    font-size: 0.88rem;
    margin-bottom: 1rem;
}
@media (prefers-color-scheme: dark) {
    .auth-error { background: #3a2422; color: #f2a8a2; border-color: #5c332f; }
}
.check-label {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem !important;
    font-weight: 500 !important;
    font-size: 0.88rem !important;
    color: var(--text) !important;
}
.check-label input { width: auto; }
.submit-row { margin-top: 1.2rem; }
.submit-row .btn-primary { width: 100%; }
.totp-qr { display: block; margin: 0 auto 0.6rem; border-radius: 12px; max-width: 200px; width: 100%; background: #fff; padding: 8px; }
code { background: var(--border-soft); border-radius: 6px; padding: 0.1rem 0.35rem; font-size: 0.85em; word-break: break-all; }

/* ---------------------------------------------------------------- narrow screens */

@media (max-width: 640px) {
    /* Phone: form fields stack full-width instead of wrapping at a fixed
       9.5rem, which overflowed the viewport inside cards. */
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form label { width: 100%; }
    .inline-form input, .inline-form select { width: 100%; }
    .inline-form .money { width: 100%; }
    .inline-form .btn-primary { width: 100%; }

    /* Three stat tiles across a phone: tighter padding and smaller figures
       so £1,297,884 fits its third without clipping the row. */
    .stat-row, .summary-strip { gap: 0.45rem; }
    .stat-row .stat-mini, .summary-strip .stat-mini { padding: 0.6rem 0.55rem; }
    .stat-mini-value { font-size: 0.9rem; }
    .stat-mini .stat-label { font-size: 0.66rem; letter-spacing: 0.03em; }
}

/* ---------------------------------------------------------------- wide screens */

@media (min-width: 760px) {
    .hero-stats { display: grid; grid-template-columns: 1.2fr 1fr; gap: 0.9rem; align-items: stretch; }
    .hero-stats .stat-hero { margin-bottom: 0.9rem; justify-content: center; }
    .stat-row { grid-template-columns: 1fr; margin-bottom: 0.9rem; }
    .stat-row .stat-mini { flex-direction: row; justify-content: space-between; align-items: center; }
}

/* ================================================================ TripTrek */

/* Estimate (≈, awaiting statement) amber, reusing the warn palette */
.est-badge { color: var(--warn-fg); margin-right: 2px; font-weight: 700; }
.notice-card { background: var(--warn-bg); color: var(--warn-fg);
    border-color: transparent; font-size: 0.9rem; text-decoration: none;
    display: block; }

/* Current-leg banner */
.leg-banner { display: flex; align-items: center; gap: 0.8rem;
    background: var(--accent-soft); border-radius: 16px;
    padding: 0.8rem 1rem; margin-bottom: 0.9rem; }
.leg-emoji { font-size: 1.8rem; }
.leg-name { font-weight: 800; font-size: 1.05rem; }
.leg-sub { color: var(--muted); font-size: 0.8rem; }
.leg-log { margin-left: auto; text-decoration: none; white-space: nowrap; }

/* Spend-by-day bars */
.bars { display: flex; flex-direction: column; gap: 0.3rem; }
.bar-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; }
.bar-date { width: 2.6rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-track { flex: 1; background: var(--border-soft); border-radius: 4px; height: 0.85rem; }
.bar-fill { background: var(--accent); border-radius: 4px; height: 100%; min-width: 2px; }
.bar-val { width: 3rem; text-align: right; font-variant-numeric: tabular-nums; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.mini-table td { padding: 0.4rem 0; border-top: 1px solid var(--border-soft); }
.mini-table tr:first-child td { border-top: none; }
.mini-table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.current-leg td:first-child { font-weight: 800; color: var(--accent); }

/* Expense rows */
.expense-row { display: flex; justify-content: space-between; align-items: center;
    gap: 0.7rem; padding: 0.55rem 0; border-top: 1px solid var(--border-soft);
    color: inherit; text-decoration: none; }
.expense-row:first-of-type { border-top: none; }
a.expense-row.card { border: 1px solid var(--border-soft); padding: 0.7rem 1rem;
    margin-bottom: 0.55rem; }
.expense-main { display: flex; flex-direction: column; min-width: 0; gap: 0.05rem; }
.expense-item { font-weight: 650; font-size: 0.92rem; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; }
.expense-sub { color: var(--muted); font-size: 0.75rem; }
.expense-amts { display: flex; flex-direction: column; align-items: flex-end;
    flex-shrink: 0; gap: 0.05rem; }
.expense-gbp { font-weight: 750; font-variant-numeric: tabular-nums; }
.expense-orig { color: var(--muted); font-size: 0.75rem;
    font-variant-numeric: tabular-nums; }
.day-group { margin-bottom: 0.9rem; }
.day-head { display: flex; justify-content: space-between; font-size: 0.78rem;
    font-weight: 700; color: var(--muted); padding: 0.2rem 0.3rem 0.35rem; }

/* Segmented control (currency picker, list filters) */
.seg { display: flex; gap: 0.35rem; align-items: center; justify-content: center;
    flex-wrap: wrap; }
.page-seg { margin-bottom: 0.8rem; }
.seg-btn { border: 1px solid var(--border); background: var(--card);
    color: var(--text); border-radius: 999px; padding: 0.42rem 0.9rem;
    font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
    text-decoration: none; }
.seg-btn.active { background: var(--accent); border-color: var(--accent);
    color: #fff; }
#more-cur { border: 1px solid var(--border); background: var(--card);
    color: var(--muted); border-radius: 999px; padding: 0.42rem 0.6rem;
    font: inherit; font-size: 0.8rem; }

/* Category chips */
.chips { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: center; }
.chip { border: 1px solid var(--border); background: var(--card);
    color: var(--text); border-radius: 999px; padding: 0.38rem 0.75rem;
    font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.chip.active { background: var(--accent-soft); border-color: var(--accent);
    color: var(--accent); }

/* Logger */
.log-form { display: flex; flex-direction: column; gap: 0.8rem;
    max-width: 30rem; margin: 0 auto; }
.amount-wrap { display: flex; align-items: center; justify-content: center;
    gap: 0.3rem; margin-top: 0.5rem; }
.amount-symbol { font-size: 2rem; color: var(--muted); font-weight: 700; }
#amount { font-size: 2.9rem; font-weight: 800; width: 60%; border: none;
    background: none; color: var(--text); outline: none;
    font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
#amount::placeholder { color: var(--border); }
.gbp-preview { text-align: center; font-size: 0.95rem; color: var(--muted);
    min-height: 1.3rem; }
.log-form input[type="text"], .log-form input[type="date"] {
    font: inherit; font-size: 0.9rem; color: var(--text); background: var(--card);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 0.6rem 0.75rem; width: 100%; }
.log-form input[type="date"] { -webkit-appearance: none; appearance: none;
    height: 2.6rem; line-height: 2.6rem; padding-top: 0; padding-bottom: 0;
    text-align: left; overflow: hidden; background: var(--card); }
.field-row { display: flex; gap: 0.6rem; }
.field-row > * { flex: 1 1 auto; min-width: 0; }
.btn-big { width: 100%; padding: 0.85rem; font-size: 1.05rem; }
.log-status { text-align: center; color: var(--muted); font-size: 0.85rem;
    min-height: 1.2rem; }

/* Edit form */
.edit-form { display: flex; flex-direction: column; gap: 0.7rem;
    max-width: 30rem; margin: 0 auto; }
.edit-form label { display: flex; flex-direction: column; gap: 0.25rem;
    font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.edit-form input, .edit-form select, .edit-form textarea {
    font: inherit; font-size: 0.9rem; color: var(--text); background: var(--card);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 0.6rem 0.75rem; width: 100%; }
.edit-form input[type="date"] { -webkit-appearance: none; appearance: none;
    height: 2.6rem; line-height: 2.6rem; padding-top: 0; padding-bottom: 0; }
.edit-form input:focus, .edit-form select:focus, .edit-form textarea:focus,
.log-form input:focus { outline: 2px solid var(--accent); outline-offset: 0;
    border-color: transparent; }
.settle-box { background: var(--warn-bg); border-radius: 14px;
    padding: 0.8rem 0.9rem; display: flex; flex-direction: column; gap: 0.5rem; }
.settle-box.settled { background: var(--ok-bg); }
.settle-box.settled .settle-head { color: var(--ok-fg); }
.settle-head { font-size: 0.9rem; color: var(--warn-fg); }
.actions-row { display: flex; gap: 0.6rem; margin-top: 0.3rem; }
.actions-row > * { flex: 1 1 auto; text-align: center; }
.delete-row { text-align: center; margin: 0.3rem 0 1rem; }

/* Center + button in the tab nav */
.nav-add { background: var(--accent); color: #fff !important; font-size: 1.7rem;
    width: 3.3rem; height: 3.3rem; flex: 0 0 3.3rem; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin-top: -1.4rem; box-shadow: var(--shadow-md), 0 4px 14px rgba(0,0,0,0.22);
    line-height: 1; text-decoration: none; font-weight: 700; }

.rates-note { text-align: center; color: var(--muted); font-size: 0.75rem;
    margin: 0.5rem 0 0.8rem; }
.muted { color: var(--muted); }
.small { font-size: 0.78rem; }
.center { text-align: center; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.row-between h3 { margin: 0 0 0.4rem; }
.chip-link { color: var(--accent); font-size: 0.82rem; font-weight: 650;
    text-decoration: none; }
.big-line { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em;
    margin: 0.1rem 0; }

/* ==================================================== Logger v2 (keypad) */

.logv2 {
    --lg-bg: #f6f7f8;
    --lg-card: #ffffff;
    --lg-border: #e3e6e8;
    --lg-key: #ffffff;
    --lg-key-fn: #eef1f3;
    --lg-text: #16181a;
    --lg-muted: #6b7680;
    --lg-accent: #0ea5e9;
    --lg-accent-press: #0284c7;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    max-width: 26rem;
    margin: 0 auto;
    min-height: calc(100vh - 8rem);
    min-height: calc(100dvh - 8rem);
    position: relative;
    color: var(--lg-text);
}
@media (prefers-color-scheme: dark) {
    .logv2 {
        --lg-bg: #121214;
        --lg-card: #1c1c1e;
        --lg-border: #2c2c2e;
        --lg-key: #1c1c1e;
        --lg-key-fn: #242427;
        --lg-text: #f2f4f6;
        --lg-muted: #8e9aa4;
        --lg-accent: #0ea5e9;
        --lg-accent-press: #38bdf8;
    }
}

.logv2-close {
    position: absolute; top: -0.2rem; right: 0;
    width: 2.6rem; height: 2.6rem; display: flex;
    align-items: center; justify-content: center;
    border-radius: 50%; text-decoration: none;
    color: var(--lg-muted); font-size: 1.05rem; font-weight: 700;
    background: var(--lg-key-fn); z-index: 2;
}

.logv2-amount-zone { text-align: center; padding: 0.4rem 0 0; }
.logv2-amount {
    display: flex; align-items: center; justify-content: center;
    gap: 0.4rem; min-height: 3.6rem;
}
.logv2-symbol { font-size: 1.4rem; font-weight: 700; color: var(--lg-muted);
    align-self: center; }
.logv2-digits {
    font-size: 3.2rem; font-weight: 800; letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums; line-height: 1;
}
.logv2-digits.placeholder {
    color: color-mix(in srgb, var(--lg-muted) 40%, transparent); }
.logv2-preview { color: var(--lg-muted); font-size: 0.9rem; min-height: 1.25rem;
    font-variant-numeric: tabular-nums; }

.logv2-selectors { display: flex; flex-direction: column; gap: 0.55rem; }
.logv2-seg { justify-content: center; }
.logv2-seg .seg-btn { min-height: 44px; }

.logv2-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }
.logv2-chips .chip {
    min-height: 44px; padding: 0.45rem 0.8rem;
    display: inline-flex; align-items: center; gap: 0.35rem;
    background: var(--lg-card); border: 1px solid var(--lg-border);
    color: var(--lg-text);
}
.logv2-chips .chip.active { background: color-mix(in srgb, var(--lg-accent) 16%, var(--lg-card));
    border-color: var(--lg-accent); color: var(--lg-accent); }
.chip-ico { font-size: 1rem; }

.logv2-who {
    display: flex; border: 1px solid var(--lg-border); border-radius: 12px;
    overflow: hidden; background: var(--lg-card);
}
.who-btn {
    flex: 1 1 0; min-height: 48px; border: none; background: none;
    font: inherit; font-size: 0.88rem; font-weight: 650; color: var(--lg-muted);
    cursor: pointer; border-left: 1px solid var(--lg-border);
}
.who-btn:first-child { border-left: none; }
.who-btn.active { background: var(--lg-accent); color: #fff; }

.logv2-meta {
    border: 1px solid var(--lg-border); border-radius: 12px;
    background: var(--lg-card); overflow: hidden;
}
.logv2-meta-toggle {
    width: 100%; min-height: 48px; border: none; background: none;
    font: inherit; font-size: 0.85rem; color: var(--lg-muted);
    text-align: left; padding: 0 0.9rem; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.logv2-meta-fields { padding: 0 0.75rem 0.75rem;
    display: flex; flex-direction: column; gap: 0.55rem; }
.logv2-meta-fields[hidden] { display: none; }
.logv2-meta-fields input {
    font: inherit; font-size: 0.9rem; color: var(--lg-text);
    background: var(--lg-key-fn); border: 1px solid var(--lg-border);
    border-radius: 10px; padding: 0.6rem 0.75rem; width: 100%;
    -webkit-appearance: none; appearance: none;
}
.logv2-meta-fields input[type="date"] { height: 2.7rem; line-height: 2.7rem;
    padding-top: 0; padding-bottom: 0; }

.logv2-keypad {
    margin-top: auto;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: minmax(56px, 1fr);
    gap: 0.45rem;
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
}
.key {
    border: 1px solid var(--lg-border);
    border-radius: 14px;
    background: var(--lg-key);
    color: var(--lg-text);
    font: inherit; font-size: 1.45rem; font-weight: 650;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.05s ease, filter 0.05s ease;
}
.key:active { transform: scale(0.96); filter: brightness(0.92); }
@media (prefers-color-scheme: dark) {
    .key:active { filter: brightness(1.25); }
}
.key-fn { background: var(--lg-key-fn); font-size: 1.15rem; color: var(--lg-muted); }
.key-fn:disabled { opacity: 0.35; cursor: default; }
.key-save {
    grid-column: 4; grid-row: 3 / span 2;
    background: var(--lg-accent); border-color: var(--lg-accent);
    color: #fff; font-size: 1rem; font-weight: 800; line-height: 1.35;
}
.key-save:active { background: var(--lg-accent-press); transform: scale(0.97); }
.key-save:disabled { opacity: 0.6; }
/* Key grid placement: ⌫ and C sit in column 4 rows 1-2; Save owns rows 3-4. */
.logv2 .log-status { min-height: 1.3rem; padding-bottom: 0.4rem; }

/* Quick-pick note pills (appear per category) */
.logv2-picks {
    display: flex; gap: 0.35rem; overflow-x: auto;
    padding: 0.1rem 0.1rem 0.25rem; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.logv2-picks::-webkit-scrollbar { display: none; }
.pick {
    flex: 0 0 auto; min-height: 40px; padding: 0.3rem 0.75rem;
    border-radius: 999px; border: 1px dashed var(--lg-border);
    background: none; color: var(--lg-muted);
    font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer;
}
.pick.active { border-style: solid; border-color: var(--lg-accent);
    color: var(--lg-accent);
    background: color-mix(in srgb, var(--lg-accent) 12%, transparent); }

.logv2-impact { text-align: center; font-size: 0.82rem; min-height: 1.15rem;
    color: var(--lg-accent); font-weight: 600;
    font-variant-numeric: tabular-nums; }

/* Logger v2.1 — header bar, currency badge, stats tiles, scrolling cats */
.logv2-topbar { display: flex; align-items: center; justify-content: center;
    position: relative; min-height: 2.6rem; }
.logv2-title { font-weight: 700; font-size: 1rem; }
.logv2-topbar .logv2-close { position: absolute; top: 0; right: 0; }

.cur-badge { position: relative; display: inline-flex; align-items: center;
    gap: 0.15rem; margin-left: 0.2rem; padding: 0.32rem 0.6rem;
    border: 1px solid var(--lg-border); border-radius: 999px;
    background: var(--lg-key-fn); color: var(--lg-muted);
    font-size: 0.8rem; font-weight: 700; align-self: center; }
.cur-caret { font-size: 0.6rem; }
.cur-badge select { position: absolute; inset: 0; opacity: 0;
    width: 100%; height: 100%; cursor: pointer; }

.logv2-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem; margin-top: 0.55rem; }
.stat-tile { background: var(--lg-card); border: 1px solid var(--lg-border);
    border-radius: 12px; padding: 0.45rem 0.3rem; display: flex;
    flex-direction: column; align-items: center; gap: 0.1rem; min-width: 0; }
.stat-tile-label { font-size: 0.62rem; font-weight: 700; letter-spacing: 0.04em;
    text-transform: uppercase; color: var(--lg-muted); white-space: nowrap; }
.stat-tile-value { font-size: 0.82rem; font-weight: 750;
    font-variant-numeric: tabular-nums; white-space: nowrap; }
.logv2-stats.projecting #tile-today, .logv2-stats.projecting #tile-trip,
.logv2-stats .stat-tile.hot { border-color: var(--lg-accent); }
.logv2-stats.projecting #tile-today .stat-tile-value,
.logv2-stats.projecting #tile-trip .stat-tile-value,
.logv2-stats .stat-tile.hot .stat-tile-value { color: var(--lg-accent); }

.logv2-catrow { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
    padding: 0.1rem 0.1rem 0.25rem; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; }
.logv2-catrow::-webkit-scrollbar { display: none; }
.logv2-catrow .chip { flex: 0 0 auto; }

/* Dashboard polish — pills, bill list rows, tappable banner */
.autocharge-pill { display: inline-block; margin-top: 0.45rem;
    padding: 0.3rem 0.7rem; border-radius: 999px; font-size: 0.78rem;
    font-weight: 600; background: var(--warn-bg); color: var(--warn-fg); }
.bill-row { display: flex; justify-content: space-between; align-items: center;
    gap: 0.7rem; padding: 0.65rem 0; border-top: 1px solid var(--border-soft); }
.bill-row:first-of-type { border-top: none; }
.bill-main { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.bill-name { font-weight: 700; font-size: 0.95rem; }
.bill-sub { color: var(--muted); font-size: 0.78rem; }
.bill-total { font-weight: 800; font-size: 1rem;
    font-variant-numeric: tabular-nums; white-space: nowrap; }
.bill-footer { color: var(--muted); font-size: 0.75rem; margin: 0.5rem 0 0;
    text-align: right; }
.bill-footer a { color: var(--accent); font-weight: 600; text-decoration: none; }
.notice-card { display: flex; justify-content: space-between;
    align-items: center; gap: 0.6rem; border-left: 3px solid var(--warn-fg); }
.notice-chevron { font-size: 1.3rem; font-weight: 700; line-height: 1; }

.bill-row-due .bill-name { color: var(--warn-fg); }
.bill-row-due .bill-total { color: var(--warn-fg); }

.days-badge { display: inline-block; padding: 0.05rem 0.4rem;
    border-radius: 999px; background: var(--accent-soft); color: var(--accent);
    font-size: 0.68rem; font-weight: 700; }
.cycle-badge { color: var(--accent); font-weight: 600; }

.logv2-topbar.close-left .logv2-close { left: 0; right: auto; }

/* Dashboard v3 — micro stats + per-card bill modules */
.micro-stats { display: grid; grid-template-columns: repeat(3, minmax(0,1fr));
    gap: 0.5rem; margin-top: 0.5rem; }
.micro-stat { display: flex; flex-direction: column; gap: 0.05rem; }
.micro-label { color: var(--muted); font-size: 0.68rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.04em; }
.micro-value { font-size: 0.88rem; font-weight: 650;
    font-variant-numeric: tabular-nums; }
.section-title { margin: 0 0.3rem 0.5rem; font-size: 1.05rem; }
.bill-card { margin-bottom: 0.7rem; }
.bill-card-top { display: flex; justify-content: space-between;
    align-items: baseline; gap: 0.6rem; }
.bill-big { font-size: 1.25rem; font-weight: 800;
    font-variant-numeric: tabular-nums; white-space: nowrap; }
.bill-card-mid { display: flex; align-items: center; gap: 0.5rem;
    flex-wrap: wrap; margin-top: 0.35rem; }
.close-pill { display: inline-block; padding: 0.15rem 0.55rem;
    border-radius: 999px; background: var(--accent-soft); color: var(--accent);
    font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.bill-formula { color: var(--muted); font-size: 0.8rem; white-space: nowrap;
    font-variant-numeric: tabular-nums; }
.bill-topay { display: flex; justify-content: space-between; gap: 0.6rem;
    margin-top: 0.5rem; padding: 0.45rem 0.6rem; border-radius: 10px;
    background: var(--warn-bg); color: var(--warn-fg); font-size: 0.8rem;
    align-items: center; }
.bill-topay-amt { font-weight: 800; font-variant-numeric: tabular-nums;
    white-space: nowrap; }
.next-cycle { display: flex; justify-content: space-between; gap: 0.6rem;
    margin-top: 0.45rem; color: var(--muted); font-size: 0.8rem;
    font-variant-numeric: tabular-nums; }

.bill-left { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.bill-right { display: flex; flex-direction: column; align-items: flex-end;
    gap: 0.3rem; flex-shrink: 0; }
.bill-left .bill-formula { white-space: normal; }
/* Align the pill's text (not its padded edge) with the amount above it */
.bill-right .close-pill { margin-right: -0.55rem; }

/* Dashboard v3.1 — boxed hero stats, inline close badge, divided next-cycle */
.micro-stats { background: var(--border-soft); border-radius: 12px;
    padding: 0.55rem 0.7rem; }
.autocharge-pill { display: block; width: 100%; text-align: center;
    margin-top: 0.55rem; }
.bill-name-group { display: inline-flex; align-items: center; gap: 0.45rem;
    min-width: 0; flex-wrap: wrap; }
.bill-formula-row { color: var(--muted); font-size: 0.8rem; margin-top: 0.3rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-variant-numeric: tabular-nums; }
.next-cycle { border-top: 1px solid var(--border-soft); padding-top: 0.45rem;
    margin-top: 0.55rem; }
.bill-right .close-pill { margin-right: 0; }
/* Centre each column so the three stats spread evenly in the box */
.micro-stat { align-items: center; text-align: center; }

.topbar-gear { font-size: 1.05rem; text-decoration: none; padding: 0.25rem;
    margin-right: 0.35rem; filter: grayscale(0.3); }
.topbar-actions { display: flex; align-items: center; }

/* Hero card v2 — no duplicated totals, tighter rhythm */
.hero-card { padding: 0.85rem 1rem; }
.hero-subtitle { color: var(--muted); font-size: 0.85rem; margin: 0.15rem 0 0;
    font-variant-numeric: tabular-nums; }
.hero-box { background: var(--border-soft); border-radius: 12px;
    padding: 0.55rem 0.7rem; margin-top: 0.55rem; display: flex;
    flex-direction: column; gap: 0.4rem; }
.hero-box-stat { font-size: 0.82rem; color: var(--sub);
    font-variant-numeric: tabular-nums; }
.hero-box .autocharge-pill { margin-top: 0; }

/* Total-cost + By-leg in the bills pattern */
.row-link { text-decoration: none; color: inherit; display: flex; }
.row-link span:first-child { color: var(--accent); font-weight: 650; }
.bill-card .autocharge-pill { margin-top: 0.55rem; }
.leg-row { display: flex; justify-content: space-between; align-items: center;
    gap: 0.7rem; padding: 0.5rem 0; border-top: 1px solid var(--border-soft); }
.leg-row:first-child { border-top: none; padding-top: 0.1rem; }
.leg-row-name { font-weight: 700; font-size: 0.92rem; }
.leg-row.current .leg-row-name { color: var(--accent); }
.leg-row-amt { font-weight: 750; font-variant-numeric: tabular-nums; }
.leg-row-amt.muted { font-weight: 500; }
/* Spend-page tabs scroll horizontally instead of wrapping */
.page-seg { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    padding-bottom: 0.15rem; }
.page-seg::-webkit-scrollbar { display: none; }
.page-seg .seg-btn { flex: 0 0 auto; white-space: nowrap; }

/* Swipe-to-delete on spend rows */
.swipe-wrap { position: relative; overflow: hidden; border-radius: 16px;
    margin-bottom: 0.55rem; touch-action: pan-y; }
.swipe-wrap a.expense-row.card { margin-bottom: 0;
    transition: transform 0.18s ease; position: relative; z-index: 1;
    background: var(--card); }
.swipe-delete { position: absolute; top: 0; right: 0; bottom: 0;
    width: 88px; display: flex; z-index: 0; }
.swipe-delete button { flex: 1; border: none; background: #d33a2c;
    color: #fff; font: inherit; font-size: 0.85rem; font-weight: 700;
    cursor: pointer; border-radius: 0 16px 16px 0; }

/* Aesthetic pass — gradient hero, statement progress, itinerary timeline */
.hero-gradient {
    background: linear-gradient(140deg,
        var(--accent-soft) 0%, var(--card) 55%);
}
.cycle-track { height: 4px; border-radius: 2px; background: var(--border-soft);
    margin-top: 0.6rem; overflow: hidden; }
.cycle-fill { height: 100%; border-radius: 2px; min-width: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent-dark)); }

.leg-timeline { position: relative; }
.leg-timeline::before { content: ''; position: absolute; left: 5px;
    top: 14px; bottom: 14px; width: 2px; background: var(--border); }
.leg-row { position: relative; padding-left: 1.35rem; }
.leg-dot { position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 12px; height: 12px; border-radius: 50%; background: var(--card);
    border: 2px solid var(--border); z-index: 1; }
.leg-row.past .leg-dot { background: var(--accent); border-color: var(--accent); }
.leg-row.current .leg-dot { background: var(--card); border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft); }
.leg-row.past .leg-row-name { color: var(--sub); }

.swipe-wrap .expense-row { background: var(--card); }
.swipe-wrap { border-radius: 12px; }

/* The journey — TripTrek's trail */
.journey-card { padding: 0.8rem 1rem 0.7rem; overflow: hidden;
    background: linear-gradient(180deg,
        color-mix(in srgb, var(--accent-soft) 55%, var(--card)) 0%,
        var(--card) 80%); }
.journey-label { font-weight: 800; font-size: 0.95rem; text-align: center; }
.journey-svg { width: 100%; height: auto; display: block; margin-top: 0.2rem; }
.journey-track { fill: none; stroke: var(--border); stroke-width: 2.5;
    stroke-linecap: round; stroke-dasharray: 0.1 3; }
.journey-done { fill: none; stroke: var(--accent); stroke-width: 2.5;
    stroke-linecap: round; }
.journey-node { fill: var(--card); stroke: var(--border); stroke-width: 2; }
.journey-node.past { fill: var(--accent); stroke: var(--accent); }
.journey-node.current { stroke: var(--accent); }
.journey-emoji { font-size: 11px; }
.journey-plane { font-size: 13px; }
.journey-plane.flying { animation: plane-bob 2.2s ease-in-out infinite; }
@keyframes plane-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
    .journey-plane.flying { animation: none; }
}
.journey-node.current { animation: node-pulse 2s ease-in-out infinite; }
@keyframes node-pulse {
    0%, 100% { stroke-width: 2; r: 4.5; }
    50% { stroke-width: 3.5; r: 5.5; }
}
.journey-dates { color: var(--muted); font-size: 0.72rem; text-align: center;
    margin-top: 0.1rem; }

/* A fabulous trip to Asia — sky by day, night flight in dark mode */
.journey-card {
    background: linear-gradient(180deg, #e8f4ff 0%, #fdf3e3 78%, var(--card) 100%);
}
@media (prefers-color-scheme: dark) {
    .journey-card {
        background: linear-gradient(180deg, #0d1b2e 0%, #1b2233 70%, var(--card) 100%);
    }
    .journey-track { stroke: #3b4a63; }
}
.journey-decor { opacity: 0.85; }
.journey-label { letter-spacing: -0.01em; }
