/* FinMgmt — mobile-first stylesheet. */

:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #0f766e;
    --primary-ink: #ffffff;
    --pos: #15803d;
    --pos-bg: #dcfce7;
    --neg: #b91c1c;
    --neg-bg: #fee2e2;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220;
        --surface: #111a2e;
        --text: #e2e8f0;
        --muted: #94a3b8;
        --border: #1e293b;
        --primary: #14b8a6;
        --primary-ink: #042f2e;
        --pos: #4ade80;
        --pos-bg: rgba(74, 222, 128, .12);
        --neg: #f87171;
        --neg-bg: rgba(248, 113, 113, .12);
        --shadow: none;
    }
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

main { flex: 1; padding-bottom: 96px; }

a { color: var(--primary); }

.container {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px;
}

.container.narrow { max-width: 560px; }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
}

.topbar-inner {
    display: flex;
    flex-wrap: wrap;            /* phones: section tabs drop to their own line */
    align-items: center;
    gap: 8px;
    min-height: 60px;
    padding: 0 12px 0 8px;
}
/* Phones: TX | Other | Admin as a full-width second line of the header */
.topbar-inner .top-tabs { order: 10; flex: 1 0 100%; margin: 0 0 8px; }
.topbar-inner .top-tabs a { flex: 1; }

.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar-title h1 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-date { display: none; font-size: 12px; color: var(--muted); }

/* TX / Other section tabs in the header */
.top-tabs {
    display: flex;
    gap: 2px;
    padding: 3px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    flex: none;
}
.top-tabs a {
    display: grid;
    place-items: center;
    min-width: 52px;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 7px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}
.top-tabs a:hover { color: var(--text); }
.top-tabs a.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

/* Dropdown in the header (account menu) */
.quick-add { position: relative; }
.quick-add summary { list-style: none; gap: 6px; padding: 0 12px; }
.quick-add summary::-webkit-details-marker { display: none; }
.quick-add .menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 180px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .15);
    display: flex;
    flex-direction: column;
    z-index: 50;
}
.quick-add .menu a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
}
.quick-add .menu a:hover, .quick-add .menu a:focus-visible { background: var(--bg); outline: none; }

main { padding-top: 20px; }

.icon-btn {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}
.icon-btn:hover { background: var(--bg); }

/* ---------- Left navigation ---------- */
.sidebar {
    --sidebar-w: 248px;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(var(--sidebar-w), 84vw);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
    transform: translateX(-100%);
    transition: transform .22s ease;
    overflow-y: auto;
}
.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
.nav-open { overflow: hidden; }

.scrim {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(15, 23, 42, .45);
}
.scrim[hidden] { display: none; }

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 16px 8px;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.side-label {
    padding: 16px 12px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.side-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    color: var(--text);
    font-weight: 500;
    text-decoration: none;
}
.side-nav a svg { width: 20px; height: 20px; flex: none; color: var(--muted); }
.side-nav a:hover { background: var(--bg); }
.side-nav a.active { background: var(--pos-bg); color: var(--primary); font-weight: 600; }
.side-nav a.active svg { color: var(--primary); }


.app { flex: 1; display: flex; flex-direction: column; min-width: 0; }

@media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 18px;
    color: var(--text);
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--primary);
    color: var(--primary-ink);
    font-size: 16px;
}

/* ---------- Typography ---------- */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 28px 0 12px;
}
.section-head h2 { font-size: 18px; margin: 0; }

/* ---------- Stats ---------- */
.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.stat-balance { grid-column: 1 / -1; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value {
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}
.stat-balance .stat-value { font-size: 28px; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- Card & list ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.empty { padding: 24px 16px; margin: 0; color: var(--muted); text-align: center; }

.tx-list { list-style: none; margin: 0; padding: 0; }

.tx {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.tx:last-child { border-bottom: 0; }

.tx-main { display: flex; align-items: center; gap: 12px; min-width: 0; }

.tx-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-weight: 700;
}
.tx-icon.in { background: var(--pos-bg); color: var(--pos); }
.tx-icon.out { background: var(--neg-bg); color: var(--neg); }
.tx-icon.rate { font-size: 11px; letter-spacing: -.02em; }

.tx-text { display: flex; flex-direction: column; min-width: 0; }
.tx-desc { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { color: var(--muted); font-size: 13px; }

.tx-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.tx-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.tx-actions { display: flex; gap: 12px; font-size: 13px; }
.tx-actions form { margin: 0; }

.link {
    background: none;
    border: 0;
    padding: 4px 0;
    font: inherit;
    color: var(--primary);
    cursor: pointer;
    text-decoration: none;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--neg); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;           /* touch-friendly target */
    padding: 0 20px;
    border-radius: 10px;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }

.fab {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--primary-ink);
    font-size: 30px;
    line-height: 1;
    text-decoration: none;
    box-shadow: 0 6px 16px rgba(15, 118, 110, .35);
    z-index: 20;
}

/* ---------- Forms ---------- */
.form { padding: 20px 16px; }

.field { margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }

.label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }

.input {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: 16px;            /* prevents iOS zoom on focus */
}
.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.input.invalid { border-color: var(--neg); }

.error { color: var(--neg); font-size: 13px; margin: 6px 0 0; }
.optional, .hint { color: var(--muted); font-weight: 400; font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 16px; }

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
    display: grid;
    place-items: center;
    min-height: 40px;
    border-radius: 9px;
    font-weight: 600;
    color: var(--muted);
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); }

.form-actions { display: flex; gap: 12px; margin-top: 8px; }
.form-actions .btn { flex: 1; }

/* ---------- Monthly budget ---------- */
.month-switch {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
}
.month-switch h2 { margin: 0; font-size: 18px; min-width: 170px; text-align: center; }
.month-switch .icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); }

.budget-form { padding: 16px; }

/* Mobile: Type + Amount side by side, the rest stacked; 640px+: one row with the button at the right end */
.budget-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.budget-row .field { margin: 0; min-width: 0; }
.budget-row .field:nth-child(n+3) { grid-column: 1 / -1; }
.budget-row .spacer { display: none; }
.budget-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.budget-buttons .btn { flex: 1; min-height: 46px; }

.tx.editing { background: var(--pos-bg); }

.badge {
    display: inline-block;
    padding: 0 8px;
    margin-right: 4px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.badge-credit { background: var(--pos-bg); color: var(--pos); }
.badge-debit { background: var(--neg-bg); color: var(--neg); }

/* ---------- TX section ---------- */
.badge-phonepe, .pay-phonepe { background: rgba(95, 37, 159, .12); color: #6d28d9; }
.badge-gpay, .pay-gpay { background: rgba(26, 115, 232, .12); color: #1a73e8; }
.badge-cash, .pay-cash { background: var(--pos-bg); color: var(--pos); }
@media (prefers-color-scheme: dark) {
    .badge-phonepe, .pay-phonepe { color: #c4b5fd; }
    .badge-gpay, .pay-gpay { color: #93c5fd; }
}

.list-note { margin: 8px 4px 0; }

.filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px;
    margin-bottom: 16px;
}
.filter-bar .field { margin: 0; min-width: 0; }
.filter-bar .spacer { display: none; }
.filter-bar .field:first-child { grid-column: 1 / -1; }
.filter-submit { grid-column: 1 / -1; }
.filter-submit .btn { width: 100%; }

/* Record TX: Receiving / Paying radio choice above the field row */
.tx-direction { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
.direction { max-width: 340px; }
.direction span { gap: 6px; min-height: 42px; }
.direction .dir-in input:checked + span { background: var(--pos-bg); color: var(--pos); box-shadow: none; }
.direction .dir-out input:checked + span { background: var(--neg-bg); color: var(--neg); box-shadow: none; }

/* Record TX row on phones: Date|Amount, Payment|Received from, Paid to|Receiver, then Description and Submit full width */
/* Fields in order: Date, Amount, Payment type, UPI Txn ID, Received from, Paid to, Receiver, Description (8th), Submit (9th).
   Fields that don't apply (other direction, UPI for Cash) are hidden, and the grid flows around them.
   Phones: two per line; Description and Submit full width. */
.tx-row .field:nth-child(n+3) { grid-column: auto; }
.tx-row .field:nth-child(n+8) { grid-column: 1 / -1; }
.tx-row .field[hidden] { display: none; }

.form-note { margin: 12px 0 0; }

/* ---------- Approvals ---------- */
.nav-count {
    margin-left: auto;
    min-width: 22px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--neg);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}
.pending-note { color: var(--muted); }
.badge-pending { background: rgba(217, 119, 6, .14); color: #b45309; margin-top: 4px; }
.badge-create { background: var(--pos-bg); color: var(--pos); }
.badge-update { background: rgba(26, 115, 232, .12); color: #1a73e8; }
.badge-delete { background: var(--neg-bg); color: var(--neg); }
.req-icon.req-create { background: var(--pos-bg); color: var(--pos); }
.req-icon.req-update { background: rgba(26, 115, 232, .12); color: #1a73e8; }
.req-icon.req-delete { background: var(--neg-bg); color: var(--neg); }
.submitted-by { font-size: 12px; }
.pending-card { border-color: rgba(217, 119, 6, .45); }
.approval-item { padding: 0 0 14px; border-bottom: 1px solid var(--border); list-style: none; }
.approval-item:last-child { border-bottom: 0; }
.approval-item > .tx-list > .tx { border-bottom: 0; }
.diff { margin: 0 16px 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg); font-size: 14px; }
.diff-title { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.diff dl { margin: 0; }
.diff dl div { display: flex; gap: 10px; padding: 2px 0; }
.diff dt { min-width: 110px; color: var(--muted); }
.diff dd { margin: 0; }
.diff s { color: var(--neg); }
.decision { display: grid; grid-template-columns: 1fr; gap: 8px; padding: 0 16px; }
.decision-form { display: flex; gap: 8px; }
.decision-form .input { flex: 1; min-width: 0; min-height: 44px; }
.danger-btn { color: var(--neg); border-color: var(--neg-bg); }

/* ---------- Application history ---------- */
.history { list-style: none; margin: 0; padding: 0; }
.history-item { display: flex; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.history-item:last-child { border-bottom: 0; }
.history-time { display: flex; flex-direction: column; flex: none; min-width: 86px; font-variant-numeric: tabular-nums; }
.history-time strong { font-size: 15px; }
.history-time span { font-size: 12px; color: var(--muted); }
.history-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.profile-tag { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.profile-avatar {
    display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
    background: var(--pos-bg); color: var(--primary); font-size: 12px; font-weight: 700;
}
.profile-name { font-weight: 600; }
.history-action { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.history-details { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.cat-sign_in { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.cat-tx, .cat-tx_users { background: rgba(26, 115, 232, .12); color: #1a73e8; }
.cat-approval { background: var(--pos-bg); color: var(--pos); }
.cat-admin { background: rgba(124, 58, 237, .12); color: #6d28d9; }
.cat-security { background: var(--neg-bg); color: var(--neg); }
.cat-other { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }
.tx-history-what { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px; font-size: 14px; }
.tx-history-who { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.tx-filter-note { margin-top: -6px; }
.history-link { font-size: 13px; }
.history-filters .field:first-child { grid-column: auto; }

/* ---------- Error pop-up ---------- */
.error-dialog h2 { color: var(--neg); }
.error-list { margin: 10px 0 16px; padding-left: 20px; }
.error-list li { margin: 4px 0; font-weight: 600; }
.confirm-approval { margin: 14px 0 0; }

/* ---------- Record TX confirmation pop-up ---------- */
.confirm-dialog {
    width: min(440px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 24px 60px rgba(15, 23, 42, .3);
}
.confirm-dialog::backdrop { background: rgba(15, 23, 42, .55); }
.confirm-body { padding: 22px 20px 18px; }
.confirm-body h2 { margin: 0 0 6px; font-size: 18px; }
.confirm-amount { margin: 0 0 14px; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.confirm-list { margin: 0; border-top: 1px solid var(--border); }
.confirm-list div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.confirm-list div[hidden] { display: none; }
.confirm-list dt { color: var(--muted); flex: none; }
.confirm-list dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.confirm-question { margin: 16px 0 14px; font-weight: 600; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; }

/* ---------- Sign in ---------- */
.auth-body { justify-content: center; }
.auth-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.auth-card { width: 100%; max-width: 380px; padding: 28px 22px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; margin-bottom: 18px; }
.auth-title { margin: 0; font-size: 22px; }
.auth-sub { margin: 4px 0 18px; }
.auth-form .field { margin-bottom: 14px; }
.auth-submit { width: 100%; margin-top: 4px; }
.auth-alert { padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 500; margin-bottom: 14px; }
.error-alert { background: var(--neg-bg); color: var(--neg); }
.ok-alert { background: var(--pos-bg); color: var(--pos); }

/* ---------- Account menu in the header ---------- */
.avatar-btn {
    list-style: none;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--pos-bg);
    color: var(--primary);
    font-weight: 700;
    cursor: pointer;
}
.avatar-btn::-webkit-details-marker { display: none; }
.quick-add .menu a svg { margin-right: 8px; flex: none; }
.account-card { display: flex; align-items: center; gap: 14px; padding: 16px; margin: 0 0 16px; }
.account-avatar {
    display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; flex: none;
    background: var(--pos-bg); color: var(--primary); font-size: 22px; font-weight: 700;
}
.account-info { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
.account-info strong { font-size: 18px; }
.menu-head { display: flex; flex-direction: column; padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-btn-item {
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--neg);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.menu-btn-item:hover { background: var(--bg); }

/* ---------- Admin: roles ---------- */
.role-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.role-grid .field { margin: 0; min-width: 0; }
.input[readonly] { color: var(--muted); cursor: not-allowed; }
.perm-field { border: 0; padding: 0; margin: 16px 0 0; min-width: 0; }
.perm-help { margin: 0 0 10px; }
.perm-groups { display: grid; grid-template-columns: 1fr; gap: 12px; }
.perm-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.perm-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 2px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.perm-all { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; cursor: pointer; text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--primary); }
.perm-all input { width: 16px; height: 16px; accent-color: var(--primary); }
.perm {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    cursor: pointer;
}
.perm input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex: none; }
.perm span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.perm small { color: var(--muted); font-size: 12px; }
.perm:has(input:checked) { border-color: var(--primary); background: var(--pos-bg); }
.perm.locked { cursor: not-allowed; opacity: .85; }
.role-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }

/* ---------- Admin: user management ---------- */
.card-title { margin: 0 0 14px; font-size: 16px; }
.check-field .check { display: flex; align-items: center; gap: 8px; min-height: 46px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.badge-admin { background: rgba(124, 58, 237, .12); color: #6d28d9; }
.badge-user { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.badge-off { background: var(--neg-bg); color: var(--neg); }
.badge-you { background: var(--pos-bg); color: var(--primary); }
@media (prefers-color-scheme: dark) { .badge-admin { color: #c4b5fd; } }

/* Record TX sub-navigation: Record TX | Recorded TX */
.sub-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    overflow-x: auto;
}
.sub-tabs a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 14px;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.sub-tabs a:hover { color: var(--text); }
.sub-tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.sub-tabs .count {
    min-width: 22px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    color: var(--muted);
}
.sub-tabs a.active .count { background: var(--pos-bg); border-color: transparent; color: var(--primary); }
.flash-link { margin: 6px 4px 0; font-weight: 600; }
.req { color: var(--neg); font-weight: 700; }
.req[hidden] { display: none; }
.parties { color: var(--text); font-weight: 500; }
.upi-ref { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; margin-right: 4px; }
.tx-icon.avatar { background: var(--pos-bg); color: var(--primary); }

/* Users page: name + button */
.user-row { display: grid; grid-template-columns: 1fr; gap: 12px; }
.user-row .field { margin: 0; min-width: 0; }
.user-row .spacer { display: none; }

.sub-head { margin: 20px 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; }
.pay-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pay-stats .stat { padding: 12px; }
.pay-stats .stat-value { font-size: 16px; }
.budget-totals {
    margin: 0;
    padding: 6px 16px;
    border-top: 1px solid var(--border);
}
.budget-totals div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}
.budget-totals dt { color: var(--muted); font-weight: 500; }
.budget-totals dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.budget-totals .budget-net { border-top: 1px dashed var(--border); margin-top: 4px; padding-top: 10px; }
.budget-totals .budget-net dt { color: var(--text); font-weight: 600; }
.budget-totals .budget-net dd { font-size: 18px; }

/* ---------- Flash ---------- */
.flash {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: 10px;
    background: var(--pos-bg);
    color: var(--pos);
    font-weight: 500;
}

/* ---------- Footer ---------- */
.footer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    padding-bottom: env(safe-area-inset-bottom);
}
.footer-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding-top: 16px;
    padding-bottom: 16px;
    text-align: center;
}

/* ---------- Responsive helpers ---------- */
.hide-mobile { display: none; }
.show-mobile { display: grid; place-items: center; }

@media (max-width: 380px) {
    .tx-meta time { display: none; }
}

/* Desktop: sidebar is always visible; header sits beside it without the menu button */
@media (min-width: 900px) {
    .menu-btn, .close-btn, .scrim { display: none !important; }
    .topbar-inner { height: 68px; padding: 0 24px; }
    .topbar-title h1 { font-size: 20px; }
    .sidebar { transform: none; transition: none; width: var(--sidebar-w); }
    .app { margin-left: 248px; }
    .nav-open { overflow: auto; }
}

@media (min-width: 640px) {
    main { padding-bottom: 32px; padding-top: 28px; }
    .topbar-inner { flex-wrap: nowrap; height: 60px; }
    .topbar-inner .top-tabs { order: 0; flex: none; margin: 0; }
    .topbar-inner .top-tabs a { flex: none; }
    .auth-card { padding: 32px 28px; }
    .role-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
    .perm-groups { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
    /* Admin form: Username | Display name | Role / Password | Active | Button */
    .budget-row.admin-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .budget-row.admin-row .field:nth-child(n+3) { grid-column: auto; }
    .topbar-date { display: block; }
    .stats { grid-template-columns: repeat(3, 1fr); gap: 16px; }
    .stat-balance { grid-column: auto; }
    .stat-balance .stat-value { font-size: 24px; }
    .stat { padding: 20px; }
    .grid-2 { grid-template-columns: 1fr 1fr; }
    .form { padding: 24px; }
    .form-actions { justify-content: flex-end; }
    .form-actions .btn { flex: none; }
    .footer-inner { flex-direction: row; justify-content: space-between; }
    .hide-mobile { display: inline-flex; }
    .show-mobile { display: none; }
    .tx { padding: 14px 20px; }
    .tx-side { flex-direction: row; align-items: center; gap: 20px; }
    .tx-actions { order: 2; }
    .budget-form { padding: 20px; }
    .budget-row {
        grid-template-columns:
            minmax(120px, .9fr) minmax(96px, 1fr) minmax(120px, 1.1fr) minmax(100px, 1.8fr) auto;
        align-items: start;
    }
    .budget-row .field:nth-child(n+3) { grid-column: auto; }
    .budget-row .spacer { display: block; }
    .budget-buttons .btn { flex: none; }
    .budget-totals { padding: 6px 20px; }
    /* Record TX, 2 rows of 4: Date | Amount | Payment | Received from / Paid to | Receiver | Description | Submit */
    .tx-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .tx-row .field:nth-child(n+8) { grid-column: auto; }
    /* Description takes two columns so the lines fill up */
    .tx-row .field:nth-child(8) { grid-column: span 2; }
    .tx-row .budget-buttons .btn { flex: 1; }
    .user-row { grid-template-columns: minmax(0, 420px) auto; justify-content: start; }
    .user-row .spacer { display: block; }
    .filter-bar {
        grid-template-columns: minmax(150px, 220px) minmax(120px, 180px) minmax(120px, 180px) auto;
        padding: 16px 20px;
    }
    .filter-bar .field:first-child { grid-column: auto; }
    .filter-bar.history-filters { grid-template-columns: repeat(4, minmax(0, 1fr)) auto; }
    /* TX history has five filters plus Clear */
    .filter-bar.tx-history-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .decision { grid-template-columns: 1fr 1fr; padding: 0 20px; }
    .diff { margin: 0 20px 10px; }
    .history-item { padding: 12px 20px; }
    .filter-bar .spacer { display: block; }
    .filter-submit { grid-column: auto; }
    .pay-stats .stat { padding: 16px 20px; }
    .pay-stats .stat-value { font-size: 18px; }
}

/* Wide screens: the chosen direction's fields on one row (under the Receiving / Paying choice), Submit at the right end */
@media (min-width: 1100px) {
    .filter-bar.tx-history-filters { grid-template-columns: repeat(5, minmax(0, 1fr)) auto; }
}

@media (min-width: 1400px) {
    /* Admin form on one row */
    .budget-row.admin-row { grid-template-columns: minmax(120px, 1fr) minmax(130px, 1.2fr) minmax(100px, .8fr) minmax(140px, 1.1fr) auto auto; }
    .admin-row .budget-buttons .btn { flex: none; }
    /* Paying: Date | Amount | Payment | Paid to | Description | Submit */
    /* As many columns as there are visible fields (6–8 depending on direction and UPI), all on one line */
    .tx-row { grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); }
    .tx-row .field:nth-child(8) { grid-column: auto; }
}
