/* Budget Tracker: one stylesheet, mobile-friendly, printable. */

:root {
    --font: 'Barlow', 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --lh: 1.6;

    /* Brand palette (from the original design) */
    --light-blue: #E5EAF1;
    --blue: #3546AB;
    --dark-blue: #0C145A;
    --logo: #3546AB;
    --chart-gap: var(--surface); /* gaps between doughnut slices: the colour behind the chart */
    --orange: #F0582E;

    --text: #1b1f3b;
    --muted: #5f6b8f;
    --muted-2: #9aa3bd;
    --subtle-text: #444;
    --line: #e3e7ef;
    --sidebar-line: #d5dbe6;
    --input-border: #cfd6e4;
    --soft: #f5f7fb;
    --surface: #fff;
    --on-heat: var(--dark-blue); /* text on the darkest calendar shade */
    --page-bg: var(--light-blue);
    --card-warm: #faf7f5;
    --income: var(--blue);
    --expense: var(--orange);
    --expense-text: #c4441b; /* darker orange for readable text */
    --danger: #c62828;
    --danger-fill: #c62828;
    --danger-hover: #a31f1f;
    --danger-line: #f1c4c4;
    --danger-tint: #fdf0f0;

    /* Fills that carry white text (buttons etc.) */
    --primary: #3546AB;
    --primary-hover: #0C145A;
    --on-primary: #fff;

    /* Tints, tracks and overlays */
    --tint-expense: #fdebe5;
    --tint-income: #e7eafb;
    --bar-track: #e9edf5;
    --focus-ring: rgb(53 70 171 / .15);
    --backdrop: rgb(12 20 90 / .55);
    --pop-shadow: 0 12px 32px rgb(12 20 90 / .16);
    --nav-glass: rgba(255, 255, 255, .96);
    --toast-bg: #0C145A;

    /* "Heads up" amber */
    --warn: #E8A33D;
    --success: #177a42;  /* goal reached; 5.4:1 on white */
    --warn-text: #9a5b00;
    --warn-bg: #fff8ea;
    --warn-line: #f1d39b;
    --warn-tint: #fdebc6;
    --warn-body: #5c3b00;

    /* Category chart colours */
    --chart-1: #F0582E;
    --chart-2: #3546AB;
    --chart-3: #0C145A;
    --chart-4: #F2A541;
    --chart-5: #2A9D8F;
    --chart-6: #8E6FD8;
    --chart-7: #E76F96;
    --chart-8: #7E8CAC;

    color-scheme: light;

    --radius: 1.5rem;
    --radius-sm: .8rem;
    --shadow: 0 24px 38px 3px rgba(0, 0, 0, .14), 0 9px 46px 8px rgba(0, 0, 0, .12), 0 11px 15px -7px rgba(0, 0, 0, .2);
    --trans: .2s ease;

    --sidebar-w: 13rem;
    --nav-h: 6.4rem;
}

/* ---- Dark theme (screen only, so printed reports stay light) --------- */

