/* ═══════════════════════════════════════════════
   Finance Planner · style.css
   Dark theme — refined industrial/utilitarian
   Google Fonts: DM Sans + DM Mono
═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── Reset ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ────────────────────────────────── */
:root {
    /* backgrounds */
    --bg:        #0a0a0b;
    --surface:   #111113;
    --surface2:  #1a1a1e;
    --surface3:  #222228;
    --overlay:   rgba(0,0,0,.72);

    /* borders */
    --border:    #252529;
    --border2:   #2e2e34;

    /* accent */
    --accent:    #4f9cf9;
    --accent2:   #2e7de9;
    --accent-bg: rgba(79,156,249,.10);

    /* semantic */
    --green:     #3dd68c;
    --green-bg:  rgba(61,214,140,.10);
    --red:       #f87171;
    --red-bg:    rgba(248,113,113,.10);
    --amber:     #fbbf24;
    --amber-bg:  rgba(251,191,36,.10);

    /* text */
    --text:      #f2f2f7;
    --text-dim:  #aeaebe;
    --text-muted:#6e6e82;

    /* layout */
    --nav-h:     58px;
    --topbar-h:  54px;
    --radius:    14px;
    --radius-sm: 9px;
    --radius-xs: 6px;

    /* type */
    --font:  'DM Sans', system-ui, sans-serif;
    --mono:  'DM Mono', 'SF Mono', monospace;

    /* transitions */
    --t: .18s cubic-bezier(.4,0,.2,1);
}

/* ── Base ──────────────────────────────────── */
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: calc(var(--nav-h) + 16px);
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font-family: inherit; }

/* ── Top bar ───────────────────────────────── */
.topbar {
    position: sticky; top: 0; z-index: 200;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.topbar-title {
    font-size: .92rem; font-weight: 600;
    letter-spacing: .01em; color: var(--text);
}
.topbar-avatar {
    position: absolute; left: 14px;
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: .78rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    text-decoration: none;
    transition: opacity var(--t);
    user-select: none;
    flex-shrink: 0;
}
.topbar-avatar:hover { opacity: .82; }
.topbar-action {
    position: absolute; right: 12px;
    width: 34px; height: 34px;
    background: var(--accent);
    border: none; color: #fff;
    border-radius: 50%;
    font-size: 1.4rem; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: opacity var(--t), transform var(--t);
}
.topbar-action:hover  { opacity: .88; }
.topbar-action:active { transform: scale(.92); }

/* ── Bottom nav ────────────────────────────── */
.nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex; z-index: 200;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.nav a {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    color: var(--text-muted); font-size: .58rem;
    letter-spacing: .05em; text-transform: uppercase;
    font-weight: 500;
    transition: color var(--t);
    -webkit-tap-highlight-color: transparent;
}
.nav a.active { color: var(--accent); }
.nav a svg {
    width: 20px; height: 20px;
    fill: none; stroke: currentColor; stroke-width: 1.75;
    stroke-linecap: round; stroke-linejoin: round;
}

/* ── Page ──────────────────────────────────── */
.page { max-width: 860px; margin: 0 auto; padding: 16px 13px; }

/* ── Section label ─────────────────────────── */
.section-label {
    font-size: .62rem; font-weight: 600;
    letter-spacing: .12em; text-transform: uppercase;
    color: var(--text-muted);
    margin: 22px 0 7px 2px;
}
.section-label:first-child { margin-top: 8px; }

/* ── Card ──────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.card-row {
    display: flex; align-items: center;
    padding: 13px 15px;
    border-bottom: 1px solid var(--border);
    gap: 11px;
    transition: background var(--t);
}
.card-row:last-child { border-bottom: none; }
.card-row:hover { background: var(--surface2); }

/* ── Row parts ─────────────────────────────── */
.row-icon {
    width: 36px; height: 36px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; flex-shrink: 0;
    background: var(--surface2);
}
.row-label { font-size: .88rem; font-weight: 500; }
.row-sub   { font-size: .72rem; color: var(--text-dim); margin-top: 1px; }
.row-amount {
    font-family: var(--mono); font-size: .85rem;
    font-weight: 500; white-space: nowrap;
    text-align: right;
}
.row-amount.income  { color: var(--green); }
.row-amount.expense { color: var(--red); }

/* ── Icon buttons (edit / delete) ──────────── */
.icon-btn {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer;
    width: 32px; height: 32px;
    border-radius: var(--radius-xs);
    display: flex; align-items: center; justify-content: center;
    font-size: .95rem; flex-shrink: 0;
    transition: color var(--t), background var(--t);
}
.icon-btn:hover         { color: var(--text); background: var(--surface3); }
.icon-btn.danger:hover  { color: var(--red);  background: var(--red-bg); }
.icon-btn.edit:hover    { color: var(--accent); background: var(--accent-bg); }

/* ── Buttons ───────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: .84rem; font-weight: 600; cursor: pointer;
    border: none; transition: opacity var(--t), transform var(--t);
    white-space: nowrap;
}
.btn:active { transform: scale(.96); }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .88; }
.btn-ghost {
    background: var(--surface2); color: var(--text);
    border: 1px solid var(--border2);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid rgba(248,113,113,.2); }
.btn-danger:hover { background: rgba(248,113,113,.18); }
.btn-sm   { padding: 6px 12px; font-size: .78rem; }
.btn-full { width: 100%; }

/* ── Summary chips ─────────────────────────── */
.chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-bottom: 14px;
}
.chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 14px 12px;
}
.chip-label { font-size: .6rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 5px; }
.chip-val   { font-family: var(--mono); font-size: 1.1rem; font-weight: 500; }
.chip-val.income  { color: var(--green); }
.chip-val.expense { color: var(--red); }
.chip-val.neutral { color: var(--text); }

