/* =====================================================================
   Passbook — neo-bank minimal design system
   =====================================================================
   Theming contract (DO NOT RENAME — deploy-frontend.yaml writes a
   per-instance theme.css that overrides exactly these four inputs):
       --primary-color   instance accent
       --primary-dark    pressed/deep accent
       --background      instance page tint (light scheme only)
       --negative-color  overspend red (only emitted when the instance
                         allows overspending)
   Everything else derives from those inputs via internal tokens, which
   is also how dark mode works: theme.css loads after this file and only
   touches the four inputs, so the scheme-dependent derived tokens below
   keep authority over surfaces and ink in both schemes.
   ===================================================================== */

/* Self-hosted variable display font (OFL). CSP allows font-src 'self'
   only — no font CDNs. */
@font-face {
    font-family: 'Bricolage Grotesque';
    src: url('../assets/fonts/bricolage-grotesque-var.woff2') format('woff2');
    font-weight: 200 800;
    font-stretch: 75% 100%;
    font-display: swap;
}

:root {
    /* ---- theming inputs (overridden by per-instance theme.css) ---- */
    --primary-color: #4A90A4;
    --primary-dark: #357a8a;
    --background: #f5f7fa;
    --negative-color: #e23d3d;

    /* ---- semantic palette ---- */
    --accent: var(--primary-color);
    --accent-deep: var(--primary-dark);
    --danger: var(--negative-color);
    --success-color: #2e9e5b;
    --danger-color: var(--negative-color); /* legacy alias */

    /* ---- scheme tokens: light ---- */
    --bg: var(--background);
    --surface: #ffffff;
    --surface-2: color-mix(in srgb, var(--accent) 7%, #ffffff);
    --ink: #191c20;
    --ink-2: #5a616b;
    --ink-3: #9aa1ab;
    --line: color-mix(in srgb, var(--ink) 9%, transparent);
    --wash: color-mix(in srgb, var(--accent) 13%, transparent);
    --shadow: 0 1px 2px rgba(16, 20, 28, 0.05), 0 8px 24px rgba(16, 20, 28, 0.07);
    --shadow-lg: 0 2px 6px rgba(16, 20, 28, 0.08), 0 16px 40px rgba(16, 20, 28, 0.16);
    --backdrop: rgba(18, 20, 26, 0.45);

    /* ---- type ---- */
    --font-display: 'Bricolage Grotesque', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;

    /* ---- shape & rhythm ---- */
    --r-lg: 24px;
    --r-md: 16px;
    --r-sm: 10px;
    --r-pill: 999px;
    --border-radius: var(--r-md);     /* legacy alias */
    --border-radius-sm: var(--r-sm);  /* legacy alias */
    --spacing: 16px;
    --spacing-sm: 8px;
    --spacing-lg: 24px;

    /* ---- motion ---- */
    --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
    --transition: 0.18s var(--ease-spring);
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark ignores the instance --background tint and builds its own
           accent-breathed near-black, so theme.css (which loads later but
           only sets the four inputs) cannot fight the scheme. */
        --bg: color-mix(in srgb, var(--accent) 4%, #0c0e12);
        --surface: color-mix(in srgb, var(--accent) 5%, #14171d);
        --surface-2: color-mix(in srgb, var(--accent) 11%, #181c23);
        --ink: #e9ebee;
        --ink-2: #a6adb8;
        --ink-3: #6b727d;
        --line: color-mix(in srgb, #ffffff 11%, transparent);
        --wash: color-mix(in srgb, var(--accent) 10%, transparent);
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
        --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.5), 0 18px 48px rgba(0, 0, 0, 0.5);
        --backdrop: rgba(4, 5, 8, 0.6);
    }
}

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

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Ambient accent wash — gives each instance its personality without a
   heavy filled card. Fixed so it doesn't scroll with content. */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(420px 320px at 88% -8%, var(--wash), transparent 70%),
        radial-gradient(360px 280px at -12% 12%, color-mix(in srgb, var(--accent) 6%, transparent), transparent 70%);
    z-index: 0;
}

/* Keep app content above the wash */
.screen, .menu, .modal, .toast, .overlay, .fab {
    position: relative;
    z-index: 1;
}

/* Focus visibility (keyboard users) */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

/* Utilities */
.hidden {
    display: none !important;
}

.error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: var(--spacing-sm);
    text-align: center;
}

/* Screen layout */
.screen {
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--spacing);
    display: flex;
    flex-direction: column;
}

