:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --ink: #1a2230;
    --muted: #6b7280;
    --line: #e6e9f0;
    --accent: #3b5bdb;
    --accent-ink: #ffffff;
    --pos: #15803d;
    --pos-bg: #e7f6ec;
    --neg: #c92a2a;
    --neg-bg: #fdecec;
    --shadow: 0 1px 2px rgba(16,24,40,.04), 0 6px 20px rgba(16,24,40,.06);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; padding: 16px 28px;
    background: var(--panel); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
    width: 40px; height: 40px; border-radius: 11px;
    display: grid; place-items: center; font-size: 20px;
    background: linear-gradient(135deg, var(--accent), #7048e8); color: #fff;
}
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -.2px; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.inline-form { display: inline; margin: 0; }

/* ---------- Buttons ---------- */
.btn {
    font: inherit; font-weight: 600; cursor: pointer;
    border-radius: 10px; padding: 9px 15px; border: 1px solid transparent;
    text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
    transition: transform .04s ease, background .15s ease, border-color .15s ease;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #34499d; }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: #c9cfdd; background: #fafbff; }
.btn.ghost.danger { color: var(--neg); }
.btn.ghost.danger:hover { background: var(--neg-bg); border-color: #f3c6c6; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }

/* ---------- Layout ---------- */
.wrap { max-width: none; margin: 0; padding: 16px 28px 48px; }
.panel {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 14px 16px; margin-bottom: 14px;
}
.panel-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { font-size: 15px; margin: 0; }

/* Two-column dashboard: summary cards (left) + filter & transactions (right) */
.layout { display: flex; gap: 14px; align-items: flex-start; }
.sidecards { flex: 0 0 232px; }
.sidecards .cards { flex-direction: column; flex-wrap: nowrap; gap: 10px; margin: 0; }
.sidecards .card { width: 100%; max-width: none; flex: 0 0 auto; }
.maincol { flex: 1 1 auto; min-width: 0; }   /* min-width:0 lets the table scroll inside */

@media (max-width: 900px) {
    .layout { flex-direction: column; }
    .sidecards { flex-basis: auto; width: 100%; }
    .sidecards .cards { flex-direction: row; flex-wrap: wrap; }
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }

/* ---------- Flash ---------- */
.flash {
    max-width: none; margin: 16px 28px 0; padding: 12px 44px 12px 16px;
    border-radius: 12px; position: relative; font-weight: 500;
}
.flash.success { background: var(--pos-bg); color: #166534; border: 1px solid #b7e4c7; }
.flash.error   { background: var(--neg-bg); color: #991b1b; border: 1px solid #f3c6c6; }
.flash-x { position: absolute; right: 14px; top: 12px; cursor: pointer; opacity: .6; }
.flash-x:hover { opacity: 1; }

/* ---------- Uploader ---------- */
.uploader { display: none; margin: 22px 0 0; max-width: none; padding: 0 28px; }
.uploader.open { display: block; }
.dropzone {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    text-align: center; padding: 34px 20px; cursor: pointer;
    background: var(--panel); border: 2px dashed #cdd4e6; border-radius: var(--radius);
    transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: #f6f8ff; }
.dz-icon { font-size: 28px; color: var(--accent); }
.dz-title { font-weight: 600; font-size: 15px; }
.dz-sub { font-size: 12.5px; color: var(--muted); }
.dz-file { font-size: 13px; color: var(--accent); font-weight: 600; margin-top: 4px; }
.uploader-actions { display: flex; gap: 10px; margin-top: 14px; }
.empty-hint { max-width: none; margin: 18px 0 0; padding: 0 28px; color: var(--muted); }

/* ---------- Summary cards ---------- */
.cards {
    display: flex; flex-wrap: wrap; justify-content: flex-start;
    gap: 12px; margin-bottom: 14px;
}
.card {
    flex: 1 1 150px; min-width: 140px; max-width: 220px;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 12px 14px;
}
.card-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 18px; font-weight: 700; margin: 3px 0 1px; letter-spacing: -.3px; }
.card-sub { font-size: 11px; color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- Chart ---------- */
.balance-chart { width: 100%; height: 220px; display: block; }
.balance-chart .grid { stroke: #eef0f5; stroke-width: 1; }
.balance-chart .axis { fill: #9aa1af; font-size: 11px; font-family: 'Inter', sans-serif; }
.chart-empty { color: var(--muted); padding: 20px 0; }

/* ---------- Filters (top of the transactions) ---------- */
.filters {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.filters > * { flex: 0 0 auto; }              /* controls keep their size */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg-btn {
    padding: 7px 11px; text-decoration: none; color: var(--ink);
    font-weight: 600; font-size: 12.5px; background: #fff; white-space: nowrap;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.active { background: var(--accent); color: #fff; }
.fld {
    font: inherit; font-size: 13px; padding: 7px 9px; border: 1px solid var(--line);
    border-radius: 9px; background: #fff; color: var(--ink);
}
.fld:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,91,219,.12); }
.fld.grow { flex: 1 1 150px; min-width: 130px; }   /* search box takes the slack */
.fld.sm { width: 80px; }
select.fld { max-width: 140px; }
.inline { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.inline .fld { min-width: 0; }

/* ---------- Table ---------- */
.table-scroll {
    overflow: auto;                 /* scroll inside the box (both axes) */
    max-height: 62vh;               /* the list scrolls here; the page does not */
    border: 1px solid var(--line);
    border-radius: 12px;
    overscroll-behavior: contain;   /* don't chain scroll to the whole page */
    scroll-behavior: smooth;        /* smooth scrolling within the list */
    -webkit-overflow-scrolling: touch; /* momentum scrolling on iOS */
}
.table-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.table-scroll::-webkit-scrollbar-thumb { background: #cdd4e6; border-radius: 8px; border: 2px solid #fff; }
.table-scroll::-webkit-scrollbar-thumb:hover { background: #b6bfd6; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
table { width: 100%; border-collapse: collapse; }
table.txn { font-size: 13px; }
.txn th, .txn td { padding: 8px 12px; text-align: left; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
.txn thead th {
    position: sticky; top: 0; background: #fbfcfe; z-index: 2;
    font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 0 var(--line);
}
.txn tbody tr:hover { background: #f8faff; }
.txn .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-date { white-space: nowrap; }
.col-act { width: 74px; white-space: nowrap; text-align: right; }
.sortlink { color: inherit; text-decoration: none; }
.sortlink:hover { color: var(--accent); }

/* Accounting-style cell badges (like the reference layout) */
.badge-date {
    display: inline-block; background: #eaf1ff; color: #2c53c9; font-weight: 600;
    font-size: 12px; padding: 4px 8px; border-radius: 7px; white-space: nowrap;
}
.vendor { font-weight: 700; font-size: 13.5px; color: #1f2937; }
.badge-amt {
    display: inline-block; font-weight: 700; font-size: 12.5px; padding: 4px 9px;
    border-radius: 7px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.badge-amt.in  { background: var(--pos-bg); color: var(--pos); }   /* credit */
.badge-amt.out { background: var(--neg-bg); color: var(--neg); }   /* debit  */
.chip.cat {
    display: inline-block; background: #eef0fb; color: #4b3fb0; font-weight: 600;
    font-size: 11.5px; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.cell-type {
    font-size: 11.5px; color: #5566d6; white-space: nowrap; letter-spacing: .02em;
    font-family: ui-monospace, Menlo, Consolas, monospace;
}
.bal { color: #6b7280; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-desc { max-width: 380px; }

.pill {
    display: inline-block; font-weight: 700; font-size: 11px; letter-spacing: .03em;
    padding: 3px 8px; border-radius: 999px;
}
.pill.dr { background: var(--neg-bg); color: var(--neg); }
.pill.cr { background: var(--pos-bg); color: var(--pos); }
.desc-main { font-weight: 600; }
.desc-toggle {
    background: none; border: none; color: var(--accent); font: inherit; font-size: 11.5px;
    padding: 1px 0 0; cursor: pointer;
}
.desc-full {
    display: none; margin-top: 6px; font-size: 12px; color: #3a4152;
    background: #f6f7fb; border: 1px solid var(--line); border-radius: 8px;
    padding: 8px 10px; font-family: ui-monospace, Menlo, Consolas, monospace;
    white-space: pre-wrap; word-break: break-word; max-width: 560px;
}
.desc-full.show { display: block; }

.icon-btn {
    display: inline-grid; place-items: center; width: 27px; height: 27px;
    border-radius: 8px; border: 1px solid var(--line); text-decoration: none;
    color: var(--ink); font-size: 13px; background: #fff; margin-left: 4px;
    transition: background .12s ease, border-color .12s ease;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); background: #f6f8ff; }
.icon-btn.danger:hover { border-color: var(--neg); color: var(--neg); background: var(--neg-bg); }

.empty-row { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- Pager ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; gap: 12px; flex-wrap: wrap; }
.pager-btns { display: flex; gap: 6px; }

/* ---------- Statements table ---------- */
.stmts th, .stmts td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.stmts thead th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }

/* ---------- Footer ---------- */
.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 24px; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) { .cards { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px) {
    .cards { grid-template-columns: repeat(2, 1fr); }
    .topbar { padding: 14px 16px; }
    .wrap { padding: 18px 14px 50px; }
    .brand p { display: none; }
}