@media screen {
    /* Dark mode: black & gold (gold #E8BD70 -> #EDD185) */
    :root[data-theme="dark"] {
        color-scheme: dark;

        --gold: #E8BD70;
        --gold-light: #EDD185;
        --gold-gradient: linear-gradient(135deg, #E8BD70 0%, #EDD185 100%);

        --blue: var(--gold);      /* accent for text, icons, links, active tab, income */
        --dark-blue: #ffffff;     /* strong text */
        --orange: #ff6f61;        /* spending: coral, so it never looks like gold */
        --logo: var(--gold);
        --chart-gap: var(--page-bg); /* the dashboard sits on black here */

        --text: #ededed;
        --muted: #9b9b9b;
        --muted-2: #6f6f6f;
        --subtle-text: #cfcfcf;
        --line: #2a2a2a;
        --sidebar-line: #262626;
        --input-border: #3a3a3a;
        --soft: #222222;
        --surface: #161616;
        --on-heat: #161616;
        --page-bg: #000000;
        --card-warm: #1c1c1c;
        --expense-text: #ff8a7d;
        --danger: #ff7b7b;
        --danger-fill: #d64545;
        --danger-hover: #e35a5a;
        --danger-line: #5c2b2b;
        --danger-tint: rgb(255 107 107 / .12);

        --primary: var(--gold);
        --primary-hover: var(--gold-light);
        --on-primary: #000000;    /* black text on gold, as in the scheme */

        --tint-expense: rgb(255 111 97 / .15);
        --tint-income: rgb(232 189 112 / .15);
        --bar-track: #2a2a2a;
        --focus-ring: rgb(232 189 112 / .3);
        --backdrop: rgb(0 0 0 / .72);
        --pop-shadow: 0 12px 32px rgb(0 0 0 / .6);
        --nav-glass: rgb(10 10 10 / .96);
        --toast-bg: #262626;

        --warn: #f0a33a;
        --success: #4cc38a;
        --warn-text: #f5c27a;
        --warn-bg: rgb(240 163 58 / .1);
        --warn-line: rgb(240 163 58 / .35);
        --warn-tint: rgb(240 163 58 / .2);
        --warn-body: #f3dcb4;

        /* Charts: coral, gold, then colours that stay apart from both */
        --chart-1: #ff6f61;
        --chart-2: #E8BD70;
        --chart-3: #e6e6e6;
        --chart-4: #5fb3a3;
        --chart-5: #8c9eff;
        --chart-6: #c58af0;
        --chart-7: #ff8fb1;
        --chart-8: #8a8a8a;

        --shadow: 0 24px 38px 3px rgba(0, 0, 0, .55), 0 9px 46px 8px rgba(0, 0, 0, .45), 0 11px 15px -7px rgba(0, 0, 0, .6);
    }

    /* Gold buttons use the gradient from the scheme */
    :root[data-theme="dark"] .btn-primary,
    :root[data-theme="dark"] .icon-btn-solid { background-image: var(--gold-gradient); }
    :root[data-theme="dark"] .btn-primary:hover:not(:disabled),
    :root[data-theme="dark"] .icon-btn-solid:hover { background-image: none; }

    /* "This month": the gold hero card, black text on the gold gradient */
    :root[data-theme="dark"] .amount-block { background: var(--gold-gradient); color: #000; }
    :root[data-theme="dark"] .amount-block small { color: rgb(0 0 0 / .72); } /* 6.9:1 on gold */
    :root[data-theme="dark"] .amount-block strong { color: #000; }
    :root[data-theme="dark"] .amount-block strong.expense { color: #000; }
    :root[data-theme="dark"] .amount-block strong.income { color: #000; }
    :root[data-theme="dark"] .amount-block div:last-child strong.expense { color: #8f1d12; } /* "Spent extra" stays a warning */

    /* Black page behind charcoal cards (the content pane is the card colour in light mode) */
    :root[data-theme="dark"] .pane { background: var(--page-bg); }
    :root[data-theme="dark"] .avatar { background: var(--soft); } /* the light-mode page colour would vanish on black */
    /* Headings in white like the scheme; gold is kept for accents */
    :root[data-theme="dark"] .topbar h1,
    :root[data-theme="dark"] .section-head h2,
    :root[data-theme="dark"] .panel h2,
    :root[data-theme="dark"] .sheet-body h2,
    :root[data-theme="dark"] .auth-card h1 { color: var(--dark-blue); }
}

/* ---- Base ---------------------------------------------------------- */

html { font-size: 62.5%; -webkit-text-size-adjust: 100%; }

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

body {
    font-family: var(--font);
    font-size: 1.5rem;
    line-height: var(--lh);
    color: var(--text);
    background: var(--page-bg);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

ul { list-style: none; }
a { color: var(--blue); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
img { display: block; max-width: 100%; }
h1, h2, h3 { line-height: 1.3; }
h1, h2 { font-weight: 800; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }

.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.icon {
    width: 2rem; height: 2rem;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.muted { color: var(--muted); }
.income { color: var(--income); }
.expense { color: var(--expense-text); }
.net { color: var(--dark-blue); }
.nowrap { white-space: nowrap; }
.link { font-size: 1.3rem; font-weight: 500; }
button.link { padding: 0; border: 0; background: none; color: var(--blue); cursor: pointer; }
.link:hover { text-decoration: underline; }
.link-btn { border: 0; background: none; color: var(--blue); font-weight: 500; text-decoration: underline; padding: 0; }

/* ---- App frame ------------------------------------------------------- */

/* Full-screen dashboard: sidebar pinned on the left, content fills the rest. */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
    min-height: 100dvh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    background: var(--page-bg);
    border-right: 1px solid var(--sidebar-line);
    padding: 2rem 1rem;
    text-align: center;
}

.sidebar .brand { display: block; width: 4.8rem; margin: 0 auto 3rem; }
.brand-logo { display: block; color: var(--logo); }
.sidebar .brand .brand-logo { width: 100%; height: auto; }

.nav li { border-bottom: 1px solid var(--sidebar-line); }
.nav li:last-child { border-bottom: 0; }

.nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
    padding: 1.6rem 0;
    font-size: 1.3rem;
    color: var(--muted);
    transition: color var(--trans);
}

.nav a .icon { width: 2.2rem; height: 2.2rem; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--dark-blue); }
.nav a[aria-current="page"] { font-weight: 600; }

.pane {
    background: var(--surface);
    padding: 2rem 4rem 4rem;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    padding-bottom: 2rem;
    margin-bottom: 2.5rem;
    border-bottom: 1px solid var(--line);
}

.topbar h1 { font-size: 3rem; color: var(--blue); }
.topbar p { font-size: 1.4rem; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 1.6rem; }
.avatar-btn { display: block; padding: 0; border: 0; border-radius: 50%; background: none; }
.avatar-btn:hover .avatar, body:has(.profile-pop:popover-open) .avatar-btn .avatar { outline: 2px solid var(--blue); outline-offset: 2px; }

.avatar {
    display: grid;
    place-items: center;
    width: 4rem; height: 4rem;
    border-radius: 50%;
    overflow: hidden;
    background: var(--page-bg);
    color: var(--blue);
    font-weight: 600;
    font-size: 1.4rem;
}

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


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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    padding: .9rem 1.8rem;
    border: 1px solid transparent;
    border-radius: 2rem;
    background: none;
    font-size: 1.4rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background-color var(--trans), border-color var(--trans), transform .1s;
}

.btn .icon { width: 1.8rem; height: 1.8rem; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border-color: var(--input-border); color: var(--dark-blue); }
.btn-ghost:hover:not(:disabled) { border-color: var(--blue); }
.btn-danger { background: var(--danger-fill); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-danger-ghost { color: var(--danger); border-color: var(--danger-line); background: var(--surface); }
.btn-danger-ghost:hover { background: var(--danger-tint); }
.btn-row { display: flex; flex-wrap: wrap; gap: 1rem; }
.file-btn { cursor: pointer; position: relative; }
.file-btn:focus-within { outline: 2px solid var(--blue); outline-offset: 2px; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 3.6rem; height: 3.6rem;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--blue);
    transition: background-color var(--trans);
}

.icon-btn:hover { background: var(--soft); }

.icon-btn-solid {
    width: 4.4rem; height: 4.4rem;
    background: var(--primary);
    color: var(--on-primary);
}

.icon-btn-solid:hover { background: var(--primary-hover); }
.icon-btn-solid .icon { width: 2.4rem; height: 2.4rem; }

/* ---- Layout blocks --------------------------------------------------- */

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4rem; }
.block { margin-bottom: 3rem; }

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 4.4rem;
    margin-bottom: 1.6rem;
}

.section-head h2 { font-size: 2rem; color: var(--blue); }

.month-switch {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: 1.6rem;
    padding: .2rem;
    border: 1px solid var(--line);
    border-radius: 2rem;
}

.month-switch span { min-width: 15rem; text-align: center; font-weight: 500; font-size: 1.4rem; }
.year-switch span { min-width: 8rem; }

/* Dashboard: this month's totals */
.amount-block {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    padding: 1.6rem;
    border-radius: var(--radius);
    background: var(--soft);
}

.amount-block small, .stat small { display: block; color: var(--blue); font-weight: 500; font-size: 1.25rem; }
.amount-block strong { font-size: 1.7rem; font-weight: 600; word-break: break-word; }

/* Transactions list */
.day-group + .day-group { margin-top: 1.6rem; }

.day-label {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .4rem 1rem;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--subtle-text);
    padding-bottom: .6rem;
    border-bottom: 1px solid var(--line);
}

.day-total { display: flex; gap: 1rem; font-weight: 500; }

.tx-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 1.2rem;
    width: 100%;
    padding: 1.1rem .8rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    text-align: left;
    transition: background-color var(--trans);
}

.tx-item:hover { background: var(--soft); }

.tx-icon {
    display: grid;
    place-items: center;
    width: 3.6rem; height: 3.6rem;
    border-radius: 50%;
}

.tx-icon.expense { background: var(--tint-expense); color: var(--expense-text); }
.tx-icon.income { background: var(--tint-income); color: var(--blue); }
.tx-icon .icon { width: 1.8rem; height: 1.8rem; }

.tx-main { display: flex; flex-direction: column; min-width: 0; }
.tx-main strong { font-size: 1.4rem; font-weight: 600; color: var(--dark-blue); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-main small { font-size: 1.2rem; color: var(--muted); }
.tx-amount { font-weight: 600; font-size: 1.4rem; white-space: nowrap; }

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--input-border);
    border-radius: var(--radius);
}

.empty > .icon { width: 3.6rem; height: 3.6rem; color: var(--muted-2); }

/* Dashboard: monthly trend cards */
.trend-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.6rem; }

.trend-card {
    display: block;
    padding: 1.4rem 1.6rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    transition: border-color var(--trans);
}

.trend-card:hover { border-color: var(--blue); }
.trend-card > small { font-weight: 500; }
.trend-card.expense > small, .trend-card.expense .trend-change { color: var(--expense-text); }
.trend-card.income > small, .trend-card.income .trend-change { color: var(--blue); }
.trend-card.expense .mini-bars { color: var(--orange); }
.trend-card.income .mini-bars { color: var(--blue); }
.trend-card strong { display: block; font-size: 1.7rem; font-weight: 700; word-break: break-word; }
.trend-change { font-size: 1.2rem; }