/* ── Chart ─────────────────────────────────── */
.chart-wrap {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
    margin-bottom: 4px;
}
.chart-title {
    font-size: .62rem; font-weight: 600;
    letter-spacing: .1em; text-transform: uppercase;
    color: var(--text-muted); margin-bottom: 14px;
}
canvas { width: 100% !important; display: block; }

/* ── Progress bar ──────────────────────────── */
.progress-bar {
    height: 5px; border-radius: 99px;
    background: var(--surface3);
    overflow: hidden; margin-top: 6px;
}
.progress-fill {
    height: 100%; border-radius: 99px;
    background: var(--accent);
    transition: width .5s cubic-bezier(.4,0,.2,1);
}
.progress-fill.red    { background: var(--red); }
.progress-fill.amber  { background: var(--amber); }
.progress-fill.green  { background: var(--green); }

/* ── Modal / drawer ────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 400;
    background: var(--overlay);
    display: flex; align-items: flex-end;
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    border-top: 1px solid var(--border2);
    width: 100%; max-height: 92vh; overflow-y: auto;
    padding: 6px 17px 36px;
    transform: translateY(100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.modal-backdrop.open .modal { transform: translateY(0); }

/* drag handle */
.modal-handle {
    width: 36px; height: 4px; border-radius: 2px;
    background: var(--border2); margin: 10px auto 16px;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 18px;
}
.modal-header h2 { font-size: .98rem; font-weight: 600; }
.modal-close {
    background: var(--surface3); border: none; color: var(--text-dim);
    border-radius: 50%; width: 28px; height: 28px;
    font-size: .85rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--t);
}
.modal-close:hover { background: var(--border2); }

/* ── Forms ─────────────────────────────────── */
.form-group { margin-bottom: 13px; }
.form-group label {
    display: block; font-size: .73rem; font-weight: 500;
    color: var(--text-dim); margin-bottom: 5px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%; padding: 10px 12px;
    background: var(--surface2); border: 1px solid var(--border2);
    border-radius: var(--radius-sm); color: var(--text);
    font-family: var(--font); font-size: .88rem;
    transition: border-color var(--t), box-shadow var(--t);
    -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}
.form-group input::placeholder { color: var(--text-muted); }
.form-group textarea { resize: vertical; min-height: 72px; }
.form-group select { cursor: pointer; }

