/* client/css/styles.css */
:root {
    /* "Black card" palette — charcoal + emerald + warm gold.
       All foreground/background pairs verified ≥ 4.5:1 (AA).            */
    --bg: #161a1f;            /* deep charcoal — like a metal card     */
    --surface: #1f242c;       /* card / panel                          */
    --surface-2: #2a313b;     /* inputs, secondary buttons             */
    --surface-3: #353d49;     /* hover state                           */
    --text: #f3eddc;          /* warm off-white (AmEx ivory)           */
    --muted: #b9b1a0;         /* warm muted ivory                      */
    --accent: #d4a64a;        /* warm gold — primary CTA               */
    --accent-2: #b8862c;      /* gold hover                            */
    --accent-text: #161a1f;   /* dark text on gold (≥10:1)             */
    --secondary: #2f8568;     /* deep emerald — secondary CTA          */
    --secondary-2: #25684f;
    --danger: #d96a6a;        /* desaturated coral on dark             */
    --danger-2: #b94c4c;
    --ok: #4cc391;            /* emerald accent for balances           */
    --border: #3a414c;
    --radius: 10px;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        /* Cream + ink + emerald — like a paper statement w/ gold trim */
        --bg: #f6f1e6;           /* warm cream                          */
        --surface: #ffffff;
        --surface-2: #f0e9da;
        --surface-3: #e6dcc6;
        --text: #1a1f17;         /* near-black green-tinted ink         */
        --muted: #4f5648;
        --accent: #1d6b4a;       /* deep emerald — CTAs                 */
        --accent-2: #144f37;
        --accent-text: #ffffff;
        --secondary: #8a5a1f;    /* burnt gold — secondary              */
        --secondary-2: #6b4416;
        --danger: #a32424;
        --danger-2: #7d1a1a;
        --ok: #1d6b4a;
        --border: #d4c9af;
        --shadow: 0 6px 22px rgba(60, 40, 10, 0.12);
    }
}

/* User-selected theme overrides the OS preference. Mirror values from the
 * default :root (dark) and the prefers-color-scheme: light block above. */
:root[data-theme="dark"] {
    --bg: #161a1f;
    --surface: #1f242c;
    --surface-2: #2a313b;
    --surface-3: #353d49;
    --text: #f3eddc;
    --muted: #b9b1a0;
    --accent: #d4a64a;
    --accent-2: #b8862c;
    --accent-text: #161a1f;
    --secondary: #2f8568;
    --secondary-2: #25684f;
    --danger: #d96a6a;
    --danger-2: #b94c4c;
    --ok: #4cc391;
    --border: #3a414c;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

:root[data-theme="light"] {
    --bg: #f6f1e6;
    --surface: #ffffff;
    --surface-2: #f0e9da;
    --surface-3: #e6dcc6;
    --text: #1a1f17;
    --muted: #4f5648;
    --accent: #1d6b4a;
    --accent-2: #144f37;
    --accent-text: #ffffff;
    --secondary: #8a5a1f;
    --secondary-2: #6b4416;
    --danger: #a32424;
    --danger-2: #7d1a1a;
    --ok: #1d6b4a;
    --border: #d4c9af;
    --shadow: 0 6px 22px rgba(60, 40, 10, 0.12);
}

* { box-sizing: border-box; }

/* Honor [hidden] even when an explicit display is set elsewhere */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.skip-link {
    position: absolute;
    left: -9999px;
}

/* Compact circular icon button (e.g. header gear). Grid centering with
 * line-height: 0 keeps inline SVGs visually centered regardless of font. */
.icon-btn {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 999px;
    width: 36px;
    height: 36px;
    padding: 0;
    line-height: 0;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.icon-btn svg { display: block; width: 18px; height: 18px; }
.icon-btn:hover { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Settings dialog: stretch the segmented theme toggle to the full row width
 * so each option is easy to read and tap and visually matches the modal. */
.toggle-row.toggle-row-wide { display: flex; width: 100%; }
.toggle-row.toggle-row-wide .radio-pill { flex: 1; }
.settings-footnote { margin-top: 0.5rem; font-size: 0.85rem; }
    top: 0;
    background: var(--accent);
    color: var(--accent-text);
    padding: 0.5rem 1rem;
    z-index: 1000;
}

.skip-link:focus { left: 0; }

header {
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-bottom: 2px solid var(--accent);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
}

header h1 {
    margin: 0;
    font-size: 1.25rem;
    letter-spacing: 0.02em;
}

.subtitle {
    color: var(--muted);
    margin: 0;
    font-size: 0.85rem;
    flex: 1;
}

/* Brand: logo mark + wordmark, sits on the left of the header. */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1.35rem;
    letter-spacing: 0.01em;
    margin-right: auto; /* push #user-nav to the right edge */
}
.brand:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
    border-radius: 8px;
}
.brand-mark {
    display: inline-grid;
    place-items: center;
    color: var(--accent); /* drives the rect fill via currentColor */
    line-height: 0;
    width: 40px; height: 40px;
}
.brand-mark svg { display: block; }
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
.brand-word { line-height: 1; }

#user-nav {
    margin-left: auto; /* belt-and-suspenders so logout sits hard-right */
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.hello { color: var(--muted); font-size: 0.9rem; }

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.25rem;
}

button, input, select {
    font: inherit;
    color: inherit;
}

button {
    background: var(--accent);
    color: var(--accent-text);
    border: 0;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    transition: background .15s, transform .05s;
}

button:hover { background: var(--accent-2); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

button.danger {
    background: var(--danger);
    color: var(--accent-text);
}
button.danger:hover { background: var(--danger-2); }

input, select, textarea {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.65rem;
    width: 100%;
    font: inherit;
    color: var(--text);
}

textarea {
    resize: vertical;
    min-height: 2.5rem;
}

input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    color: var(--muted);
}

label input, label select, label textarea { color: var(--text); }

/* Auth */
#auth-view {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0;
}
.landing-auth {
    max-width: 460px;
    margin: 3rem auto 0;
    padding: 0 0.5rem;
    scroll-margin-top: 100px;
}
.landing-auth-card {
    background: transparent;
}
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.tabs button {
    flex: 1;
    background: var(--surface-2);
    color: var(--text);
}
.tabs button[aria-selected="true"] {
    background: var(--accent);
    color: var(--accent-text);
}

.card-form {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 100%;
    box-shadow: var(--shadow);
}
.card-form h2 { margin-top: 0; text-align: center; }
.card-form > button[type="submit"] {
    display: block;
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.7rem 1rem;
    font-weight: 600;
}
.form-error {
    color: var(--danger);
    min-height: 1.25rem;
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    text-align: center;
}

/* Optional grouped sub-sections inside the card form */
.form-group {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem 0.4rem;
    margin: 0.5rem 0;
    background: rgba(255,255,255,0.015);
}
.form-group > legend {
    padding: 0 0.4rem;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text);
    font-weight: 700;
}
.form-group label { display: block; margin: 0.25rem 0; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
@media (max-width: 600px) { .row-2 { grid-template-columns: 1fr; } }

/* Yes/No segmented toggle used by the Annual fee / Sign-up bonus questions.
 * Hides the native radio bullet so the pills read as a clean segmented control.
 * A pseudo-element "thumb" slides between options driven by :has() — no JS. */
.toggle-row {
    position: relative;
    display: inline-flex; gap: 0;
    margin: 0.2rem 0 0.5rem;
    padding: 3px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    isolation: isolate;
}
/* The sliding selection indicator. Width is set per-variant below. */
.toggle-row::before {
    content: "";
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 3px;
    width: calc((100% - 6px) / 2); /* default: 2-option toggle */
    background: var(--accent);
    border-radius: 999px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.18), 0 4px 10px rgba(0,0,0,0.12);
    transform: translateX(0);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
    pointer-events: none;
}
/* 2-option: slide thumb to second pill when checked. */
.toggle-row:has(.radio-pill:nth-child(2) input:checked)::before {
    transform: translateX(100%);
}
/* 3-option (settings theme picker): thumb is 1/3 wide and slides 0/100/200%. */
.toggle-row.toggle-row-wide::before { width: calc((100% - 6px) / 3); }
.toggle-row.toggle-row-wide:has(.radio-pill:nth-child(2) input:checked)::before {
    transform: translateX(100%);
}
.toggle-row.toggle-row-wide:has(.radio-pill:nth-child(3) input:checked)::before {
    transform: translateX(200%);
}
/* Use .toggle-row .radio-pill (specificity 0,2,0) so it beats
 * `.form-group label { display: block }` which would otherwise win. */
.toggle-row .radio-pill {
    position: relative;
    z-index: 1;
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 84px;
    margin: 0;
    padding: 0.5rem 1.25rem;
    border: 0; border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem; font-weight: 600;
    line-height: 1.1;
    text-align: center;
    color: var(--text);
    background: transparent;
    user-select: none;
    transition: color 0.22s ease, background-color 0.22s ease;
}
/* Hide the native radio dot entirely — visual state is communicated by the pill itself. */
.radio-pill input {
    position: absolute; opacity: 0; pointer-events: none; inset: 0;
    width: 100%; height: 100%; margin: 0;
}
.radio-pill:hover { color: var(--text); }
/* The checked pill gets its own solid background so static contrast checkers
 * (and forced-colors mode) see the white-on-accent contrast directly, not
 * just the decorative ::before slide thumb. */
.radio-pill:has(input:checked) { color: #fff; background: var(--accent); }
.radio-pill:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
    .toggle-row::before { transition: none; }
}
.conditional-fields { margin-top: 0.3rem; }

/* Perks repeater inside the Add Card modal. */
.card-perks-rows {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.card-perk-row {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.2fr) auto;
    gap: 0.4rem;
    align-items: center;
}
.card-perk-row .cp-remove {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}
.card-perk-row .cp-remove:hover {
    color: #b91c1c;
    border-color: #fca5a5;
    background: #fee2e2;
}
.card-perks-add {
    width: auto;
    max-width: 100%;
    margin-top: 0.25rem;
    padding-inline: 1rem;
}
@media (max-width: 560px) {
    .card-perk-row {
        grid-template-columns: 1fr 1fr auto;
        grid-template-areas:
            "title title remove"
            "value period period";
    }
    .card-perk-row .cp-title { grid-area: title; }
    .card-perk-row .cp-value { grid-area: value; }
    .card-perk-row .cp-period { grid-area: period; }
    .card-perk-row .cp-remove { grid-area: remove; }
}