.mini-bars { display: flex; gap: .4rem; height: 8rem; margin: 1rem 0 1.4rem; }
.mb-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .4rem; }
.mb-track { flex: 1; width: .8rem; position: relative; }
.mb-track i { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 1rem; background: currentColor; opacity: .3; }
.mb-col.current .mb-track i { opacity: 1; }
.mb-col small { font-size: 1rem; line-height: 1; color: var(--muted); }

/* Dashboard: expenses by category */
.cat-list { display: grid; gap: 1.2rem; margin-bottom: 1.2rem; }

.cat-card {
    display: flex;
    align-items: center;
    gap: 1.6rem;
    padding: 1.2rem 1.6rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card-warm);
}

.pie-wrap { position: relative; height: 22rem; margin-bottom: 1.6rem; } /* Chart.js fills this box */
.pie-wrap[hidden] { display: none; }
.pie-total { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 0; text-align: center; pointer-events: none; } /* sits in the doughnut's hole; taps go through to the chart */
.pie-total small { font-size: 1.25rem; color: var(--muted); }
.pie-total strong { font-size: 2rem; font-weight: 700; color: var(--expense-text); line-height: 1.2; }
.cat-dot { width: 1.4rem; height: 1.4rem; flex-shrink: 0; border-radius: 50%; }

.cat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.cat-main small { color: var(--muted); font-size: 1.3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-main strong { font-size: 1.6rem; }
.cat-pct { font-weight: 600; color: var(--dark-blue); }

/* ---- Lists: toolbar -------------------------------------------------- */

.toolbar { display: grid; grid-template-columns: auto auto auto minmax(0, 1fr); gap: 1rem; margin-bottom: 1.6rem; }
.list-summary { display: flex; flex-wrap: wrap; gap: .4rem 2rem; margin-bottom: 1.6rem; font-weight: 500; font-size: 1.4rem; }
.list-summary:empty { display: none; }

.toolbar select, .search input, .field input, .field select, .add-cat input {
    width: 100%;
    padding: 1rem 1.2rem;
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 1.6rem; /* 16px: stops iOS zooming into the field */
    transition: border-color var(--trans);
}

.toolbar select:focus, .search input:focus, .field input:focus, .field select:focus, .add-cat input:focus {
    border-color: var(--blue);
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.search { position: relative; }
.search .icon { position: absolute; left: 1.2rem; top: 50%; transform: translateY(-50%); color: var(--muted); width: 1.8rem; height: 1.8rem; }
.search input { padding-left: 4rem; }

/* ---- Stats and tables (Monthly, Report) ----------------------------- */

.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.2rem; margin-bottom: 3rem; }
.stat { padding: 1.4rem 1.6rem; border-radius: var(--radius); background: var(--soft); }
.stat strong { display: block; font-size: 1.8rem; font-weight: 600; word-break: break-word; }

.legend { display: flex; gap: 1.6rem; font-size: 1.3rem; }
.legend span { display: inline-flex; align-items: center; gap: .6rem; }
.legend span::before { content: ''; width: 1rem; height: 1rem; border-radius: .3rem; background: currentColor; }
.legend .expense::before { background: var(--orange); }

.year-chart { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: .6rem; height: 22rem; }
.yc-col { display: flex; flex-direction: column; align-items: center; gap: .6rem; border-radius: var(--radius-sm); padding-top: .6rem; }
.yc-col.current { background: var(--soft); }
.yc-bars { flex: 1; width: 100%; display: flex; justify-content: center; align-items: flex-end; gap: .3rem; }
.yc-bars i { width: min(1.2rem, 35%); border-radius: .4rem .4rem 0 0; }
.yc-bars i.income { background: var(--blue); }
.yc-bars i.expense { background: var(--orange); }
.yc-col small { font-size: 1.1rem; color: var(--muted); padding-bottom: .4rem; }
.chart-scale { font-size: 1.2rem; text-align: right; margin-top: .6rem; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 1.4rem; }
.data-table th, .data-table td { padding: 1rem 1.2rem; text-align: right; border-bottom: 1px solid var(--line); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table thead th { font-size: 1.2rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.data-table tbody th { font-weight: 500; }
.data-table tfoot th, .data-table tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--line); }
.data-table tr.is-empty td { color: var(--muted-2); }
.data-table tr.is-current th a { font-weight: 700; }
.data-table tbody tr:hover { background: var(--soft); }
.hint { font-size: 1.3rem; margin-top: 1rem; }

/* Report */
.report-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 2rem; }
.report-actions .month-switch { margin-bottom: 0; }
.report-head { display: flex; align-items: center; gap: 1.6rem; margin-bottom: 2.4rem; }
.report-head .brand-logo { width: 4rem; height: auto; }
.report-head h2 { font-size: 2.2rem; color: var(--blue); }
.report h3 { font-size: 1.7rem; color: var(--blue); margin: 2.4rem 0 1rem; }
.tx-table th:nth-child(-n+3), .tx-table td:nth-child(-n+3) { text-align: left; }

/* ---- Settings -------------------------------------------------------- */

/* Two columns on wide screens: personal setup on the left, data & device on the right. */
.settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2rem; align-items: start; }
.settings-col { display: grid; gap: 2rem; }
.panel { padding: 2.4rem; border: 1px solid var(--line); border-radius: var(--radius); container-type: inline-size; }
.panel h2 { font-size: 1.8rem; color: var(--blue); margin-bottom: 1.2rem; }
.panel h3 { font-size: 1.4rem; margin-bottom: 1rem; }
.panel > p { margin-bottom: 1.4rem; font-size: 1.4rem; }
.panel-danger { border-color: var(--danger-line); }
.panel-danger h2 { color: var(--danger); }
/* Compact profile: the avatar is the photo button, name field sits beside it. */
.profile-row { display: flex; align-items: center; gap: 1.6rem; }
.profile-name { flex: 1; min-width: 0; margin-bottom: 0; }
.avatar-edit { position: relative; flex-shrink: 0; border-radius: 50%; cursor: pointer; }
.avatar-edit:focus-within { outline: 2px solid var(--blue); outline-offset: 2px; }
.avatar-md { width: 5.6rem; height: 5.6rem; font-size: 1.9rem; }
.avatar-edit:hover .avatar { outline: 2px solid var(--blue); }

.avatar-badge {
    position: absolute;
    right: -.4rem;
    bottom: -.4rem;
    display: grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 50%;
    border: 2px solid var(--surface);
    background: var(--primary);
    color: var(--on-primary);
}

.avatar-badge .icon { width: 1.3rem; height: 1.3rem; }

/* Profile popup, anchored under the header avatar (position set in profile.js) */
.profile-pop {
    position: fixed;
    inset: auto;
    margin: 0;
    width: min(34rem, calc(100vw - 3.2rem));
    padding: 2rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: inherit;
    box-shadow: var(--pop-shadow);
}

.profile-pop:popover-open { animation: pop .15s ease-out; }

.pop-foot {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.6rem;
    padding-top: 1.2rem;
    border-top: 1px solid var(--line);
    font-size: 1.3rem;
}

.pop-link { display: inline-flex; align-items: center; gap: .2rem; margin-left: auto; font-weight: 600; }
.pop-link .icon { width: 1.6rem; height: 1.6rem; }
.pop-link:hover { text-decoration: underline; }

.cat-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3rem; }

/* Stack expense/income categories when their panel is narrow. */
@container (max-width: 520px) {
    .cat-columns { grid-template-columns: minmax(0, 1fr); gap: 2rem; }
}