/* ── Toggle row ────────────────────────────── */
.toggle-row {
    display: flex; margin-bottom: 14px;
    background: var(--surface2); border-radius: var(--radius-sm);
    border: 1px solid var(--border2); overflow: hidden;
    padding: 3px;
    gap: 3px;
}
.toggle-row button {
    flex: 1; padding: 8px; border: none; background: none;
    color: var(--text-dim); font-size: .82rem; font-weight: 500;
    cursor: pointer; border-radius: var(--radius-xs);
    transition: background var(--t), color var(--t);
}
.toggle-row button.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.toggle-row button.active.income  { color: var(--green); }
.toggle-row button.active.expense { color: var(--red); }

/* ── Badges ────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 99px;
    font-size: .64rem; font-weight: 600; letter-spacing: .03em;
    vertical-align: middle;
}
.badge-blue    { background: var(--accent-bg); color: var(--accent); }
.badge-green   { background: var(--green-bg);  color: var(--green); }
.badge-red     { background: var(--red-bg);    color: var(--red); }
.badge-amber   { background: var(--amber-bg);  color: var(--amber); }
.badge-muted   { background: var(--surface3);  color: var(--text-dim); }

/* ── Account badge ─────────────────────────── */
.acct-dot {
    display: inline-flex; align-items: center;
    gap: 5px; padding: 3px 10px 3px 5px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 99px; font-size: .78rem; color: var(--text-dim);
}
.acct-dot::before {
    content: ''; width: 7px; height: 7px;
    border-radius: 50%; background: var(--accent);
    display: inline-block;
}

/* ── Search / filter bar ───────────────────── */
.filter-bar {
    display: flex; gap: 8px; margin-bottom: 12px;
}
.filter-bar input {
    flex: 1; padding: 9px 12px;
    background: var(--surface); border: 1px solid var(--border2);
    border-radius: var(--radius-sm); color: var(--text);
    font-size: .85rem;
    transition: border-color var(--t);
}
.filter-bar input:focus { outline: none; border-color: var(--accent); }
.filter-bar input::placeholder { color: var(--text-muted); }
.filter-bar select {
    padding: 9px 10px; background: var(--surface);
    border: 1px solid var(--border2); border-radius: var(--radius-sm);
    color: var(--text-dim); font-size: .82rem; cursor: pointer;
    -webkit-appearance: none;
}

/* ── Totals strip ──────────────────────────── */
.totals-strip {
    display: flex; gap: 8px; margin-bottom: 10px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 14px;
    font-size: .78rem;
}
.totals-strip span { color: var(--text-dim); }
.totals-strip b { font-family: var(--mono); }
.totals-strip .in  { color: var(--green); }
.totals-strip .out { color: var(--red); }

/* ── Empty state ───────────────────────────── */
.empty {
    text-align: center; padding: 48px 20px;
    color: var(--text-muted);
}
.empty-icon { font-size: 2.4rem; margin-bottom: 10px; }
.empty p { font-size: .83rem; line-height: 1.7; }

/* ── Alerts ────────────────────────────────── */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 13px; font-size: .84rem; }
.alert-ok  { background: var(--green-bg); color: var(--green); border: 1px solid rgba(61,214,140,.2); }
.alert-err { background: var(--red-bg);   color: var(--red);   border: 1px solid rgba(248,113,113,.2); }
.alert-info{ background: var(--accent-bg);color: var(--accent); border: 1px solid rgba(79,156,249,.2); }

/* ── Auth pages ────────────────────────────── */
.auth-wrap {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 24px;
}
.auth-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 36px 28px;
    max-width: 380px; width: 100%;
}
.auth-logo { font-size: 2.4rem; text-align: center; margin-bottom: 10px; }
.auth-card h1 { font-size: 1.2rem; text-align: center; margin-bottom: 5px; font-weight: 600; }
.auth-sub  { color: var(--text-dim); font-size: .8rem; text-align: center; margin-bottom: 24px; }
.auth-footer { color: var(--text-muted); font-size: .8rem; text-align: center; margin-top: 16px; }
.auth-footer a { color: var(--accent); }
.auth-hint { color: var(--text-muted); font-size: .75rem; text-align: center; margin-top: 10px; }
.auth-hint code { background: var(--surface2); padding: 1px 5px; border-radius: 4px; color: var(--accent); }
.field-hint { font-size: .7rem; color: var(--text-muted); margin-top: 3px; }

