:root {
    --navy: #172b4d;
    --blue: #1d5f9e;
    --blue-dark: #164d82;
    --cream: #f7f5ef;
    --line: #e8e7e2;
    --text: #263238;
    --muted: #79838a;
    --green: #2c8a66;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    color: var(--text);
    background: var(--cream);
    overflow-x: hidden;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #eff3f6 0%, #faf8f2 100%);
}

.login-card {
    width: min(420px, 100%);
    padding: 44px;
    border-radius: 18px;
    background: white;
    box-shadow: 0 18px 50px rgba(23, 43, 77, 0.12);
}

.setup-card { width: min(680px, 100%); }
.login-card h1, .panel-heading h2 { margin: 4px 0; color: var(--navy); }
.login-card .muted { margin-bottom: 28px; color: var(--muted); }
.brand-mark {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin-bottom: 24px;
    border-radius: 50%;
    color: white;
    background: var(--blue);
    font-size: 28px;
    font-weight: 700;
}
.brand-mark.small { width: 36px; height: 36px; margin: 0; font-size: 20px; }
.eyebrow { margin: 0; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }

.login-form label, .expense-form label {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
    color: #4e5961;
    font-size: 13px;
    font-weight: 700;
}

input, select, textarea {
    width: 100%;
    border: 1px solid #dfe2e5;
    border-radius: 8px;
    padding: 11px 12px;
    color: var(--text);
    background: white;
    font: inherit;
    outline: none;
    font-size: 16px;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,95,158,.09); }
textarea { resize: vertical; }