/* Sign-up bonus progress strip on card tiles */
.cc-bonus-strip {
    margin-top: 0.4rem;
    font-size: 0.72rem;
    color: var(--text);
}
.cc-bonus-strip .cc-bonus-label {
    display: flex; justify-content: space-between; gap: 0.5rem;
    margin-bottom: 0.18rem; opacity: 0.92;
}
.cc-bonus-strip .cc-bonus-bar {
    background: var(--surface-3);
    border-radius: 999px;
    height: 6px; overflow: hidden;
}
.cc-bonus-strip .cc-bonus-fill {
    background: linear-gradient(90deg, #4ea888 0%, #6cd4a0 100%);
    height: 100%; transition: width 0.3s ease;
}
.cc-bonus-strip.is-met .cc-bonus-fill { background: linear-gradient(90deg, #2f8568 0%, #5fbb88 100%); }
.cc-bonus-strip.is-overdue .cc-bonus-fill { background: linear-gradient(90deg, #c97179 0%, #e09898 100%); }
.cc-bonus-strip .cc-bonus-meta {
    display: flex; justify-content: space-between; gap: 0.5rem;
    margin-bottom: 0; margin-top: 0.18rem;
    opacity: 0.78; font-size: 0.66rem;
    color: var(--text);
}
.cc-bonus-strip .cc-bonus-status { color: #4ea888; font-weight: 600; }

.card-tile .cc-fee-pill {
    position: absolute; top: 10px; right: 12px;
    /* Solid dark background pairs with white text for adequate contrast on
     * any card variant (light or dark). Avoids relying on the gradient. */
    background-color: #1a1d22;
    color: #fff;
    font-size: 0.75rem; padding: 3px 9px; border-radius: 999px;
    text-transform: uppercase; letter-spacing: 0.06em;
    font-weight: 600;
    pointer-events: none;
    z-index: 2;
}
.card-tile { position: relative; }

/* Annual-fee renewal warning — the fee pill itself tints yellow when the
   anniversary is within ANN_FEE_WARN_DAYS and red when within
   ANN_FEE_URGENT_DAYS. Pill becomes hoverable/focusable and reveals a
   small popover tooltip with the renewal details. */
/* Any fee pill that carries a renewal popover should be hoverable so the
   tooltip can fire — not just the colored warn/urgent variants. */
.card-tile .cc-fee-pill:has(.cc-fee-warning-pop),
.card-tile .cc-fee-pill.warn,
.card-tile .cc-fee-pill.urgent {
    pointer-events: auto;
    cursor: help;
    outline: none;
    z-index: 3;
}
.card-tile .cc-fee-pill.warn {
    background-color: #e0a32a;
    color: #1a1d22;
    box-shadow: 0 0 0 1px rgba(255, 220, 130, 0.55), 0 1px 3px rgba(0, 0, 0, 0.25);
}
.card-tile .cc-fee-pill.urgent {
    background-color: #d64545;
    color: #fff;
    box-shadow: 0 0 0 1px rgba(255, 170, 170, 0.55), 0 1px 3px rgba(0, 0, 0, 0.25);
}
.card-tile .cc-fee-pill.warn:focus-visible,
.card-tile .cc-fee-pill.urgent:focus-visible {
    box-shadow: 0 0 0 3px var(--accent), 0 1px 3px rgba(0, 0, 0, 0.35);
}

.card-tile .cc-fee-warning-pop {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 240px;
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    font-size: 0.82rem;
    line-height: 1.35;
    letter-spacing: normal;
    text-transform: none;
    font-weight: 400;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0s linear 0.12s;
    pointer-events: none;
    z-index: 20;
}
.card-tile .cc-fee-pill:hover .cc-fee-warning-pop,
.card-tile .cc-fee-pill:focus-visible .cc-fee-warning-pop,
.card-tile .cc-fee-pill:focus .cc-fee-warning-pop {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0s;
}
.cc-fee-warning-pop-title {
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--text);
}
.cc-fee-warning-pop-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    color: var(--muted);
}
.cc-fee-warning-pop-row > span:last-child {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.cc-fee-warning-pop-foot {
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px dashed var(--border);
    font-size: 0.74rem;
    color: var(--muted);
}

.csv-import-modal { max-width: 720px; width: 92vw; }
.csv-import-summary { margin: 0 0 0.5rem; opacity: 0.9; }
.csv-import-preview { max-height: 50vh; overflow: auto; margin-bottom: 0.5rem; }
.csv-preview-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.csv-preview-table th, .csv-preview-table td {
    border-bottom: 1px solid var(--border);
    padding: 0.3rem 0.5rem; text-align: left;
}
.csv-import-errors { margin-top: 0.6rem; font-size: 0.8rem; opacity: 0.85; }
.csv-import-errors ul { padding-left: 1.1rem; margin: 0.2rem 0 0; }

/* CSV paste/upload entry dialog */
.csv-paste-help { margin: 0 0 0.6rem; font-size: 0.85rem; opacity: 0.9; }
.csv-paste-help code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 0.78rem; }
.csv-paste-toolbar {
    display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center;
    margin-bottom: 0.6rem;
}
.csv-sample-details { font-size: 0.82rem; flex: 1 1 auto; min-width: 0; }
.csv-sample-details summary { cursor: pointer; opacity: 0.85; }
.csv-sample-preview {
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 0.5rem 0.7rem; margin: 0.4rem 0 0;
    max-height: 220px; overflow: auto;
    font-size: 0.72rem; line-height: 1.35;
    white-space: pre;
}
.csv-paste-label {
    display: block; font-size: 0.78rem; margin: 0.4rem 0 0.2rem; opacity: 0.85;
}
#csv-paste-input {
    width: 100%; box-sizing: border-box;
    min-height: 180px; resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.78rem; line-height: 1.4;
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 0.5rem 0.6rem;
}
.link-btn {
    background: none; border: none; padding: 0;
    color: var(--accent); cursor: pointer;
    text-decoration: underline; font: inherit;
}
.link-btn:hover { opacity: 0.85; }

/* --- Transaction history filter view --------------------------------- */
#transactions-section { margin-top: 1.5rem; }
#transactions-section > details { border: 1px solid var(--border); border-radius: 10px; padding: 0.4rem 0.8rem; }
#transactions-section > details > summary {
    cursor: pointer; padding: 0.3rem 0;
    list-style: none;
}
#transactions-section > details > summary::-webkit-details-marker { display: none; }
#transactions-section > details > summary h2 { margin: 0; font-size: 1.05rem; }
.tx-filter-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.5rem; margin: 0.6rem 0;
}
.tx-filter-form label { font-size: 0.78rem; }
.tx-filter-form .tx-filter-search { grid-column: span 2; min-width: 160px; }
.tx-filter-form input, .tx-filter-form select {
    width: 100%; box-sizing: border-box;
}
.tx-filter-form button { align-self: end; }
.tx-filter-summary { font-size: 0.78rem; opacity: 0.7; margin: 0.3rem 0 0.5rem; }

.tx-list { list-style: none; padding: 0; margin: 0; max-height: 60vh; overflow: auto; }
.tx-row {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 1rem; padding: 0.55rem 0.4rem;
    border-bottom: 1px solid var(--border);
}
.tx-row:last-child { border-bottom: none; }
.tx-row-card { font-weight: 600; font-size: 0.88rem; }
.tx-row-note { font-size: 0.78rem; opacity: 0.75; margin-top: 0.1rem; word-break: break-word; }
.tx-row-amount { font-variant-numeric: tabular-nums; font-weight: 700; }
.tx-row.earn .tx-row-amount { color: var(--ok); }
.tx-row.redeem .tx-row-amount { color: var(--danger); }
.tx-row-date { font-size: 0.72rem; opacity: 0.65; text-align: right; }
.tx-row-right { text-align: right; min-width: 120px; }
.tx-load-more-wrap { text-align: center; padding: 0.5rem 0; }

/* Inline field validation */
input.invalid, select.invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 1px var(--danger);
    background: rgba(217, 106, 106, 0.08);
}
input.invalid:focus-visible, select.invalid:focus-visible {
    outline: 3px solid var(--danger);
    outline-offset: 1px;
    border-color: var(--danger);
}
.field-error {
    display: block;
    margin-top: 0.25rem;
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 600;
}
.field-hint {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-muted, #9aa0aa);
    font-size: 0.75rem;
    font-style: italic;
}

/* Summary */
#summary {
    background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}