.chips { display: flex; flex-wrap: wrap; gap: .8rem; margin-bottom: 1.4rem; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    padding: .4rem .4rem .4rem 1.2rem;
    border-radius: 2rem;
    background: var(--soft);
    border: 1px solid var(--line);
    font-size: 1.3rem;
}

.chip:not(:has(button)) { padding-right: 1.2rem; }
.chip button { display: grid; place-items: center; width: 2.4rem; height: 2.4rem; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.chip button:hover { background: var(--danger-tint); color: var(--danger); }
.chip .icon { width: 1.4rem; height: 1.4rem; }
.add-cat { display: flex; gap: .8rem; }
.add-cat input { padding: .7rem 1.2rem; }
.backup-status { font-weight: 500; }
.backup-status.warn { color: var(--expense-text); }
.storage-line { font-size: 1.3rem; margin-top: 1.4rem; }

/* ---- Dialogs --------------------------------------------------------- */

dialog.sheet {
    margin: auto;
    width: min(46rem, calc(100vw - 3.2rem));
    max-height: calc(100dvh - 3.2rem);
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: var(--surface);
    color: inherit;
    box-shadow: var(--shadow);
}

dialog.sheet-sm { width: min(40rem, calc(100vw - 3.2rem)); }
dialog.sheet::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
dialog.sheet[open] { animation: pop .18s ease-out; }

@keyframes pop {
    from { opacity: 0; transform: scale(.96); }
}

.sheet-body { padding: 2.4rem; }
.sheet-body h2 { font-size: 2.2rem; color: var(--blue); }
.sheet-body > p { margin: 1rem 0 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.6rem; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 2.4rem; }
.sheet-actions #tx-delete { margin-right: auto; }
.sheet-actions .btn-primary { min-width: 12rem; }

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .4rem;
    padding: .4rem;
    margin-bottom: 1.8rem;
    border: 0;
    border-radius: 1.2rem;
    background: var(--soft);
}

.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; opacity: 0; }

.segmented span {
    display: block;
    padding: .9rem;
    border-radius: .9rem;
    text-align: center;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: background-color var(--trans), color var(--trans);
}

.segmented input:checked + span { background: var(--surface); outline: 1px solid var(--line); }
.segmented input[value="expense"]:checked + span { color: var(--expense-text); }
.segmented input[value="income"]:checked + span { color: var(--blue); }
.segmented input:focus-visible + span { outline: 2px solid var(--blue); }

.field { display: block; margin-bottom: 1.4rem; }
.field > span:first-child, .field > label:first-child { display: block; margin-bottom: .5rem; font-size: 1.4rem; font-weight: 500; }
.field small { color: var(--muted); font-weight: 400; }
.amount-wrap { position: relative; display: block; }
.amount-wrap b { position: absolute; left: 1.4rem; top: 50%; transform: translateY(-50%); font-size: 2.2rem; font-weight: 600; color: var(--muted); }
.field .amount-input { padding-left: 4rem; font-size: 2.4rem; font-weight: 600; }
.field input[aria-invalid] { border-color: var(--danger); }
.field-error { margin: -.8rem 0 1.4rem; color: var(--danger); font-size: 1.3rem; }

/* ---- Toast ----------------------------------------------------------- */

.toast {
    position: fixed;
    inset: auto 0 calc(2.4rem + env(safe-area-inset-bottom)) 0;
    margin: 0 auto;
    width: max-content;
    max-width: calc(100vw - 3.2rem);
    display: flex;
    align-items: center;
    gap: 1.6rem;
    padding: 1.2rem 1.8rem;
    border: 0;
    border-radius: 1.2rem;
    background: var(--toast-bg);
    color: #fff;
    font-size: 1.4rem;
    box-shadow: var(--shadow);
    overflow: visible;
}

.toast:not(.show) { display: none; }
.toast.show { animation: toast-in .2s ease-out; }
.toast button { border: 0; background: none; color: #ffb59f; font-weight: 600; text-transform: uppercase; font-size: 1.3rem; letter-spacing: .04em; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(1rem); }
}

.noscript { padding: 2rem; text-align: center; }

/* ---- Budgets ------------------------------------------------------------- */

.budget-overall, .budget-row { --level: var(--blue); --level-text: var(--blue); }
.level-warn { --level: var(--warn); --level-text: var(--warn-text); }
.level-over { --level: var(--danger); --level-text: var(--danger); }

.bar { height: .8rem; border-radius: 1rem; background: var(--soft); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--level); transition: width .3s ease; }

.budget-overall { padding: 1.6rem; margin-bottom: 1.4rem; border: 1px solid var(--line); border-radius: var(--radius); }
.budget-overall .bar { height: 1.2rem; margin: 1rem 0 0; background: var(--bar-track); }
.bo-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .4rem 1rem; font-size: 1.4rem; }
.bo-top strong { font-size: 1.8rem; }
.bo-left { font-weight: 600; color: var(--level-text); }
.bo-note { margin-top: 1rem; font-size: 1.3rem; color: var(--muted); }
.bo-note strong { color: var(--dark-blue); }
.level-over .bo-note strong { color: var(--danger); }

.budget-list { display: grid; gap: 1.4rem; }
.br-top { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .5rem; font-size: 1.4rem; }
.br-name { font-weight: 600; color: var(--dark-blue); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.br-amt { font-weight: 600; white-space: nowrap; }
.br-amt small { font-weight: 400; color: var(--muted); }
.br-status { display: block; margin-top: .4rem; font-size: 1.2rem; color: var(--level-text); }
.budget-outside { margin-top: 1.4rem; font-size: 1.3rem; }

.budget-empty { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1.2rem; padding: 1.6rem; border: 1px dashed var(--input-border); border-radius: var(--radius); }
.budget-empty p { flex: 1 1 22rem; font-size: 1.4rem; color: var(--muted); }

/* Budget form */
.budget-intro { font-size: 1.35rem; margin-bottom: 1.6rem; }
.budget-fields { display: grid; gap: .2rem; max-height: min(48vh, 46rem); overflow-y: auto; padding-right: .4rem; overscroll-behavior: contain; }
.budget-field { display: grid; grid-template-columns: minmax(0, 1fr) 15rem; align-items: center; gap: 1.2rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.bf-name { display: flex; flex-direction: column; font-weight: 500; font-size: 1.4rem; min-width: 0; }
.bf-name small { font-weight: 400; color: var(--muted); font-size: 1.2rem; }
.budget-field .amount-wrap b { left: 1.1rem; font-size: 1.5rem; }
.budget-field input { width: 100%; padding: .8rem 1rem .8rem 2.8rem; border: 1px solid var(--input-border); border-radius: var(--radius-sm); font-size: 1.6rem; text-align: right; background: var(--surface); color: var(--text); }
.budget-field input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.budget-field input[aria-invalid] { border-color: var(--danger); }
.budget-total { display: flex; justify-content: space-between; align-items: baseline; margin-top: 1.6rem; font-weight: 500; }
.budget-total strong { font-size: 1.8rem; color: var(--dark-blue); }
#budget-form .field-error { margin: 1rem 0 0; }

/* Report: budget column */
.data-table small.over { color: var(--danger); font-weight: 600; }

/* ---- Recurring ------------------------------------------------------------ */

.repeat-hint { display: block; margin-top: .5rem; font-size: 1.25rem; color: var(--blue); }
.repeat-hint:empty { display: none; }

/* Payment method chips in the add form */
.method-pick { padding: 0; border: 0; min-width: 0; }
.method-pick legend { display: block; margin-bottom: .5rem; padding: 0; font-size: 1.4rem; font-weight: 500; }
.method-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; }
.method-options label { position: relative; }
.method-options input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.method-options span {
    display: block;
    padding: .9rem .4rem;
    border: 1px solid var(--line);
    border-radius: 1rem;
    background: var(--surface);
    text-align: center;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--muted);
    transition: border-color var(--trans), background-color var(--trans), color var(--trans);
}
.method-options input:checked + span { border-color: var(--blue); background: var(--soft); color: var(--blue); }
.method-options input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 1px; }

