/* Financial Copilot — styles translated from the "AI Financial Copilot" design. */

:root {
    --bg: #F6F7F9;
    --surface: #FFFFFF;
    --surface-sunken: #FAFBFC;
    --border: #E4E7EC;
    --border-soft: #EEF0F3;
    --input-border: #D0D5DD;
    --text: #101828;
    --text-2: #344054;
    --muted: #5D6675;
    --chip: #F2F4F7;
    --track: #EEF0F3;
    --bar-muted: #A9B4C2;

    --brand: #1A6B57;
    --brand-dark: #0F4D3E;
    --brand-tint: #E8F2EE;
    --brand-border: #B7D6CB;
    --brand-ring: #D3E8E0;

    --warn: #B54708;
    --warn-bg: #FEF3E8;
    --warn-border: #F5C9A0;
    --danger: #B42318;
    --danger-bg: #FEF3F2;
    --danger-border: #FDA29B;

    --radius: 12px;
    --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
}

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

h1, h2, h3, p { margin: 0; }

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

/* ---------- Shell ---------- */

.shell { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    overflow: hidden;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
    width: 44px; height: 32px; border-radius: 8px;
    object-fit: contain; background: var(--surface);
    display: flex; align-items: center; justify-content: center;
}
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    min-height: 44px; padding: 0 12px; border-radius: var(--radius-sm);
    color: var(--text-2); font-weight: 500; font-size: 14px; text-decoration: none;
}
.nav-link:hover { background: var(--chip); color: var(--text-2); }
.nav-link.active { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
.nav-link.disabled { color: #98A2B3; cursor: not-allowed; }
.nav-link.disabled:hover { background: transparent; color: #98A2B3; }
.nav-soon {
    margin-left: auto; font-size: 11px; font-weight: 600; padding: 2px 8px;
    border-radius: 999px; background: var(--chip); color: var(--muted);
}

.user-chip {
    margin-top: auto; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto;
    align-items: center; gap: 10px; min-width: 0;
    padding: 16px 8px 4px; border-top: 1px solid var(--border);
}
.avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--brand-tint);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700; color: var(--brand);
}
.user-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.user-name { overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.user-sub { font-size: 12px; color: var(--muted); }
.user-signout {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 32px; padding: 0 8px; border-radius: 6px;
    color: var(--muted); font-size: 12px; text-decoration: none; white-space: nowrap;
}
.user-signout:hover { background: var(--chip); color: var(--brand-dark); }
.currency-picker {
    display: flex; flex-direction: column; gap: 4px; padding: 10px 8px 0;
    border-top: 1px solid var(--border); color: var(--muted); font-size: 11px;
    font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.currency-picker select {
    width: 100%; min-height: 32px; border: 1px solid var(--input-border);
    border-radius: 6px; background: var(--surface); color: var(--text-2);
    font: inherit; font-size: 12px; text-transform: none; letter-spacing: normal;
}

.auth-required {
    min-height: 60vh; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 12px; text-align: center;
}
.auth-required h1 { font-size: 28px; }
.auth-required p { color: var(--muted); }

/* Login background: poster shows at once, animated WebP fades in once loaded. */
.login-shell { min-height: 100vh; position: relative; isolation: isolate; overflow: hidden; background: var(--brand-dark); }
.login-bg { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; background: var(--brand-dark); }
.login-bg::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(180deg, rgba(6, 24, 20, .55) 0%, rgba(6, 24, 20, .35) 50%, rgba(6, 24, 20, .65) 100%);
}
.login-bg img, .login-bg picture { position: absolute; inset: 0; width: 100%; height: 100%; }
.login-bg img { object-fit: cover; user-select: none; }
.login-bg-anim { opacity: 0; transition: opacity .8s ease; }
.login-bg-anim.is-loaded { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .login-bg-anim { transition: none; } }

.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    gap: clamp(32px, 6vw, 96px); padding: 32px; max-width: 1200px; margin: 0 auto;
}
.login-hero { flex: 1 1 0; min-width: 0; max-width: 520px; color: #fff; display: flex; flex-direction: column; gap: 24px; }
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-mark { width: 56px; height: 56px; border-radius: 14px; flex: none; }
.login-brand-name { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.login-tagline { font-size: clamp(28px, 3.4vw, 42px); line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; text-shadow: 0 2px 16px rgba(0, 0, 0, .45); }
.login-features { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 14px; }
.login-features li { position: relative; padding-left: 28px; font-size: 15px; line-height: 1.5; color: #E6F1ED; text-shadow: 0 1px 8px rgba(0, 0, 0, .5); }
.login-features li::before { content: ""; position: absolute; left: 0; top: .45em; width: 12px; height: 12px; border-radius: 50%; background: #5FD3B0; box-shadow: 0 0 0 4px rgba(95, 211, 176, .25); }
.login-features strong { display: block; color: #fff; font-weight: 600; }
.login-card {
    flex: 0 0 auto; width: min(100%, 400px); padding: 36px; display: flex; flex-direction: column;
    align-items: stretch; gap: 16px; text-align: left; background: rgba(255, 255, 255, .95);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, .5); border-radius: 16px; box-shadow: 0 16px 48px rgba(0, 0, 0, .35);
}
.login-card h1 { font-size: 28px; letter-spacing: -0.02em; }
.login-card h1:focus { outline: none; }
.login-card > p { color: var(--muted); }
.login-card .notice { text-align: left; }
.google-signin {
    width: 100%; min-height: 48px; display: inline-flex; align-items: center;
    justify-content: center; gap: 10px; padding: 0 16px; border: 1px solid var(--input-border);
    border-radius: var(--radius-sm); background: var(--surface); color: var(--text-2);
    font-weight: 600; text-decoration: none;
}
.google-signin:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.google-signin:hover { background: var(--surface-sunken); color: var(--text); }
.google-signin svg { width: 20px; height: 20px; }
.login-note { font-size: 12px; }
@media (max-width: 820px) {
    .login-page { flex-direction: column; justify-content: center; gap: 24px; padding: 24px 16px; }
    .login-hero { flex: none; max-width: 400px; width: 100%; gap: 12px; }
    .login-mark { width: 44px; height: 44px; }
    .login-tagline { font-size: 24px; }
    .login-features { display: none; }
    .login-card { padding: 28px 20px; }
}

.main {
    min-height: 100vh;
    min-width: 0;
    margin-left: 240px;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: calc(100% - 240px);
}

.page-header {
    display: flex; flex-wrap: wrap; align-items: center;
    justify-content: space-between; gap: 16px;
}
.page-title { display: flex; flex-direction: column; gap: 4px; }
.page-title h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.page-title h1:focus { outline: none; }
.page-title p { font-size: 14px; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------- Buttons & inputs ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px; padding: 0 16px;
    border: 1px solid var(--input-border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-2);
    font: inherit; font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-sunken); color: var(--text-2); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; padding: 0 18px; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }

.btn-dark { background: var(--text); border-color: var(--text); color: #fff; font-weight: 600; }
.btn-dark:hover { background: #1D2939; border-color: #1D2939; color: #fff; }

.btn-tint { background: var(--surface); border-color: var(--brand-border); color: var(--brand); font-weight: 600; }
.btn-tint:hover { background: var(--brand-tint); color: var(--brand); }

.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover { color: var(--danger); background: var(--danger-bg); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.92); }
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }
.danger-card { border-color: var(--danger-border); }
.danger-card h2 { color: var(--danger); }
.danger-form { display: grid; gap: 10px; max-width: 420px; margin-top: 12px; }
.danger-form input { padding: 8px 10px; border: 1px solid var(--danger-border); border-radius: 8px; font: inherit; }

select.btn {
    appearance: none;
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23344054' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.input, .select {
    min-height: 44px; width: 100%;
    border: 1px solid var(--input-border); border-radius: var(--radius-sm);
    padding: 0 10px; background: var(--surface); color: var(--text);
    font: inherit; font-size: 14px;
}
.select {
    appearance: none; padding-right: 30px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235D6675' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}
.input:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.input-strong { font-weight: 600; }
.input.invalid, .select.invalid { border-color: var(--danger); }
.field-error { font-size: 12px; color: var(--danger); font-weight: 500; }

/* ---------- Cards ---------- */

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 24px; display: flex; flex-direction: column; gap: 18px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.card h2, .section-title { font-size: 16px; font-weight: 600; }
.card-link { font-size: 13px; font-weight: 500; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; display: flex; flex-direction: column; gap: 8px;
}
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stat-value.income { color: var(--brand); }
.stat-note { font-size: 13px; color: var(--muted); }
.stat-note.warn { color: var(--warn); font-weight: 500; }
.stat-note.good { color: var(--brand); font-weight: 500; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }

/* ---------- Quick entry & insight ---------- */

.quick {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 12px 12px 16px;
}
.quick:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.quick input {
    flex: 1 1 320px; min-width: 0; min-height: 44px; border: none; outline: none;
    font: inherit; font-size: 15px; color: var(--text); background: transparent;
}

.insight {
    display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
    background: var(--brand-tint); border-radius: var(--radius); padding: 20px 24px;
}
.insight-body { display: flex; flex-direction: column; gap: 6px; flex: 1 1 420px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); }
.insight p { font-size: 16px; line-height: 1.5; }
.insight-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Bars & charts ---------- */

.cat-row { display: flex; flex-direction: column; gap: 6px; }
.cat-line { display: flex; justify-content: space-between; font-size: 14px; gap: 12px; }
.cat-name { font-weight: 500; }
.cat-share { color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > span { display: block; height: 8px; border-radius: 4px; background: var(--brand); }

.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.income { background: var(--brand); }
.swatch.expense { background: var(--bar-muted); }
.swatch.forecast { background: var(--brand-border); }

.flow { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; height: 200px; border-bottom: 1px solid var(--border); padding: 0 4px; }
.flow-col { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: 100%; }
.flow-bar { width: 14px; border-radius: 3px 3px 0 0; min-height: 2px; }
.flow-bar.income { background: var(--brand); }
.flow-bar.expense { background: var(--bar-muted); }
.flow-labels { display: flex; justify-content: space-between; gap: 12px; padding: 0 4px; font-size: 12px; color: var(--muted); }
.flow-labels span { flex: 1; text-align: center; }

.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 14px; }
table.data.wide { min-width: 720px; }
table.data th {
    text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase;
    letter-spacing: .05em; padding: 10px 8px; font-weight: 600;
}
table.data td { padding: 12px 8px; border-top: 1px solid var(--border-soft); }
table.data.roomy td { padding: 13px 8px; }
table.data .num { text-align: right; }
table.data td.muted { color: var(--muted); }
table.data td.desc { font-weight: 500; }
table.data td.amount { text-align: right; font-weight: 600; white-space: nowrap; }
table.data td.amount.income { color: var(--brand); }
table.data td.actions { text-align: right; white-space: nowrap; width: 1%; }

.chip {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    background: var(--chip); font-size: 12px; font-weight: 500; color: var(--text-2);
}
.chip.good { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
.chip.warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.chip.neutral { background: var(--chip); color: var(--text-2); font-weight: 600; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill {
    min-height: 40px; padding: 0 14px; border-radius: 999px; font: inherit; font-size: 13px; font-weight: 500;
    border: 1px solid var(--input-border); background: var(--surface); color: var(--text-2); cursor: pointer;
}
.pill[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #fff; }
.search { min-height: 40px; width: 220px; padding: 0 12px; border: 1px solid var(--input-border); border-radius: var(--radius-sm); font: inherit; font-size: 14px; }
.search:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }

.list-foot {
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px;
    padding-top: 12px; border-top: 1px solid var(--border); font-size: 14px; color: var(--muted);
}
.list-foot strong.income { color: var(--brand); }
.list-foot strong.expense { color: var(--text); }

.month-nav { display: flex; align-items: center; gap: 8px; }
.icon-btn {
    width: 36px; height: 36px; border: 1px solid var(--input-border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-2); font: inherit; font-size: 16px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-sunken); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Copilot entry ---------- */

.nl-row { display: flex; flex-wrap: wrap; gap: 12px; }
.nl-input {
    flex: 1 1 320px; min-width: 0; min-height: 48px; padding: 0 16px;
    border: 1px solid var(--input-border); border-radius: var(--radius-sm);
    font: inherit; font-size: 15px; color: var(--text);
}
.nl-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.nl-row .btn { min-height: 48px; padding: 0 20px; }

.draft {
    border: 1px solid var(--border); border-radius: 10px; background: var(--surface-sunken);
    padding: 20px; display: flex; flex-direction: column; gap: 16px;
}
.draft-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; }
.draft-title { font-size: 13px; font-weight: 600; color: var(--text-2); }
.draft-hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.draft-foot { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.draft-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.warnings { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--warn); font-weight: 500; }
.parsed-by { font-size: 12px; color: var(--muted); }

.notice {
    border-radius: var(--radius-sm); padding: 12px 16px; font-size: 14px; font-weight: 500;
    display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px;
}
.notice.success { background: var(--brand-tint); color: var(--brand-dark); }
.notice.error { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger); }
.notice.warn { background: var(--warn-bg, #fff7e0); border: 1px solid var(--warn-border, #f0d48a); color: var(--warn, #7a5a00); }
.notice .btn { min-height: 36px; }

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

.total-budget { gap: 16px; }
.total-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; align-items: flex-end; }
.total-label { font-size: 14px; font-weight: 500; color: var(--muted); }
.total-value { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.total-value small { font-size: 18px; font-weight: 500; color: var(--muted); }
.mini-stats { display: flex; gap: 24px; flex-wrap: wrap; font-size: 13px; }
.mini-stat { display: flex; flex-direction: column; gap: 2px; }
.mini-stat span { color: var(--muted); }
.mini-stat strong { font-size: 16px; }
.mini-stat strong.good { color: var(--brand); }

.meter { position: relative; height: 12px; border-radius: 6px; background: var(--track); overflow: hidden; }
.meter .spent { position: absolute; left: 0; top: 0; height: 12px; border-radius: 6px; background: var(--brand); }
.meter .forecast {
    position: absolute; top: 0; height: 12px;
    background: repeating-linear-gradient(135deg, var(--brand-border) 0 4px, var(--track) 4px 8px);
}

.budget-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.budget-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; display: flex; flex-direction: column; gap: 12px;
}
.budget-card.warn { border-color: var(--warn-border); }
.budget-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.budget-name { font-size: 15px; font-weight: 600; }
.budget-amount { font-size: 14px; }
.budget-amount strong { font-size: 18px; }
.budget-amount span { color: var(--muted); }
.gauge { position: relative; height: 8px; border-radius: 4px; background: var(--track); }
.gauge .fill { position: absolute; left: 0; top: 0; height: 8px; border-radius: 4px; background: var(--brand); }
.budget-card.warn .gauge .fill { background: var(--warn); }
.gauge .tick { position: absolute; top: -4px; width: 2px; height: 16px; background: var(--text); }
.budget-note { font-size: 13px; color: var(--muted); }
.budget-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.inline-edit { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-edit .input { width: 140px; min-height: 36px; }
.small-note { font-size: 12px; color: var(--muted); }

/* ---------- Misc ---------- */

.loading { color: var(--muted); padding: 24px 0; }

#blazor-error-ui {
    color-scheme: light only;
    background: #FEF3C7;
    color: #101828;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* Breakpoints: 1100 px stacks the receipt review, 820 px is the phone layout (sidebar becomes a top bar and bottom tabs;
   the "compact" query (pointer: coarse) or 820 px also drives the touch upload controls), and everything else flows. */
@media (max-width: 820px) {
    .page-title h1 { font-size: 24px; }
    .form-grid .span-2 { grid-column: auto; }
}

@media (prefers-reduced-motion: no-preference) {
    .btn, .pill, .nav-link, .icon-btn { transition: background-color .12s, border-color .12s; }
}

/* ---------- Copilot chat ---------- */

.copilot-grid { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.convo { flex: 999 1 480px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }

.welcome { gap: 8px; }
.welcome p { color: var(--muted); font-size: 15px; line-height: 1.5; }

.messages { display: flex; flex-direction: column; gap: 20px; }

.bubble-user {
    align-self: flex-end; max-width: 80%;
    background: var(--text); color: #fff; border-radius: 16px 16px 4px 16px;
    padding: 14px 18px; font-size: 15px; line-height: 1.5; overflow-wrap: anywhere;
}
.bubble-bot {
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px 16px 16px 4px;
    padding: 22px; display: flex; flex-direction: column; gap: 16px; max-width: 92%;
}
.bubble-bot.thinking { flex-direction: row; align-items: center; gap: 12px; color: var(--muted); padding: 16px 22px; align-self: flex-start; }
.bubble-foot { padding-top: 4px; border-top: 1px solid var(--border-soft); }
.bubble-foot .small-note { display: block; padding-top: 10px; }
.bubble-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.bubble-actions .btn { min-height: 40px; font-size: 13px; }
.bubble-actions .btn[aria-pressed="true"] { background: var(--chip); }

.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); opacity: .35; }
@media (prefers-reduced-motion: no-preference) {
    .dots i { animation: pulse 1.2s infinite ease-in-out; }
    .dots i:nth-child(2) { animation-delay: .15s; }
    .dots i:nth-child(3) { animation-delay: .3s; }
    @keyframes pulse { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
}

/* Model output, rendered from markdown */
.markdown { font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; overflow-x: auto; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 12px; }
.markdown ul, .markdown ol { margin: 0 0 12px; padding-left: 22px; }
.markdown li { margin: 2px 0; }
.markdown strong { font-weight: 600; }
.markdown code { font-family: ui-monospace, "JetBrains Mono", monospace; font-size: 13px; background: var(--chip); padding: 1px 5px; border-radius: 4px; }
.markdown table { width: 100%; min-width: 360px; border-collapse: collapse; font-size: 14px; margin: 0 0 12px; }
.markdown th {
    text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase;
    letter-spacing: .05em; padding: 8px; font-weight: 600; white-space: nowrap; text-align: left;
}
.markdown td { padding: 10px 8px; border-top: 1px solid var(--border-soft); }

.composer { position: sticky; bottom: 0; display: flex; flex-direction: column; gap: 12px; padding: 12px 0 16px; background: linear-gradient(to bottom, rgba(246, 247, 249, 0), var(--bg) 14px); }
.suggestions .pill { font-weight: 400; }
.ask {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
    background: var(--surface); border: 1px solid var(--input-border); border-radius: var(--radius);
    padding: 10px 10px 10px 16px;
}
.ask:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.ask input { flex: 1 1 280px; min-width: 0; min-height: 44px; border: none; outline: none; font: inherit; font-size: 15px; background: transparent; color: var(--text); }
.ask .icon-btn { width: 44px; height: 44px; }

/* Trace panel */
.trace { flex: 1 1 300px; min-width: 0; padding: 20px; gap: 16px; position: sticky; top: 24px; }
.trace-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.trace-head h2 { font-size: 15px; }
.trace-head .btn { white-space: nowrap; flex-shrink: 0; }
.agent-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg); border-radius: var(--radius-sm); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.agent-name { font-size: 13px; font-weight: 600; }
.agent-meta { font-size: 12px; color: var(--muted); margin-left: auto; }
.steps { display: flex; flex-direction: column; gap: 10px; padding-left: 14px; border-left: 2px solid var(--border); margin-left: 4px; }
.step { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); }
.step.failed { border-color: var(--danger-border); background: var(--danger-bg); }
.step-top { display: flex; justify-content: space-between; gap: 8px; }
.step-agent { font-size: 13px; font-weight: 600; }
.step-ms { font-size: 12px; color: var(--muted); }
.step code { font-family: ui-monospace, "JetBrains Mono", monospace; font-size: 12px; color: var(--brand); background: #F2F7F5; padding: 4px 6px; border-radius: 4px; overflow-wrap: anywhere; }
.step-result { font-size: 12px; color: var(--muted); line-height: 1.45; }
.sources { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.eyebrow-muted { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.source-line { font-size: 13px; color: var(--text-2); }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.metrics div { display: flex; flex-direction: column; gap: 2px; }
.metrics span { font-size: 11px; color: var(--muted); }
.metrics strong { font-size: 14px; font-weight: 600; }

@media (max-width: 820px) {
    .trace { position: static; }
    .bubble-bot { max-width: 100%; }
}

/* ---------- Trace: hand-offs ---------- */

.handoffs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.handoffs li {
    display: flex; justify-content: space-between; gap: 8px; align-items: center;
    padding: 8px 12px; border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500;
}
.handoffs li.failed { border-color: var(--danger-border); background: var(--danger-bg); }

/* ---------- Goals ---------- */

.goals { display: flex; flex-direction: column; gap: 16px; }
.goal-form { gap: 16px; }
.goals-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.goal-list { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.goal-card { gap: 16px; }
.goal-name { font-size: 16px; font-weight: 600; }
.goal-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.goal-value small { font-size: 16px; font-weight: 500; color: var(--muted); }
.goal-bar { height: 10px; border-radius: 5px; background: var(--track); }
.goal-bar span { display: block; height: 10px; border-radius: 5px; background: var(--brand); }
.goal-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; font-size: 13px; }
.goal-stats div { display: flex; flex-direction: column; gap: 2px; }
.goal-stats span { color: var(--muted); }
.goal-stats strong { font-size: 16px; }
.goal-stats strong.late { color: var(--warn); }
.goal-stats strong.good { color: var(--brand); }

.advisor { background: var(--brand-tint); border: none; gap: 14px; }
.advisor .markdown { font-size: 15px; }
.advisor .markdown ol, .advisor .markdown ul { margin-bottom: 0; }
.advisor-hint { font-size: 15px; line-height: 1.5; margin: 0; }
.thinking-row { display: flex; align-items: center; gap: 12px; color: var(--muted); }

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

/* ---------- Receipts ---------- */

.chip.danger { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); }
.self-start { align-self: flex-start; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.back-link { font-size: 13px; font-weight: 500; text-decoration: none; align-self: flex-start; }

.dropzone {
    position: relative; display: flex; align-items: center; justify-content: center; gap: 14px;
    min-height: 120px; padding: 20px; text-align: left;
    border: 2px dashed var(--brand-border); border-radius: var(--radius); background: var(--brand-tint); color: var(--brand-dark);
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--brand); background: var(--brand-ring); }
.dropzone.busy { opacity: .6; }
.dropzone-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 0; }
.dropzone:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
.dropzone-text { display: flex; flex-direction: column; gap: 2px; }
.dropzone-text span { font-size: 12px; color: var(--muted); }
.camera-row { display: none; align-items: center; gap: 12px; }
.camera-btn { cursor: pointer; }
@media (pointer: coarse), (max-width: 820px) { .camera-row { display: flex; } }
.camera-row:focus-within .camera-btn { outline: 2px solid var(--brand); outline-offset: 2px; }

.small-note { font-size: 12px; color: var(--muted); }

.receipt-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.receipt-row {
    display: grid; grid-template-columns: minmax(0, 1fr) auto 90px auto; align-items: center; gap: 12px;
    padding: 12px 0; border-top: 1px solid var(--border-soft);
}
.receipt-row:first-child { border-top: none; }
.receipt-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.receipt-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.receipt-total { text-align: right; font-weight: 600; }
.receipt-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }

/* Verification view */
.review-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.review-viewer { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; padding: 12px; }
.review-form { min-width: 0; }
.reading { align-items: flex-start; }
.spinner {
    width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--brand-ring); border-top-color: var(--brand);
}
@media (prefers-reduced-motion: no-preference) { .spinner { animation: rv-spin .9s linear infinite; } }
@keyframes rv-spin { to { transform: rotate(360deg); } }

.viewer { display: flex; flex-direction: column; gap: 10px; }
.viewer-frame { position: relative; display: block; width: 100%; line-height: 0; }
.viewer-img { display: block; width: 100%; height: auto; border-radius: var(--radius-sm); }
.viewer-overlay { position: absolute; inset: 0; pointer-events: none; }
.ocr-box {
    position: absolute; pointer-events: auto; cursor: pointer; border-radius: 3px;
    border: 1px solid rgba(26, 107, 87, .35); background: rgba(26, 107, 87, .06);
}
.ocr-box:hover { background: rgba(26, 107, 87, .18); }
.ocr-box.hl-warning { border: 2px solid var(--warn); background: rgba(181, 71, 8, .18); }
.ocr-box.hl-info { border: 2px dashed #7A8699; background: rgba(93, 102, 117, .14); }
.ocr-box.hl-focus { border: 2px solid var(--brand); background: rgba(26, 107, 87, .28); box-shadow: 0 0 0 3px var(--brand-ring); }
.viewer-pdf { width: 100%; height: 70vh; min-height: 360px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-sunken); }
.viewer-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.viewer-lines li { padding: 4px 8px; border-radius: 6px; border-left: 3px solid transparent; }
.viewer-lines li.hl-warning { background: var(--warn-bg); border-left-color: var(--warn); }
.viewer-lines li.hl-info { background: var(--chip); border-left-color: #7A8699; }
.viewer-lines li.hl-focus { background: var(--brand-tint); border-left-color: var(--brand); }

.rv-warnings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rv-warning { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.rv-warning.sev-warning { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn); font-weight: 500; }
.rv-warning.sev-info { background: var(--surface-sunken); border: 1px solid var(--border-soft); color: var(--muted); }
.rv-warning-icon {
    flex: none; width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; background: currentColor;
}
.rv-warning-icon { color: inherit; position: relative; }
.rv-warning.sev-warning .rv-warning-icon { background: var(--warn); color: #fff; }
.rv-warning.sev-info .rv-warning-icon { background: #98A2B3; color: #fff; }

.refs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.ref { display: flex; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--chip); font-size: 13px; }
.ref dt { color: var(--muted); }
.ref dd { margin: 0; font-weight: 600; }

.items-section { display: flex; flex-direction: column; gap: 12px; }
.item-row {
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; align-items: end;
    padding: 12px; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: var(--surface-sunken);
}
.item-name { grid-column: span 3; }
.item-num { grid-column: span 2; }
.item-cat { grid-column: span 4; }
.item-remove { grid-column: span 2; }
.item-row .input { min-height: 40px; }

.totals-check { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13px; }
.totals-check.ok { background: var(--brand-tint); color: var(--brand-dark); }
.totals-check.off { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn); }
.totals-check.idle { background: var(--chip); color: var(--text-2); }
.totals-icon { font-weight: 700; width: 18px; text-align: center; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }
.read-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.read-items li { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--border-soft); padding-top: 6px; }

.rv-warning:focus-visible, .ref:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

@media (max-width: 1100px) {
    .review-grid { grid-template-columns: minmax(0, 1fr); }
    .review-viewer { position: static; max-height: none; }
}
@media (max-width: 820px) {
    .receipt-row { grid-template-columns: minmax(0, 1fr) auto; }
    .receipt-total { text-align: left; grid-column: 1; }
    .receipt-actions { grid-column: 1 / -1; justify-content: flex-start; }
    .item-name, .item-cat { grid-column: span 6; }
    .item-num { grid-column: span 2; }
    .item-remove { grid-column: span 6; }
    .card { padding: 16px; }
}

.date-order-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.date-order-select {
    min-height: 36px; padding: 0 8px; border: 1px solid var(--input-border);
    border-radius: 6px; background: var(--surface); color: var(--text-2); font: inherit;
}

/* ---------- Receipt storage (Settings, receipts page) ---------- */

.usage { display: flex; flex-direction: column; gap: 10px; }
.usage-bar { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
.usage-fill { height: 100%; background: var(--brand); border-radius: 999px; }
@media (prefers-reduced-motion: no-preference) { .usage-fill { transition: width 0.3s ease; } }
.usage-bar.warn .usage-fill { background: var(--warn, #b7791f); }
.usage-text { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; }
.retention { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.retention legend { font-size: 14px; font-weight: 600; padding: 0; margin-bottom: 8px; }
.retention-option {
    display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; cursor: pointer; font-size: 14px;
}
.retention-option:has(input:checked) { border-color: var(--brand); background: var(--brand-tint); }
.retention-option input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
.retention-option > span { display: flex; flex-direction: column; gap: 2px; }
.storage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.notice a { color: inherit; text-decoration: underline; font-weight: 600; }
.viewer-deleted {
    display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
    padding: 28px 16px; border: 1px dashed var(--border); border-radius: 8px; color: var(--muted);
}

/* Sortable table headings (admin report) */
.link-button {
    background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer;
    text-transform: inherit; letter-spacing: inherit; font-weight: inherit; white-space: nowrap;
}
.link-button:hover { color: var(--text); }
.link-button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Standalone WASM shell. */
.boot { color: var(--muted); padding: 48px 24px; text-align: center; font-family: Inter, system-ui, sans-serif; }
.google-signin-host { display: flex; justify-content: center; min-height: 44px; }
.google-signin-host:empty::before { content: "Loading Google sign-in…"; color: var(--muted); font-size: 0.9rem; align-self: center; }
button.user-signout { border: 0; background: transparent; font: inherit; cursor: pointer; }


/* =====================================================================================================================
   Phone layout (Phase 4). Desktop is untouched: everything phone-only is hidden by default and switched on below.
   ===================================================================================================================== */

:root {
    --appbar-h: 52px;
    --tabbar-h: 60px;
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
}

.appbar, .tabbar, .sheet, .sheet-scrim, .sheet-grab, .tx-cards, .show-mobile, .show-compact, .scroll-hint, .tx-hint { display: none; }
.chip-scroll { display: contents; }
.manual-card, #manual-card { scroll-margin-top: calc(var(--appbar-h) + 12px); }

/* Touch sizing: any touch screen, or any narrow window. Targets are at least 44 px and inputs 16 px (no iOS zoom on focus). */
@media (max-width: 820px), (pointer: coarse) {
    .btn-sm, .notice .btn, .pill, .search, .date-order-select, .inline-edit .input, .item-row .input,
    .currency-picker select, .retention-option { min-height: 44px; }
    .icon-btn { width: 44px; height: 44px; }
    .link-button, .card-link, .back-link { display: inline-flex; align-items: center; min-height: 44px; }
    .card-link { min-width: 44px; justify-content: center; }
    .rv-warning, .ref { min-height: 44px; align-items: center; }
    .bubble-actions .btn { min-height: 44px; }
    .input, .select, .search, .nl-input, .quick input, .ask input, .date-order-select, .danger-form input,
    select.btn, .currency-picker select, .inline-edit .input, .item-row .input { font-size: 16px; }
    .danger-form input { min-height: 44px; }
    ::placeholder { color: #667085; opacity: 1; }

    /* Receipts: photo first, files second, and no drag-and-drop wording. */
    .show-compact { display: initial; }
    p.show-compact { display: block; }
    .hide-compact { display: none; }
    .upload-card > .camera-row { order: 1; flex-direction: column; align-items: stretch; }
    .upload-card > .dropzone { order: 2; }
    .upload-card > .notice { order: 3; }
    .compact-lead { margin-top: -8px; font-size: 15px; color: var(--text-2); }
    .camera-btn { width: 100%; min-height: 52px; font-size: 16px; white-space: nowrap; }
    .dropzone {
        flex-direction: column; gap: 4px; min-height: 48px; padding: 12px 16px; text-align: center;
        border: 1px solid var(--input-border); background: var(--surface); color: var(--text-2); border-radius: var(--radius-sm);
    }
    .dropzone:hover, .dropzone:focus-within { border-color: var(--brand); background: var(--surface-sunken); }
    .dropzone > svg { display: none; }
    .dropzone-text { align-items: center; }
    .dropzone-text strong { font-size: 15px; }
}

@media (max-width: 820px) {
    .hide-mobile { display: none !important; }
    .show-mobile { display: initial; }
    .btn.show-mobile { display: inline-flex; }
    p.show-mobile, .tx-hint { display: block; }

    /* ---- Shell: top app bar, bottom tab bar, content in between ---- */
    .sidebar { display: none; }
    .appbar {
        display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
        height: calc(var(--appbar-h) + var(--safe-t)); padding: var(--safe-t) 16px 0;
        background: var(--surface); border-bottom: 1px solid var(--border);
    }
    .appbar .brand-mark { width: 40px; height: 30px; flex: none; }
    .appbar-title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    .tabbar {
        display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; inset: auto 0 0 0; z-index: 40;
        padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--border);
    }
    .tab {
        position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        min-height: var(--tabbar-h); padding: 6px 2px; border: 0; background: none; color: var(--muted);
        font: inherit; font-size: 11px; font-weight: 500; text-decoration: none; cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .tab span { max-width: 100%; overflow: hidden; white-space: nowrap; }
    .tab:hover { color: var(--text-2); }
    .tab[aria-current] { color: var(--brand); font-weight: 600; }
    .tab[aria-current]::before {
        content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px;
        border-radius: 0 0 3px 3px; background: var(--brand);
    }
    .tab:focus-visible { outline-offset: -4px; }

    .main {
        min-height: auto; margin-left: 0; width: 100%; gap: 16px;
        padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
    }
    #blazor-error-ui { bottom: calc(var(--tabbar-h) + var(--safe-b)); }

    /* More sheet and the Copilot trace sheet */
    .sheet-scrim { display: block; position: fixed; inset: 0; z-index: 60; background: rgba(16, 24, 40, .5); }
    .sheet-grab { display: block; width: 40px; height: 4px; margin: 0 auto 4px; border-radius: 2px; background: var(--input-border); }
    .sheet, .trace.is-open {
        position: fixed; inset: auto 0 0 0; z-index: 70; max-height: 85vh; max-height: 85dvh; overflow-y: auto;
        background: var(--surface); border-radius: 16px 16px 0 0; border: 0;
        padding: 12px 16px calc(16px + var(--safe-b)); box-shadow: 0 -8px 24px rgba(16, 24, 40, .22);
    }
    .sheet { display: flex; flex-direction: column; gap: 12px; }
    .trace { display: none; }
    .trace.is-open { display: flex; top: auto; }
    .sheet h2, .trace-head h2 { font-size: 17px; }
    .sheet h2:focus, .trace-head h2:focus { outline: none; }
    .sheet-nav { display: flex; flex-direction: column; gap: 4px; }
    .sheet-link {
        display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px;
        border-radius: var(--radius-sm); color: var(--text-2); font-size: 16px; font-weight: 500; text-decoration: none;
    }
    .sheet-link:hover { background: var(--chip); color: var(--text-2); }
    .sheet-link[aria-current] { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
    .sheet-row {
        display: flex; justify-content: space-between; align-items: center; gap: 12px;
        padding: 14px 12px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 14px;
    }
    .sheet-row strong { color: var(--text); }
    .sheet-user { display: flex; align-items: center; gap: 10px; padding: 12px 0 0; border-top: 1px solid var(--border); }
    .sheet-user .user-name { flex: 1; min-width: 0; }
    .sheet-signout { flex: none; }

    /* ---- Page headers ---- */
    .page-header { gap: 12px; }
    .page-title h1:not(.keep-h1) {
        position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
    }
    .page-title h1 { font-size: 22px; }
    .page-title p { font-size: 13px; }
    .page-actions { width: 100%; gap: 8px; flex-wrap: wrap; }
    .page-actions > * { flex: 1 1 auto; }
    .page-actions > select { flex-basis: 100%; }
    .page-actions .btn-primary { padding: 0 14px; }
    .card { padding: 16px; gap: 14px; }
    .card-head { gap: 8px; }
    .draft { padding: 14px; }
    .draft-foot { flex-direction: column; align-items: stretch; }
    .draft-actions { width: 100%; }
    .draft-actions .btn { flex: 1 1 auto; }
    .storage-actions .btn { flex: 1 1 auto; }

    /* ---- Dashboard ---- */
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat { padding: 14px; gap: 6px; }
    .stat:first-child, .stat:last-child:nth-child(even) { grid-column: 1 / -1; }
    .stat-value { font-size: 22px; overflow-wrap: anywhere; }
    .stat:first-child .stat-value { font-size: 28px; }
    .stat-note { font-size: 12px; }
    .two-col, .goals-grid, .budget-grid, .form-grid { grid-template-columns: minmax(0, 1fr); }
    .quick { flex-wrap: nowrap; gap: 8px; padding: 8px 8px 8px 12px; }
    .quick input { flex: 1 1 0; }
    .insight { padding: 16px; }
    .insight-body { flex-basis: 100%; }
    .insight-actions { width: 100%; }
    .insight-actions .btn { flex: 1 1 auto; }
    .flow { gap: 6px; }

    /* ---- Transactions: cards instead of a table ---- */
    .tx-table { display: none; }
    .tx-cards { display: flex; flex-direction: column; gap: 8px; list-style: none; margin: 0; padding: 0; }
    .tx-hint { margin-top: -6px; }
    .tx-card { border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: var(--surface-sunken); overflow: hidden; }
    .tx-card.is-open { border-color: var(--brand-border); background: var(--surface); }
    .tx-card-main {
        display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "desc amount" "cat cat" "date date" "note note";
        column-gap: 12px; row-gap: 4px; align-items: start; width: 100%; min-height: 44px; padding: 12px;
        border: 0; background: none; font: inherit; color: inherit; text-align: left;
    }
    button.tx-card-main { cursor: pointer; }
    .tx-desc {
        grid-area: desc; font-weight: 600; font-size: 15px; overflow-wrap: anywhere;
        display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    }
    .tx-amount { grid-area: amount; font-weight: 700; font-size: 15px; white-space: nowrap; }
    .tx-amount.income { color: var(--brand); }
    .tx-cat { grid-area: cat; }
    .tx-date { grid-area: date; font-size: 12px; color: var(--muted); }
    .tx-note { grid-area: note; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
    .tx-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--border-soft); }
    .tx-actions .btn { flex: 1 1 auto; }
    .tx-actions .small-note { flex: 1 0 100%; }
    .scan-btn { flex: 0 0 auto; width: 44px; min-width: 44px; padding: 0; }
    .add-btn { flex: 1 1 0; background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
    .add-btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
    .page-actions > .scan-btn { flex: 0 0 44px; }

    .nl-row { flex-wrap: nowrap; gap: 8px; }
    .nl-input { flex: 1 1 0; padding: 0 12px; }
    .nl-row .btn { padding: 0 16px; }
    .month-nav { width: 100%; justify-content: space-between; }
    .month-nav h2 { flex: 1; text-align: center; }
    .list-tools { flex-direction: column; flex-wrap: nowrap; align-items: stretch; width: 100%; gap: 10px; }
    .search { width: 100%; }
    .chip-scroll {
        display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px;
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .chip-scroll::-webkit-scrollbar { display: none; }
    .chip-scroll .pill { flex: none; white-space: nowrap; }
    .list-foot { flex-direction: column; gap: 4px; }

    /* ---- Receipt list ---- */
    .receipt-row { grid-template-columns: minmax(0, 1fr) auto; }

    /* ---- Receipt review: picture first, form below, confirm bar pinned above the tab bar ---- */
    .review-viewer { padding: 8px; }
    .review-form .draft-foot { display: contents; }
    .review-form .draft-actions {
        position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 5;
        margin: 0 -16px -16px; padding: 12px 16px; width: auto;
        background: var(--surface); border-top: 1px solid var(--border);
        border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -6px 12px rgba(16, 24, 40, .06);
    }
    .review-form .draft-actions .btn { flex: 1 1 0; min-height: 48px; }
    .item-row { padding: 10px; gap: 8px; }
    .item-row .input { padding: 0 8px; }
    .viewer-pdf { height: 60vh; }

    /* ---- Copilot: conversation scrolls, composer pinned above the tab bar ---- */
    .copilot-grid { display: block; }
    .convo {
        gap: 16px;
        min-height: calc(100vh - var(--appbar-h) - var(--safe-t) - var(--tabbar-h) - var(--safe-b) - 40px);
        min-height: calc(100dvh - var(--appbar-h) - var(--safe-t) - var(--tabbar-h) - var(--safe-b) - 40px);
    }
    .messages { flex: 1; gap: 16px; }
    .bubble-user { max-width: 88%; padding: 12px 14px; }
    .bubble-bot { padding: 14px; gap: 12px; }
    .composer {
        bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 20; gap: 8px; margin: 0 -16px;
        padding: 8px 16px; background: var(--bg); border-top: 1px solid var(--border-soft);
    }
    .suggestions {
        flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px;
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .suggestions::-webkit-scrollbar { display: none; }
    .suggestions .pill { flex: none; white-space: nowrap; }
    .ask { flex-wrap: nowrap; gap: 8px; padding: 6px 6px 6px 12px; }
    .ask input { flex: 1 1 0; }
    .ask .attach { display: none; }

    /* ---- Budgets, Settings, Admin ---- */
    .total-value { font-size: 26px; }
    .mini-stats { gap: 16px; }
    .inline-edit .input { width: 120px; }
    .danger-form { max-width: none; }
    .date-order-row select { flex: 1 1 180px; }
    .scroll-hint { display: block; margin-top: -6px; }
    .table-wrap {
        background:
            linear-gradient(to right, var(--surface) 30%, transparent),
            linear-gradient(to left, var(--surface) 30%, transparent) 100% 0,
            radial-gradient(farthest-side at 0 50%, rgba(16, 24, 40, .18), transparent),
            radial-gradient(farthest-side at 100% 50%, rgba(16, 24, 40, .18), transparent) 100% 0;
        background-repeat: no-repeat;
        background-size: 32px 100%, 32px 100%, 12px 100%, 12px 100%;
        background-attachment: local, local, scroll, scroll;
    }
    .table-wrap:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

    /* ---- Login and onboarding ---- */
    .login-page { min-height: 100svh; padding: 24px 16px calc(24px + var(--safe-b)); }
}

@media (max-width: 820px) and (prefers-reduced-motion: no-preference) {
    .sheet, .trace.is-open { animation: sheet-in .2s ease-out; }
    .sheet-scrim { animation: scrim-in .2s ease-out; }
    @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
    @keyframes scrim-in { from { opacity: 0; } to { opacity: 1; } }
}