.btn {
    border: 0;
    border-radius: 8px;
    padding: 12px 18px;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
}
.btn-primary { color: white; background: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { color: var(--blue); background: #edf4fa; }

input[type="file"]::file-selector-button {
    color: white;
    background: var(--blue) !important;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
}

.login-form .btn { width: 100%; margin-top: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.alert { margin-bottom: 18px; border-radius: 8px; padding: 12px 14px; font-size: 14px; }
.alert-error { color: #9b2c2c; background: #fff0f0; border: 1px solid #f4cccc; }
.alert-success { color: #216b50; background: #edf8f3; border: 1px solid #cce8dc; }

.app-shell { min-height: 100vh; }
.topbar {
    height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    border-bottom: 1px solid var(--line);
    background: white;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--navy); font-weight: 800; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a {
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}
.nav-links a:hover, .nav-links a.active { color: var(--blue); background: #edf4fa; }
.nav-links .logout { margin-left: 4px; }
.logout { color: var(--muted); font-size: 14px; font-weight: 700; text-decoration: none; }
.logout:hover { color: var(--blue); }
.content { max-width: 1440px; margin: 0 auto; padding: 28px 32px 40px; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.summary-card {
    min-height: 118px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 20px 24px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: white;
}
.summary-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.summary-card strong { margin: 8px 0 3px; color: var(--navy); font-size: 26px; }
.summary-card small { color: var(--muted); }
.layout-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    align-items: start;
}
.entry-layout {
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: white;
}
.entry-layout .forms-column {
    display: block;
}
.entry-layout .form-panel {
    padding: 0;
    border: 0;
    border-radius: 0;
}
.entry-tabs-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 22px;
}
.entry-tabs-bar > .btn { flex: 0 0 auto; }
.entry-tabs {
    display: flex;
    width: fit-content;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #f3f5f7;
}
.entry-tab {
    min-width: 120px;
    min-height: 42px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: color .15s ease, background .15s ease, box-shadow .15s ease;
}
.entry-tab:hover { color: var(--blue-dark); background: #e8eef4; }
.entry-tab.is-active {
    border-color: #dce5ed;
    color: var(--blue-dark);
    background: white;
    box-shadow: 0 1px 3px rgba(23, 43, 77, .12);
}
.entry-tab:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}
.forms-column, .records-column {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    align-items: start;
}
.panel { border: 1px solid var(--line); border-radius: 12px; background: white; }
.form-panel { padding: 22px; }
.panel-heading { margin-bottom: 18px; }
.panel-heading h2 { font-size: 20px; }
.expense-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.expense-form label { margin-bottom: 14px; }
.expense-form label span { color: var(--muted); font-weight: 400; }
.expense-form .full { grid-column: 1 / -1; }
.reimbursement-picker {
    min-width: 0;
    margin: 0 0 16px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.reimbursement-picker legend {
    padding: 0 5px;
    color: #4e5961;
    font-size: 13px;
    font-weight: 700;
}
.reimbursement-picker legend span { color: var(--muted); font-weight: 400; }
.reimbursement-picker > .muted { margin: 8px 0 2px; font-size: 13px; }
.reimbursement-options { display: grid; max-height: 230px; gap: 7px; overflow-y: auto; }
.statement-reimbursement-picker { min-width: 260px; margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 7px; }
.statement-reimbursement-picker legend { padding: 0 4px; color: var(--text); font-size: 11px; font-weight: 700; }
.statement-reimbursement-picker .reimbursement-option { white-space: normal; }
.reimbursement-option {
    display: flex !important;
    align-items: flex-start;
    gap: 10px !important;
    margin: 0 !important;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fafbfc;
    cursor: pointer;
}
.reimbursement-option input {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    margin: 1px 0 0;
    accent-color: var(--blue);
}
.reimbursement-option .reimbursement-amount { display: block; flex: none; width: min(220px, 100%); height: auto; margin: 6px 0 0; padding: 7px 9px; border: 1px solid #dfe2e5; border-radius: 6px; font-size: 13px; }
.reimbursement-option > span { min-width: 0; }
.reimbursement-option strong { display: block; color: var(--text); font-size: 13px; }
.reimbursement-option small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 400; }
.reimbursement-status { color: var(--blue-dark) !important; font-weight: 700; text-transform: capitalize; }
.reimbursed-row td:not(.actions-cell),
.reimbursed-row td:not(.actions-cell) * { color: #858b90; text-decoration: line-through; }
.statement-panel, .statement-review { padding: 22px; }
.statement-panel { max-width: 980px; }
.statement-panel h1 { margin: 4px 0 8px; color: var(--navy); font-size: 24px; }
.statement-panel .panel-heading { margin-bottom: 10px; }
.statement-panel .muted, .statement-review .muted { color: var(--muted); line-height: 1.5; }
.statement-notes { margin: 0 0 20px; padding-left: 20px; color: var(--text); font-size: 13px; line-height: 1.7; }
.statement-upload {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}
.statement-upload label { display: grid; gap: 8px; color: #4e5961; font-size: 13px; font-weight: 700; }
.statement-upload input[type="file"] { min-width: 0; padding: 8px; }
.statement-progress { grid-column: 1 / -1; min-height: 20px; margin: 0; color: var(--muted); font-size: 13px; }
.statement-review { margin-top: 18px; }
.statement-review .panel-heading { margin-bottom: 14px; }
.statement-review .panel-heading h2 { margin: 4px 0; }
.statement-table { min-width: 1020px; }
.statement-table td { vertical-align: top; }
.statement-table td > input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--blue); }
.statement-table td > select { min-width: 125px; margin-bottom: 5px; padding: 8px; font-size: 13px; }
.statement-subfield { display: grid; gap: 4px; margin-top: 6px; color: var(--muted); font-size: 11px; }
.statement-subfield select, .statement-subfield input { min-width: 125px; padding: 7px; font-size: 13px; }
.statement-expense-fields[hidden], .statement-income-fields[hidden] { display: none; }
.statement-wallet-used { display: block; margin-top: 8px; color: var(--muted); font-size: 12px; }
.statement-cashback-field input { min-width: 125px; padding: 7px; font-size: 13px; }
.cashback-match-note { color: var(--green) !important; font-weight: 700; }
.statement-possible-duplicate { background: #fffaf0; }
.duplicate-warning { color: #94620a !important; font-weight: 700; }
.duplicate-warning[hidden] { display: none; }
.same-day-records summary { color: var(--blue); font-size: 12px; font-weight: 700; cursor: pointer; }
.same-day-records ul { display: grid; max-height: 180px; gap: 6px; overflow-y: auto; margin: 8px 0 0; padding: 0; list-style: none; }
.same-day-records li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 8px; border-radius: 5px; background: #f5f7f9; font-size: 11px; }
.same-day-records li strong { flex: 0 0 auto; white-space: nowrap; }
.statement-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.statement-validation-message { margin: 12px 0 0; padding: 10px 12px; border: 1px solid #e8b5b5; border-radius: 7px; color: #a52e2e; background: #fff4f4; font-size: 13px; font-weight: 700; }
.statement-validation-message[hidden] { display: none; }
.statement-invalid-field { border-color: #b73a3a !important; box-shadow: 0 0 0 2px rgba(183, 58, 58, .12); }
.statement-discard { display: flex; justify-content: flex-end; margin-top: 8px; }
.statement-discard .btn { font-size: 13px; }
.expense-split-toggle { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; font-weight: 700; }
.expense-split-toggle input { width: 18px; height: 18px; accent-color: var(--blue); }
.expense-split-fields { margin-top: 10px; }
.expense-split-fields[hidden] { display: none; }
.expense-split-fields > .muted { margin: 4px 0 8px; font-size: 12px; }
.expense-split-total { margin: 10px 0; padding: 10px 12px; border: 1px solid #e8c2a2; border-radius: 8px; color: #8a4b11; background: #fff8f1; font-size: 13px; font-weight: 800; }
.expense-split-total.is-matched { border-color: #b7decc; color: #216b50; background: #eff9f3; }
.expense-split-total.is-unmatched { border-color: #e8c2a2; color: #8a4b11; background: #fff8f1; }
.expense-split-rows { display: grid; gap: 8px; }
.expense-split-row { display: grid; grid-template-columns: minmax(0, 1fr) 32px; gap: 10px; align-items: start; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #fbfcfd; }
.expense-split-main { grid-column: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(110px, 180px); gap: 10px; }
.expense-split-details { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 10px; min-width: 0; }
.expense-split-row label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; }
.expense-split-row input, .expense-split-row select, .expense-split-row textarea { min-width: 0; padding: 8px; font-size: 13px; }
.expense-split-row .split-remarks { grid-column: 1 / -1; }
.expense-split-row .split-remove-row { grid-column: 2; grid-row: 1; margin-top: 20px; }
.single-expense-detail[hidden] { display: none !important; }
.expense-split-dialog { position: fixed; z-index: 10000; isolation: isolate; top: 50%; left: 50%; width: min(900px, calc(100vw - 32px)); max-width: calc(100vw - 32px); max-height: min(90vh, 900px); overflow: auto; transform: translate(-50%, -50%); border: 0; border-radius: 12px; padding: 20px; color: var(--text); background: #fff; box-shadow: 0 20px 70px rgba(0, 0, 0, .3); }
.expense-split-dialog[hidden] { display: none; }
.expense-split-dialog.is-open { display: block; }
.expense-split-dialog.is-open::before { position: fixed; z-index: -1; inset: 0; content: ""; background: rgba(15, 27, 40, .58); }
.expense-split-dialog .expense-split-fields { margin-top: 0; }
.expense-split-dialog .expense-split-row { grid-template-columns: minmax(0, 1fr) 32px; }
.expense-split-dialog .expense-split-details { grid-column: 1 / -1; }
.expense-split-dialog .split-dialog-done { margin-top: 12px; }
.split-edit-details { width: 100%; margin: 8px 0; }
.split-add-row { margin-top: 8px; padding: 7px 10px; font-size: 12px; }
.split-remove-row { width: 30px; height: 34px; border: 1px solid var(--line); border-radius: 7px; color: #a33; background: white; font-size: 18px; cursor: pointer; }
.calculator-toggle { position: fixed; z-index: 11000; bottom: max(20px, env(safe-area-inset-bottom)); left: max(20px, env(safe-area-inset-left)); width: 58px; height: 58px; border: 0; border-radius: 50%; color: #fff; background: var(--blue); box-shadow: 0 5px 18px rgba(23, 43, 77, .28); font: inherit; font-size: 13px; font-weight: 800; cursor: pointer; }
.calculator-toggle:hover { background: var(--blue-dark); }
.calculator-panel { position: fixed; z-index: 11001; bottom: max(90px, calc(env(safe-area-inset-bottom) + 70px)); left: max(16px, env(safe-area-inset-left)); display: grid; width: min(300px, calc(100vw - 32px)); gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 12px 40px rgba(23, 43, 77, .24); }
.calculator-panel[hidden] { display: none !important; }
.calculator-header { display: flex; align-items: center; justify-content: space-between; color: var(--navy); }
.calculator-close { width: 32px; height: 32px; border: 0; border-radius: 8px; color: var(--muted); background: #f2f4f6; font-size: 22px; cursor: pointer; }
.calculator-display { display: block; min-width: 0; overflow: hidden; padding: 14px 12px; border-radius: 9px; color: #fff; background: var(--navy); font-size: 27px; font-variant-numeric: tabular-nums; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.calculator-keys { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.calculator-keys button { min-width: 0; min-height: 46px; border: 1px solid #e7ebef; border-radius: 9px; color: var(--text); background: #f6f8fa; font: inherit; font-size: 17px; font-weight: 700; cursor: pointer; }
.calculator-keys button:hover { border-color: #b7cde0; background: #edf4fa; }
.calculator-keys [data-calculator-action="operator"] { color: var(--blue); background: #edf4fa; }
.calculator-keys .calculator-equals { color: #fff; background: var(--blue); }
.calculator-keys .calculator-equals:hover { background: var(--blue-dark); }
.calculator-keys .calculator-zero { grid-column: span 2; }
.calculator-panel button:focus-visible, .calculator-toggle:focus-visible { outline: 3px solid rgba(29, 95, 158, .3); outline-offset: 2px; }
.records-panel { min-width: 0; overflow: hidden; }
.records-heading { padding: 20px 22px 12px; margin: 0; }
.filters { display: grid; grid-template-columns: minmax(140px, 1fr) 130px 130px 145px 70px auto; gap: 8px; align-items: center; padding: 0 22px 16px; }
.filters input, .filters select { padding: 9px 10px; font-size: 13px; }
.clear-filter { font-size: 13px; color: var(--muted); }
.table-wrap {
    overflow-x: auto;
    border-top: 1px solid var(--line);
    -webkit-overflow-scrolling: touch;
}
table { width: 100%; min-width: 680px; border-collapse: collapse; }
th { padding: 12px 10px; color: var(--muted); background: #fafafa; font-size: 11px; text-align: left; text-transform: uppercase; letter-spacing: .05em; }
td { padding: 14px 10px; border-top: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
tbody tr:first-child td { border-top: 0; }
td strong { display: block; }
td small { display: block; margin-top: 3px; color: var(--muted); line-height: 1.35; }
.income-reimbursement-breakdown { display: block; width: 200px; max-width: 200px; min-width: 0; white-space: normal; overflow-wrap: anywhere; line-height: 1.4; font-size: 11px; font-weight: 600; text-align: right; }
.amount-cell { text-align: right; white-space: nowrap; font-weight: 800; }
.category { display: inline-block; border-radius: 999px; padding: 5px 8px; color: var(--blue-dark); background: #edf4fa; font-size: 12px; font-weight: 700; }
.delete-btn { width: 28px; height: 28px; border: 0; border-radius: 50%; color: #a5aaae; background: transparent; font-size: 20px; cursor: pointer; }
.delete-btn:hover { color: #b73a3a; background: #fff0f0; }
.edit-link { margin-right: 6px; color: var(--blue); font-size: 12px; font-weight: 800; text-decoration: none; }
.actions-cell { min-width: 86px; white-space: nowrap; }
.actions-cell form { display: inline-block; }
.edit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    margin-right: 6px;
    padding: 8px 13px;
    border: 1px solid #c8d9e8;
    border-radius: 8px;
    color: white;
    background: var(--blue);
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
    transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.edit-btn:hover { border-color: var(--blue-dark); background: var(--blue-dark); }
.edit-btn:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}
.edit-panel { margin-bottom: 18px; padding: 22px; }
.edit-panel .expense-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.wallet-edit { margin-top: 12px; }
.wallet-edit summary { color: var(--blue); font-size: 13px; font-weight: 800; cursor: pointer; }
.payment-edit { font-size: 12px; }
.payment-edit summary { color: var(--blue); font-weight: 800; cursor: pointer; }
.payment-edit-form { display: grid; grid-template-columns: repeat(2, minmax(120px, 1fr)); gap: 8px; margin-top: 10px; }
.payment-edit-form label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.payment-edit-form .btn { grid-column: 1 / -1; }
.empty { padding: 48px 12px; color: var(--muted); text-align: center; }
.income-value { color: var(--green) !important; }
.expense-value { color: #a54545 !important; }
.income-category { color: #216b50; background: #edf8f3; }
.master-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    align-items: start;
}
.master-grid-single { grid-template-columns: minmax(0, 1fr); }
.master-view-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: end;
    margin-bottom: 18px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: white;
}
.master-view-controls label { display: grid; flex: 0 1 200px; width: 200px; max-width: 100%; min-width: 0; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.master-view-controls input, .master-view-controls select { width: 100%; min-width: 0; padding: 9px 10px; font-size: 13px; }
.master-view-controls .master-global-search { flex-basis: 240px; width: 240px; }
.master-view-controls > .muted { padding-bottom: 10px; font-size: 12px; }
.reimbursement-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.reimbursement-total-card {
    display: grid;
    gap: 6px;
    padding: 14px 18px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: white;
}
.reimbursement-total-card > span { color: var(--muted); font-size: 13px; font-weight: 700; }
.reimbursement-total-card > span small { font-weight: 400; }
.reimbursement-total-card > strong { color: var(--navy); font-size: 22px; font-variant-numeric: tabular-nums; }
.reimbursement-total-card > small { color: var(--muted); font-size: 12px; }
.reimbursement-total-actions {
    display: flex;
    flex-wrap: wrap;
    grid-column: 1 / -1;
    gap: 8px;
    align-items: center;
}
.reimbursement-total-actions > small { color: var(--muted); font-size: 12px; }
.reimbursement-select-cell { width: 48px; text-align: center; }
.reimbursement-total-checkbox { width: 18px; height: 18px; accent-color: var(--blue); cursor: pointer; }
.share-clean-view .reimbursement-status, .share-clean-view .cashback-detail,
.share-clean-view .reimbursement-detail, .share-clean-view .remark-detail { display: none !important; }
.masterlist-export-status { flex-basis: 100%; }
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    padding: 12px 16px;
    color: var(--muted);
    font-size: 13px;
}
.pagination a, .pagination-disabled { padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--blue); text-decoration: none; }
.pagination-disabled { color: #a4abb2; }
.master-filter {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) repeat(2, 130px) 145px 70px auto;
    gap: 8px;
    align-items: center;
    padding: 0 16px 16px;
}
.master-filter input, .master-filter select { padding: 9px 10px; font-size: 13px; }
.wallet-summary-grid { grid-template-columns: repeat(4, 1fr); }
.wallet-layout {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}
.wallet-form-panel { position: sticky; top: 18px; }
.wallet-list-panel { overflow: hidden; }
.wallet-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 0 16px 16px;
}
.wallet-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    background: #fff;
}
.wallet-card-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}
.wallet-card-heading h3 { margin: 4px 0 8px; color: var(--navy); }
.wallet-card-heading strong { white-space: nowrap; font-size: 18px; }
.wallet-type {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}
.wallet-card p { margin: 6px 0; color: var(--muted); font-size: 13px; }
.wallet-remarks { overflow-wrap: anywhere; }
.wallet-adjust-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
    margin-top: 14px;
}
.wallet-adjust-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}
.wallet-adjust-form input { padding: 9px 10px; }
.wallet-adjust-form .btn { min-height: 42px; }
.wallet-delete-form { margin-top: 10px; text-align: right; }
.delete-wallet-btn {
    border: 0;
    padding: 6px;
    color: #a54545;
    background: transparent;
    font-size: 12px;
    cursor: pointer;
}
.wallet-empty { grid-column: 1 / -1; }
.loan-entry-panel { margin-bottom: 18px; }
.loan-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0 12px;
}
.loan-form label {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
    color: #4e5961;
    font-size: 13px;
    font-weight: 700;
}
.loan-form .full { grid-column: 1 / -1; }
.loan-records-panel { overflow: hidden; }
.loan-list { display: grid; gap: 12px; padding: 0 16px 16px; }
.loan-card { border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.loan-card-header { display: flex; justify-content: space-between; gap: 16px; }
.loan-card-header h3 { margin: 5px 0 3px; color: var(--navy); }
.loan-card-header p { margin: 0; color: var(--muted); font-size: 13px; }
.loan-direction {
    color: var(--blue);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}
.loan-direction.borrowed { color: #a54545; }
.loan-amount { display: grid; justify-items: end; gap: 5px; }
.loan-amount strong { font-size: 20px; }
.loan-status {
    border-radius: 999px;
    padding: 4px 8px;
    color: var(--blue-dark);
    background: #edf4fa;
    font-size: 11px;
    font-weight: 800;
}
.loan-status.paid { color: #216b50; background: #edf8f3; }
.loan-status.partial { color: #8a641d; background: #fff7df; }
.loan-status.overdue { color: #a54545; background: #fff0f0; }
.loan-meta {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin: 14px 0;
    padding: 10px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}
.payment-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
    gap: 8px;
    align-items: end;
    margin-bottom: 12px;
}
.payment-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}
.payment-form input, .payment-form select { padding: 9px 10px; }
.payment-history {
    margin-top: 10px;
    border-top: 1px solid var(--line);
    padding-top: 10px;
    font-size: 13px;
}
.payment-row {
    display: grid;
    grid-template-columns: 130px 1fr 100px 36px;
    gap: 8px;
    align-items: center;
    padding: 7px 0;
    color: var(--muted);
}
.payment-row strong { color: var(--text); text-align: right; }
.loan-remarks { color: var(--muted); font-size: 13px; }
.loan-delete-form { text-align: right; }

@media (max-width: 1100px) {
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
    .layout-grid { grid-template-columns: 1fr; }
    .forms-column, .records-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .master-grid { grid-template-columns: 1fr; }
    .master-filter { grid-template-columns: 1fr 130px 130px 145px 70px auto; }
    .filters { grid-template-columns: 1fr 130px 130px 145px 70px; }
    .wallet-layout { grid-template-columns: 320px minmax(0, 1fr); }
    .wallet-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
    .topbar {
        height: 60px;
        padding: env(safe-area-inset-top) 16px 0;
    }
    .content { padding: 20px 16px; }
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .summary-card { min-height: 105px; padding: 16px; }
    .summary-card strong { font-size: 21px; }
    .layout-grid { grid-template-columns: 1fr; }
    .forms-column, .records-column { grid-template-columns: 1fr; }
    .entry-layout { padding: 18px 16px; }
    .entry-tabs { width: 100%; }
    .entry-tab { flex: 1; min-width: 0; }
    .entry-tabs-bar { flex-wrap: wrap; }
    .statement-upload { grid-template-columns: 1fr; }
    .statement-progress { grid-column: 1; }
    .statement-panel, .statement-review { padding: 18px 16px; }
    .filters { grid-template-columns: 1fr 1fr; }
    .filters input:first-child { grid-column: 1 / -1; }
    .filters .btn { width: 100%; }
    .form-panel { padding: 18px 16px; }
    .master-filter { grid-template-columns: 1fr 1fr; padding: 0 16px 14px; }
    .master-filter input[type="search"] { grid-column: 1 / -1; }
    .master-filter .btn { width: 100%; }
    .master-view-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .master-view-controls label, .master-view-controls .master-global-search { width: auto; flex: initial; }
    .master-view-controls .master-global-search,
    .master-view-controls > .muted { grid-column: 1 / -1; }
    /* .reimbursement-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); } */
    .reimbursement-total-card { padding: 12px 14px; }
    .reimbursement-total-actions { grid-column: 1 / -1; }
    .wallet-layout { grid-template-columns: 1fr; }
    .wallet-form-panel { position: static; }
    .wallet-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .loan-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .loan-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .payment-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .clear-filter { text-align: center; }
    .records-heading { padding: 18px 16px 12px; }
    .filters { padding: 0 16px 14px; }
    .clear-filter { text-align: center; }
    .table-wrap { max-width: 100%; }
    .edit-panel .expense-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .expense-split-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
    .login-card { padding: 30px 22px; }
    .form-grid, .expense-form { grid-template-columns: 1fr; }
    .expense-form .full { grid-column: 1; }
    .edit-panel .expense-form { grid-template-columns: 1fr; }
    .filters { grid-template-columns: 1fr; }
    .filters input:first-child { grid-column: 1; }
    .topbar { padding-left: 12px; padding-right: 12px; }
    .brand { gap: 7px; font-size: 14px; }
    .brand-mark.small { width: 32px; height: 32px; }
    .brand > span:last-child { display: none; }
    .nav-links { gap: 0; }
    .nav-links a { padding: 9px 7px; font-size: 12px; }
    .nav-links a[href="statement_import.php"] { padding-right: 5px; padding-left: 5px; }
    .nav-links .logout { margin-left: 0; }
    .logout { padding: 10px 4px; font-size: 13px; }
    .content { padding: 14px 10px 28px; }
    .summary-grid { gap: 8px; }
    .summary-card { min-height: 94px; padding: 13px 12px; }
    .summary-card span { font-size: 12px; }
    .summary-card strong { font-size: 18px; overflow-wrap: anywhere; }
    .summary-card small { font-size: 11px; }
    .layout-grid, .forms-column, .records-column { gap: 10px; }
    .panel { border-radius: 10px; }
    .entry-layout { padding: 16px 12px; }
    .entry-tabs-bar { gap: 10px; }
    .entry-tabs-bar > .btn { flex: 1; text-align: center; }
    .statement-panel, .statement-review { padding: 16px 12px; }
    .form-panel { padding: 16px 12px; }
    .expense-form { gap: 0; }
    .expense-form label { margin-bottom: 12px; }
    .expense-form input, .expense-form select, .expense-form textarea {
        min-height: 48px;
    }
    .expense-form textarea { min-height: 84px; }
    .expense-split-row { grid-template-columns: minmax(0, 1fr) 28px; padding: 9px; }
    .expense-split-main { grid-template-columns: minmax(0, 1fr) minmax(90px, 130px); }
    .expense-split-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .expense-split-row .split-remarks { grid-column: 1; }
    .btn { min-height: 48px; }
    .records-heading { padding: 16px 12px 10px; }
    .filters { gap: 8px; padding: 0 12px 12px; }
    .master-view-controls { gap: 8px; margin-bottom: 12px; padding: 10px; }
    .master-view-controls label { gap: 4px; font-size: 11px; }
    .master-view-controls input, .master-view-controls select { padding: 8px; font-size: 12px; }
    .master-view-controls > .btn { min-height: 40px; }
    .master-view-controls > .muted { padding-bottom: 0; }
    .reimbursement-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        margin-bottom: 12px;
    }
    .reimbursement-total-card { min-width: 0; gap: 4px; padding: 8px 6px; }
    .reimbursement-total-card > span { font-size: 10px; line-height: 1.2; overflow-wrap: anywhere; }
    .reimbursement-total-card > strong { font-size: clamp(11px, 3.5vw, 15px); overflow-wrap: anywhere; }
    .reimbursement-total-card > small { font-size: 9px; line-height: 1.2; overflow-wrap: anywhere; }
    .reimbursement-total-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        width: 100%;
    }
    .reimbursement-total-actions .btn { min-width: 0; min-height: 40px; padding: 8px; font-size: 12px; }
    .reimbursement-total-actions label { min-width: 0; font-size: 11px; }
    .reimbursement-total-actions label select { width: 100%; min-width: 0; padding: 8px; font-size: 12px; }
    .reimbursement-total-actions > .btn-primary,
    .reimbursement-total-actions > small { grid-column: 1 / -1; }
    .master-filter { grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 12px 12px; }
    .master-filter input[type="search"] { grid-column: 1 / -1; }
    .master-filter input, .master-filter select { min-width: 0; padding: 8px; font-size: 12px; }
    .master-filter .btn { min-height: 40px; padding: 8px; font-size: 12px; }
    .wallet-summary-grid { grid-template-columns: 1fr; }
    .wallet-grid { grid-template-columns: 1fr; }
    .wallet-card-heading { align-items: flex-start; }
    .wallet-card-heading strong { font-size: 16px; }
    .loan-form { grid-template-columns: 1fr; }
    .loan-form .full { grid-column: 1; }
    .loan-card-header { flex-direction: column; }
    .loan-amount { justify-items: start; }
    .loan-meta { grid-template-columns: 1fr 1fr; }
    .payment-form { grid-template-columns: 1fr; }
    .payment-form .btn { width: 100%; }
    .payment-row { grid-template-columns: 1fr 1fr; }
    th, td { padding: 12px 9px; }
    .delete-btn {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }
    @media (max-width: 600px) {
        .expense-split-details { grid-template-columns: 1fr; }
    }
    table { min-width: 720px; }
}
