/* ==========================================================================
   My Money Tracker — app.css
   Same design language as the other freehosting.nz trackers: cream paper,
   deep forest accent, quiet card surfaces. Mobile friendly throughout.
   ========================================================================== */

:root {
    --paper:        #fafaf6;
    --card:         #ffffff;
    --ink:          #1a1d24;
    --ink-soft:     #5d6470;
    --ink-faint:    #9b9588;
    --rule:         #d8d4c8;
    --rule-soft:    #ece8dc;
    --accent:       #1e5538;
    --accent-soft:  #e7f0eb;
    --accent-hover: #163e29;
    --danger:       #a83232;
    --danger-soft:  #f7ecec;
    --warn:         #b86b0a;
    --shadow:       0 1px 0 rgba(20,24,31,.04), 0 0 0 1px var(--rule-soft);
    --radius:       8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: 12.5px; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.neg { color: var(--danger); }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    background: var(--card);
    border-bottom: 1px solid var(--rule-soft);
    flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand .mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 7px;
    background: var(--accent); color: #fff; font-weight: 700;
}
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.topnav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topnav a { color: var(--ink-soft); font-weight: 500; }
.topnav a:hover { color: var(--accent); text-decoration: none; }
.who { color: var(--ink-faint); }
.who.mono { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demo-badge {
    background: var(--warn); color: #fff; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px;
}

/* ── Footer (centered, matching v1) ──────────────────────────────────── */
.bot {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 32px 48px;
    font-size: 13px;
    color: var(--ink-faint);
    display: flex;
    justify-content: center;
    gap: 8px;
    border-top: 1px solid var(--rule-soft);
}
.bot a { color: var(--ink-soft); }

/* ── Page shell ──────────────────────────────────────────────────────── */
.page { max-width: 880px; margin: 0 auto; padding: 28px 24px 72px; }
.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 20px; margin-bottom: 24px; flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 4px; font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.page-head p { margin: 0; max-width: 60ch; }

/* ── Flash messages ──────────────────────────────────────────────────── */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; font-size: 14px; }
.flash-ok   { background: var(--accent-soft); color: var(--accent-hover); }
.flash-err  { background: var(--danger-soft); color: var(--danger); }
.flash-info { background: #eef2f7; color: #33506b; }

/* ── Account list ────────────────────────────────────────────────────── */
.add-account-bar { margin-bottom: 16px; }

.acct-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 28px; }
.acct-wrap { }

.acct {
    background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius);
    padding: 16px 20px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; cursor: pointer;
}
.acct:hover { box-shadow: 0 1px 0 rgba(20,24,31,.04), 0 0 0 1px var(--rule); }
.js-acct-head:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.acct-main { display: flex; align-items: center; gap: 32px; flex: 1; min-width: 0; }
.acct-id { display: flex; flex-direction: column; min-width: 190px; }
.acct-name { font-weight: 600; }
.acct-type { color: var(--ink-faint); font-size: 12.5px; }

/* Figures laid out as fixed columns so they line up down the list, whatever
   each account's numbers are. Each figure is a right-aligned fixed-width
   cell with the label above the value. */
