/* House Building Expenses — hand-written CSS, no build step.
   Mobile first. Light/dark via [data-theme] on <html> (auto follows the device). */

/* ---------- Fonts (self-hosted Noto Sans Bengali, OFL) ---------- */
@font-face { font-family: 'Noto Sans Bengali'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/noto-bengali-bengali-400.woff2) format('woff2'); unicode-range: U+0951-0952,U+0964-0965,U+0980-09FE,U+1CD0,U+1CD2,U+1CD5-1CD6,U+1CD8,U+1CE1,U+1CEA,U+1CED,U+1CF2,U+1CF5-1CF7,U+200C-200D,U+20B9,U+25CC,U+A8F1; }
@font-face { font-family: 'Noto Sans Bengali'; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/noto-bengali-bengali-600.woff2) format('woff2'); unicode-range: U+0951-0952,U+0964-0965,U+0980-09FE,U+1CD0,U+1CD2,U+1CD5-1CD6,U+1CD8,U+1CE1,U+1CEA,U+1CED,U+1CF2,U+1CF5-1CF7,U+200C-200D,U+20B9,U+25CC,U+A8F1; }
@font-face { font-family: 'Noto Sans Bengali'; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/noto-bengali-bengali-700.woff2) format('woff2'); unicode-range: U+0951-0952,U+0964-0965,U+0980-09FE,U+1CD0,U+1CD2,U+1CD5-1CD6,U+1CD8,U+1CE1,U+1CEA,U+1CED,U+1CF2,U+1CF5-1CF7,U+200C-200D,U+20B9,U+25CC,U+A8F1; }
@font-face { font-family: 'Noto Sans Bengali'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/noto-bengali-latin-400.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Noto Sans Bengali'; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/noto-bengali-latin-600.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Noto Sans Bengali'; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/noto-bengali-latin-700.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

/* ---------- Design tokens ---------- */
:root {
    color-scheme: light;
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --border: #e2e7ef;
    --border-strong: #cbd3df;
    --text: #0f172a;
    --muted: #5b6b82;
    --faint: #8a98ad;
    --brand: #0f1f3d;
    --brand-2: #1b3360;
    --on-brand: #f1f5fb;
    --accent: #f5a524;
    --accent-hover: #f7b545;
    --on-accent: #231500;
    --focus: #3b82f6;

    --green: #15803d;  --green-bg: #e7f8ee; --green-line: #86d9a6;
    --yellow: #8a5a00; --yellow-bg: #fff7d1; --yellow-line: #f3cf55;
    --blue: #1d4ed8;   --blue-bg: #e6efff;  --blue-line: #93b4f7;
    --orange: #c2410c; --orange-bg: #fff0e3; --orange-line: #f6b27c;
    --red: #b91c1c;    --red-bg: #fdeaea;   --red-line: #f2a3a3;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 2px 8px rgba(15, 23, 42, .04);
    --tap: 48px;
    --nav-h: 68px;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0a111e;
    --surface: #121b2c;
    --surface-2: #172236;
    --border: #233049;
    --border-strong: #31405d;
    --text: #e7ecf4;
    --muted: #9aa8bf;
    --faint: #73829b;
    --brand: #0d1729;
    --brand-2: #1a2a47;
    --on-brand: #e7ecf4;
    --accent: #f8b84a;
    --accent-hover: #fac56b;
    --on-accent: #231500;
    --focus: #60a5fa;

    --green: #4ade80;  --green-bg: rgba(34, 197, 94, .13);  --green-line: rgba(74, 222, 128, .40);
    --yellow: #facc15; --yellow-bg: rgba(234, 179, 8, .13); --yellow-line: rgba(250, 204, 21, .40);
    --blue: #7cb0ff;   --blue-bg: rgba(59, 130, 246, .15);  --blue-line: rgba(124, 176, 255, .45);
    --orange: #fb9a52; --orange-bg: rgba(249, 115, 22, .14); --orange-line: rgba(251, 154, 82, .45);
    --red: #f87171;    --red-bg: rgba(239, 68, 68, .14);    --red-line: rgba(248, 113, 113, .45);

    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
        color-scheme: dark;
        --bg: #0a111e; --surface: #121b2c; --surface-2: #172236; --border: #233049; --border-strong: #31405d;
        --text: #e7ecf4; --muted: #9aa8bf; --faint: #73829b; --brand: #0d1729; --brand-2: #1a2a47; --on-brand: #e7ecf4;
        --accent: #f8b84a; --accent-hover: #fac56b; --on-accent: #231500; --focus: #60a5fa;
        --green: #4ade80;  --green-bg: rgba(34, 197, 94, .13);  --green-line: rgba(74, 222, 128, .40);
        --yellow: #facc15; --yellow-bg: rgba(234, 179, 8, .13); --yellow-line: rgba(250, 204, 21, .40);
        --blue: #7cb0ff;   --blue-bg: rgba(59, 130, 246, .15);  --blue-line: rgba(124, 176, 255, .45);
        --orange: #fb9a52; --orange-bg: rgba(249, 115, 22, .14); --orange-line: rgba(251, 154, 82, .45);
        --red: #f87171;    --red-bg: rgba(239, 68, 68, .14);    --red-line: rgba(248, 113, 113, .45);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: 'Noto Sans Bengali', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.08rem; font-weight: 700; }
h3 { font-size: .95rem; font-weight: 600; }
p { margin: 0; }
a { color: inherit; }
img, svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.user-text { white-space: pre-line; overflow-wrap: anywhere; }

.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i-lg { width: 24px; height: 24px; }
.i-sm { width: 16px; height: 16px; }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 30;
    background: var(--brand);
    color: var(--on-brand);
    padding-top: env(safe-area-inset-top);
}
.topbar-inner { max-width: 1080px; margin: 0 auto; display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; font-weight: 700; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex: none; }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1.02rem; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.icon-btn {
    min-width: 44px; height: 44px; padding: 0 10px; border: 0; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: transparent; color: inherit; font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, .09); }