#summary h2 { margin-top: 0; }
.totals {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.totals .label { color: var(--muted); font-size: 0.8rem; display: block; text-transform: uppercase; letter-spacing: 0.06em; }
.totals .value { font-size: 1.5rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
#t-total { color: var(--ok); }

/* Annual-fee notice — standalone component that sits *above* #summary.
   Echoes the summary card's surface + radius + shadow so it reads as a
   sibling tile, but stays visually lighter: thinner, no left accent bar,
   no h2, and a subtle accent-tinted wash so it never competes with the
   real summary card. Carousel + dismiss live on the right. */
.annual-fee-notice {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem 0.65rem 0.95rem;
    margin-bottom: 0.85rem;
    background:
        linear-gradient(135deg,
            color-mix(in srgb, var(--accent) 8%, var(--surface)) 0%,
            color-mix(in srgb, var(--accent) 4%, var(--surface-2)) 100%);
    border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: 0.9rem;
}
.annual-fee-notice.urgent {
    background:
        linear-gradient(135deg,
            color-mix(in srgb, var(--danger, #c2410c) 10%, var(--surface)) 0%,
            color-mix(in srgb, var(--danger, #c2410c) 5%, var(--surface-2)) 100%);
    border-color: color-mix(in srgb, var(--danger, #c2410c) 40%, var(--border));
}
.afn-icon {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 22%, var(--surface));
    color: var(--accent);
    flex-shrink: 0;
}
.annual-fee-notice.urgent .afn-icon {
    background: color-mix(in srgb, var(--danger, #c2410c) 22%, var(--surface));
    color: var(--danger, #c2410c);
}
.afn-body { flex: 1; min-width: 0; line-height: 1.25; }
.afn-title { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.afn-meta { font-size: 0.78rem; color: var(--muted); margin-top: 1px; }
.afn-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}
.afn-count {
    font-size: 0.72rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    min-width: 2.4em;
    text-align: center;
}
.afn-nav,
.afn-close {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    line-height: 0;
    border-radius: 50%;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.afn-nav svg,
.afn-close svg { display: block; }
.afn-nav:hover,
.afn-close:hover {
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    color: var(--text);
    border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
}
.afn-nav:disabled {
    opacity: 0.35;
    cursor: default;
}
.afn-nav:disabled:hover {
    background: transparent;
    color: var(--muted);
    border-color: transparent;
}
.afn-nav:focus-visible,
.afn-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 520px) {
    .annual-fee-notice { flex-wrap: wrap; }
    .afn-actions { width: 100%; justify-content: flex-end; }
}

/* Cards */
.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    align-items: flex-end;
}
.filters label {
    flex: 1 1 160px;
    margin-bottom: 0;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.filters select {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    font-weight: 500;
}
.filters #reset-filters-btn { flex: 0 0 auto; }

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 1rem;
    margin: 2.5rem auto;
    max-width: 420px;
}

/* Credit-card-shaped "add your first card" CTA */
.cc-empty {
    all: unset;
    box-sizing: border-box;
    cursor: pointer;
    width: 100%;
    aspect-ratio: 1.586 / 1;
    border-radius: 14px;
    padding: 1.1rem 1.2rem 1rem;
    color: var(--accent);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    isolation: isolate;
    background:
        linear-gradient(135deg, rgba(212, 166, 74, 0.08) 0%, rgba(31, 36, 44, 0.6) 100%),
        var(--surface);
    border: 2px dashed var(--accent);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}
.cc-empty:hover, .cc-empty:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    background:
        linear-gradient(135deg, rgba(212, 166, 74, 0.16) 0%, rgba(31, 36, 44, 0.7) 100%),
        var(--surface);
}
.cc-empty:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}
.cc-empty-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    opacity: 0.85;
}
.cc-empty-issuer {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--muted);
    font-weight: 700;
}
.cc-empty-plus {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(3.5rem, 9vw, 5rem);
    font-weight: 200;
    line-height: 1;
    color: var(--accent);
    opacity: 0.85;
    pointer-events: none;
}
.cc-empty-bottom {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    align-items: flex-start;
}
.cc-empty-cta {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    color: var(--text);
}
.cc-empty-sub {
    font-size: 0.75rem;
    color: var(--muted);
    letter-spacing: 0.02em;
}

.empty-filtered {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}

/* ---- Dashboard ---- */
#dashboard-section { margin-bottom: 1.25rem; }

.dashboard-card-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.1rem;
    background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    color: var(--text);
    font-weight: 700;
    font-size: 1rem;
    text-align: left;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: background .15s ease, box-shadow .15s ease, border-radius .25s ease;
}
.dashboard-card-toggle:hover { background: linear-gradient(135deg, var(--surface-2) 0%, var(--surface-3) 100%); }
.dashboard-card-toggle:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.dashboard-card-toggle.open {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
}
.dashboard-card-title {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}
.dashboard-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: 8px;
    background: rgba(212, 166, 74, 0.14);
    color: var(--accent);
}
.dashboard-card-sub {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.8rem;
    margin-left: 0.25rem;
}
.dashboard-card-chev {
    color: var(--accent);
    transition: transform .25s ease;
    display: inline-flex;
}
.dashboard-card-toggle.open .dashboard-card-chev { transform: rotate(180deg); }

.dashboard-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    animation: dashGrow .25s ease both;
    overflow: hidden;
}
@keyframes dashGrow {
    from { opacity: 0; transform: translateY(-4px); max-height: 0; padding-top: 0; padding-bottom: 0; }
    to   { opacity: 1; transform: translateY(0);    max-height: 1200px; }
}
@media (prefers-reduced-motion: reduce) {
    .dashboard-card-toggle, .dashboard-card-chev, .dashboard-panel { transition: none; animation: none; }
}

.dashboard-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}
.range-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    margin-bottom: 0.7rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 0.15rem;
}
.range-row .range-pill { flex: 0 0 auto; white-space: nowrap; }
.range-pill {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.range-pill:hover { color: var(--text); border-color: var(--accent); }
.range-pill.active {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}
.range-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.range-custom {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.7rem;
    padding: 0.5rem 0.6rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.range-custom label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 600;
}
.range-custom input[type="date"] {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem 0.4rem;
    font: inherit;
    color-scheme: dark;
}
.range-custom input[type="date"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#range-apply {
    background: var(--accent);
    color: var(--accent-text);
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 0.3rem 0.7rem;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
}
#range-apply:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.pie-subtoggle, .chart-subtoggle {
    display: flex;
    gap: 0.35rem;
    margin: -0.35rem 0 0.6rem 0;
    flex-wrap: wrap;
}
.sub-pill {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
}
.sub-pill:hover { color: var(--text); border-color: var(--accent); }
.sub-pill.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.sub-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Vertical divider between two logical groups of sub-pills (e.g. grouping
 * mode vs. include-fees toggle on the per-card breakdown). */
.chart-subtoggle-sep {
    align-self: stretch;
    width: 1px;
    background: var(--border);
    margin: 0.15rem 0.25rem;
}

.sankey-node-label { fill: var(--text); font-size: 12px; font-family: system-ui, sans-serif; font-weight: 600; }
.sankey-node-sub { fill: var(--muted); font-size: 10px; font-family: system-ui, sans-serif; }
.sankey-link { opacity: 0.55; transition: opacity .15s ease; }
.sankey-link:hover { opacity: 0.92; }

.kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.85rem;
}
.kpi-chip {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 0.5rem 0.7rem;
    min-width: 0;
}
.kpi-dot {
    flex: 0 0 auto;
    width: 8px; height: 8px;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.04);
}
.kpi-dot.earn { background: #2f8568; }
.kpi-dot.redeem { background: #7e1f24; }
.kpi-dot.net { background: var(--accent); }
.kpi-dot.top { background: #1c3d6e; }
.kpi-dot.fees { background: #b04826; }
.kpi-dot.net-after { background: #6b8e3d; }
.kpi-chip-label {
    font-size: 0.78rem;
    color: var(--text);
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-period { color: var(--accent); font-weight: 700; margin-left: 0.15rem; }
.kpi-chip-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kpi-top-value { font-size: 0.85rem; }
.kpi-delta {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--muted);
}
/* AA-compliant token-based colors for positive/negative readouts.
 * Use --ok / --danger which are tuned per-theme to pass 4.5:1 on the
 * surrounding surface in both dark and light palettes. */
.kpi-delta.up, .kpi-pos { color: var(--ok); }
.kpi-delta.down, .kpi-neg { color: var(--danger); }
.kpi-delta.flat { color: var(--muted); }
.chart-bar { transition: opacity .15s ease; cursor: default; }
.chart-bar:hover { opacity: 0.85; }
.chart-line-card { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; opacity: 0.95; }
.chart-line-card.dim { opacity: 0.18; }
.chart-legend-text { fill: var(--text); font-size: 12px; font-family: system-ui, sans-serif; }
@media (max-width: 600px) {
    .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    /* Range pills: single horizontally-scrollable line so all options stay visible. */
    .range-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        padding-bottom: 0.25rem;
    }
    .range-pill { flex: 0 0 auto; white-space: nowrap; }
}
.chart-tab {
    background: transparent;
    color: var(--muted);
    border: 1px solid transparent;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.85rem;
}
.chart-tab:hover { color: var(--text); background: var(--surface-2); }
.chart-tab.active {
    background: var(--accent);
    color: var(--accent-text);
}
.chart-wrap {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: var(--radius);
}
.chart-svg {
    display: block;
    width: 100%;
    height: auto;
    background: var(--surface-2);
    border-radius: var(--radius);
}
/* `display: block` above wins over the UA `[hidden] { display: none }`
 * rule by specificity — re-assert hiding so toggling between chart tabs
 * (and the no-data empty state) actually collapses inactive SVGs. */
.chart-svg[hidden] { display: none; }

/* Path-tracing animation. Renderers compute getTotalLength() and set
 * `--dash` (length) on each line/area; we animate stroke-dashoffset from the
 * full length down to zero. Areas use opacity instead so they fade in beneath
 * the tracing stroke. Pie slices grow from a tiny scale via `--pie-grow`.
 * Honors prefers-reduced-motion. */
@keyframes line-trace {
    from { stroke-dashoffset: var(--dash, 0); }
    to   { stroke-dashoffset: 0; }
}
@keyframes area-fade {
    from { opacity: 0; }
    to   { opacity: var(--target-opacity, 1); }
}
@keyframes pie-grow {
    from { transform: scale(0.001); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
@keyframes dot-pop {
    from { transform: scale(0); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
@keyframes bar-rise {
    from { transform: scaleY(0); }
    to   { transform: scaleY(1); }
}
.anim-trace {
    stroke-dasharray: var(--dash, 1) var(--dash, 1);
    stroke-dashoffset: var(--dash, 0);
    animation: line-trace 0.85s cubic-bezier(0.45, 0.05, 0.2, 1) forwards;
    animation-delay: var(--delay, 0s);
}
.anim-area {
    opacity: 0;
    animation: area-fade 0.6s ease-out forwards;
    animation-delay: var(--delay, 0s);
}
.anim-pop {
    transform-origin: center;
    transform: scale(0);
    animation: dot-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    animation-delay: var(--delay, 0s);
}
.anim-pie {
    transform-origin: var(--cx, 240px) var(--cy, 160px);
    transform: scale(0.001);
    opacity: 0;
    animation: pie-grow 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) forwards;
    animation-delay: var(--delay, 0s);
}
.anim-bar {
    transform-origin: center bottom;
    transform: scaleY(0);
    animation: bar-rise 0.55s cubic-bezier(0.34, 1.3, 0.64, 1) forwards;
    animation-delay: var(--delay, 0s);
    transform-box: fill-box;
}
/* Horizontal reveal — used to clip the gradient area beneath the total line so
 * the fill appears to follow the line as it traces. Duration MUST match the
 * .anim-trace duration so the line tip and fill edge stay in lockstep. */
@keyframes reveal-x {
    from { transform: scaleX(0); }
    to   { transform: scaleX(1); }
}
.anim-reveal-x {
    transform-origin: left center;
    transform-box: fill-box;
    transform: scaleX(0);
    animation: reveal-x 0.85s cubic-bezier(0.45, 0.05, 0.2, 1) forwards;
    animation-delay: var(--delay, 0s);
}
@media (prefers-reduced-motion: reduce) {
    .anim-trace, .anim-area, .anim-pop, .anim-pie, .anim-bar, .anim-reveal-x {
        animation: none !important;
        stroke-dashoffset: 0 !important;
        opacity: 1 !important;
        transform: none !important;
    }
}
.chart-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; }
.chart-axis-text { fill: var(--muted); font-size: 11px; font-family: system-ui, sans-serif; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--accent); opacity: 0.15; }
.chart-hover-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-slice { transition: opacity .15s ease, transform .15s ease; transform-origin: 240px 160px; cursor: default; }
.chart-slice:hover { opacity: 0.85; transform: scale(1.02); }
.chart-legend-text { fill: var(--text); font-size: 13px; font-family: system-ui, sans-serif; }
.chart-tooltip {
    position: absolute;
    top: 0; left: 0;
    pointer-events: none;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    box-shadow: 0 4px 14px rgba(0,0,0,0.5);
    white-space: nowrap;
    z-index: 5;
}

button.secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}
button.secondary:hover { background: var(--surface-3); }

.cards-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
}

.card-tile {
    background: transparent;
    border: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ---- Credit card face ---- */
.cc-face {
    position: relative;
    aspect-ratio: 1.586 / 1;
    border-radius: 14px;
    padding: 1.1rem 1.2rem 1rem;
    color: #f6efe1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    overflow: hidden;
    isolation: isolate;
    transition: transform .2s ease, box-shadow .2s ease;
    /* Solid fallback so contrast tools can evaluate text against a known
     * dark color. The visual gradient (set on each [data-theme]) layers
     * on top via background-image; if a tool only reads
     * background-color it still gets a dark surface. */
    background-color: #1a1f27;
    background-image: linear-gradient(135deg, #2b3340 0%, #1a1f27 100%);
}
.card-tile:hover .cc-face {
    transform: translateY(-3px);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.cc-face::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 85% 15%, rgba(255, 255, 255, 0.12), transparent 45%),
        radial-gradient(circle at 10% 90%, rgba(0, 0, 0, 0.25), transparent 50%);
    pointer-events: none;
    z-index: 0;
}
.cc-face > * { position: relative; z-index: 1; }

.cc-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.cc-chip {
    width: 42px;
    height: 32px;
    border-radius: 5px;
    background:
        linear-gradient(135deg, #f0d28b 0%, #c79a3a 50%, #8a6420 100%);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25), inset 0 -2px 4px rgba(0, 0, 0, 0.3);
    position: relative;
}
.cc-chip::before, .cc-chip::after {
    content: "";
    position: absolute;
    left: 4px;
    right: 4px;
    height: 1px;
    background: rgba(0, 0, 0, 0.35);
}
.cc-chip::before { top: 10px; box-shadow: 0 5px 0 rgba(0,0,0,0.35), 0 10px 0 rgba(0,0,0,0.35); }
.cc-chip::after { display: none; }

.cc-network {
    display: flex;
    align-items: center;
}
.cc-network span {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    display: inline-block;
}
.cc-network span + span {
    margin-left: -8px;
    background: rgba(212, 166, 74, 0.85);
    mix-blend-mode: screen;
}

.cc-number {
    display: flex;
    gap: 0.9rem;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: clamp(1rem, 2.4vw, 1.25rem);
    letter-spacing: 0.12em;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
    color: currentColor;
}
.cc-number span:last-child { letter-spacing: 0.18em; }

.cc-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
}
.cc-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: currentColor;
    opacity: 0.85;
    margin-bottom: 0.15rem;
}
.cc-name {
    font-weight: 600;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.15;
}
.cc-issuer {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: currentColor;
    opacity: 0.85;
    margin-top: 0.15rem;
}
.cc-balance { text-align: right; }
.cc-value {
    font-weight: 700;
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
    color: currentColor;
}
.cc-meta {
    font-size: 0.78rem;
    color: currentColor;
    opacity: 0.85;
    font-variant-numeric: tabular-nums;
}

/* Issuer themes */
/* Each variant uses background-image (not the `background` shorthand) so the
 * base background-color from .cc-face is preserved as a solid fallback for
 * contrast checkers. background-color is also re-asserted per variant to
 * match the gradient's dominant tone. */
.cc-face[data-theme="sapphire"]  { background-color: #0e1e3a; background-image: linear-gradient(135deg, #1c3d6e 0%, #0e1e3a 100%); }
.cc-face[data-theme="platinum"]  { background-color: #c8ccd2; background-image: linear-gradient(135deg, #c8ccd2 0%, #6b7079 100%); color: #1a1d22; }
.cc-face[data-theme="ember"]     { background-color: #2b0f08; background-image: linear-gradient(135deg, #7a2f1c 0%, #2b0f08 100%); }
.cc-face[data-theme="midnight"]  { background-color: #0e1024; background-image: linear-gradient(135deg, #2b2f55 0%, #0e1024 100%); }
.cc-face[data-theme="sunset"]    { background-color: #3a1a08; background-image: linear-gradient(135deg, #a0501a 0%, #3a1a08 100%); }
.cc-face[data-theme="crimson"]   { background-color: #2a0709; background-image: linear-gradient(135deg, #7e1f24 0%, #2a0709 100%); }
.cc-face[data-theme="ruby"]      { background-color: #5a0a16; background-image: linear-gradient(135deg, #c41e3a 0%, #5a0a16 100%); }
.cc-face[data-theme="slate"]     { background-color: #161e28; background-image: linear-gradient(135deg, #3a4858 0%, #161e28 100%); }
.cc-face[data-theme="noir"]      { background-color: #1a1f27; background-image: linear-gradient(135deg, #2b3340 0%, #1a1f27 100%); }

/* Card-name themes (see comment above on background-color/-image split). */
.cc-face[data-theme="reserve"]   { background-color: #050b18; background-image: linear-gradient(135deg, #0c1f3d 0%, #050b18 100%); }
.cc-face[data-theme="gold"]      { background-color: #e0c071; background-image: linear-gradient(135deg, #e0c071 0%, #8a6420 100%); color: #1a1206; }
.cc-face[data-theme="forest"]    { background-color: #08231a; background-image: linear-gradient(135deg, #1f5d3a 0%, #08231a 100%); }
.cc-face[data-theme="azure"]     { background-color: #0a2855; background-image: linear-gradient(135deg, #1f5fb0 0%, #0a2855 100%); }
.cc-face[data-theme="teal"]      { background-color: #062028; background-image: linear-gradient(135deg, #0f5d6e 0%, #062028 100%); }
.cc-face[data-theme="ink"]       { background-color: #050610; background-image: linear-gradient(135deg, #181a25 0%, #050610 100%); }
.cc-face[data-theme="ventureX"]  { background-color: #050505; background-image: linear-gradient(135deg, #2a2a2a 0%, #050505 100%); }
.cc-face[data-theme="venture"]   { background-color: #d8c6a4; background-image: linear-gradient(135deg, #d8c6a4 0%, #6e5a3a 100%); color: #1a1206; }
.cc-face[data-theme="savor"]     { background-color: #1a0510; background-image: linear-gradient(135deg, #5a1430 0%, #1a0510 100%); }
.cc-face[data-theme="silver"]    { background-color: #c9ccd1; background-image: linear-gradient(135deg, #c9ccd1 0%, #5e6168 100%); color: #1a1d22; }
.cc-face[data-theme="cash"]      { background-color: #08220f; background-image: linear-gradient(135deg, #1d6a3b 0%, #08220f 100%); }
.cc-face[data-theme="premier"]   { background-color: #0a0820; background-image: linear-gradient(135deg, #2a2255 0%, #0a0820 100%); }
.cc-face[data-theme="miles"]     { background-color: #1a1308; background-image: linear-gradient(135deg, #5a4720 0%, #1a1308 100%); }
.cc-face[data-theme="altitude"]  { background-color: #08141c; background-image: linear-gradient(135deg, #1f3a4a 0%, #08141c 100%); }
.cc-face[data-theme="travel"]    { background-color: #08222a; background-image: linear-gradient(135deg, #1f5d6e 0%, #08222a 100%); }
.cc-face[data-theme="rewards"]   { background-color: #0a200a; background-image: linear-gradient(135deg, #2f5d2a 0%, #0a200a 100%); }

/* Light-text-on-dark by default; the few light themes set their own color above. */

.card-tile .actions {
    display: flex;
    gap: 0.5rem;
}
.card-tile .actions button {
    flex: 1;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    padding: 0.45rem 0.5rem;
}
.card-tile .actions button:hover { background: var(--surface-3); }
.card-tile .actions button.danger {
    background: var(--danger);
    color: var(--accent-text);
    border-color: var(--danger);
}
.card-tile .actions button.danger:hover { background: var(--danger-2); }

/* Modal */
dialog {
    border: 1px solid var(--border);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 1.25rem;
    max-width: 480px;
    width: calc(100% - 2rem);
    max-height: calc(100vh - 2rem);
    margin: auto;
    inset: 0;
    box-shadow: var(--shadow);
    overflow: hidden; /* the inner form scrolls; dialog clips */
}
dialog[open] {
    display: flex;
    flex-direction: column;
    /* Always render visible and in place. The previous CSS used a keyframe
     * animation (`modal-pop`) starting at opacity:0 + translateY+scale to
     * fade/slide the modal in. On iOS WebKit (iPhone Safari and
     * Chrome-on-iPad), animations on elements entering the top-layer via
     * showModal() intermittently fail to start — even with fill-mode
     * `forwards` the dialog can stay stuck at its base style with the
     * keyframe `from` state half-applied, leaving the modal frame visible
     * but the form contents invisible ("no options at all" on iPhone). We
     * now keep the dialog visible by default and animate the entrance via
     * `@starting-style` only, which is opt-in per render and safely
     * ignored on browsers that haven't implemented it. */
    opacity: 1;
    transform: none;
    transition:
        opacity 0.22s ease,
        transform 0.22s cubic-bezier(0.16, 1, 0.3, 1),
        overlay 0.22s allow-discrete,
        display 0.22s allow-discrete;
}
@starting-style {
    dialog[open] {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }
}
/* Make the form inside the dialog the scroll container so the sticky
 * close button (positioned on the dialog) stays put while content scrolls.
 * Inline padding (with matching negative margin) gives focus outlines room
 * to render without being clipped by overflow-x: hidden.
 *
 * Sizing note: the dialog has only `max-height` (no explicit `height`), so
 * a `max-height: 100%` on the form creates a circular sizing dependency.
 * Blink resolves it; iOS WebKit (iPhone Safari / Chrome on iOS — which
 * also runs on WebKit) collapses the form to 0 height, leaving the dialog
 * frame visible with the close button but no form fields ("popup opens
 * but nothing appears" on iPhone). We instead size the form against the
 * viewport plus a flex layout fallback so it always has real height. */
dialog > form {
    flex: 1 1 auto;
    min-height: 0; /* allow proper flex shrinking inside dialog[open] */
    overflow-y: auto;
    overflow-x: hidden;
    /* Bound the form to the viewport (matches dialog's own max-height of
     * 100vh - 2rem, minus headroom for the dialog padding + sticky close
     * button). Anchoring to vh instead of `%` avoids the iOS WebKit
     * circular-dependency collapse described above. */
    max-height: calc(100vh - 4rem);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-inline: 6px;
    margin-inline: -6px;
}
@supports (height: 100dvh) {
    dialog > form { max-height: calc(100dvh - 4rem); }
}
dialog[open]::backdrop {
    /* See note on dialog[open] above — animate the backdrop with
     * transition + @starting-style instead of a keyframe animation so a
     * failed top-layer animation on iOS can't leave the backdrop stuck
     * fully transparent or fully opaque at the wrong state. */
    background: rgba(0, 0, 0, 0.5);
    transition: background 0.22s ease, overlay 0.22s allow-discrete, display 0.22s allow-discrete;
}
@starting-style {
    dialog[open]::backdrop {
        background: rgba(0, 0, 0, 0);
    }
}
@media (prefers-reduced-motion: reduce) {
    dialog[open], dialog[open]::backdrop { transition: none; }
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }

/* Modern circular close button — sticks to the top-right of any dialog and
 * stays visible while long modal content scrolls underneath. */
.modal-close {
    position: sticky;
    top: 0;
    align-self: flex-end;
    z-index: 5;
    width: 30px;
    height: 30px;
    margin: -0.5rem -0.5rem 0.25rem auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.modal-close:hover { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.modal-close:active { transform: scale(0.94); }
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
dialog menu {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    padding: 0;
    margin: 0.75rem 0 0;
}
dialog menu button[data-action="cancel"] {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

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

/* Toast */
#toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
    max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.error { border-color: var(--danger); color: var(--danger); }
#toast.success { border-color: var(--ok); color: var(--ok); }

@media (max-width: 600px) {
    header {
        padding: 0.6rem 0.85rem;
        gap: 0.5rem 0.75rem;
        flex-wrap: wrap;
    }
    header h1 {
        font-size: 1rem;
        flex: 1 1 auto;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .subtitle { display: none; }
    #user-nav {
        flex: 0 0 auto;
        justify-content: flex-end;
        gap: 0.5rem;
    }
    #user-nav span:first-child { display: none; }   /* hide "Hi," */
    #logout-btn { padding: 0.4rem 0.75rem; font-size: 0.85rem; }

    main { padding: 0.75rem; }

    .totals { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
    .totals .value { font-size: 1.2rem; }

    .row-between {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .row-between h2 { margin: 0; }
    .header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        width: 100%;
    }
    .header-actions button { width: 100%; }

    .filters {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        align-items: end;
    }
    .filters label { flex: unset; }
    .filters #reset-filters-btn {
        grid-column: 1 / -1;
        width: 100%;
    }

    .cards-grid { grid-template-columns: 1fr; }

    .card-tile .actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    dialog {
        margin: auto;
        max-width: calc(100vw - 1rem);
    }
    #auth-view { margin-top: 1rem; }
}

@media (max-width: 360px) {
    .totals { grid-template-columns: 1fr; }
}

/* History modal */
#history-modal { max-width: 540px; }
.history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 60vh;
    overflow-y: auto;
    border-top: 1px solid var(--border);
}
.history-row {
    padding: 0.65rem 0.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.history-main {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
}
.history-type {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.8rem;
}
.history-amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: 1.05rem;
}
.history-amount.earn { color: var(--ok); }
.history-amount.redeem { color: var(--danger); }
.history-meta {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}
.history-note {
    color: var(--muted);
    font-size: 0.82rem;
    font-style: italic;
}
.history-loading { padding: 1rem 0.25rem; }
.history-toolbar {
    display: flex;
    justify-content: flex-end;
    margin: 0.15rem 0 0.6rem;
}
.history-bulk-delete {
    padding: 0.45rem 0.7rem;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: rgba(126, 31, 36, 0.06);
    color: var(--danger);
    border: 1px solid rgba(126, 31, 36, 0.22);
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.history-bulk-delete:hover {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.history-bulk-delete:active { transform: translateY(1px); }
.history-bulk-delete:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }
.history-bulk-delete-count {
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.72);
    color: currentColor;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;
}
.history-actions {
    display: flex;
    gap: 0.35rem;
    justify-content: flex-end;
    margin-top: 0.15rem;
}
.history-icon-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.history-icon-btn:hover { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.history-icon-btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.history-icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.history-row.history-opening {
    background: linear-gradient(90deg, rgba(212, 166, 74, 0.08), transparent);
    border-left: 3px solid var(--accent);
    padding-left: 0.5rem;
}
.history-row.history-opening .history-type { color: var(--accent); }
.history-row.history-adjust { background: rgba(212, 166, 74, 0.05); }
.history-row.history-adjust .history-type {
    color: var(--accent);
    font-style: italic;
}

/* ===== Perks tracker ============================================== */
.perks-panel {
    padding-top: 0.75rem;
    /* The shared .dashboard-panel uses a `dashGrow` keyframe whose end
     * state is `max-height: 1200px` with animation-fill-mode: both. With
     * 100+ perks the list exceeds 1200px and gets clipped behind the
     * cards section below. Disable the animation here so the panel grows
     * to its natural height and the page scrolls normally. */
    animation: none;
    max-height: none;
    overflow: visible;
}
.perks-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1rem;
}
.perks-toolbar label { display: flex; flex-direction: column; font-size: 0.85rem; gap: 0.25rem; }
.perks-toolbar select, .perks-toolbar input {
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--border, #d1d5db);
    background: var(--surface, #fff);
    font-size: 0.9rem;
    min-width: 140px;
}
.perks-status-pills {
    display: inline-flex;
    background: var(--surface-2, #f1f5f9);
    border-radius: 999px;
    padding: 3px;
    gap: 2px;
}
.perks-pill {
    background: transparent;
    border: 0;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-2, #475569);
}
.perks-pill.active {
    background: var(--surface, #fff);
    color: var(--text, #0f172a);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    font-weight: 600;
}
.perks-toolbar-actions { margin-left: auto; display: flex; gap: 0.5rem; }

.perks-sync-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--surface, #fff);
    color: var(--text, #0f172a);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.perks-sync-btn:hover:not(:disabled) {
    background: var(--surface-2, #f8fafc);
    border-color: #1D6B4A;
    color: #1D6B4A;
}
.perks-sync-btn:disabled {
    opacity: 0.6;
    cursor: progress;
}
.perks-sync-btn svg { flex: 0 0 auto; }

.settings-gcal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.settings-gcal-warning {
    margin-top: 0.6rem;
    padding: 0.6rem 0.75rem;
    background: #fff8e1;
    border: 1px solid #f0d680;
    border-radius: 8px;
    color: #5c4a08;
    font-size: 0.85rem;
    line-height: 1.4;
}
.settings-gcal-warning a { color: #5c4a08; text-decoration: underline; }
[data-theme="dark"] .settings-gcal-warning {
    background: rgba(240, 214, 128, 0.12);
    border-color: rgba(240, 214, 128, 0.35);
    color: #f3e1a8;
}
[data-theme="dark"] .settings-gcal-warning a { color: #f3e1a8; }

/* Brief attention pulse for the Connect Google button when the user is
   routed to Settings from the perks Sync button without being signed in. */
.pulse-attn {
    animation: pulse-attn 0.8s ease-in-out 0s 3;
    box-shadow: 0 0 0 0 rgba(29, 107, 74, 0.6);
}
@keyframes pulse-attn {
    0%   { box-shadow: 0 0 0 0   rgba(29, 107, 74, 0.55); }
    70%  { box-shadow: 0 0 0 10px rgba(29, 107, 74, 0); }
    100% { box-shadow: 0 0 0 0   rgba(29, 107, 74, 0); }
}

.settings-sub-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.settings-sub-details {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 0.75rem;
    margin: 0.5rem 0 0.25rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface-2, #f8fafc);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    font-size: 0.875rem;
}
.settings-sub-details dt {
    color: var(--text-muted, #6b7280);
    font-weight: 500;
}
.settings-sub-details dd {
    margin: 0;
    color: var(--text, #111827);
    font-weight: 500;
}
.settings-sub-details dd[data-tone="ok"] { color: #047857; }
.settings-sub-details dd[data-tone="warn"] { color: #b45309; }

#settings-sub-status { font-weight: 500; }
#settings-sub-status[data-state="canceling"],
#settings-sub-status[data-state="past_due"],
#settings-sub-status[data-state="expired"] { color: #b45309; }
#settings-sub-status[data-state="active"],
#settings-sub-status[data-state="trialing"] { color: #047857; }

.perks-gauge-wrap {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    background: var(--surface-2, #f8fafc);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border, #e5e7eb);
}
#perks-gauge { width: 220px; height: 130px; flex: 0 0 auto; }
.perks-gauge-value {
    transition: stroke-dashoffset 0.7s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.3s ease;
}
.perks-gauge-pct { transition: fill 0.3s ease; }

/* KPI strip beside the gauge — mirrors the dashboard's .kpi-chip style. */
.perks-kpi-strip {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    min-width: 0;
}
.perks-kpi-chip {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 0.5rem 0.7rem;
    min-width: 0;
}
.perks-kpi-dot {
    flex: 0 0 auto;
    width: 8px; height: 8px;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.04);
}
.perks-kpi-dot.used { background: #16a34a; }
.perks-kpi-dot.available { background: #0891b2; }
.perks-kpi-dot.remaining { background: #f59e0b; }
.perks-kpi-dot.items { background: var(--accent); }
.perks-kpi-label {
    font-size: 0.78rem;
    color: var(--text);
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.perks-kpi-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.perks-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Each period (Monthly / Quarterly / etc.) is its own self-contained card
 * with an internal scroll, so all groups stay visible even when one has
 * many entries. */
.perks-group {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    background: var(--surface, #fff);
    overflow: hidden;
}
.perks-group-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0.55rem 0.85rem 0.55rem 2rem;
    background: var(--surface-2, #f8fafc);
    border-bottom: 1px solid var(--border, #e5e7eb);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-2, #64748b);
    margin: 0;
    position: relative;
    width: 100%;
    text-align: left;
    border: 0;
    border-bottom: 1px solid var(--border, #e5e7eb);
    cursor: pointer;
    font-family: inherit;
}
.perks-group-header:hover {
    background: var(--surface-3, #f1f5f9);
}
.perks-group-caret {
    position: absolute;
    left: 0.7rem;
    top: 0.7rem;
    color: var(--text-2, #64748b);
    transition: transform 0.2s ease;
}
.perks-group.is-collapsed .perks-group-caret {
    transform: rotate(-90deg);
}
.perks-group.is-collapsed {
    /* Header rounds back into the section bottom edge when collapsed. */
}
.perks-group.is-collapsed .perks-group-header {
    border-bottom: 0;
}
.perks-group-content[hidden] { display: none; }
.perks-show-more {
    display: block;
    width: 100%;
    padding: 0.55rem;
    background: transparent;
    border: 0;
    border-top: 1px dashed var(--border, #e5e7eb);
    color: var(--accent, #2563eb);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.perks-show-more:hover { background: var(--surface-2, #f8fafc); }
.perk-row-hidden { display: none !important; }
.perks-group-header-top {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: wrap;
}
.perks-group-money {
    margin-left: auto;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-1, #0f172a);
    text-transform: none;
    letter-spacing: 0;
}
.perks-group-money-sep {
    font-weight: 400;
    color: var(--muted);
}
.perks-group-progress {
    position: relative;
    height: 8px;
    width: 100%;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.perks-group-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
    background: #94a3b8;
}
/* Progress row: percent badge + bar share a single line, badge leads.
 * Modern look: subtle accent-tinted pill, monospace numerics, tight spacing. */
.perks-group-progress-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
}
.perks-group-progress-row .perks-group-progress {
    flex: 1;
    min-width: 0;
    height: 10px;
}
.perks-group-pct-badge {
    flex: none;
    min-width: 32px;
    text-align: right;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
}
.perks-period-monthly-fill { background: linear-gradient(90deg, #60a5fa, #1d4ed8); }
.perks-period-quarterly-fill { background: linear-gradient(90deg, #c4b5fd, #6d28d9); }
.perks-period-semi-annual-fill { background: linear-gradient(90deg, #f9a8d4, #be185d); }
.perks-period-annual-fill { background: linear-gradient(90deg, #fcd34d, #b45309); }
.perks-period-anniversary-fill { background: linear-gradient(90deg, #fda4af, #be123c); }
.perks-period-one-time-fill { background: linear-gradient(90deg, #a5b4fc, #4338ca); }
.perks-period-other-fill { background: linear-gradient(90deg, #cbd5e1, #475569); }
.perks-group-body {
    list-style: none;
    padding: 0.5rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.perks-group-label {
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
}
.perks-group-overdue { background: #fee2e2; color: #b91c1c; }
.perks-group-soon { background: #fef3c7; color: #92400e; }
.perks-group-future { background: #e0e7ff; color: #3730a3; }
.perks-group-used { background: #dcfce7; color: #166534; }
.perks-period-monthly { background: #dbeafe; color: #1e40af; }
.perks-period-quarterly { background: #ede9fe; color: #5b21b6; }
.perks-period-semi-annual { background: #fce7f3; color: #9d174d; }
.perks-period-annual { background: #fef3c7; color: #92400e; }
.perks-period-anniversary { background: #ffe4e6; color: #9f1239; }
.perks-period-one-time { background: #e0e7ff; color: #3730a3; }
.perks-period-other { background: #e2e8f0; color: #334155; }
.perks-group-count { font-size: 0.78rem; color: var(--muted); }

.perk-row {
    display: grid;
    grid-template-columns: auto 1fr auto auto auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.75rem;
    border-radius: 10px;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    transition: background 0.15s;
}
.perk-row:hover { background: var(--surface-2, #f8fafc); }
.perk-row.perk-overdue { border-left: 3px solid #ef4444; }
.perk-row.perk-soon { border-left: 3px solid #f59e0b; }
.perk-row.perk-future { border-left: 3px solid #94a3b8; }
.perk-row.perk-used { border-left: 3px solid #16a34a; }
.perk-row.perk-used .perk-title { text-decoration: line-through; color: var(--muted); }
.perk-row.perk-used .perk-value { color: var(--muted); }

.perk-check, .perk-check input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #16a34a;
}
.perk-main { min-width: 0; }
.perk-title { font-weight: 600; color: var(--text, #0f172a); font-size: 0.95rem; }
.perk-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: baseline; }
.perk-meta .perk-sep { opacity: 1; }
.perk-cap { color: var(--accent); font-weight: 600; }
.perk-period { text-transform: capitalize; }
.perk-notes { width: 100%; margin-top: 4px; font-style: italic; color: var(--muted); }
.perk-value { font-weight: 700; color: var(--text); font-size: 0.95rem; text-align: right; min-width: 70px; }
.perk-deadline { font-size: 0.85rem; color: var(--muted); min-width: 100px; text-align: right; }
.perk-actions { display: flex; gap: 4px; }
.perk-actions .icon-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--text-2, #64748b);
}
.perk-actions .icon-btn:hover { background: var(--surface-2, #f1f5f9); border-color: var(--border, #e5e7eb); color: var(--text, #0f172a); }
.perk-actions .icon-btn-danger:hover { color: #b91c1c; border-color: #fca5a5; }

.perk-used-row { display: flex; flex-direction: row !important; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.perk-used-row input[type="checkbox"] { width: 18px; height: 18px; }

@media (max-width: 720px) {
    .perks-gauge-wrap { flex-direction: column; align-items: stretch; }
    #perks-gauge { width: 100%; max-width: 280px; margin: 0 auto; }
    .perks-kpi-strip { grid-template-columns: 1fr 1fr; }
    .perk-row {
        grid-template-columns: auto 1fr auto;
        grid-template-areas:
            "check main value"
            "check deadline actions";
    }
    .perk-check { grid-area: check; }
    .perk-main { grid-area: main; }
    .perk-value { grid-area: value; }
    .perk-deadline { grid-area: deadline; text-align: left; }
    .perk-actions { grid-area: actions; }
}

/* =================================================================
 * Landing page (pre-auth marketing surface inside #auth-view).
 * Visual language: monarch-inspired — generous whitespace, warm
 * cream background, deep-emerald accents, soft card shadows.
 * ================================================================= */
.landing-hero {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 3rem;
    align-items: center;
    padding: 4rem 2rem 3rem;
    max-width: 1200px;
    margin: 0 auto;
}
.landing-hero-copy { display: flex; flex-direction: column; gap: 1.2rem; }
.landing-eyebrow {
    margin: 0;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
}
.landing-headline {
    margin: 0;
    font-size: clamp(2.4rem, 5vw, 3.6rem);
    line-height: 1.05;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
}
.landing-sub {
    margin: 0;
    font-size: 1.15rem;
    color: var(--muted);
    max-width: 38ch;
}
.landing-cta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}
.landing-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 1.4rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 1rem;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.landing-cta.primary {
    background: var(--accent);
    color: var(--accent-text);
}
.landing-cta.primary:hover { background: var(--accent-2); }
.landing-cta.ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}
.landing-cta.ghost:hover { background: var(--surface-2); border-color: var(--accent); }
.landing-cta:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.landing-microcopy {
    margin: 0.75rem 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}
.landing-microcopy code {
    background: var(--surface-2);
    padding: 1px 6px;
    border-radius: 6px;
    font-size: 0.85em;
}

/* Hero art: a small fan of stacked "cards" to evoke the product */
.landing-hero-art {
    position: relative;
    min-height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.landing-card {
    position: absolute;
    width: 260px;
    height: 160px;
    border-radius: 18px;
    padding: 1.1rem 1.25rem;
    color: #f6f1e6;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    letter-spacing: 0.04em;
    transition: transform 0.3s ease;
}
.landing-card-issuer { font-size: 0.72rem; opacity: 0.85; }
.landing-card-balance { font-size: 1.5rem; font-weight: 700; }
.landing-card-balance em { font-style: normal; font-size: 0.85rem; opacity: 0.85; margin-left: 4px; }
.landing-card-chip {
    width: 36px; height: 26px; border-radius: 5px;
    background: linear-gradient(135deg, #d4a64a 0%, #b8862c 100%);
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
}
.landing-card-1 {
    background: linear-gradient(135deg, #1d6b4a 0%, #144f37 100%);
    transform: translate(-110px, -50px) rotate(-8deg);
    z-index: 3;
}
.landing-card-2 {
    background: linear-gradient(135deg, #2a313b 0%, #161a1f 100%);
    transform: translate(20px, 10px) rotate(2deg);
    z-index: 2;
}
.landing-card-3 {
    background: linear-gradient(135deg, #8a5a1f 0%, #6b4416 100%);
    transform: translate(110px, 60px) rotate(10deg);
    z-index: 1;
}
.landing-hero-art:hover .landing-card-1 { transform: translate(-130px, -60px) rotate(-10deg); }
.landing-hero-art:hover .landing-card-3 { transform: translate(130px, 70px) rotate(12deg); }

/* Features grid */
.landing-features {
    max-width: 1100px;
    margin: 4rem auto 0;
    padding: 3rem 2rem;
    background: var(--surface);
    border-radius: 24px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.landing-section-title {
    margin: 0 0 0.5rem;
    text-align: center;
    font-size: clamp(1.6rem, 3.5vw, 2.2rem);
    font-weight: 700;
    letter-spacing: -0.01em;
}
.landing-section-sub {
    margin: 0 auto 2.5rem;
    text-align: center;
    color: var(--muted);
    max-width: 60ch;
}
.landing-feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}
.landing-feature {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1.5rem 1.25rem;
    background: var(--surface-2);
    border-radius: 16px;
    border: 1px solid var(--border);
}
.landing-feature-icon {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: var(--accent);
    color: var(--accent-text);
    display: inline-grid;
    place-items: center;
    margin-bottom: 0.35rem;
}
.landing-feature h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}
.landing-feature p {
    margin: 0;
    font-size: 0.95rem;
    color: var(--muted);
    line-height: 1.5;
}

/* Quote */
.landing-quote {
    max-width: 720px;
    margin: 3rem auto 0;
    padding: 0 2rem;
    text-align: center;
}
.landing-quote blockquote {
    margin: 0;
    padding: 0;
}
.landing-quote p {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text);
}
.landing-quote cite {
    display: block;
    margin-top: 0.75rem;
    color: var(--muted);
    font-style: normal;
    font-size: 0.9rem;
}

/* Footer */
.landing-footer {
    max-width: 1200px;
    margin: 4rem auto 2rem;
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    color: var(--muted);
    font-size: 0.9rem;
}
.landing-footer-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--text);
}
.landing-footer-brand .brand-mark { color: var(--accent); }

@media (max-width: 800px) {
    .landing-hero {
        grid-template-columns: 1fr;
        padding: 2.5rem 1.25rem 1.5rem;
        gap: 2rem;
        text-align: center;
    }
    .landing-hero-copy { align-items: center; }
    .landing-sub { max-width: 100%; }
    .landing-hero-art { min-height: 260px; }
    .landing-card { width: 220px; height: 138px; }
    .landing-card-1 { transform: translate(-70px, -40px) rotate(-8deg); }
    .landing-card-2 { transform: translate(10px, 5px) rotate(2deg); }
    .landing-card-3 { transform: translate(80px, 40px) rotate(10deg); }
    .landing-features { margin: 2.5rem 1rem 0; padding: 2rem 1.25rem; }
    .landing-footer { flex-direction: column; text-align: center; }
}

/* ------------------------------------------------------------------
 * Trial banner + paywall view (Phase C — subscription gating)
 * Restyled to mirror the marketing site `.v2 .promo` bar so the top
 * of the app reads as a single dark ribbon across light + dark mode,
 * replacing the washed-out ivory→cream gradient that looked like a box.
 * ------------------------------------------------------------------ */
.trial-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.45rem 1rem;
    background: #0B1F1A;            /* v2 ink */
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #F6F1E6;                 /* v2 bg ivory */
    font-size: 0.85rem;
    letter-spacing: 0.01em;
}
.trial-banner strong { color: #E8B948; font-weight: 600; }  /* v2 gold */
.trial-banner-link {
    color: #F6F1E6;
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 600;
}
.trial-banner-link:hover { color: #E8B948; }
.trial-banner.warn {
    background: #3a1d0f;
    border-bottom-color: rgba(255, 255, 255, 0.08);
    color: #fde4b8;
}
.trial-banner.warn strong { color: #fbbf24; }

/* Tour banner — new-user nudge to /getting-started.html.
   Mirrors trial-banner palette but uses emerald accent so the two
   ribbons stay visually distinct when both are visible. */
.tour-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.45rem 1rem;
    background: #103a2c;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #F6F1E6;
    font-size: 0.85rem;
    letter-spacing: 0.01em;
}
.tour-banner-link {
    color: #E8B948;
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 600;
}
.tour-banner-link:hover { color: #fff; }
.tour-banner-dismiss {
    background: transparent;
    border: 0;
    color: #F6F1E6;
    opacity: 0.7;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0 0.25rem;
    cursor: pointer;
}
.tour-banner-dismiss:hover { opacity: 1; }
.paywall-view {
    display: grid;
    place-items: center;
    padding: 60px 24px;
    min-height: 60vh;
}
.paywall-card {
    max-width: 540px;
    width: 100%;
    background: #fff;
    border-radius: 18px;
    padding: 40px;
    box-shadow: 0 12px 50px rgba(20, 40, 25, 0.08);
    border: 1px solid rgba(20, 40, 25, 0.06);
    text-align: center;
}
.paywall-card h1 {
    font-family: 'Instrument Serif', serif;
    font-size: 2.2rem;
    margin-bottom: 10px;
}
.paywall-card > p {
    color: #4f5648;
    margin-bottom: 22px;
}
.paywall-tiers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 16px;
}
.paywall-tier {
    background: #f6f1e6;
    border: 1.5px solid rgba(20, 40, 25, 0.1);
    border-radius: 14px;
    padding: 18px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
    font-family: inherit;
    color: #0B1F1A;                 /* explicit — was inheriting UA button color */
    transition: border-color .15s, transform .15s, background .15s;
}
.paywall-tier:hover {
    border-color: #1D6B4A;
    transform: translateY(-1px);
    background: #f0eadc;
}
.paywall-tier.featured {
    background: #eef7f1;
    border-color: #1D6B4A;
    color: #0B1F1A;
}
.paywall-tier-name {
    font-weight: 700;
    font-size: 1.05rem;
    color: #0B1F1A;
}
.paywall-tier-price {
    color: #0B1F1A;
    font-size: 0.95rem;
}
.paywall-tier-price strong {
    font-size: 1.6rem;
    color: #0B1F1A;
    font-weight: 800;
}
.paywall-tier-price em {
    font-style: normal;
    color: #8a5a1f;
    font-size: 0.8rem;
    margin-left: 6px;
    font-weight: 600;
}
.paywall-tier-cta {
    color: #1D6B4A;
    font-weight: 600;
    font-size: 0.9rem;
    margin-top: 4px;
}
.paywall-foot {
    font-size: 0.9rem;
    color: #4f5648;
}
.paywall-foot a {
    color: #1D6B4A;
    font-weight: 600;
}
@media (max-width: 560px) {
    .paywall-tiers { grid-template-columns: 1fr; }
}

/* ===== Offers tracker ============================================= */
.offers-panel {
    padding-top: 0.75rem;
    animation: none;
    max-height: none;
    overflow: visible;
}
.offers-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1rem;
}
.offers-toolbar label { display: flex; flex-direction: column; font-size: 0.85rem; gap: 0.25rem; }
.offers-toolbar select,
.offers-toolbar input {
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--border, #d1d5db);
    background: var(--surface, #fff);
    color: var(--text, #0f172a);
    font-size: 0.9rem;
    min-width: 140px;
}
.offers-search-label { flex: 1 1 200px; min-width: 180px; }
.offers-search-label input { min-width: 100%; }
.offers-status-pills {
    display: inline-flex;
    background: var(--surface-2, #f1f5f9);
    border-radius: 999px;
    padding: 3px;
    gap: 2px;
    flex-wrap: wrap;
}
.offers-pill {
    background: transparent;
    border: 0;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-2, #475569);
    font-family: inherit;
}
.offers-pill.active {
    background: var(--surface, #fff);
    color: var(--text, #0f172a);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    font-weight: 600;
}
.offers-toolbar-actions { margin-left: auto; display: flex; gap: 0.5rem; }

.offers-category-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px dashed var(--border, #e5e7eb);
}
.offers-cat-pill {
    background: var(--surface-2, #f1f5f9);
    border: 1px solid transparent;
    color: var(--text-2, #475569);
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.offers-cat-pill:hover { background: var(--surface-3, #e2e8f0); }
.offers-cat-pill.active {
    background: var(--accent, #2563eb);
    color: #fff;
    border-color: var(--accent, #2563eb);
    font-weight: 600;
}

.offers-kpi-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.5rem;
    background: var(--surface-2, #f8fafc);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}
.offers-kpi-chip {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}
.offers-kpi-dot {
    flex: 0 0 auto;
    width: 8px; height: 8px;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.04);
}
.offers-kpi-dot.total { background: #475569; }
.offers-kpi-dot.available { background: #16a34a; }
.offers-kpi-dot.used { background: #0891b2; }
.offers-kpi-dot.soon { background: #f59e0b; }
.offers-kpi-dot.expired { background: #dc2626; }
.offers-kpi-label {
    font-size: 0.72rem;
    color: var(--text, #0f172a);
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
}
.offers-kpi-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text, #0f172a);
}

/* ---- Featured offers rail (top 3 by value) -----------------------------
 * Sits between the KPI strip and the per-card list. Horizontal scroll-snap
 * carousel so it stays slim on narrow viewports and scrollable on mobile.
 * Reuses the same brand tokens as the rest of the offers panel.
 */
.offers-featured {
    margin: 0 0 1rem;
    padding: 0.85rem 1rem 1rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 14px;
    background:
        linear-gradient(180deg, rgba(47, 133, 104, 0.06) 0%, transparent 60%),
        var(--surface, #fff);
    position: relative;
}
.offers-featured-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
}
.offers-featured-titleblock { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.offers-featured-eyebrow {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--secondary, #2f8568);
}
.offers-featured-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text, #0f172a);
    line-height: 1.2;
}
.offers-featured-nav { display: inline-flex; gap: 0.35rem; flex: 0 0 auto; }
.offers-featured-arrow {
    width: 30px; height: 30px;
    border-radius: 999px;
    border: 1px solid var(--border, #e5e7eb);
    background: var(--surface, #fff);
    color: var(--text, #0f172a);
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
    line-height: 0;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.offers-featured-arrow:hover {
    background: var(--secondary, #2f8568);
    border-color: var(--secondary, #2f8568);
    color: #fff;
}
.offers-featured-arrow:focus-visible { outline: 2px solid var(--secondary, #2f8568); outline-offset: 2px; }
.offers-featured-arrow svg { display: block; }

.offers-featured-track {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    padding-bottom: 0.25rem;
}
.offers-featured-track::-webkit-scrollbar { display: none; }

/* Each featured card reuses the .offer-tile look from the per-card list.
 * The track shows up to 3 cards at once, falling to 2 and then 1 on
 * narrower viewports. Cards are flex children with a fixed basis so they
 * never squish below their target width — anything beyond is reachable
 * via the carousel arrows / horizontal scroll.
 */
.offers-featured-track .offer-tile-featured {
    flex: 0 0 calc((100% - 1.5rem) / 3);
    scroll-snap-align: start;
    min-width: 0;
}
@media (max-width: 720px) {
    .offers-featured-track .offer-tile-featured {
        flex-basis: calc((100% - 0.75rem) / 2);
    }
}
@media (max-width: 480px) {
    .offers-featured-track .offer-tile-featured {
        flex-basis: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .offers-featured-track { scroll-behavior: auto; }
}

.offers-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.offers-group {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    background: var(--surface, #fff);
    overflow: hidden;
}
.offers-group-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.6rem 0.9rem 0.6rem 2.2rem;
    background: var(--surface-2, #f8fafc);
    border: 0;
    border-bottom: 1px solid var(--border, #e5e7eb);
    cursor: pointer;
    font-family: inherit;
    color: var(--text, #0f172a);
    position: relative;
    text-align: left;
}
.offers-group-caret {
    position: absolute;
    left: 0.7rem;
    top: 50%;
    transform: translateY(-50%) rotate(0deg);
    transition: transform 0.18s ease;
    color: var(--text-2, #64748b);
}
.offers-group.is-collapsed .offers-group-caret { transform: translateY(-50%) rotate(-90deg); }
.offers-group-label {
    font-weight: 700;
    font-size: 0.95rem;
}
.offers-group-count {
    font-size: 0.78rem;
    color: var(--text-2, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.offers-group-money {
    margin-left: auto;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text, #0f172a);
}
.offers-group-content[hidden] { display: none; }

.offers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
    padding: 0.75rem;
}
.offer-tile {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 0.85rem 0.85rem 0.7rem;
    background: var(--surface, #fff);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    position: relative;
}
.offer-tile:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
    border-color: var(--accent, #2563eb);
}
.offer-tile-hidden { display: none !important; }
.offer-tile-expiring { border-left: 3px solid #f59e0b; }
.offer-tile-expired { opacity: 0.6; border-left: 3px solid #dc2626; }
/* Whole-tile "used" state — selector is .offer-used (the article gets this
 * class via renderList). Softer than the previous strikethrough + heavy
 * dim: a faint green tint, left accent bar, and a muted merchant color. */
.offer-used {
    background: #f6fbf7;
    border-color: #cfe8d6;
    border-left: 3px solid #16a34a;
}
.offer-used .offer-tile-merchant {
    color: var(--text-2, #64748b);
    text-decoration: none;
}
.offer-used .offer-tile-title,
.offer-used .offer-tile-desc { color: var(--text-2, #64748b); }
.offer-used .offer-tile-badge { opacity: 0.7; }

.offer-tile-head {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    /* Leave room for the top-left used tab anchored to the tile corner. */
    padding-left: 30px;
}
.offer-tile-avatar {
    position: relative;
    flex: 0 0 auto;
    width: 38px; height: 38px;
    border-radius: 10px;
    color: #fff;
    display: grid;
    place-items: center;
    overflow: hidden;
}
.offer-tile-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.offer-tile-initial {
    font-weight: 800;
    font-size: 1.1rem;
    line-height: 1;
}
.offer-tile-headline {
    flex: 1 1 auto;
    min-width: 0;
}
.offer-tile-merchant {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text, #0f172a);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.offer-tile-title {
    margin: 0.2rem 0 0;
    font-size: 0.82rem;
    color: var(--text-2, #475569);
    line-height: 1.3;
}
.offer-tile-badge {
    flex: 0 0 auto;
    background: var(--surface-2, #f1f5f9);
    color: var(--text, #0f172a);
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
    align-self: flex-start;
}
.offer-tile-badge-statement_credit { background: #ecfdf5; color: #065f46; }
.offer-tile-badge-pct_back         { background: #eff6ff; color: #1e40af; }
.offer-tile-badge-bonus_points     { background: #fef3c7; color: #92400e; }

.offer-tile-desc {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-2, #475569);
    line-height: 1.35;
}
.offer-tile-foot {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: auto;
}
.offer-tile-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-2, #64748b);
}
.offer-tile-tag {
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--surface-2, #f1f5f9);
    color: var(--text-2, #475569);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.68rem;
}
.offer-tile-tag-dining        { background: #fef3c7; color: #92400e; }
.offer-tile-tag-travel        { background: #dbeafe; color: #1e40af; }
.offer-tile-tag-streaming     { background: #ede9fe; color: #5b21b6; }
.offer-tile-tag-retail        { background: #fce7f3; color: #9d174d; }
.offer-tile-tag-grocery       { background: #dcfce7; color: #166534; }
.offer-tile-tag-gas           { background: #fee2e2; color: #991b1b; }
.offer-tile-tag-entertainment { background: #cffafe; color: #155e75; }
.offer-tile-tag-other         { background: #f1f5f9; color: #475569; }

.offer-tile-min { white-space: nowrap; }
.offer-tile-expiry { margin-left: auto; font-weight: 600; }
.offer-tile-expiry-expiring { color: #b45309; }
.offer-tile-expiry-expired  { color: #b91c1c; }
.offer-tile-expiry-used     { color: #15803d; }

.offer-tile-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    border-top: 1px dashed var(--border, #e5e7eb);
    padding-top: 0.5rem;
}
.offer-tile-link {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent, #2563eb);
    text-decoration: none;
}
/* First icon button in the actions row pushes itself (and any siblings
 * after it) to the right edge, regardless of whether the View link is
 * present. Keeps edit + trash anchored bottom-right consistently. */
.offer-tile-actions .icon-btn:first-of-type {
    margin-left: auto;
}
.offer-tile-link:hover { text-decoration: underline; }
/* "Used" toggle — oval tab anchored to the top-left of the tile. Shows a
 * faint outlined check hint when empty (so the affordance is obvious),
 * fills solid green with a white check when toggled. */
.offer-tile-used-tab {
    position: absolute;
    top: -1px;
    left: -1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 28px;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-top-left-radius: 12px;        /* matches .offer-tile radius */
    border-bottom-right-radius: 14px;
    border-top-right-radius: 0;
    border-bottom-left-radius: 0;
    cursor: pointer;
    z-index: 2;
    color: #94a3b8;                      /* unchecked check-hint color */
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.offer-tile-used-tab:hover {
    border-color: #16a34a;
    color: #16a34a;
}
.offer-tile-used-tab input[type="checkbox"] {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}
.offer-tile-used-check {
    width: 16px;
    height: 16px;
    color: inherit;
    pointer-events: none;
    transition: color 0.12s ease, transform 0.12s ease;
}
.offer-tile-used-tab:has(input:checked) {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}
.offer-tile-used-tab:has(input:checked) .offer-tile-used-check {
    color: #fff;
    transform: scale(1.05);
}
.offer-tile-used-tab:has(input:focus-visible) {
    outline: 2px solid #16a34a;
    outline-offset: 2px;
}
.offer-tile-actions .icon-btn {
    padding: 0.3rem;
    border-radius: 6px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-2, #64748b);
    cursor: pointer;
}
.offer-tile-actions .icon-btn:hover {
    background: var(--surface-2, #f1f5f9);
    border-color: var(--border, #e5e7eb);
}
.offer-tile-actions .icon-btn-danger:hover {
    color: #dc2626;
    border-color: #fca5a5;
    background: #fef2f2;
}

.offers-show-more {
    display: block;
    width: 100%;
    padding: 0.55rem;
    background: transparent;
    border: 0;
    border-top: 1px dashed var(--border, #e5e7eb);
    color: var(--accent, #2563eb);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.offers-show-more:hover { background: var(--surface-2, #f8fafc); }

/* Match #dashboard-section spacing so Offers sits a comfortable gap below
 * Perks (mirrors Dashboard → Perks rhythm). */
#perks-section,
#offers-section { margin-bottom: 1.25rem; }

/* Big "total saved" progress bar at the top of the panel. */
.offers-total-saved {
    background: var(--surface-2, #f8fafc);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 0.85rem 1rem 0.95rem;
    margin-bottom: 1rem;
}
.offers-total-saved-head {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    margin-bottom: 0.55rem;
    flex-wrap: wrap;
}
.offers-total-saved-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    color: var(--text, #0f172a);
}
.offers-total-saved-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text, #0f172a);
    font-variant-numeric: tabular-nums;
}
.offers-total-saved-of {
    font-size: 0.8rem;
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}
.offers-total-saved-bar {
    position: relative;
    height: 14px;
    width: 100%;
    background: var(--surface-3, #e2e8f0);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 999px;
    overflow: hidden;
}
.offers-total-saved-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #34d399, #047857);
    transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Per-card progress row sits directly under each group header. */
.offers-group-progress-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.9rem 0.65rem;
    background: var(--surface-2, #f8fafc);
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.offers-group.is-collapsed .offers-group-progress-row { display: none; }
.offers-group-progress {
    flex: 1;
    min-width: 0;
    position: relative;
    height: 8px;
    background: var(--surface-3, #e2e8f0);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 999px;
    overflow: hidden;
}
.offers-group-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #60a5fa, #1d4ed8);
    transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.offers-group-pct-badge {
    flex: none;
    min-width: 32px;
    text-align: right;
    color: var(--text, #0f172a);
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.offers-group-money-sep {
    font-weight: 400;
    color: var(--text-2, #64748b);
    margin: 0 0.15rem;
}

@media (max-width: 560px) {
    .offers-toolbar-actions { margin-left: 0; width: 100%; }
    .offers-grid { grid-template-columns: 1fr; padding: 0.6rem; }
    .offer-tile-badge { align-self: flex-end; }
}

/* =========================================================================
   AI ASSISTANT — bottom-right floating launcher + slide-up chat panel.
   ========================================================================= */
.visually-hidden {
    position: absolute !important; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
}

.chat-widget {
    position: fixed;
    right: max(1.25rem, env(safe-area-inset-right));
    bottom: max(1.25rem, env(safe-area-inset-bottom));
    z-index: 950;
    pointer-events: none; /* let children opt in */
}
.chat-widget > * { pointer-events: auto; }

.chat-launcher {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.1rem;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
    color: var(--accent-text);
    border: 0;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.35), 0 2px 6px rgba(0,0,0,0.25);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.chat-launcher:hover { transform: translateY(-1px); box-shadow: 0 14px 36px rgba(0,0,0,0.45); }
.chat-launcher:active { transform: translateY(0); }
.chat-launcher:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.chat-launcher svg { display: block; }
.chat-launcher-badge {
    background: rgba(0,0,0,0.25);
    color: var(--accent-text);
    border-radius: 999px;
    padding: 0.05rem 0.45rem;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.4;
}
@media (max-width: 480px) {
    .chat-launcher-label { display: none; }
    .chat-launcher { padding: 0.85rem; }
}

.chat-panel {
    position: fixed;
    right: max(1.25rem, env(safe-area-inset-right));
    bottom: calc(max(1.25rem, env(safe-area-inset-bottom)) + 64px);
    width: min(460px, calc(100vw - 2rem));
    height: min(620px, calc(100vh - 8rem));
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 24px 70px rgba(0,0,0,0.55), 0 4px 14px rgba(0,0,0,0.3);
    display: grid;
    grid-template-columns: 0 1fr;       /* sidebar hidden in compact mode */
    overflow: hidden;
    transform-origin: bottom right;
    animation: chat-pop 0.18s ease-out;
    transition: width 0.22s ease, height 0.22s ease, right 0.22s ease, bottom 0.22s ease, border-radius 0.22s ease;
}
.chat-panel.is-expanded {
    width: min(960px, calc(100vw - 2rem));
    height: min(86vh, 920px);
    bottom: max(1.25rem, env(safe-area-inset-bottom));
    grid-template-columns: 240px 1fr;
}
@keyframes chat-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@media (max-width: 480px) {
    .chat-panel {
        right: 0.5rem; left: 0.5rem;
        width: auto;
        bottom: calc(max(0.75rem, env(safe-area-inset-bottom)) + 60px);
        height: min(72vh, 540px);
    }
    .chat-panel.is-expanded {
        right: 0.5rem; left: 0.5rem;
        width: auto;
        height: calc(100vh - max(1rem, env(safe-area-inset-top)) - max(1rem, env(safe-area-inset-bottom)));
        bottom: max(0.5rem, env(safe-area-inset-bottom));
        grid-template-columns: 0 1fr;   /* mobile: keep sidebar hidden */
    }
}

/* ---- Sidebar (visible only in expanded desktop mode) ---- */
.chat-sidebar {
    display: flex;
    flex-direction: column;
    background: var(--surface-2);
    border-right: 1px solid var(--border);
    overflow: hidden;
    min-width: 0;
}
.chat-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    height: 56px;
    flex: 0 0 56px;
    box-sizing: border-box;
    padding: 0 0.85rem;
    border-bottom: 1px solid var(--border);
}
.chat-sidebar-title {
    color: var(--accent);
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
}
.chat-thread-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0.4rem 0.4rem 0.6rem;
}
.chat-thread-bucket {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.6rem 0.55rem 0.25rem;
}
.chat-thread-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: transparent;
    border: 0;
    color: var(--text);
    text-align: left;
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    line-height: 1.25;
    transition: background 0.12s ease;
}
.chat-thread-item:hover { background: var(--surface-3); }
.chat-thread-item.is-active {
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    color: var(--text);
}
.chat-thread-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-thread-del {
    flex: 0 0 auto;
    display: inline-grid;
    place-items: center;
    color: var(--muted);
    padding: 2px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.12s ease, color 0.12s ease, background 0.12s ease;
    cursor: pointer;
}
.chat-thread-item:hover .chat-thread-del,
.chat-thread-item.is-active .chat-thread-del { opacity: 1; }
.chat-thread-del:hover { color: var(--danger); background: var(--surface-2); }

.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 0.5rem;
    min-width: 0;
    height: 56px;
    flex: 0 0 56px;
    box-sizing: border-box;
    padding: 0 0.9rem;
    background: linear-gradient(135deg, var(--surface-2) 0%, var(--surface-3) 100%);
    border-bottom: 1px solid var(--border);
}
.chat-header-title { position: relative; display: inline-flex; align-items: center; gap: 0.5rem; min-width: 0; flex: 0 1 auto; }
.chat-header-title h3 { margin: 0; font-size: 0.95rem; }
.chat-thread-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.7rem 0.3rem 0.85rem;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    max-width: 100%;
    min-width: 0;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.chat-thread-trigger:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.chat-thread-trigger:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.chat-thread-trigger[aria-expanded="true"] { background: var(--surface-2); border-color: var(--accent); }
.chat-thread-chev {
    flex: 0 0 auto;
    color: var(--muted);
    transition: transform 0.15s ease;
}
.chat-thread-trigger[aria-expanded="true"] .chat-thread-chev { transform: rotate(180deg); }
.chat-thread-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
    min-width: 0;
    font-size: 0.9rem;
    font-weight: 600;
}
.chat-panel.is-expanded .chat-thread-title { max-width: 420px; }

/* Dropdown menu anchored under the trigger */
.chat-thread-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 20;
    min-width: 260px;
    max-width: min(320px, calc(100vw - 2rem));
    max-height: 60vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 18px 50px rgba(0,0,0,0.45), 0 4px 12px rgba(0,0,0,0.25);
    padding: 0.35rem;
}
.chat-thread-menu-list {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}
.chat-thread-menu-list .chat-thread-item {
    border-radius: 8px;
    padding: 0.5rem 0.6rem;
    font-size: 0.9rem;
}
.chat-thread-menu-sep {
    height: 1px;
    background: var(--border);
    margin: 0.35rem 0;
    flex: 0 0 auto;
}
.chat-thread-menu-delete {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: var(--danger);
    padding: 0.55rem 0.6rem;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    flex: 0 0 auto;
}
.chat-thread-menu-delete:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.chat-thread-menu-delete svg { flex: 0 0 auto; }
.chat-header-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent);
}
.chat-header-meta { display: inline-flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; }
.chat-quota {
    color: var(--muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}
.chat-quota.warn { color: var(--accent); }
.chat-quota.danger { color: var(--danger); }
.chat-icon-btn {
    background: transparent;
    border: 0;
    color: var(--muted);
    padding: 0.25rem;
    line-height: 0;
    cursor: pointer;
    border-radius: 6px;
}
.chat-icon-btn:hover { color: var(--text); background: var(--surface-3); }

/* Expand/shrink toggle: show only the relevant icon for current state. */
#chat-expand .chat-icon-shrink { display: none; }
.chat-panel.is-expanded #chat-expand .chat-icon-expand { display: none; }
.chat-panel.is-expanded #chat-expand .chat-icon-shrink { display: block; }

.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    background: var(--bg);
}
.chat-msg {
    max-width: 85%;
    padding: 0.55rem 0.75rem;
    border-radius: 12px;
    line-height: 1.4;
    font-size: 0.92rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.chat-msg p { margin: 0 0 0.4rem; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg ul, .chat-msg ol { margin: 0.25rem 0 0.4rem; padding-left: 1.2rem; }
.chat-msg li { margin: 0.15rem 0; }
.chat-msg li + li { margin-top: 0.2rem; }
.chat-msg .chat-h {
    margin: 0.55rem 0 0.3rem;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--accent);
}
.chat-msg .chat-h:first-child { margin-top: 0; }
.chat-msg code {
    background: color-mix(in srgb, var(--bg) 50%, transparent);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 0.25rem;
    font-size: 0.85em;
}
.chat-msg-user {
    align-self: flex-end;
    background: var(--accent);
    color: var(--accent-text);
    border-bottom-right-radius: 4px;
}
.chat-msg-assistant {
    align-self: flex-start;
    background: var(--surface-2);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.chat-msg-error {
    align-self: stretch;
    max-width: 100%;
    background: color-mix(in srgb, var(--danger) 18%, transparent);
    color: var(--text);
    border: 1px solid var(--danger);
}
.chat-msg-greeting {
    background: transparent;
    padding: 1.25rem 0.25rem 0.5rem;
    max-width: 100%;
    align-self: stretch;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}
.chat-greet-eyebrow {
    margin: 0;
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.chat-greet-title {
    margin: 0 0 0.4rem;
    font-size: 1.25rem;
    line-height: 1.25;
    font-weight: 700;
    color: var(--text);
}
.chat-msg-greeting .chat-suggestions {
    align-items: stretch;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}
.chat-msg-greeting .chat-suggestion {
    background: var(--surface);
    border-radius: 14px;
    text-align: center;
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

/* ---- Inline charts in assistant replies -------------------------- */
.chat-chart {
    margin: 0.6rem 0 0.2rem;
    padding: 0.75rem 0.75rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}
.chat-chart-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 0.35rem;
    letter-spacing: 0.02em;
}
.cc-chart { width: 100%; height: auto; display: block; }
.cc-grid { stroke: var(--border); stroke-width: 1; opacity: 0.55; }
.cc-axis { fill: var(--muted); font-size: 10px; font-family: inherit; }
.cc-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.cc-area { fill: var(--accent); opacity: 0.12; }
.cc-point { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }
.cc-bar { fill: var(--accent); transition: opacity 0.12s ease; }
.cc-bar:hover { opacity: 0.85; }
.cc-slice { stroke: var(--surface); stroke-width: 2; }
.cc-pie-wrap {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
}
.cc-pie-wrap .cc-chart-pie { flex: 0 0 220px; max-width: 220px; }
.cc-legend {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.82rem;
    flex: 1 1 140px;
    min-width: 0;
}
.cc-legend li { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.cc-legend .cc-swatch {
    width: 10px; height: 10px; border-radius: 3px;
    flex: 0 0 auto;
}
.cc-legend .cc-legend-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}
.cc-legend strong { color: var(--muted); font-weight: 600; }

.chat-suggestions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    margin-top: 0.6rem;
}
.chat-suggestion {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    padding: 0.4rem 0.75rem;
    font-size: 0.82rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}
.chat-suggestion:hover { background: var(--surface-3); border-color: var(--accent); transform: translateY(-1px); }
.chat-suggestion:active { transform: translateY(0); }

.chat-typing {
    align-self: flex-start;
    display: inline-flex; gap: 4px;
    padding: 0.6rem 0.8rem;
    background: var(--surface-2);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}
.chat-typing span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--muted);
    animation: chat-bounce 1s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-4px); opacity: 1; }
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.7rem 0.8rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.chat-form textarea {
    flex: 1;
    resize: none;
    box-sizing: border-box;
    min-height: 44px;
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    line-height: 1.4;
    overflow-y: hidden; /* JS toggles to auto only at the height cap */
    transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.chat-form textarea::placeholder {
    color: var(--muted);
    opacity: 0.85;
}
.chat-form textarea:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.chat-form textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.chat-send {
    background: var(--accent);
    color: var(--accent-text);
    border: 0;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    padding: 0;
    line-height: 0;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background 0.12s ease, transform 0.08s ease;
}
.chat-send:hover { background: var(--accent-2); transform: translateY(-1px); }
.chat-send:active { transform: translateY(0); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.chat-send svg { display: block; }

.chat-foot {
    margin: 0;
    padding: 0.4rem 0.9rem 0.6rem;
    color: var(--muted);
    font-size: 0.7rem;
    text-align: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.chat-upgrade-link {
    color: var(--accent);
    text-decoration: underline;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    font: inherit;
}


/* ---- Skeleton loading placeholders ----------------------------------
   Used while async data is in flight so the UI doesn't flash empty.
   Apply .skeleton to any element to give it a shimmering surface; helper
   shapes (.skeleton-card, .skeleton-tile, .skeleton-row) come pre-sized
   for the grid contexts they replace. */
@keyframes skeleton-shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.skeleton {
    position: relative;
    background-color: var(--surface-2, #1f2937);
    background-image: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0,
        rgba(255, 255, 255, 0.08) 40%,
        rgba(255, 255, 255, 0.16) 50%,
        rgba(255, 255, 255, 0.08) 60%,
        rgba(255, 255, 255, 0) 100%
    );
    background-size: 800px 100%;
    background-repeat: no-repeat;
    animation: skeleton-shimmer 1.2s linear infinite;
    border-radius: 8px;
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}
.skeleton * { visibility: hidden; }

.skeleton-card {
    aspect-ratio: 1.586 / 1;
    border-radius: 14px;
    width: 100%;
}
.skeleton-tile {
    height: 120px;
    border-radius: 12px;
}
.skeleton-row {
    height: 56px;
    border-radius: 8px;
    margin-bottom: 0.5rem;
}
@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; }
}

/* =================================================================
 * 0.1 — Mobile centering utilities + audit overrides.
 *
 * Provides two reusable classes (.mobile-center / .mobile-center-grid)
 * for ad-hoc centering on phones, and a handful of audit rules that
 * tighten alignment for full-width action buttons under <=600px.
 * PRESERVES .tx-row-amount right alignment (currency column stays
 * right-aligned for tabular-num scanability).
 * ================================================================= */
@media (max-width: 600px) {
    .mobile-center { text-align: center; }
    .mobile-center-grid { display: grid; place-items: center; justify-items: center; }

    /* Full-width action buttons read better with centered glyphs/text. */
    .header-actions button,
    .card-tile .actions button,
    .perk-actions button,
    .row-action,
    .tx-load-more-wrap,
    .tx-load-more-wrap button {
        text-align: center;
        justify-content: center;
    }
    /* Perk meta lines are centered when they wrap below the title on
       narrow screens; the value (right-aligned currency) is exempt. */
    .perk-deadline { text-align: center; }
    /* Currency column stays right-aligned — intentional. */
    .tx-row-amount { text-align: right; }
}

@media (max-width: 360px) {
    .row-action,
    .header-actions button { text-align: center; justify-content: center; }
    .tx-row-amount { text-align: right; }
}

/* ============================================================
 * Wave 3 §2.1 — Onboarding wizard
 * ============================================================ */
.wizard-modal { max-width: 640px; width: 92vw; }
.wizard-modal h4 { margin: 0.5em 0 0.4em; }
.wizard-card-grid,
.wizard-pill-grid,
.wizard-goal-grid {
    display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0;
}
/* Compact card chip grid for "which cards do you carry" */
.wizard-card-grid#wizard-wallet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}
.wallet-chip {
    position: relative;
    display: flex; flex-direction: column; align-items: flex-start;
    gap: 2px;
    border: 1px solid var(--border, #d4d4d8);
    border-radius: 10px;
    padding: 8px 10px;
    cursor: pointer;
    background: var(--surface, #fff);
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    user-select: none;
}
.wallet-chip:hover { border-color: var(--accent, #1D6B4A); }
.wallet-chip:focus-within {
    outline: 2px solid var(--accent, #1D6B4A);
    outline-offset: 2px;
}
.wallet-chip.is-selected {
    border-color: var(--accent, #1D6B4A);
    background: color-mix(in srgb, var(--accent, #1D6B4A) 8%, transparent);
    box-shadow: 0 0 0 1px var(--accent, #1D6B4A) inset;
}
.wallet-chip input[type="checkbox"] {
    position: absolute; opacity: 0; pointer-events: none;
}
.wallet-chip-name {
    font-size: 13px; font-weight: 600; line-height: 1.25;
    color: var(--text, #111);
}
.wallet-chip-issuer {
    font-size: 11px; color: var(--muted, #71717a); line-height: 1.2;
}
.radio-pill {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--border, #ccc); border-radius: 999px;
    padding: 6px 12px; cursor: pointer; font-size: 14px;
    background: var(--surface, #fff);
}
.radio-pill input { margin: 0; }
.wizard-balances-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.wizard-spend-sliders {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}
.wizard-nav {
    display: flex; gap: 8px; justify-content: flex-end;
    margin-top: 12px; padding: 0; list-style: none;
}
.wizard-recs-list { list-style: none; padding: 0; display: grid; gap: 12px; }
.wizard-rec-row {
    border: 1px solid var(--border, #ddd); border-radius: 8px;
    padding: 12px; background: var(--surface, #fff);
}
.wizard-rec-head { display: flex; justify-content: space-between; gap: 8px; }
.wizard-rec-meta { font-size: 14px; margin: 4px 0; }
.wizard-rec-reason { font-size: 13px; margin: 4px 0 8px; }

/* ============================================================
 * Wave 3 §2.2 — Goals
 * ============================================================ */
.goals-toolbar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.goals-list { list-style: none; padding: 0; display: grid; gap: 10px; }
.goal-row {
    border: 1px solid var(--border, #ddd); border-radius: 8px;
    padding: 10px 12px; background: var(--surface, #fff);
}
.goal-row-head { display: flex; justify-content: space-between; gap: 8px; }
.goal-row progress { width: 100%; height: 8px; margin: 6px 0; }
.goal-eta { font-size: 13px; margin: 4px 0; }
.goal-row-actions { display: flex; gap: 8px; justify-content: flex-end; }