/* ── Password strength ─────────────────────── */
.pw-strength { height: 3px; border-radius: 99px; margin-top: 6px; background: var(--surface3); overflow: hidden; }
.pw-strength-fill { height: 100%; border-radius: 99px; transition: width .3s, background .3s; }

/* ── TOTP / 2FA ────────────────────────────── */
.totp-code-input {
    display: flex; gap: 8px; justify-content: center;
    margin: 20px 0;
}
.totp-digit {
    width: 44px; height: 56px;
    background: var(--surface2); border: 2px solid var(--border2);
    border-radius: var(--radius-sm);
    font-size: 1.5rem; font-family: var(--mono);
    text-align: center; color: var(--text);
    transition: border-color var(--t);
}
.totp-digit:focus { outline: none; border-color: var(--accent); }

/* ── QR code placeholder ───────────────────── */
.qr-box {
    background: #fff; border-radius: var(--radius-sm);
    padding: 10px; display: inline-block;
    margin: 14px auto; display: block; width: fit-content;
}
.qr-box canvas, .qr-box img { display: block; }

/* ── Backup codes ──────────────────────────── */
.backup-codes {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 6px; margin: 14px 0;
}
.backup-code {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 8px 10px;
    font-family: var(--mono); font-size: .82rem;
    text-align: center; letter-spacing: .08em;
    color: var(--text-dim);
}
.backup-code.used {
    text-decoration: line-through; opacity: .4;
}

/* ── Tabs (settings) ───────────────────────── */
.tab-bar {
    display: flex; border-bottom: 1px solid var(--border);
    margin-bottom: 18px; gap: 2px;
}
.tab-btn {
    padding: 10px 14px; background: none; border: none;
    color: var(--text-muted); font-size: .82rem; font-weight: 500;
    cursor: pointer; border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--t), border-color var(--t);
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Import / QIF ──────────────────────────── */
.import-row {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
    font-size: .82rem;
}
.import-row:last-child { border-bottom: none; }
.import-row input[type=checkbox] {
    width: 16px; height: 16px; accent-color: var(--accent);
    cursor: pointer; flex-shrink: 0;
}
.import-skip { opacity: .45; text-decoration: line-through; }

/* ── Activity log ──────────────────────────── */
.log-row {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 11px 15px; border-bottom: 1px solid var(--border);
    font-size: .8rem;
}
.log-row:last-child { border-bottom: none; }
.log-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-muted); flex-shrink: 0; margin-top: 4px;
}
.log-dot.success { background: var(--green); }
.log-dot.fail    { background: var(--red); }

/* ── Install / Admin ───────────────────────── */
.install-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.install-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 36px 28px;
    max-width: 440px; width: 100%; text-align: center;
}
.install-logo { font-size: 3rem; margin-bottom: 12px; }
.install-card h1 { font-size: 1.4rem; margin-bottom: 8px; }
.install-sub { color: var(--text-dim); font-size: .85rem; margin-bottom: 24px; }
.install-hint { color: var(--text-muted); font-size: .8rem; margin-bottom: 16px; }
.install-hint code { background: var(--surface2); padding: 1px 5px; border-radius: 4px; color: var(--accent); }

/* ── Utilisation bar (debts) ───────────────── */
.util-bar-wrap { width: 60px; flex-shrink: 0; }
.util-bar {
    height: 4px; border-radius: 99px;
    background: var(--surface3); overflow: hidden;
}
.util-fill { height: 100%; border-radius: 99px; }

/* ── Avatar colour picker ──────────────────── */
.color-swatches {
    display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px;
}
.color-swatch {
    width: 28px; height: 28px; border-radius: 50%;
    cursor: pointer; border: 2px solid transparent;
    transition: border-color var(--t), transform var(--t);
}
.color-swatch:hover { transform: scale(1.12); }
.color-swatch.selected { border-color: var(--text); }

/* ── Checkbox ──────────────────────────────── */
input[type="checkbox"] {
    width: 16px; height: 16px;
    accent-color: var(--accent); cursor: pointer;
}

/* ── Responsive ────────────────────────────── */
@media (min-width: 600px) {
    .page  { padding: 20px 22px; }
    .chips { grid-template-columns: repeat(4, 1fr); }
}

/* ── Numpad active button ───────────────────── */
.btn-ghost.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}