/* Loading */
#loading-screen {
    justify-content: center;
    align-items: center;
}

.loading-content {
    text-align: center;
    color: var(--ink-2);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--spacing);
}

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

/* =====================================================================
   PIN screens
   ===================================================================== */

.pin-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    max-width: 320px;
    margin: 0 auto;
    padding: var(--spacing);
}

.pin-container h1 {
    font-family: var(--font-display);
    font-weight: 640;
    font-size: 1.9rem;
    letter-spacing: -0.02em;
    margin-bottom: var(--spacing-sm);
    color: var(--ink);
}

.pin-container p {
    color: var(--ink-2);
    margin-bottom: var(--spacing-lg);
    font-size: 0.95rem;
}

.pin-hint {
    font-size: 0.75rem;
    color: var(--ink-3);
    margin-top: var(--spacing);
}

.pin-display {
    display: flex;
    gap: 14px;
    margin-bottom: calc(var(--spacing-lg) + 4px);
}

.pin-dot {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 2px solid var(--ink-3);
    background: transparent;
    transition: var(--transition);
}

.pin-dot.filled {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.12);
}

.pin-dot.error {
    border-color: var(--danger);
    background: var(--danger);
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.pin-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    width: 100%;
    max-width: 280px;
}

.pin-key {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    background: var(--surface);
    box-shadow: var(--shadow);
    font-family: var(--font-body);
    color: var(--ink);
    cursor: pointer;
    transition: transform var(--transition), background var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    line-height: 1;
}

.key-num {
    font-size: 1.45rem;
    font-weight: 600;
}

.key-letters {
    font-size: 0.55rem;
    font-weight: 500;
    letter-spacing: 1.5px;
    margin-top: 3px;
    color: var(--ink-3);
}

.pin-key:active {
    transform: scale(0.92);
    background: var(--surface-2);
}

.pin-key[data-value="clear"],
.pin-key[data-value="back"] {
    font-size: 1.2rem;
    background: transparent;
    box-shadow: none;
    color: var(--ink-2);
}

.pin-key-submit {
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
}

.pin-key-submit .key-num { color: #fff; }

.pin-key-submit:active {
    background: var(--accent-deep);
}

.pin-key:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Verifying text animation */
#auth-message .dot,
#setup-message .dot {
    display: inline-block;
    opacity: 0;
    animation: dot-appear 1.5s ease-in-out infinite;
}

#auth-message .dot:nth-child(2),
#setup-message .dot:nth-child(2) { animation-delay: 0.25s; }

#auth-message .dot:nth-child(3),
#setup-message .dot:nth-child(3) { animation-delay: 0.5s; }

@keyframes dot-appear {
    0%, 100% { opacity: 0; transform: translateY(0); }
    25% { opacity: 1; transform: translateY(-3px); }
    50%, 80% { opacity: 0; transform: translateY(0); }
}

.pin-display.loading .pin-dot {
    background: var(--accent);
    border-color: var(--accent);
    animation: pin-wave 1.2s ease-in-out infinite;
    transition: none;
}