.sound-field { margin-top: 1.6rem; }
.repeat-end { display: grid; gap: .5rem; margin-top: 1rem; }
.repeat-end > label { font-size: 1.4rem; font-weight: 500; }
.repeat-end-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: .8rem; } /* menu, then the number or date under it: options stay readable on phones */
.rec-edit-note { grid-column: 1 / -1; margin: -.4rem 0 .8rem; font-size: 1.25rem; color: var(--muted); }

/* Settings: fingerprint or face unlock */
.bio-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 1.2rem; margin: .4rem 0 1.6rem; padding: 1.2rem 1.4rem; border: 1px solid var(--line); border-radius: var(--radius); }
.bio-row[hidden] { display: none; }
.bio-icon { display: grid; place-items: center; width: 3.6rem; height: 3.6rem; border-radius: 50%; background: var(--soft); color: var(--blue); }
.bio-icon .icon { width: 2rem; height: 2rem; }
.bio-text strong { display: block; font-size: 1.45rem; font-weight: 600; }
.bio-text small { display: block; font-size: 1.25rem; color: var(--muted); }
.auth-bio { margin-top: 1.2rem; }
.auth-bio .icon { width: 2rem; height: 2rem; }

/* Foldable dashboard cards */
.fold-btn { display: inline-flex; align-items: center; gap: .6rem; padding: 0; border: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.fold-btn .icon { width: 1.6rem; height: 1.6rem; color: var(--muted); transform: rotate(90deg); transition: transform var(--trans); flex-shrink: 0; }
.fold-btn[aria-expanded="false"] .icon { transform: none; }
.fold-btn:hover .icon { color: var(--blue); }
.fold-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: .4rem; }
.block.is-folded > :not(.section-head) { display: none; }
.block.is-folded { margin-bottom: 1.6rem; }
.block.is-folded > .section-head { margin-bottom: 0; padding-bottom: 1.2rem; border-bottom: 1px solid var(--line); }

/* "More you can do": features not used yet */
.more-list { display: grid; gap: .8rem; margin: 0; padding: 0; list-style: none; }
.more-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 1.2rem; width: 100%; padding: 1.2rem 1.4rem; border: 1px dashed var(--input-border); border-radius: var(--radius); background: none; color: var(--dark-blue); text-align: left; transition: border-color var(--trans), background-color var(--trans); }
.more-item:hover { border-color: var(--blue); background: var(--soft); }
.more-item strong { display: block; font-size: 1.45rem; font-weight: 600; }
.more-item small { display: block; font-size: 1.25rem; color: var(--muted); }
.more-item > .icon { width: 1.6rem; height: 1.6rem; color: var(--muted); }
.more-plus { display: grid; place-items: center; width: 3.2rem; height: 3.2rem; border-radius: 50%; background: var(--soft); color: var(--blue); }
.more-plus .icon { width: 1.6rem; height: 1.6rem; }

/* Savings goals */
.goal-list { display: grid; gap: 1.2rem; margin: 0; padding: 0; list-style: none; }
.goal { container: goal / inline-size; --level: var(--blue); padding: 1.4rem 1.6rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.goal.reached { --level: var(--success); }
.goal.overdue { --level: var(--warn); }
.goal.overdue .goal-pct { color: var(--dark-blue); } /* amber is too faint as text */
.goal-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .8rem; }
.goal-name { display: inline-flex; align-items: center; gap: .6rem; min-width: 0; padding: 0; border: 0; background: none; font-size: 1.6rem; font-weight: 700; color: var(--dark-blue); text-align: left; }
.goal-name .icon { width: 1.4rem; height: 1.4rem; color: var(--muted); flex-shrink: 0; }
.goal-name:hover .icon { color: var(--blue); }
.goal-pct { font-weight: 700; color: var(--level); }
.goal .bar { height: 1rem; background: var(--bar-track); }
.goal-amt { margin: .8rem 0 0; font-size: 1.4rem; color: var(--muted); }
.goal-amt strong { color: var(--dark-blue); font-weight: 700; }
.goal-pace { margin: .2rem 0 0; font-size: 1.3rem; color: var(--muted); }
.goal.reached .goal-pace { color: var(--level); font-weight: 600; }
.goal-actions { display: flex; align-items: center; gap: 1.6rem; margin-top: 1.2rem; }
.goal-actions:empty { display: none; }
.goal-money-hint { margin: -.6rem 0 1.4rem; font-size: 1.3rem; }
.goal-history-toggle { margin-left: auto; }
.goal-history { display: grid; margin: 1.2rem 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.gh-row { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr) auto auto; align-items: center; gap: .4rem 1rem; padding: .7rem 0; border-bottom: 1px solid var(--line); font-size: 1.35rem; }
.gh-row:last-child { border-bottom: 0; }
.gh-date { color: var(--muted); white-space: nowrap; }
.gh-what { font-weight: 600; color: var(--dark-blue); }
.gh-row.withdraw .gh-what { color: var(--expense-text); }
.gh-bal { color: var(--muted); white-space: nowrap; text-align: right; }
.gh-remove { width: 3.2rem; height: 3.2rem; color: var(--muted); }
.gh-remove .icon { width: 1.5rem; height: 1.5rem; }
.gh-remove:hover { color: var(--danger); background: var(--danger-tint); }
@container goal (max-width: 440px) {
    .gh-row { grid-template-columns: minmax(0, 1fr) auto; gap: .1rem 1rem; }
    .gh-date, .gh-what, .gh-bal { grid-column: 1; text-align: left; }
    .gh-remove { grid-column: 2; grid-row: 1 / span 3; }
}