.top-actions form { margin: 0; }

.desktop-nav { display: none; }

/* ---------- Bottom navigation (phones) ---------- */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav ul { list-style: none; margin: 0 auto; padding: 0; max-width: 520px; display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; }
.bottom-nav a {
    min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    text-decoration: none; color: var(--muted); font-size: .74rem; font-weight: 600; padding: 6px 2px;
}
.bottom-nav a[aria-current="page"] { color: var(--text); }
.bottom-nav a[aria-current="page"] .i { color: var(--accent); stroke-width: 2.4; }
.bottom-nav .fab-wrap { display: flex; justify-content: center; }
.fab {
    width: 60px; height: 60px; margin-top: -22px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent); color: var(--on-accent);
    box-shadow: 0 6px 16px rgba(245, 165, 36, .38), 0 0 0 5px var(--surface);
    text-decoration: none;
}
.fab .i { width: 28px; height: 28px; stroke-width: 2.6; }

/* ---------- Layout ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 18px 16px calc(var(--nav-h) + 36px + env(safe-area-inset-bottom)); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.stack { display: grid; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-head h2 .i { color: var(--muted); }
.link { color: var(--blue); font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; min-height: 40px; }
.link:hover { text-decoration: underline; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; text-decoration: none; display: block; }
.stat-top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .84rem; font-weight: 600; }
.stat-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); }
.stat-ico .i { width: 18px; height: 18px; }
.stat-value { font-size: 1.32rem; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.25; }
.stat-sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.stat.hero { grid-column: 1 / -1; background: var(--brand); border-color: transparent; color: var(--on-brand); }
.stat.hero .stat-top { color: rgba(241, 245, 251, .75); }
.stat.hero .stat-ico { background: rgba(255, 255, 255, .1); color: var(--accent); }
.stat.hero .stat-value { font-size: 1.9rem; }
.stat.hero .stat-sub { color: rgba(241, 245, 251, .7); }
.stat.t-blue .stat-ico { background: var(--blue-bg); color: var(--blue); }
.stat.t-orange .stat-ico { background: var(--orange-bg); color: var(--orange); }
.stat.t-orange .stat-value { color: var(--orange); }
.stat.t-yellow .stat-ico { background: var(--yellow-bg); color: var(--yellow); }

/* ---------- Buttons ---------- */
.btn {
    min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font: inherit; font-weight: 600; font-size: .98rem; cursor: pointer; text-decoration: none; white-space: nowrap;
    background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand-2); color: #fff; border-color: transparent; }