.acct-figs { display: flex; gap: 0; margin-left: auto; }
.fig {
    display: flex; flex-direction: column; align-items: flex-end;
    width: 120px; padding: 0 8px;
}
.fig small { color: var(--ink-faint); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.fig b { font-weight: 600; font-variant-numeric: tabular-nums; }
.fig b.neg { color: var(--danger); }
.card-figs .fig:first-child b { color: var(--danger); }

.acct-actions { display: flex; align-items: center; gap: 8px; }
.tag-empty {
    font-size: 11.5px; color: var(--warn); background: #fbf1e2;
    padding: 3px 9px; border-radius: 999px; font-weight: 600;
}

/* Inline edit box under an account. */
.acct-edit {
    background: var(--card); box-shadow: var(--shadow);
    border-radius: 0 0 var(--radius) var(--radius);
    margin-top: -6px; padding: 20px 24px 24px;
    border-top: 1px solid var(--rule-soft);
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn-primary, .btn-ghost, .btn-small, .btn-danger, .btn-signin, button[type=submit] {
    display: inline-block; padding: 9px 18px; font: inherit; font-weight: 600;
    border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
    text-align: center; line-height: 1.3;
}
.btn-primary, .btn-signin, button[type=submit] { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover, .btn-signin:hover, button[type=submit]:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--rule); }
.btn-ghost:hover { border-color: var(--ink-soft); text-decoration: none; }
.btn-danger { background: var(--card); color: var(--danger); border-color: #e6c9c9; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); text-decoration: none; }
.btn-small { padding: 6px 12px; font-size: 13px; }
.inline { display: inline; margin: 0; }

/* ── Cards & forms ───────────────────────────────────────────────────── */
.card { background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); padding: 28px; }
.card.narrow { max-width: 520px; }
.form-card { margin-top: 8px; }
.card h2 { margin: 0 0 18px; font-size: 18px; font-weight: 600; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13.5px; }
.stack label span { color: var(--ink-soft); }
.stack input, .stack select {
    font: inherit; padding: 10px 12px; border: 1px solid var(--rule);
    border-radius: var(--radius); background: #fff; color: var(--ink); font-weight: 400;
}
.stack input:focus, .stack select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { color: var(--ink-faint); font-weight: 400; }
.field-row { display: flex; gap: 16px; }
.field-row label { flex: 1; }
.form-actions { display: flex; gap: 12px; align-items: center; margin-top: 4px; }
.add-more { margin-top: 20px; }
.form-actions-split { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.form-actions-split .fa-left { display: flex; gap: 12px; align-items: center; }
.form-actions-split .fa-right { margin-left: auto; }

/* ── Mobile ──────────────────────────────────────────────────────────── */
@media (max-width: 620px) {
    .top { padding: 14px 16px; }
    .page { padding: 22px 16px 60px; }
    .who.mono { display: none; }
    .acct { align-items: flex-start; flex-direction: column; }
    .acct-main { gap: 12px; flex-direction: column; align-items: stretch; }
    .acct-id { min-width: 0; }
    .acct-figs { margin-left: 0; }
    .fig { width: auto; flex: 1; align-items: flex-start; padding: 0; }
    .acct-actions { width: 100%; }
    .acct-actions .btn-small { flex: 1; }
    .form-actions-split { flex-direction: column; align-items: stretch; }
    .form-actions-split .fa-left { justify-content: space-between; }
    .form-actions-split .fa-right { margin-left: 0; }
    .form-actions-split .fa-right .btn-danger { width: 100%; }
    .field-row { flex-direction: column; gap: 16px; }
    .page-head { flex-direction: column; }
}

/* ── Landing page ────────────────────────────────────────────────────── */
.landing-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.btn-lg { padding: 12px 26px; font-size: 16px; }
.landing-note { margin: 0 0 28px; max-width: 60ch; }
.start-steps { background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); padding: 24px 28px; }
.start-steps h2 { margin: 0 0 12px; font-size: 17px; }
.start-steps ol { margin: 0; padding-left: 20px; }
.start-steps li { margin-bottom: 8px; color: var(--ink-soft); }
.start-steps strong { color: var(--ink); }

/* ── Upload: column mapping ──────────────────────────────────────────── */
.map-form { max-width: 560px; }
.amount-modes { border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px; margin: 0; }
.amount-modes legend { padding: 0 6px; font-weight: 600; font-size: 13.5px; color: var(--ink-soft); }
.radio { flex-direction: row !important; align-items: center; gap: 10px !important; font-weight: 500 !important; }
.radio input { width: auto; }
.mode-body { margin: 8px 0 14px 28px; }
.mode-body label { margin-bottom: 0; }

.table-scroll { overflow-x: auto; margin-top: 8px; }
table.preview { border-collapse: collapse; font-size: 12.5px; width: 100%; }
table.preview th, table.preview td {
    border: 1px solid var(--rule-soft); padding: 6px 10px; text-align: left; white-space: nowrap;
}
table.preview th { background: var(--paper); font-weight: 600; }



/* ── Processing ──────────────────────────────────────────────────────── */
.proc-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.acct-picker { display: flex; align-items: center; gap: 8px; }
.acct-picker select {
    font: inherit; padding: 8px 12px; border: 1px solid var(--rule);
    border-radius: var(--radius); background: #fff; font-weight: 600; min-width: 220px;
}
.acct-picker select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.cols-panel { background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 16px; }
.cols-panel p { margin: 0 0 10px; }
.col-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.col-chip { position: relative; }
.col-chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.col-chip span {
    display: inline-block; padding: 5px 12px; border: 1px solid var(--rule);
    border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.col-chip input:checked + span { background: var(--accent-soft); color: var(--accent-hover); border-color: #bcd9c9; }

.remap-row { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--rule-soft); }
.remap-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.remap-form select { padding: 6px 10px; border: 1px solid var(--rule); border-radius: var(--radius); font: inherit; font-size: 13px; }
.proc-form { background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); padding: 20px 24px; }
.proc-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.proc-table th { text-align: left; color: var(--ink-faint); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 6px 10px; border-bottom: 1px solid var(--rule-soft); }
.proc-table td { padding: 9px 10px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
.proc-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.proc-table .pos { color: var(--accent); }
.type-col { white-space: nowrap; }

/* Type dropdown, tinted by its current value. */
.type-select {
    font: inherit; font-weight: 600; font-size: 13px; padding: 6px 10px;
    border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; color: var(--ink-soft);
}
.type-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.type-select.type-income   { background: var(--accent-soft); color: var(--accent-hover); border-color: #bcd9c9; }
.type-select.type-expense  { background: var(--danger-soft); color: var(--danger); border-color: #e6c9c9; }
.type-select.type-transfer { background: #eef2f7; color: #33506b; border-color: #cdd9e6; }

.proc-actions { margin-top: 16px; }

@media (max-width: 620px) {
    .proc-table thead { display: none; }
    .proc-table, .proc-table tbody, .proc-table tr, .proc-table td { display: block; width: 100%; }
    .proc-table tr { border: 1px solid var(--rule-soft); border-radius: var(--radius); margin-bottom: 12px; padding: 6px 10px; }
    .proc-table td { border: 0; padding: 4px 0; }
    .proc-table .num { text-align: left; font-size: 16px; font-weight: 600; }
    .type-select { width: 100%; margin-top: 6px; }
    .acct-picker select { min-width: 0; flex: 1; }
}

/* ── Fix-descriptions banner ─────────────────────────────────────────── */
.fix-banner {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    background: #fbf1e2; border: 1px solid #f0d9a8; border-radius: var(--radius);
    padding: 14px 18px; margin-bottom: 16px; flex-wrap: wrap;
}
.fix-banner strong { display: block; color: #8a5800; margin-bottom: 2px; }
.fix-banner .btn-primary { white-space: nowrap; }

.desc-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 620px) {
    .fix-banner { flex-direction: column; align-items: stretch; }
    .desc-cell { max-width: none; white-space: normal; }
}

/* ── Page head actions (Breakdown / Dashboard buttons) ───────────────── */
.page-head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Breakdowns (categories) ─────────────────────────────────────────── */
.bd-typebar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.bd-typebar select {
    font: inherit; font-weight: 600; padding: 8px 12px; border: 1px solid var(--rule);
    border-radius: var(--radius); background: #fff; min-width: 220px;
}
.bd-typebar select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.bd-box { max-width: 640px; }
.bd-box h2 { margin: 0 0 14px; font-size: 17px; font-weight: 600; }

.bd-add-top { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--rule-soft); }
.bd-add-top input { flex: 1; padding: 9px 12px; border: 1px solid var(--rule); border-radius: var(--radius); font: inherit; }
.bd-add-top input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.bd-empty { margin: 4px 0 0; }

.bd-list { display: flex; flex-direction: column; gap: 8px; }
.bd-wrap { border: 1px solid var(--rule-soft); border-radius: var(--radius); overflow: hidden; }
.bd-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 16px; cursor: pointer; background: var(--paper);
}
.bd-head:hover { background: #f3f0e7; }
.js-bd-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.bd-name { font-weight: 600; }
.bd-meta { display: flex; align-items: center; gap: 12px; color: var(--ink-faint); font-size: 12.5px; }
.bd-chevron { font-size: 18px; transition: transform .15s ease; display: inline-block; }
.bd-head.open .bd-chevron { transform: rotate(90deg); }

.bd-body { padding: 12px 16px 16px; background: #fff; border-top: 1px solid var(--rule-soft); }
.bd-edit { margin-bottom: 10px; }
.bd-edit-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.bd-edit-form input[type=text] { flex: 1; min-width: 120px; padding: 7px 10px; border: 1px solid var(--rule); border-radius: var(--radius); font: inherit; }
.bd-edit-form select { padding: 7px 8px; border: 1px solid var(--rule); border-radius: var(--radius); font: inherit; }
.bd-edit-form .bd-del { margin-left: auto; }

.bd-sublist { margin: 0 0 10px 14px; padding-left: 12px; border-left: 2px solid var(--rule-soft); display: flex; flex-direction: column; gap: 8px; }
.bd-sub-edit .bd-edit { margin-bottom: 0; }
.bd-sub-edit .bd-edit-form input[type=text] { font-size: 13px; }

.bd-add-sub { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.bd-add-sub input { flex: 1; padding: 7px 10px; border: 1px solid var(--rule); border-radius: var(--radius); font: inherit; font-size: 13px; }
.bd-add-sub input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

@media (max-width: 620px) {
    .bd-typebar select { min-width: 0; flex: 1; }
    .bd-edit-form .bd-del { margin-left: 0; width: 100%; }
}

/* ── Categorize (transaction breakdown) ──────────────────────────────── */
.cat-toolbar { display: flex; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

.cat-list { display: flex; flex-direction: column; gap: 12px; }
.cat-card { background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); padding: 16px 18px; }
.cat-txinfo { display: flex; align-items: baseline; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.cat-date { color: var(--ink-faint); font-size: 12.5px; white-space: nowrap; }
.cat-desc { font-weight: 600; flex: 1; min-width: 0; }
.cat-amt { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.cat-amt.pos { color: var(--accent); }

.split-lines { display: flex; flex-direction: column; gap: 8px; }
.split-line { display: flex; gap: 8px; align-items: center; }
.split-cat { flex: 1; padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius); font: inherit; background: #fff; min-width: 0; }
.split-amt { width: 120px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius); font: inherit; text-align: right; font-variant-numeric: tabular-nums; }
.split-cat:focus, .split-amt:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.split-remove {
    width: 30px; height: 30px; border: 1px solid var(--rule); border-radius: var(--radius);
    background: #fff; color: var(--ink-soft); font-size: 18px; line-height: 1; cursor: pointer; flex-shrink: 0;
}
.split-remove:hover { border-color: var(--danger); color: var(--danger); }

.cat-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.split-remaining { margin-left: auto; font-weight: 600; }
.split-remaining.ok { color: var(--accent-hover); }
.split-remaining.warn { color: var(--warn); }
.split-remaining.over { color: var(--danger); }
.js-cat-save[disabled] { opacity: .5; cursor: not-allowed; }

@media (max-width: 620px) {
    .cat-toolbar { flex-direction: column; gap: 10px; }
    .cat-toolbar .acct-picker select { min-width: 0; flex: 1; }
    .split-amt { width: 100px; }
    .cat-foot { flex-wrap: wrap; }
    .split-remaining { margin-left: 0; width: 100%; order: -1; }
}