.pin-display.loading .pin-dot:nth-child(1) { animation-delay: 0s; }
.pin-display.loading .pin-dot:nth-child(2) { animation-delay: 0.15s; }
.pin-display.loading .pin-dot:nth-child(3) { animation-delay: 0.30s; }
.pin-display.loading .pin-dot:nth-child(4) { animation-delay: 0.45s; }
.pin-display.loading .pin-dot:nth-child(5) { animation-delay: 0.60s; }
.pin-display.loading .pin-dot:nth-child(6) { animation-delay: 0.75s; }

@keyframes pin-wave {
    0%, 100% { opacity: 0.2; transform: scale(0.75); }
    50% { opacity: 1; transform: scale(1.15); }
}

/* =====================================================================
   Main screen
   ===================================================================== */

/* Contain vertical overscroll so the custom pull-to-refresh gesture isn't
   fought by the browser's native PTR / scroll chaining. */
html, body {
    overscroll-behavior-y: contain;
}

#main-screen {
    overscroll-behavior-y: contain;
}

/* ---- Pull-to-refresh indicator ----
   Absolutely positioned at the top of the main screen, parked off-screen and
   slid down by the --pull custom property (set via CSSOM in JS — CSP-safe). */
.ptr-indicator {
    position: absolute;
    top: 0;
    left: 50%;
    width: 36px;
    height: 36px;
    margin-left: -18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    z-index: 50;
    transform: translateY(calc(var(--pull, 0px) - 44px));
}

.ptr-indicator.ptr-visible {
    opacity: 1;
}

.ptr-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
}

/* Armed (past threshold): nudge the accent ring fuller as a "release to
   refresh" cue. */
.ptr-indicator.ptr-armed .ptr-spinner {
    border-top-color: var(--accent);
    border-right-color: var(--accent);
}

/* Refreshing: spin. Respects prefers-reduced-motion (handled globally below,
   which neutralises the animation). */
.ptr-indicator.ptr-refreshing .ptr-spinner {
    animation: spin 0.8s linear infinite;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) 0;
    margin-bottom: var(--spacing-sm);
}

header h1 {
    font-family: var(--font-display);
    font-weight: 560;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
    color: var(--ink-2);
}

.icon-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    border-radius: var(--r-pill);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    transition: var(--transition);
}

.icon-btn:active {
    background: var(--surface-2);
    transform: scale(0.94);
}

/* ---- Hero: the one number that matters ---- */
.hero {
    padding: var(--spacing) 4px var(--spacing-lg);
}

.hero-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-3);
    margin-bottom: 6px;
}

.hero-amount {
    display: block;
    font-family: var(--font-display);
    font-optical-sizing: auto;
    font-weight: 600;
    font-size: clamp(2.9rem, 13vw, 3.8rem);
    line-height: 1.05;
    letter-spacing: -0.035em;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    animation: rise 0.5s var(--ease-spring) both;
}

.hero-amount.balance-negative {
    color: var(--danger);
}

/* ---- Stat chips ---- */
.stat-chips {
    display: flex;
    gap: 10px;
    margin-top: var(--spacing);
    flex-wrap: wrap;
}

.chip {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 10px 14px;
    min-width: 108px;
    box-shadow: var(--shadow);
    animation: rise 0.5s var(--ease-spring) both;
    animation-delay: 0.06s;
}

.chip + .chip { animation-delay: 0.12s; }

.chip-label {
    display: block;
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-3);
    margin-bottom: 2px;
    white-space: nowrap;
}

.chip-value {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    white-space: nowrap;
}

.chip-value.balance-negative {
    color: var(--danger);
}

/* Legacy hook used outside the hero (months list). */
.amount.balance-negative {
    color: var(--danger);
}

/* =====================================================================
   Expenses
   ===================================================================== */

.expenses-section {
    flex: 1;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: var(--spacing-sm);
}

.section-header h2 {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 620;
    letter-spacing: -0.01em;
    color: var(--ink);
}

.expenses-total {
    font-size: 0.8rem;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
}

.expenses-list {
    display: flex;
    flex-direction: column;
}