/* Dashboard: bills to confirm ("ask me" repeats that are due) */
.confirm-block { padding: 1.6rem 1.8rem; border: 1px solid var(--warn-line); border-radius: var(--radius); background: var(--warn-bg); }
.confirm-intro { margin: -.6rem 0 1.2rem; font-size: 1.3rem; }
.confirm-list { display: grid; gap: 1rem; margin: 0; padding: 0; list-style: none; }
.confirm-item { display: grid; grid-template-columns: minmax(0, 1fr) 13rem auto; align-items: center; gap: .8rem 1.2rem; padding: 1.2rem 1.4rem; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); }
.ci-top strong { display: block; font-size: 1.5rem; font-weight: 600; color: var(--dark-blue); }
.ci-top small { font-size: 1.25rem; color: var(--muted); }
.ci-amount .amount-wrap input { width: 100%; padding: .8rem 1rem .8rem 2.8rem; border: 1px solid var(--input-border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: 1.6rem; font-weight: 600; text-align: right; }
.ci-amount .amount-wrap b { left: 1rem; font-size: 1.4rem; }
.ci-actions { display: flex; align-items: center; gap: 1.2rem; }
.confirm-item .field-error { grid-column: 1 / -1; margin: 0; }
@media (max-width: 560px) {
    .confirm-item { grid-template-columns: minmax(0, 1fr) auto; }
    .ci-top { grid-column: 1 / -1; }
}
.up-skip, .rec-skip { font-size: inherit; padding: 0 .2rem; }
.up-amt small { font-size: 1.15rem; font-weight: 500; color: var(--muted); }
.ask-field, .rec-ask { margin-top: .8rem; grid-column: 1 / -1; }

/* Dashboard: coming up (repeats due soon) */
.up-switch { display: inline-flex; padding: .3rem; gap: .2rem; border-radius: 99px; background: var(--soft); }
.up-switch button { padding: .4rem 1.1rem; border: 0; border-radius: 99px; background: none; color: var(--muted); font: inherit; font-size: 1.25rem; font-weight: 600; cursor: pointer; }
.up-switch button[aria-pressed="true"] { background: var(--surface); color: var(--dark-blue); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.up-switch button:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.up-sum { margin: -.4rem 0 1rem; font-size: 1.4rem; color: var(--muted); }
.up-sum strong { font-weight: 700; }
.up-list { display: grid; margin: 0; padding: 0; list-style: none; }
.up-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 1.2rem; padding: 1rem 0; border-top: 1px solid var(--line); }
.up-item:first-child { border-top: 0; }
.up-date { display: grid; place-items: center; width: 4.4rem; padding: .4rem 0; border-radius: 1rem; background: var(--soft); line-height: 1.1; }
.up-date b { font-size: 1.7rem; font-weight: 700; color: var(--dark-blue); }
.up-date small { font-size: 1.1rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.up-item.income .up-date { background: var(--tint-income); }
.up-main { min-width: 0; }
.up-main strong { display: block; font-size: 1.45rem; font-weight: 600; color: var(--dark-blue); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-main small { font-size: 1.25rem; color: var(--muted); }
.up-amt { font-weight: 600; font-size: 1.4rem; white-space: nowrap; }
.up-amt.expense { color: var(--expense-text); }
.up-amt.income { color: var(--blue); }
.up-empty { font-size: 1.4rem; margin: 0 0 1rem; }
.up-manage { display: inline-block; margin-top: .8rem; }

/* Lend & borrow */
.debt-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.4rem; padding: 1.4rem 1.6rem; border-radius: var(--radius); background: var(--soft); }
.debt-totals small { display: block; font-size: 1.3rem; color: var(--muted); }
.debt-totals strong { font-size: 1.9rem; font-weight: 700; }
.debt-list { display: grid; margin: 0; padding: 0; list-style: none; }
.debt { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.2rem; padding: 1.2rem 0; border-top: 1px solid var(--line); }
.debt:first-child { border-top: 0; padding-top: .2rem; }
.debt-main { min-width: 0; }
.debt-title { display: block; padding: 0; border: 0; background: none; font-size: 1.5rem; font-weight: 600; color: var(--dark-blue); text-align: left; }
.debt-title:hover { text-decoration: underline; }
.debt-detail { display: block; margin-top: .2rem; font-size: 1.3rem; color: var(--muted); }
.debt.due-overdue .debt-detail, .debt.due-today .debt-detail { color: var(--danger); font-weight: 600; }
.debt.due-soon .debt-detail { color: var(--dark-blue); font-weight: 600; }
.debt.settled { opacity: .7; }
.debt-actions { display: flex; align-items: center; gap: 1.6rem; margin-top: .8rem; }
.debt-actions .link { display: inline-flex; align-items: center; gap: .5rem; }
.debt-actions .icon { width: 1.5rem; height: 1.5rem; }
.debt-toggle { margin-top: 1rem; }
.debt-clear { margin: 0 0 .4rem; font-size: 1.4rem; }
.field-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 1.2rem; }

/* Dashboard insights */
.insights { display: grid; gap: 1rem; margin: 0; padding: 0; list-style: none; }
.insight { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.2rem; align-items: start; padding: 1.2rem 1.4rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.insight strong { display: block; font-size: 1.5rem; font-weight: 600; color: var(--dark-blue); }
.insight small { display: block; margin-top: .2rem; font-size: 1.3rem; color: var(--muted); }
.insight-icon { display: grid; place-items: center; width: 3.2rem; height: 3.2rem; border-radius: 50%; background: var(--soft); color: var(--blue); }
.insight-icon .icon { width: 1.7rem; height: 1.7rem; }
.insight.up .insight-icon { background: var(--danger-tint); color: var(--expense-text); }

/* Dashboard: spending calendar (heat-map) */
.cal-sub { margin: -.6rem 0 1.2rem; font-size: 1.3rem; }
.cal { display: grid; gap: .4rem; }
.cal-head, .cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .4rem; }
.cal-head span { text-align: center; font-size: 1.15rem; font-weight: 600; color: var(--muted); }
.cal-cell {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 0;
    aspect-ratio: 1 / 1;
    padding: .4rem .5rem;
    border: 1px solid transparent;
    border-radius: .8rem;
    background: var(--soft);
    color: var(--dark-blue);
    text-align: left;
    overflow: hidden;
}
.cal-blank { background: none; }
@media (min-width: 900px) {
    .cal-cell { aspect-ratio: 5 / 3; } /* wide columns: keep the month from getting very tall */
}
.cal-n { font-size: 1.25rem; font-weight: 600; line-height: 1; }
.cal-amt { font-size: 1.05rem; font-weight: 600; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-cell.lv1, .cal-legend .lv1 { background: color-mix(in srgb, var(--expense) 18%, var(--surface)); }
.cal-cell.lv2, .cal-legend .lv2 { background: color-mix(in srgb, var(--expense) 38%, var(--surface)); }
.cal-cell.lv3, .cal-legend .lv3 { background: color-mix(in srgb, var(--expense) 62%, var(--surface)); }
.cal-cell.lv4, .cal-legend .lv4 { background: var(--expense); }
.cal-cell.lv4 { color: var(--on-heat); }
.cal-legend .lv0 { background: var(--soft); }
.cal-cell.is-future { opacity: .45; }
.cal-cell.is-today { border-color: var(--blue); }
.cal-cell[aria-pressed="true"] { outline: 2px solid var(--blue); outline-offset: 1px; }
.cal-cell:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.cal-legend { display: flex; align-items: center; justify-content: flex-end; gap: .4rem; margin-top: .8rem; font-size: 1.15rem; color: var(--muted); }
.cal-legend i { width: 1.2rem; height: 1.2rem; border-radius: .3rem; }
.cal-legend span:first-child { margin-right: .2rem; }
.cal-legend span:last-child { margin-left: .2rem; }
.cal-panel { margin-top: 1.6rem; }
.cal-hint { font-size: 1.3rem; }

/* Dashboard: spending per payment method */
.method-bar { display: flex; height: 1.2rem; overflow: hidden; border-radius: 1rem; background: var(--soft); gap: 2px; }
.method-bar i { display: block; min-width: 3px; }
.method-legend { display: grid; gap: .2rem; margin: 1.2rem 0 0; padding: 0; list-style: none; }
.method-legend li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto 4.4rem; align-items: center; gap: 1rem; padding: .6rem 0; font-size: 1.4rem; }
.method-legend .dot { width: 1rem; height: 1rem; border-radius: 50%; }
.method-legend strong { font-weight: 600; }
.method-legend small { color: var(--muted); text-align: right; }

/* Notes used before, shown while typing a note */
.note-suggest { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .8rem; }
.note-suggest[hidden] { display: none; }
.note-chip {
    display: inline-flex;
    align-items: baseline;
    gap: .6rem;
    max-width: 100%;
    min-height: 3.6rem;
    padding: .6rem 1.2rem;
    border: 1px solid var(--line);
    border-radius: 2rem;
    background: var(--soft);
    color: var(--dark-blue);
    font-size: 1.35rem;
    text-align: left;
    transition: border-color var(--trans), background-color var(--trans);
}
.note-chip strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-chip small { color: var(--muted); font-size: 1.2rem; white-space: nowrap; }
.note-chip:hover { border-color: var(--blue); }
.repeat-note { margin: -.4rem 0 1.4rem; padding: .9rem 1.2rem; border-radius: var(--radius-sm); background: var(--soft); font-size: 1.3rem; color: var(--dark-blue); }
.tx-repeat { display: inline-flex; vertical-align: -2px; margin-right: .4rem; color: var(--blue); }
.tx-repeat .icon { width: 1.3rem; height: 1.3rem; }

.rec-list { display: grid; }
.rec-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 1.2rem; padding: 1.2rem 0; border-top: 1px solid var(--line); }
.rec-item:first-child { border-top: 0; padding-top: .2rem; }
.rec-main { display: flex; flex-direction: column; min-width: 0; }
.rec-main strong { font-size: 1.4rem; color: var(--dark-blue); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-main small { font-size: 1.25rem; color: var(--muted); }
.rec-main small .income, .rec-main small .expense { font-weight: 600; }
.rec-actions { display: flex; align-items: center; gap: .4rem; }
.rec-actions .icon-btn { color: var(--muted); }
.rec-actions .icon-btn:hover { color: var(--danger); background: var(--danger-tint); }
.rec-item.is-paused .tx-icon, .rec-item.is-paused .rec-main { opacity: .55; }
.rec-item.is-finished .rec-main small:last-child { color: var(--success); font-weight: 600; }
.rec-end { grid-column: 1 / -1; }
.rec-end > label { display: block; margin-bottom: .5rem; font-size: 1.4rem; font-weight: 500; }
.rec-end small { display: block; margin-top: .4rem; }
.btn-sm { padding: .5rem 1.2rem; font-size: 1.3rem; }

/* ---- Backups ------------------------------------------------------------- */

.backup-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.2rem 1.6rem;
    margin-bottom: 2.4rem;
    padding: 1.4rem 1.6rem;
    border: 1px solid var(--warn-line);
    border-radius: var(--radius);
    background: var(--warn-bg);
}