:root[data-theme="dark"] .btn-primary { background: #2a4a85; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .btn-primary { background: #2a4a85; } }
.btn-primary:hover { filter: brightness(1.1); background: var(--brand-2); }
.btn-accent { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-danger { color: var(--red); border-color: var(--red-line); background: var(--surface); }
.btn-danger:hover { background: var(--red-bg); }
.btn-green { color: var(--green); border-color: var(--green-line); background: var(--green-bg); }
.btn-blue { color: var(--blue); border-color: var(--blue-line); background: var(--blue-bg); }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .65; cursor: progress; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions > * { flex: 1 1 auto; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 14px; }
.section-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1rem; }
.section-title .i { color: var(--muted); }
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: 600; font-size: .92rem; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.field .opt { color: var(--faint); font-weight: 400; font-size: .8rem; }
.req { color: var(--red); }
.input, select.input, textarea.input {
    width: 100%; min-height: var(--tap); padding: 10px 12px;
    border: 1px solid var(--border-strong); border-radius: 12px;
    background: var(--surface); color: var(--text);
    font: inherit; font-size: 16px; /* 16px stops iOS zooming */
}
textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
select.input { appearance: none; -webkit-appearance: none; padding-right: 38px;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.input::placeholder { color: var(--faint); }
.input-money { position: relative; }
.input-money .cur { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; pointer-events: none; }
.input-money .input { padding-left: 32px; }
.input.big { font-size: 1.25rem; font-weight: 700; min-height: 56px; }
.has-error .input { border-color: var(--red); }
.field-error { color: var(--red); font-size: .86rem; display: flex; gap: 6px; align-items: flex-start; }
.field-error .i { width: 16px; height: 16px; margin-top: 3px; }
.hint { color: var(--muted); font-size: .84rem; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cols-qty { display: grid; grid-template-columns: 1.1fr 1fr; gap: 12px; }
.checkbox { display: flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; font-weight: 500; }
.checkbox input { width: 22px; height: 22px; accent-color: var(--brand-2); }

.calc {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--border-strong);
    font-size: .9rem; color: var(--muted);
}
.calc strong { color: var(--text); }
.calc .btn { margin-left: auto; }
.manual-note { color: var(--orange); font-size: .85rem; display: flex; gap: 6px; align-items: flex-start; }
.manual-note .i { width: 16px; height: 16px; margin-top: 3px; }

/* Status choice cards: big, colourful radio buttons */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice span {
    min-height: 64px; padding: 10px 12px; border-radius: 14px;
    border: 2px solid var(--border); background: var(--surface);
    display: flex; align-items: center; gap: 10px; font-weight: 600; line-height: 1.3; color: var(--muted);
    transition: background .12s, border-color .12s;
}
.choice span .i { width: 24px; height: 24px; }
.choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice.c-green input:checked + span { border-color: var(--green); background: var(--green-bg); color: var(--green); }
.choice.c-yellow input:checked + span { border-color: var(--yellow-line); background: var(--yellow-bg); color: var(--yellow); }
.choice.c-blue input:checked + span { border-color: var(--blue); background: var(--blue-bg); color: var(--blue); }
.choice.c-orange input:checked + span { border-color: var(--orange); background: var(--orange-bg); color: var(--orange); }
.choice input:checked + span::after { content: ''; margin-left: auto; width: 10px; height: 10px; border-radius: 50%; background: currentColor; flex: none; }

/* Conditional fields (pure CSS, no JS needed) */
.when-delivery-partial, .when-payment-partial { display: none; }
.form:has(input[name="delivery_status"][value="partial"]:checked) .when-delivery-partial { display: grid; }
.form:has(input[name="payment_status"][value="partial"]:checked) .when-payment-partial { display: grid; }
.sub-panel { gap: 6px; padding: 12px; border-radius: 12px; }
.when-delivery-partial.sub-panel { background: var(--yellow-bg); border: 1px solid var(--yellow-line); }
.when-payment-partial.sub-panel { background: var(--orange-bg); border: 1px solid var(--orange-line); }
.sub-panel .input { background: var(--surface); }
.due-live { font-weight: 700; color: var(--orange); }

.sticky-save {
    position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; box-shadow: 0 6px 24px rgba(15, 23, 42, .12);
}

/* ---------- Badges ---------- */
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px 3px 7px; border-radius: 999px;
    font-size: .78rem; font-weight: 600; line-height: 1.4; border: 1px solid transparent; white-space: nowrap;
}
.badge .i { width: 14px; height: 14px; }
.badge.green { color: var(--green); background: var(--green-bg); border-color: var(--green-line); }
.badge.yellow { color: var(--yellow); background: var(--yellow-bg); border-color: var(--yellow-line); }
.badge.blue { color: var(--blue); background: var(--blue-bg); border-color: var(--blue-line); }
.badge.orange { color: var(--orange); background: var(--orange-bg); border-color: var(--orange-line); }
.badge.grey { color: var(--muted); background: var(--surface-2); border-color: var(--border); }
.cat-chip { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: .82rem; }
.cat-chip .i { width: 14px; height: 14px; }

/* ---------- Entry cards (phones) ---------- */
.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-list li + li { border-top: 1px solid var(--border); }
.entry-link { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 16px; text-decoration: none; color: inherit; }
.entry-link:hover { background: var(--surface-2); }
.entry-title { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.entry-amount { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; color: var(--muted); font-size: .84rem; }
.entry-meta > span { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
.entry-meta .i { width: 14px; height: 14px; }
.entry-link .badges { grid-column: 1 / -1; margin-top: 4px; }
.serial { color: var(--faint); font-size: .8rem; font-weight: 600; margin-right: 6px; font-variant-numeric: tabular-nums; }
.due-sub { color: var(--orange); font-size: .8rem; font-weight: 600; text-align: right; white-space: nowrap; }

/* ---------- Tables (desktop) ---------- */
.table-wrap { display: none; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table tbody tr:hover { background: var(--surface-2); }
.table a.row-link { text-decoration: none; font-weight: 600; overflow-wrap: anywhere; }
.table a.row-link:hover { text-decoration: underline; }
.table tfoot td { font-weight: 700; background: var(--surface-2); }

/* Simple tables used on all sizes (reports) */
.mini-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.mini-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: .8rem; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.mini-table td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.mini-table .r { text-align: right; }
.mini-table tr:last-child td { border-bottom: 0; }
.bar { display: block; width: 100%; height: 6px; margin-top: 6px; appearance: none; -webkit-appearance: none; border: 0; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar::-webkit-progress-bar { background: var(--surface-2); border-radius: 99px; }
.bar::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
.bar::-moz-progress-bar { background: var(--accent); border-radius: 99px; }

/* ---------- Alerts ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; border: 1px solid; font-size: .94rem; margin-bottom: 14px; }
.alert .i { margin-top: 2px; }
.alert.ok { color: var(--green); background: var(--green-bg); border-color: var(--green-line); }
.alert.warn { color: var(--yellow); background: var(--yellow-bg); border-color: var(--yellow-line); }
.alert.error { color: var(--red); background: var(--red-bg); border-color: var(--red-line); }
.alert.info { color: var(--blue); background: var(--blue-bg); border-color: var(--blue-line); }
.alert-body { display: grid; gap: 4px; color: var(--text); }
.alert-body strong { color: inherit; }
.offline-banner { position: sticky; top: 60px; z-index: 25; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; background: var(--red); color: #fff; font-weight: 600; font-size: .9rem; text-align: center; }
:root[data-theme="dark"] .offline-banner { color: #1a0505; }

.conflict-table { width: 100%; border-collapse: collapse; font-size: .88rem; margin-top: 6px; }
.conflict-table th, .conflict-table td { text-align: left; padding: 6px 8px; border-top: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }

/* ---------- Filters, tabs, pager ---------- */
.searchbar { position: relative; }
.searchbar .i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.searchbar .input { padding-left: 42px; }
details.filters > summary { list-style: none; cursor: pointer; }
details.filters > summary::-webkit-details-marker { display: none; }
.filters-body { display: grid; gap: 12px; padding-top: 12px; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); display: inline-flex; align-items: center; gap: 6px; font-size: .88rem; font-weight: 600; text-decoration: none; color: var(--muted); white-space: nowrap; }
.chip[aria-current="true"] { background: var(--brand-2); color: #fff; border-color: transparent; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; }
.tabs a { min-height: 42px; display: flex; align-items: center; justify-content: center; gap: 6px; border-radius: 9px; text-decoration: none; font-weight: 600; font-size: .88rem; color: var(--muted); text-align: center; padding: 0 6px; }
.tabs a[aria-current="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs a .i { width: 16px; height: 16px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.pager .muted { font-size: .86rem; }
.summary-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--border); }
.summary-strip > div { padding: 10px 12px; min-width: 0; }
.summary-strip > div + div { border-left: 1px solid var(--border); }
.summary-strip .k { color: var(--muted); font-size: .78rem; font-weight: 600; }
.summary-strip .v { font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.summary-strip .v.orange { color: var(--orange); }
.period-extra { display: none; }
.report-form:has(option[value="day"]:checked) .p-day,
.report-form:has(option[value="month"]:checked) .p-month,
.report-form:has(option[value="custom"]:checked) .p-custom { display: grid; }

/* ---------- Details page ---------- */
.detail-hero { display: grid; gap: 10px; }
.detail-amount { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr); margin: 0; }
.kv > div { display: grid; grid-template-columns: 42% 1fr; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.kv dt { color: var(--muted); font-size: .9rem; display: flex; gap: 8px; align-items: flex-start; }
.kv dt .i { width: 16px; height: 16px; margin-top: 4px; }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.progress-line { display: grid; gap: 4px; }

/* ---------- Empty / login ---------- */
.empty { text-align: center; padding: 34px 20px; display: grid; justify-items: center; gap: 8px; }
.empty .empty-ico { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.empty .empty-ico .i { width: 28px; height: 28px; }
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-brand { display: grid; justify-items: center; gap: 10px; text-align: center; margin-bottom: 18px; }
.auth-brand .brand-mark { width: 56px; height: 56px; border-radius: 16px; }
.auth-brand .brand-mark .i { width: 30px; height: 30px; }
.auth-tools { display: flex; justify-content: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.seg { display: inline-flex; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); gap: 4px; }
.seg button { min-height: 40px; min-width: 64px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg form { margin: 0; display: contents; }

/* ---------- Wider screens ---------- */
@media (min-width: 600px) {
    .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .stat.hero { grid-column: span 3; }
    .grid-2 { grid-template-columns: 1fr 1fr; }
    .actions > * { flex: 0 0 auto; }
}

@media (min-width: 900px) {
    h1 { font-size: 1.7rem; }
    .bottom-nav { display: none; }
    .container { padding: 26px 24px 48px; }
    .desktop-nav { display: flex; align-items: center; gap: 2px; margin-left: 16px; }
    .desktop-nav a { min-height: 42px; padding: 0 12px; border-radius: 10px; display: inline-flex; align-items: center; gap: 7px; text-decoration: none; font-weight: 600; font-size: .92rem; color: rgba(241, 245, 251, .78); }
    .desktop-nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
    .desktop-nav a[aria-current="page"] { background: rgba(255, 255, 255, .12); color: #fff; }
    .desktop-nav .add { background: var(--accent); color: var(--on-accent); margin-left: 8px; }
    .desktop-nav .add:hover { background: var(--accent-hover); color: var(--on-accent); }
    .stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .stat.hero { grid-column: span 2; }
    .cards-only { display: none; }
    .table-wrap { display: block; overflow-x: auto; }
    .sticky-save { position: static; box-shadow: none; border: 0; padding: 0; background: transparent; }
    .form-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
    .form-layout .full { grid-column: 1 / -1; }
    .kv > div { grid-template-columns: 30% 1fr; }
}

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