.no-expenses {
    text-align: center;
    color: var(--ink-3);
    padding: calc(var(--spacing-lg) * 1.5) var(--spacing-lg);
    font-size: 0.92rem;
}

/* Skeleton shimmer for hero amounts while the first load is in flight
   (review F3). Applied as a class so it replaces the believable $0.00. */
.loading-placeholder {
    color: transparent !important;
    border-radius: var(--r-sm);
    background: linear-gradient(
        90deg,
        var(--surface-2) 25%,
        var(--wash) 37%,
        var(--surface-2) 63%
    );
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
    min-width: 5ch;
    display: inline-block;
}

@keyframes shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* Visible error state with a Retry button when the dashboard load fails. */
.dashboard-error {
    text-align: center;
    padding: var(--spacing-lg) var(--spacing);
    display: flex;
    flex-direction: column;
    gap: var(--spacing);
    align-items: center;
}

/* Day group headers inside the list */
.day-header {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-3);
    padding: var(--spacing) 4px 6px;
}

.expense-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 13px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: var(--shadow);
    animation: rise 0.4s var(--ease-spring) both;
}

.expense-item + .expense-item {
    margin-top: 8px;
}

/* Staggered entrance, capped so long lists don't crawl */
.expense-item:nth-child(2)  { animation-delay: 0.03s; }
.expense-item:nth-child(3)  { animation-delay: 0.06s; }
.expense-item:nth-child(4)  { animation-delay: 0.09s; }
.expense-item:nth-child(5)  { animation-delay: 0.12s; }
.expense-item:nth-child(6)  { animation-delay: 0.15s; }
.expense-item:nth-child(n+7) { animation-delay: 0.18s; }

@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.expense-info {
    flex: 1;
    min-width: 0;
}

.expense-desc {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.expense-date {
    font-size: 0.74rem;
    color: var(--ink-3);
    margin-top: 1px;
}

.expense-amount {
    font-weight: 700;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    margin-left: var(--spacing);
    white-space: nowrap;
}

.expense-edit,
.expense-delete {
    /* 44px minimum hit area (WCAG 2.5.5 / iOS HIG) while the icon itself
       stays 20px — the extra is invisible padding around the glyph. */
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    border-radius: var(--r-pill);
    cursor: pointer;
    margin-left: 2px;
    opacity: 0.6;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.expense-edit svg,
.expense-delete svg {
    width: 20px;
    height: 20px;
}

.expense-edit svg { color: var(--ink-2); }
.expense-delete svg { color: var(--danger); }

.expense-edit:active {
    opacity: 1;
    background: var(--surface-2);
}

.expense-delete:active {
    opacity: 1;
    background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* Load more */
.load-more-btn {
    margin-top: var(--spacing);
    padding: 12px;
    text-align: center;
}

.load-more-item {
    justify-content: center;
    color: var(--accent);
    font-weight: 600;
}

.btn-text {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--r-pill);
    transition: var(--transition);
}

.btn-text:active {
    background: var(--surface-2);
}

.section-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.menu-header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.form-hint {
    font-size: 0.8rem;
    color: var(--ink-3);
    margin-bottom: var(--spacing);
}

/* =====================================================================
   FAB
   ===================================================================== */

.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent), var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition), background var(--transition), box-shadow var(--transition);
    z-index: 100;
}

.fab:active {
    transform: scale(0.92);
    background: var(--accent-deep);
}

/* =====================================================================
   Modals — bottom sheets on mobile, centered cards on desktop
   ===================================================================== */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--backdrop);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: fade-in 0.25s ease both;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: calc(var(--spacing-lg) + 8px) var(--spacing-lg) var(--spacing-lg);
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    animation: sheet-up 0.34s var(--ease-spring) both;
}

/* Sheet drag-handle affordance */
.modal-content::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: var(--r-pill);
    background: var(--line);
}