.bb-icon { display: grid; place-items: center; width: 3.6rem; height: 3.6rem; border-radius: 50%; background: var(--warn-tint); color: var(--warn-text); flex-shrink: 0; }
.backup-banner p { flex: 1 1 26rem; font-size: 1.4rem; color: var(--warn-body); }
.bb-actions { display: flex; align-items: center; gap: 1.4rem; }

.backup-facts { display: grid; gap: .8rem; margin-bottom: 1.4rem; }
.backup-facts li { display: flex; gap: 1rem; align-items: flex-start; font-size: 1.3rem; color: var(--muted); }
.backup-facts .icon { width: 1.7rem; height: 1.7rem; margin-top: .1rem; color: var(--blue); }
.backup-facts strong { color: var(--dark-blue); }
.pw-dialog-field { margin-top: 1.6rem; }

/* ---- Quick add ------------------------------------------------------------- */

.quick-add { margin-top: 1.6rem; }
.qa-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .8rem; }
.qa-head .qa-label { margin-bottom: 0; }
.qa-label { display: block; margin-bottom: .8rem; font-size: 1.25rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.qa-chips { display: flex; flex-wrap: wrap; gap: .8rem; }

.qa-chip {
    display: inline-flex;
    align-items: center;
    gap: .8rem;
    padding: .8rem 1.4rem;
    border: 1px solid var(--line);
    border-radius: 2rem;
    background: var(--surface);
    font-size: 1.4rem;
    color: var(--dark-blue);
    transition: border-color var(--trans), background-color var(--trans), transform .1s;
}

.qa-chip b { font-weight: 700; color: var(--expense-text); }
.qa-chip.income b { color: var(--blue); }
.qa-chip:hover { border-color: var(--blue); background: var(--soft); }
.qa-chip:active { transform: scale(.96); }

.qa-tip { display: flex; gap: .8rem; align-items: flex-start; margin-top: 1.4rem; font-size: 1.3rem; color: var(--muted); }
.qa-tip .icon { width: 1.6rem; height: 1.6rem; margin-top: .2rem; color: var(--warn); flex-shrink: 0; }

.check-field { display: flex; align-items: flex-start; gap: 1rem; margin: .2rem 0 .4rem; font-size: 1.4rem; cursor: pointer; }
.check-field input { width: 1.8rem; height: 1.8rem; margin-top: .2rem; accent-color: var(--blue); flex-shrink: 0; }
.check-field small { display: block; color: var(--muted); font-size: 1.2rem; }

.fav-list { display: grid; }
.fav-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 1.2rem; padding: 1rem 0; border-top: 1px solid var(--line); }
.fav-item:first-child { border-top: 0; padding-top: .2rem; }
.fav-item .tx-icon .icon { width: 1.6rem; height: 1.6rem; }
.fav-item .icon-btn { color: var(--muted); }
.fav-item .icon-btn:hover { color: var(--danger); background: var(--danger-tint); }
.fav-item .icon-btn:not(.icon-btn-danger):hover { color: var(--blue); background: var(--soft); }
.fav-item.is-editing { display: block; padding: 1.4rem; margin: .6rem 0; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--soft); }
.fav-edit { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 0 1.2rem; }
.fav-edit .field { margin-bottom: 1rem; }
.fav-edit .field-error, .fav-edit .btn-row { grid-column: 1 / -1; } /* name | amount, then category | paid with */
.fav-edit .amount-wrap b { left: 1.1rem; font-size: 1.5rem; }
.fav-edit .amount-wrap input { padding-left: 2.8rem; }
.fav-edit .field-error { margin: 0 0 1rem; }

/* ---- Appearance switch ----------------------------------------------------- */