@keyframes sheet-up {
    from { transform: translateY(48px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-content h2 {
    font-family: var(--font-display);
    font-weight: 620;
    letter-spacing: -0.01em;
    margin-bottom: var(--spacing);
    font-size: 1.3rem;
}

.form-group {
    margin-bottom: var(--spacing);
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink-2);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 14px var(--spacing);
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--ink);
    border-radius: var(--r-sm);
    font-size: 1rem;
    font-family: var(--font-body);
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

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

.form-group input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.pin-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.pin-input-wrapper input {
    padding-right: 44px;
}

.btn-show-pin {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--ink-3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-show-pin:hover { color: var(--ink-2); }
.btn-show-pin:active { color: var(--accent); }

.modal-actions {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-lg);
}

/* =====================================================================
   Buttons
   ===================================================================== */

.btn {
    flex: 1;
    padding: 13px var(--spacing);
    border-radius: var(--r-pill);
    font-size: 0.95rem;
    font-weight: 650;
    font-family: var(--font-body);
    cursor: pointer;
    transition: var(--transition);
    border: none;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:active {
    background: var(--accent-deep);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--ink);
}

.btn-secondary:active {
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

/* ui.showConfirm toggles .btn-danger for destructive confirms. */
.btn-primary.btn-danger {
    background: var(--danger);
}

.btn-primary.btn-danger:active {
    background: color-mix(in srgb, var(--danger) 75%, black);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink);
}

.btn-outline:active {
    background: var(--surface-2);
}

.btn-full {
    width: 100%;
}

/* =====================================================================
   Side menu (history)
   ===================================================================== */

.overlay {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 500;
}

.menu {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 85%;
    max-width: 330px;
    background: var(--surface);
    border-radius: var(--r-lg) 0 0 var(--r-lg);
    box-shadow: var(--shadow-lg);
    z-index: 600;
    display: flex;
    flex-direction: column;
    transform: translateX(102%);
    transition: transform 0.32s var(--ease-spring);
}

.menu.visible {
    transform: translateX(0);
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing) var(--spacing) var(--spacing-sm);
}

.menu-header h2 {
    font-family: var(--font-display);
    font-weight: 620;
    font-size: 1.25rem;
    letter-spacing: -0.01em;
}

.months-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-sm);
    list-style: none;
}

.month-row {
    list-style: none;
}

/* .month-item is now a real <button> (keyboard/SR accessible); reset native
   button chrome and stretch it to fill its list row. */
.month-item {
    width: 100%;
    padding: 13px var(--spacing);
    border: none;
    background: transparent;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-family: var(--font-body);
    color: var(--ink);
    text-align: left;
}

/* Top row of a month item: name on the left, savings pill on the right. */
.month-item-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Thin horizontal spend bar beneath each month's row. The track is a faint
   rail; the fill width is driven by the CSSOM --w custom property set in JS
   (CSP-safe; no inline style attribute). */
.month-spend-bar {
    height: 4px;
    border-radius: var(--r-pill);
    background: var(--line);
    overflow: hidden;
}

.month-spend-fill {
    display: block;
    height: 100%;
    width: var(--w, 0%);
    border-radius: var(--r-pill);
    background: var(--accent);
    transition: width var(--transition);
}

.month-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.month-item:active,
.month-item.active {
    background: var(--surface-2);
}

.month-item.active .month-name {
    color: var(--accent);
}

.month-item .month-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.month-item .month-balance {
    font-size: 0.82rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--success-color);
    background: color-mix(in srgb, var(--success-color) 10%, transparent);
    padding: 3px 10px;
    border-radius: var(--r-pill);
}

.month-item .month-balance.balance-negative {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.menu-footer {
    padding: var(--spacing);
    border-top: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.app-version {
    font-size: 0.7rem;
    color: var(--ink-3);
    text-align: center;
    margin-top: var(--spacing-sm);
}

/* =====================================================================
   Toast
   ===================================================================== */

.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--bg);
    padding: 12px 22px;
    border-radius: var(--r-pill);
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: fadeInUp 0.3s var(--ease-spring);
}

.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success-color); color: #fff; }

@keyframes fadeInUp {
    from { opacity: 0; transform: translate(-50%, 16px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Action toast (undo): message + a tappable Undo button. Reuses the toast
   pill but switches to a flex row and tightens vertical padding so the 44px
   touch target doesn't make the pill oversized. */
.toast.toast-action {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px 4px 18px;
}

.toast-message {
    font-size: 0.875rem;
    font-weight: 600;
}

.toast-undo {
    /* 44px minimum hit area (WCAG 2.5.5 / iOS HIG). */
    min-width: 44px;
    min-height: 44px;
    padding: 0 16px;
    border: none;
    background: transparent;
    color: var(--accent);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-radius: var(--r-pill);
    cursor: pointer;
}

/* The toast sits on a dark --ink background; the theme accent can be too dim
   there, so brighten the Undo affordance for contrast. */
.toast-undo {
    color: color-mix(in srgb, var(--accent) 55%, #ffffff);
}

.toast-undo:active {
    background: color-mix(in srgb, #ffffff 16%, transparent);
}

/* =====================================================================
   Desktop / tablet
   ===================================================================== */

@media (min-width: 768px) {
    .screen {
        max-width: 480px;
        margin: 0 auto;
    }

    .modal {
        align-items: center;
    }

    .modal-content {
        border-radius: var(--r-lg);
    }

    .modal-content::before {
        display: none;
    }

    .fab {
        bottom: 32px;
        right: calc(50% - 240px + 24px);
    }

    .fab:hover {
        transform: translateY(-2px);
        box-shadow: 0 12px 32px color-mix(in srgb, var(--accent) 50%, transparent), var(--shadow-lg);
    }

    .pin-key:hover {
        background: var(--surface-2);
    }

    .pin-key-submit:hover {
        background: var(--accent-deep);
    }

    .expense-item:hover {
        border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
    }

    .expense-edit:hover {
        opacity: 1;
        background: var(--surface-2);
    }

    .expense-delete:hover {
        opacity: 1;
        background: color-mix(in srgb, var(--danger) 12%, transparent);
    }

    .btn-text:hover {
        background: var(--surface-2);
    }

    .btn:hover {
        filter: brightness(1.05);
    }

    .month-item:hover {
        background: var(--surface-2);
    }
}

/* Reduced motion: keep state, drop theatrics */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .screen {
        padding-bottom: calc(var(--spacing) + env(safe-area-inset-bottom));
    }

    .fab {
        bottom: calc(24px + env(safe-area-inset-bottom));
    }

    .modal-content {
        padding-bottom: calc(var(--spacing-lg) + env(safe-area-inset-bottom));
    }

    .menu-footer {
        padding-bottom: calc(var(--spacing) + env(safe-area-inset-bottom));
    }
}

/* =====================================================================
   Expense date picker — compact row beneath the description field
   ===================================================================== */

/* Tighten the bottom margin so the date field sits snug between the
   description and the action buttons without adding extra scroll. */
.form-group-date {
    margin-bottom: var(--spacing-sm);
}

/* date inputs render differently across browsers/OSes; reset to match the
   app's existing text inputs exactly. The color-scheme property tells the
   browser to match the OS dark/light mode so the native date picker widget
   is consistent with the rest of the UI. */
.form-group-date input[type="date"] {
    color-scheme: light dark;
    font-family: var(--font-body);
    font-size: 0.95rem;
    cursor: pointer;
}

/* Remove the inner spin/clear buttons that some engines add to date fields. */
.form-group-date input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: 0.5;
    cursor: pointer;
    filter: var(--date-picker-filter, none);
}

@media (prefers-color-scheme: dark) {
    .form-group-date input[type="date"]::-webkit-calendar-picker-indicator {
        filter: invert(0.8);
    }
}