.segmented.theme-switch { grid-template-columns: repeat(3, 1fr); margin-bottom: 0; }
.theme-switch span { display: flex; align-items: center; justify-content: center; gap: .6rem; padding: .7rem .4rem; font-size: 1.35rem; }
.theme-switch .icon { width: 1.6rem; height: 1.6rem; }
.theme-switch input:checked + span { color: var(--blue); }
.pop-theme { margin-top: 1.6rem; }
.pop-theme-label { display: block; margin-bottom: .6rem; font-size: 1.2rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---- Login / registration ---------------------------------------------- */

.auth {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: calc(2.4rem + env(safe-area-inset-top)) 1.6rem calc(2.4rem + env(safe-area-inset-bottom));
    background: var(--page-bg);
}

.auth-card {
    width: min(42rem, 100%);
    padding: 3.2rem 2.8rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.auth-logo { width: 4.4rem; height: auto; margin: 0 auto 2rem; }
.auth-card h1 { font-size: 2.6rem; color: var(--blue); margin-bottom: .6rem; }
.auth-card h1, .auth-card h1 + p { text-align: center; } /* heading + intro line on every auth screen */
.auth-card > p { font-size: 1.4rem; margin-bottom: 2.2rem; }
.auth-card .auth-note { padding: 1rem 1.2rem; border-radius: var(--radius-sm); background: var(--soft); color: var(--dark-blue); font-size: 1.3rem; }
.auth-fine { margin: 2rem 0 0 !important; font-size: 1.25rem !important; color: var(--muted); }
.auth-credit { margin: 2.4rem 0 0 !important; font-size: 1.2rem !important; color: var(--muted); text-align: center; }
.auth-credit a, .app-credit a { color: var(--blue); }
.app-credit { margin-top: 1.6rem; padding-top: 1.4rem; border-top: 1px solid var(--line); font-size: 1.3rem; color: var(--muted); line-height: 1.7; }
.report-credit { margin-top: 2.4rem; padding-top: 1rem; border-top: 1px solid var(--line); font-size: 1.15rem; color: var(--muted); text-align: center; }
.auth-forgot { display: block; margin: 1.8rem auto 0; font-size: 1.3rem; } /* centred under the Unlock buttons */
.btn-block { width: 100%; padding-block: 1.2rem; margin-top: .4rem; }

.pw-wrap { position: relative; display: block; }
.field .pw-wrap input { padding-right: 7rem; }

.pw-toggle {
    position: absolute;
    right: .6rem;
    top: 50%;
    transform: translateY(-50%);
    padding: .5rem .9rem;
    border: 0;
    border-radius: .6rem;
    background: none;
    color: var(--blue);
    font-size: 1.3rem;
    font-weight: 600;
}

.pw-toggle:hover { background: var(--soft); }

/* Security panel */
.pw-change { margin-bottom: 1.6rem; }
.pw-change summary { cursor: pointer; width: max-content; font-size: 1.4rem; font-weight: 600; color: var(--blue); padding: .4rem 0; }
.pw-change form { margin-top: 1.4rem; padding: 1.6rem; border-radius: var(--radius-sm); background: var(--soft); }

/* Profile popup actions */
.pop-actions { display: flex; align-items: center; gap: 1.6rem; margin-left: auto; }
.pop-actions .pop-link { margin-left: 0; }
.pop-lock { display: inline-flex; align-items: center; gap: .4rem; text-decoration: none; font-weight: 600; }
.pop-lock .icon { width: 1.5rem; height: 1.5rem; }
.pop-lock:hover { text-decoration: underline; }

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

@media (max-width: 1100px) {
    .settings { grid-template-columns: minmax(0, 1fr); }
    .pane { padding: 2rem 2.4rem 3rem; }
    .grid-2 { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    body { background: var(--surface); }
    :root[data-theme="dark"] body { background: var(--page-bg); }

    .app {
        display: block;
        width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        background: none;
    }

    /* Sidebar becomes a bottom navigation bar */
    .sidebar {
        position: fixed;
        z-index: 20;
        inset: auto 0 0 0;
        height: auto;
        overflow: visible;
        border-right: 0;
        padding: 0 .4rem env(safe-area-inset-bottom);
        border-radius: 0;
        border-top: 1px solid var(--line);
        background: var(--nav-glass);
        backdrop-filter: blur(10px);
    }

    .sidebar .brand { display: none; }
    .nav { display: flex; height: var(--nav-h); }
    .nav li { flex: 1; border: 0; }
    .nav a { height: 100%; justify-content: center; gap: .3rem; padding: 0; font-size: 1.05rem; }
    .nav a .icon { width: 2.2rem; height: 2.2rem; }
    .nav a[aria-current="page"] { color: var(--blue); }

    .pane {
        min-height: 100vh;
        border-radius: 0;
        box-shadow: none;
        padding: calc(1.2rem + env(safe-area-inset-top)) 1.6rem calc(var(--nav-h) + 2.4rem + env(safe-area-inset-bottom));
    }

    .topbar { margin-bottom: 1.6rem; padding-bottom: 1.2rem; gap: 1rem; }
    .topbar h1 { font-size: 2rem; }
    .topbar p { font-size: 1.3rem; }
    /* Card titles: a step above the body text, not a shout */
    .section-head h2 { font-size: 1.6rem; }
    .panel h2 { font-size: 1.6rem; }
    .sheet-body h2 { font-size: 1.9rem; }
    .topbar-actions { gap: 1rem; }

    .summary .icon-btn-solid { display: none; } /* the header already has Add */
    .toolbar { grid-template-columns: 1fr 1fr; }
    .toolbar .search, .toolbar > label:first-child { grid-column: 1 / -1; }
    .amount-block { padding: 1.2rem; gap: .6rem; }
    .amount-block strong { font-size: 1.45rem; }
    .trend-cards { gap: 1rem; }
    .trend-card { padding: 1.2rem; }
    .trend-card strong { font-size: 1.5rem; }
    .stat-row { gap: .8rem; }
    .stat { padding: 1.2rem; }
    .stat strong { font-size: 1.5rem; }
    .year-chart { height: 16rem; gap: .2rem; }
    .yc-col small { font-size: .95rem; }
    .panel { padding: 1.8rem; }
    .data-table { font-size: 1.3rem; }
    .data-table th, .data-table td { padding: .8rem; }
    .report-head h2 { font-size: 1.8rem; }

    .toast { bottom: calc(var(--nav-h) + 1.2rem + env(safe-area-inset-bottom)); }

    /* Dialogs slide up from the bottom like a native sheet */
    dialog.sheet, dialog.sheet-sm {
        width: 100%;
        max-width: 100%;
        margin: auto 0 0;
        border-radius: var(--radius) var(--radius) 0 0;
        max-height: 92dvh;
    }

    dialog.sheet[open] { animation: slide-up .22s ease-out; }
    .sheet-actions .btn { flex: 1; padding-block: 1.2rem; }
    .sheet-body { padding: 2rem 2rem calc(2rem + env(safe-area-inset-bottom)); }
}

@keyframes slide-up {
    from { transform: translateY(100%); }
}

@media (max-width: 380px) {
    .amount-block { grid-template-columns: 1fr; }
    .trend-cards { grid-template-columns: minmax(0, 1fr); }
    /* icon-only on tiny screens, but the label stays for screen readers */
    .topbar .btn-primary { padding: .9rem 1.2rem; }
    .topbar .btn-primary span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- Print (Report page) -------------------------------------------- */

@media print {
    @page { margin: 14mm; }
    body { background: #fff; font-size: 11pt; }
    .sidebar, .topbar, .no-print, .toast, dialog { display: none !important; }
    .app, .pane { display: block; width: auto; max-width: none; margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none; background: none; min-height: 0; }
    .stat { background: none; border: 1px solid #ccc; }
    .data-table tr { break-inside: avoid; }
    .data-table tbody tr:hover { background: none; }
    .report h3 { break-after: avoid; }
    .income, .expense { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
