/* ==========================================================================
   PayDue — design system
   Light / dark themes via [data-theme] on <html>.
   Status colours: upcoming = blue, paid = green, overdue = red, partial = amber.
   ========================================================================== */

:root {
    --bg: #f3f5fa;
    --surface: #ffffff;
    --surface-2: #f6f8fc;
    --surface-3: #eef1f7;
    --border: #e4e8f0;
    --border-strong: #d3d9e5;
    --text: #0d1526;
    --text-2: #3b4559;
    --muted: #6b7489;
    --faint: #9aa3b5;

    --primary: #1f5eff;
    --primary-hover: #1a50db;
    --primary-soft: #e9efff;
    --primary-text: #1747c4;

    --brand-1: #0b1f4b;
    --brand-2: #1c3f9e;
    --brand-3: #2f6bff;

    --upcoming: #2563eb;
    --upcoming-soft: #e8f0ff;
    --paid: #12a150;
    --paid-soft: #e5f7ed;
    --overdue: #e03a3a;
    --overdue-soft: #fdecec;
    --partial: #d98a06;
    --partial-soft: #fdf3e1;
    --violet: #6d5cff;
    --violet-soft: #efedff;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px -12px rgba(16, 24, 40, .12);
    --shadow-lg: 0 24px 60px -20px rgba(16, 24, 40, .35);

    --radius-sm: 10px;
    --radius: 16px;
    --radius-lg: 22px;

    --sidebar-w: 264px;
    --topbar-h: 64px;
    --bottom-h: 68px;

    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #080d1a;
    --surface: #10172a;
    --surface-2: #151d33;
    --surface-3: #1b2440;
    --border: #222c47;
    --border-strong: #2d3958;
    --text: #e8ecf5;
    --text-2: #c2c9d9;
    --muted: #8b95ad;
    --faint: #5f6a85;

    --primary: #4d82ff;
    --primary-hover: #6795ff;
    --primary-soft: rgba(77, 130, 255, .14);
    --primary-text: #8fb0ff;

    --brand-1: #0f2560;
    --brand-2: #1f45b0;
    --brand-3: #3c74ff;

    --upcoming: #5b8dff;
    --upcoming-soft: rgba(91, 141, 255, .15);
    --paid: #2fcc71;
    --paid-soft: rgba(47, 204, 113, .14);
    --overdue: #ff5d5d;
    --overdue-soft: rgba(255, 93, 93, .14);
    --partial: #f5a524;
    --partial-soft: rgba(245, 165, 36, .14);
    --violet: #9184ff;
    --violet-soft: rgba(145, 132, 255, .15);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 10px 30px -14px rgba(0, 0, 0, .6);
    --shadow-lg: 0 30px 70px -20px rgba(0, 0, 0, .75);
    color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: 'cv11', 'ss01';
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.015em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
svg.lucide { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; }

.num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-lg { font-size: 17px; }
.bold { font-weight: 700; }
.semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.c-paid { color: var(--paid); }
.c-overdue { color: var(--overdue); }
.c-upcoming { color: var(--upcoming); }
.c-partial { color: var(--partial); }
.c-primary { color: var(--primary); }

/* ---------- Layout helpers ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-lg { display: flex; flex-direction: column; gap: 24px; }
.row { display: flex; align-items: center; gap: 12px; }
.row-sm { display: flex; align-items: center; gap: 6px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid-2, .grid-3, .grid-4, .grid-main { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 640px) {
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1100px) {
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(4, 1fr); }
    .grid-main { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 20px; }
}
.span-2 { grid-column: 1 / -1; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }

@media (max-width: 1023px) { .hide-mobile { display: none !important; } }
@media (min-width: 1024px) { .hide-desktop { display: none !important; } }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }
.main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
@media (min-width: 1024px) {
    .app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
}

.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 18px 14px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    overflow-y: auto;
}
.sidebar.is-open { transform: none; box-shadow: var(--shadow-lg); }
@media (min-width: 1024px) {
    .sidebar { position: sticky; top: 0; height: 100vh; transform: none; }
}
.sidebar-backdrop {
    position: fixed; inset: 0; z-index: 55;
    background: rgba(5, 10, 25, .45);
    opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark {
    width: 36px; height: 36px; border-radius: 11px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--brand-2), var(--brand-3));
    color: #fff; font-weight: 800; font-size: 17px;
    box-shadow: 0 6px 16px -6px rgba(31, 94, 255, .6);
}
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -.03em; }
.brand-name span { color: var(--primary); }

.nav-section { margin-top: 18px; }
.nav-title {
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
    color: var(--faint); padding: 0 12px 6px;
}
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 12px;
    color: var(--text-2); font-weight: 550; font-size: 14px;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary-text); font-weight: 650; }
.nav-link.is-active svg { color: var(--primary); }
.nav-badge {
    margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
    border-radius: 999px; background: var(--overdue); color: #fff;
    font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.sidebar-footer { margin-top: auto; padding-top: 16px; }
.user-chip {
    display: flex; align-items: center; gap: 10px; padding: 10px;
    border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border);
}

.avatar {
    width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
    display: grid; place-items: center; overflow: hidden;
    background: linear-gradient(135deg, var(--brand-2), var(--brand-3));
    color: #fff; font-weight: 700; font-size: 14px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 32px; height: 32px; border-radius: 10px; font-size: 12px; }
.avatar-lg { width: 72px; height: 72px; border-radius: 22px; font-size: 24px; }

.topbar {
    position: sticky; top: 0; z-index: 40;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px;
    padding: 0 16px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-bottom: 1px solid transparent;
}
.topbar.is-scrolled { border-bottom-color: var(--border); }
.topbar-title { font-size: 18px; font-weight: 750; letter-spacing: -.02em; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
@media (min-width: 1024px) { .topbar { padding: 0 32px; } }

.content {
    flex: 1; width: 100%; max-width: 1280px; margin: 0 auto;
    padding: 8px 16px calc(var(--bottom-h) + 32px);
}
@media (min-width: 1024px) { .content { padding: 12px 32px 48px; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; font-weight: 800; }
.page-head p { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* ---------- Bottom navigation (mobile) ---------- */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
    padding: 0 8px env(safe-area-inset-bottom);
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(160%) blur(16px);
    -webkit-backdrop-filter: saturate(160%) blur(16px);
    border-top: 1px solid var(--border);
}
@media (min-width: 1024px) { .bottom-nav { display: none; } }
.bottom-link {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: 11px; font-weight: 600; color: var(--muted);
    padding: 8px 0; position: relative; background: none; border: 0; cursor: pointer;
}
.bottom-link svg { width: 22px; height: 22px; }
.bottom-link.is-active { color: var(--primary); }
.bottom-link .dot {
    position: absolute; top: 4px; right: calc(50% - 18px);
    width: 8px; height: 8px; border-radius: 50%; background: var(--overdue);
    box-shadow: 0 0 0 2px var(--surface);
}
.fab {
    justify-self: center;
    width: 54px; height: 54px; border-radius: 18px; border: 0; cursor: pointer;
    display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, var(--brand-2), var(--brand-3));
    box-shadow: 0 10px 24px -8px rgba(31, 94, 255, .7);
    transform: translateY(-14px);
    transition: transform .15s;
}
.fab:active { transform: translateY(-12px) scale(.96); }
.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 18px;
    min-width: 0;
}
@media (min-width: 640px) { .card { padding: 22px; } }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { font-size: 16px; font-weight: 700; }
.card-head .link { font-size: 13px; font-weight: 600; color: var(--primary); display: inline-flex; align-items: center; gap: 4px; }
.card-sub { font-size: 13px; color: var(--muted); }

.hero {
    position: relative; overflow: hidden;
    border-radius: var(--radius-lg);
    padding: 22px;
    color: #fff;
    background:
        radial-gradient(120% 140% at 100% 0%, rgba(80, 140, 255, .55) 0%, transparent 55%),
        linear-gradient(135deg, var(--brand-1) 0%, var(--brand-2) 70%, var(--brand-3) 100%);
    box-shadow: 0 20px 44px -22px rgba(15, 40, 110, .8);
}
.hero::after {
    content: ''; position: absolute; right: -60px; bottom: -80px;
    width: 240px; height: 240px; border-radius: 50%;
    border: 40px solid rgba(255, 255, 255, .06);
}
@media (min-width: 640px) { .hero { padding: 28px; } }
.hero-label { font-size: 13px; color: rgba(255, 255, 255, .72); font-weight: 550; }
.hero-value { font-size: 32px; font-weight: 800; letter-spacing: -.03em; margin-top: 4px; }
.hero-value small { font-size: 15px; font-weight: 650; opacity: .7; margin-left: 4px; }
@media (min-width: 640px) { .hero-value { font-size: 40px; } }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 22px; position: relative; z-index: 1; }
.hero-stat { background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .12); border-radius: 14px; padding: 10px 12px; min-width: 0; }
.hero-stat span { display: block; font-size: 11px; color: rgba(255, 255, 255, .7); font-weight: 600; }
.hero-stat strong { display: block; font-size: 15px; font-weight: 750; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 640px) { .hero-stat strong { font-size: 18px; } .hero-stat { padding: 12px 16px; } }
.hero-progress { margin-top: 18px; position: relative; z-index: 1; }
.hero-progress .bar { height: 8px; background: rgba(255, 255, 255, .16); border-radius: 99px; overflow: hidden; }
.hero-progress .bar i { display: block; height: 100%; background: #6ff0a8; border-radius: 99px; }
.hero-progress .between { font-size: 12px; color: rgba(255, 255, 255, .75); margin-bottom: 6px; }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 550; }
.stat-value { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.stat-value small { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 3px; }

.icon-tile {
    width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
    display: grid; place-items: center;
    background: var(--primary-soft); color: var(--primary);
}
.icon-tile.sm { width: 34px; height: 34px; border-radius: 10px; }
.icon-tile.sm svg { width: 16px; height: 16px; }
.icon-tile.lg { width: 48px; height: 48px; border-radius: 14px; }
.tone-paid { background: var(--paid-soft); color: var(--paid); }
.tone-overdue { background: var(--overdue-soft); color: var(--overdue); }
.tone-upcoming { background: var(--upcoming-soft); color: var(--upcoming); }
.tone-partial { background: var(--partial-soft); color: var(--partial); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }

/* ---------- Quick actions ---------- */
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 640px) { .quick-grid { grid-template-columns: repeat(6, 1fr); } }
.quick {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 14px 6px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border);
    font-size: 12.5px; font-weight: 600; color: var(--text-2); text-align: center;
    cursor: pointer; transition: transform .12s, border-color .15s, box-shadow .15s;
}
.quick:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 42px; padding: 0 16px; border-radius: 12px;
    font-size: 14px; font-weight: 650; white-space: nowrap;
    border: 1px solid transparent; cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px -8px rgba(31, 94, 255, .8); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-soft { background: var(--primary-soft); color: var(--primary-text); }
.btn-soft:hover { filter: brightness(.97); }
.btn-success { background: var(--paid); color: #fff; }
.btn-success:hover { filter: brightness(1.05); }
.btn-danger { background: var(--overdue-soft); color: var(--overdue); }
.btn-danger:hover { background: var(--overdue); color: #fff; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-xs { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; gap: 5px; }
.btn-xs svg { width: 14px; height: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 34px; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text-2);
    display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Segmented control (language, periods) ---------- */
.segmented {
    display: inline-flex; padding: 3px; gap: 2px;
    background: var(--surface-3); border-radius: 12px; border: 1px solid var(--border);
}
.segmented button, .segmented a, .segmented label {
    border: 0; background: none; cursor: pointer;
    height: 32px; padding: 0 12px; border-radius: 9px;
    font-size: 12.5px; font-weight: 700; color: var(--muted);
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.segmented .is-active, .segmented input:checked + label {
    background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented.full { display: flex; }
.segmented.full > * { flex: 1; }

/* ---------- Pills / badges ---------- */
.pill {
    display: inline-flex; align-items: center; gap: 5px;
    height: 24px; padding: 0 9px; border-radius: 999px;
    font-size: 11.5px; font-weight: 700; white-space: nowrap;
    background: var(--surface-3); color: var(--text-2);
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.no-dot::before { display: none; }
.pill-upcoming { background: var(--upcoming-soft); color: var(--upcoming); }
.pill-paid { background: var(--paid-soft); color: var(--paid); }
.pill-overdue { background: var(--overdue-soft); color: var(--overdue); }
.pill-partial { background: var(--partial-soft); color: var(--partial); }
.pill-violet { background: var(--violet-soft); color: var(--violet); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 0; border-top: 1px solid var(--border); min-width: 0;
}
.list-item:first-child { border-top: 0; padding-top: 0; }
.list-item:last-child { padding-bottom: 0; }
.list-item .title { font-weight: 650; font-size: 14.5px; }
.list-item .meta { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.list-item .amount { font-weight: 750; font-size: 15px; text-align: right; white-space: nowrap; }
.list-item .amount small { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.card .list-item.is-link:hover .title { color: var(--primary); }
.cat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.date-head { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 18px 0 6px; }
.date-head:first-child { padding-top: 0; }

.bill-row {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
    padding: 14px 16px; border-top: 1px solid var(--border);
}
.bill-row:first-child { border-top: 0; }
.bill-row:hover { background: var(--surface-2); }
.bill-row .actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }
@media (min-width: 768px) {
    .bill-row { grid-template-columns: auto minmax(0, 1fr) 150px 120px auto; padding: 14px 20px; }
    .bill-row .actions { margin-top: 0; }
}
.bill-row .col-due { font-size: 13px; color: var(--muted); }

/* ---------- Progress ---------- */
.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 99px; background: var(--primary); transition: width .4s ease; }
.progress.paid > i { background: var(--paid); }
.progress.violet > i { background: var(--violet); }

/* ---------- Alerts / toasts ---------- */
.alert {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px; border-radius: var(--radius);
    border: 1px solid transparent; font-size: 14px;
}
.alert-overdue { background: var(--overdue-soft); color: var(--overdue); border-color: color-mix(in srgb, var(--overdue) 25%, transparent); }
.alert-overdue strong { color: var(--text); }
.alert .grow { color: var(--text-2); }

.toasts {
    position: fixed; z-index: 100; left: 16px; right: 16px; top: 16px;
    display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
@media (min-width: 640px) { .toasts { left: auto; right: 24px; top: 76px; width: 380px; } }
.toast {
    pointer-events: auto;
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px; border-radius: 14px;
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
    font-size: 13.5px; font-weight: 550;
    animation: toast-in .25s ease;
}
.toast .icon-tile { width: 28px; height: 28px; border-radius: 8px; }
.toast .icon-tile svg { width: 15px; height: 15px; }
.toast .grow { padding-top: 3px; }
.toast button { border: 0; background: none; cursor: pointer; color: var(--faint); padding: 4px; }
.toast.is-leaving { opacity: 0; transform: translateY(-6px); transition: all .25s; }
@keyframes toast-in { from { transform: translateY(-8px); } }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } .form-grid .span-2 { grid-column: 1 / -1; } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 13px; font-weight: 650; color: var(--text-2); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.label .hint, .hint { font-size: 12px; font-weight: 500; color: var(--faint); }
.input, .field input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=color]):not([type=range]), .field select, .field textarea {
    width: 100%; min-height: 44px;
    padding: 10px 14px; border-radius: 12px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border-strong);
    font: inherit; font-size: 15px;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none; appearance: none;
}
.field textarea, textarea.input { min-height: 84px; resize: vertical; }
.field select, select.input {
    padding-right: 38px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b95ad' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}
.input::placeholder, .field input::placeholder, .field textarea::placeholder { color: var(--faint); }
.input-amount { font-size: 22px !important; font-weight: 750; letter-spacing: -.02em; }
.input-group { display: flex; gap: 8px; }
.input-group > :first-child { flex: 1; min-width: 0; }
.input-group > select, .input-group > .select-sm { width: 96px !important; flex-shrink: 0; }
input[type=color] {
    width: 44px; height: 44px; padding: 4px; border-radius: 12px; cursor: pointer;
    border: 1px solid var(--border-strong); background: var(--surface);
}
.checkbox, .check input {
    width: 20px; height: 20px; border-radius: 6px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0;
}
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 550; cursor: pointer; }
.file-input, .field input[type=file] {
    width: 100%; font-size: 13px; color: var(--muted);
    padding: 8px; border-radius: 12px; border: 1px dashed var(--border-strong); background: var(--surface-2);
}
.file-input::file-selector-button, .field input[type=file]::file-selector-button {
    border: 0; border-radius: 9px; padding: 8px 12px; margin-right: 10px; cursor: pointer;
    background: var(--primary-soft); color: var(--primary-text); font-weight: 650; font-family: inherit;
}
.word-counter { font-size: 11.5px; color: var(--faint); text-align: right; }
.word-counter.is-over { color: var(--overdue); }
.errors {
    padding: 12px 14px; border-radius: 12px; font-size: 13px;
    background: var(--overdue-soft); color: var(--overdue);
}
.errors ul { margin: 4px 0 0; padding-left: 18px; }
.field-error { font-size: 12px; color: var(--overdue); }
.pwd-wrap { position: relative; }
.pwd-wrap input { padding-right: 46px !important; }
.pwd-toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    width: 34px; height: 34px; border: 0; background: none; color: var(--faint); cursor: pointer;
    display: grid; place-items: center; border-radius: 8px;
}
.pwd-toggle:hover { color: var(--text); }
details.more summary {
    list-style: none; cursor: pointer; font-size: 13px; font-weight: 650; color: var(--primary);
    display: inline-flex; align-items: center; gap: 6px;
}
details.more summary::-webkit-details-marker { display: none; }
details.more[open] summary svg { transform: rotate(180deg); }
details.more > div { margin-top: 14px; }

/* Type switch (payment / debt) */
.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-switch input { position: absolute; opacity: 0; pointer-events: none; }
.type-switch label {
    display: flex; align-items: center; gap: 10px; padding: 12px; cursor: pointer;
    border-radius: 14px; border: 1.5px solid var(--border-strong); background: var(--surface);
    font-weight: 650; font-size: 14px;
}
.type-switch label small { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); }
.type-switch input:checked + label { border-color: var(--primary); background: var(--primary-soft); }

/* ---------- Tabs ---------- */
.tabs {
    display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
    margin: 0 -16px 16px; padding: 0 16px;
}
.tabs::-webkit-scrollbar { display: none; }
@media (min-width: 1024px) { .tabs { margin: 0 0 16px; padding: 0; } }
.tab {
    display: inline-flex; align-items: center; gap: 7px; flex-shrink: 0;
    height: 38px; padding: 0 14px; border-radius: 999px;
    font-size: 13.5px; font-weight: 650; color: var(--text-2);
    background: var(--surface); border: 1px solid var(--border); cursor: pointer;
}
.tab .count { font-size: 11.5px; font-weight: 700; color: var(--muted); background: var(--surface-3); border-radius: 99px; padding: 1px 7px; }
.tab.is-active { background: var(--text); color: var(--surface); border-color: var(--text); }
.tab.is-active .count { background: rgba(255, 255, 255, .2); color: inherit; }
[data-theme="dark"] .tab.is-active .count { background: rgba(0, 0, 0, .15); }

/* ---------- Dialog / bottom sheet ---------- */
dialog.sheet {
    border: 0; padding: 0; margin: auto auto 0;
    width: 100%; max-width: 100%; max-height: 92vh;
    background: var(--surface); color: var(--text);
    border-radius: 24px 24px 0 0;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-up .28s cubic-bezier(.2, .9, .3, 1); }
dialog.sheet::backdrop { background: rgba(5, 10, 25, .55); backdrop-filter: blur(3px); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } }
@media (min-width: 640px) {
    dialog.sheet { margin: auto; width: calc(100% - 48px); max-width: 560px; border-radius: 24px; max-height: 88vh; }
    dialog.sheet.wide { max-width: 760px; }
    dialog.sheet[open] { animation: pop .22s ease; }
    @keyframes pop { from { transform: scale(.97); opacity: 0; } }
}
.sheet-handle { width: 40px; height: 5px; border-radius: 9px; background: var(--border-strong); margin: 10px auto 0; }
@media (min-width: 640px) { .sheet-handle { display: none; } }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px 12px; }
.sheet-head h3 { font-size: 18px; font-weight: 750; }
.sheet-head p { font-size: 13px; color: var(--muted); }
.sheet-body { padding: 4px 20px 20px; overflow-y: auto; }
.sheet-foot {
    display: flex; gap: 10px; padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); background: var(--surface);
}
.sheet-foot .btn { flex: 1; }
@media (min-width: 640px) { .sheet-foot { justify-content: flex-end; } .sheet-foot .btn { flex: 0 0 auto; min-width: 120px; } }
.sheet-shortcuts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.sheet-shortcuts a {
    display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px;
    border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
    font-size: 12px; font-weight: 650; color: var(--text-2);
}

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.cal-head h3 { font-size: 17px; font-weight: 750; text-transform: capitalize; }
.cal-nav { display: flex; gap: 6px; }
.cal-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.cal-sum { border-radius: 12px; padding: 8px 10px; min-width: 0; }
.cal-sum span { font-size: 11px; font-weight: 700; display: flex; align-items: center; gap: 5px; }
.cal-sum span::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.cal-sum strong { display: block; font-size: 14px; font-weight: 750; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.cal-sum.upcoming { background: var(--upcoming-soft); color: var(--upcoming); }
.cal-sum.paid { background: var(--paid-soft); color: var(--paid); }
.cal-sum.overdue { background: var(--overdue-soft); color: var(--overdue); }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-week div { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--faint); padding: 4px 0 6px; text-transform: uppercase; }
.cal-day {
    position: relative; height: clamp(42px, 10vw, 58px);
    border-radius: 12px; border: 1px solid transparent; background: none; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    font-size: 14px; font-weight: 600; color: var(--text-2);
    transition: background .12s, border-color .12s;
}
.cal-day:hover { background: var(--surface-2); }
.cal-day.is-other { color: var(--faint); opacity: .45; }
.cal-day.is-today { color: var(--primary); font-weight: 800; background: var(--primary-soft); }
.cal-day.is-selected { border-color: var(--text); background: var(--surface); box-shadow: var(--shadow-sm); }
.cal-day.has-overdue { background: var(--overdue-soft); }
.cal-day.is-today.has-overdue { background: var(--overdue-soft); }
.cal-dots { display: flex; gap: 3px; height: 6px; }
.cal-dots i { width: 6px; height: 6px; border-radius: 50%; }
.cal-dots .upcoming { background: var(--upcoming); }
.cal-dots .paid { background: var(--paid); }
.cal-dots .overdue { background: var(--overdue); }
.cal-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 12px; color: var(--muted); font-weight: 600; }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend i { width: 8px; height: 8px; border-radius: 50%; }
.cal-agenda { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.cal-agenda-title { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.cal-event {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
    border-left: 3px solid var(--upcoming); background: var(--surface-2); margin-bottom: 8px;
}
.cal-event.paid { border-left-color: var(--paid); }
.cal-event.overdue { border-left-color: var(--overdue); }
.cal-event .title { font-weight: 650; font-size: 14px; }
.cal-event .meta { font-size: 12px; color: var(--muted); }
.cal-event .amount { font-weight: 750; white-space: nowrap; font-size: 14px; }
.cal-loading { opacity: .5; pointer-events: none; }
@media (min-width: 1024px) {
    .cal-big .cal-day { height: auto; min-height: 96px; align-items: stretch; justify-content: flex-start; padding: 8px; gap: 4px; border-color: var(--border); }
    .cal-big .cal-day .d { align-self: flex-end; font-size: 13px; }
    .cal-big .cal-day .chip {
        display: block; font-size: 11px; font-weight: 650; padding: 2px 6px; border-radius: 6px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
    }
    .cal-big .cal-day .chip.upcoming { background: var(--upcoming-soft); color: var(--upcoming); }
    .cal-big .cal-day .chip.paid { background: var(--paid-soft); color: var(--paid); }
    .cal-big .cal-day .chip.overdue { background: var(--overdue-soft); color: var(--overdue); }
    .cal-big .cal-day .more { font-size: 11px; color: var(--muted); text-align: left; }
    .cal-big .cal-dots { display: none; }
}
.cal-day .chip, .cal-day .more { display: none; }
@media (min-width: 1024px) { .cal-big .cal-day .chip, .cal-big .cal-day .more { display: block; } }

/* ---------- Accounts / goals ---------- */
.acc-card {
    position: relative; overflow: hidden; border-radius: var(--radius); padding: 16px;
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.acc-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--acc, var(--primary)); }
.acc-card .acc-icon { background: color-mix(in srgb, var(--acc, var(--primary)) 14%, transparent); color: var(--acc, var(--primary)); }
.acc-card .balance { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.acc-card.is-inactive { opacity: .6; }
.h-scroll { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 12px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 4px; }
.h-scroll::-webkit-scrollbar { display: none; }
@media (min-width: 1024px) { .h-scroll { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); margin: 0; padding: 0; overflow: visible; } }

.ring { --p: 0; --c: var(--paid); width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0;
    background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--surface-3) 0);
    display: grid; place-items: center; }
.ring::after { content: attr(data-label); width: 50px; height: 50px; border-radius: 50%; background: var(--surface);
    display: grid; place-items: center; font-size: 13px; font-weight: 800; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; max-height: 360px; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { position: sticky; top: 0; background: var(--surface-2); text-align: right; font-weight: 700; color: var(--muted); padding: 10px 12px; font-size: 12px; }
.table td { padding: 9px 12px; border-top: 1px solid var(--border); text-align: right; white-space: nowrap; }
.table th:first-child, .table td:first-child { text-align: left; }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 220px; }
.legend-list { display: flex; flex-direction: column; gap: 10px; }
.legend-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13.5px; }
.legend-row .bar { grid-column: 2 / -1; height: 6px; border-radius: 9px; background: var(--surface-3); overflow: hidden; }
.legend-row .bar i { display: block; height: 100%; border-radius: 9px; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty .icon-tile { margin: 0 auto 12px; width: 52px; height: 52px; border-radius: 16px; background: var(--surface-3); color: var(--faint); }
.empty h4 { color: var(--text); font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.empty p { font-size: 13.5px; }
.empty .btn { margin-top: 14px; }

/* ---------- Menus ---------- */
.menu { position: relative; }
.menu-list {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 190px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
    box-shadow: var(--shadow-lg); padding: 6px; display: none;
}
.menu.is-open .menu-list { display: block; }
.menu-list a, .menu-list button {
    width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
    font-size: 13.5px; font-weight: 550; border: 0; background: none; cursor: pointer; text-align: left;
}
.menu-list a:hover, .menu-list button:hover { background: var(--surface-2); }
.menu-list .danger { color: var(--overdue); }
.menu-list form { margin: 0; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
@media (min-width: 1024px) { .auth { grid-template-columns: 1.05fr 1fr; } }
.auth-aside {
    display: none; position: relative; overflow: hidden; color: #fff; padding: 48px;
    background:
        radial-gradient(80% 60% at 90% 10%, rgba(90, 150, 255, .55), transparent 60%),
        linear-gradient(150deg, var(--brand-1), var(--brand-2) 65%, var(--brand-3));
}
@media (min-width: 1024px) { .auth-aside { display: flex; flex-direction: column; justify-content: space-between; } }
.auth-aside h2 { font-size: 38px; font-weight: 800; letter-spacing: -.03em; max-width: 460px; line-height: 1.15; }
.auth-aside p { color: rgba(255, 255, 255, .75); font-size: 16px; max-width: 440px; margin-top: 14px; }
.auth-features { display: grid; gap: 12px; max-width: 420px; }
.auth-feature { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 14px; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .12); font-weight: 600; font-size: 14px; }
.auth-feature .icon-tile { background: rgba(255, 255, 255, .14); color: #fff; }
.auth-main { display: flex; flex-direction: column; padding: 20px 16px 32px; }
@media (min-width: 640px) { .auth-main { padding: 28px 40px; } }
.auth-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.auth-card { width: 100%; max-width: 420px; margin: auto; padding: 32px 0; }
.auth-card h1 { font-size: 28px; font-weight: 800; letter-spacing: -.03em; }
.auth-card > p { color: var(--muted); margin-top: 6px; margin-bottom: 26px; }
.auth-switch { text-align: center; margin-top: 22px; font-size: 14px; color: var(--muted); }
.auth-switch a { color: var(--primary); font-weight: 700; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); margin: 4px 0; }
.kbd-hint { font-size: 12px; color: var(--faint); }
.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }
.calc-result { border-radius: var(--radius); padding: 18px; background: var(--surface-2); border: 1px solid var(--border); }
.calc-result .big { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 6px 0; }
.kv span { color: var(--muted); }
.kv strong { font-weight: 700; text-align: right; }

/* Theme toggle icon: show moon in light mode, sun in dark mode */
[data-theme="dark"] .theme-icon-dark { display: none; }
html:not([data-theme="dark"]) .theme-icon-light { display: none; }
.input-group > select:first-child { flex: 0 0 96px; }

/* Phones: hero stats as rows so full amounts always fit */
@media (max-width: 639px) {
    .hero-stats { grid-template-columns: 1fr; gap: 6px; }
    .hero-stat { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; }
    .hero-stat span { font-size: 12.5px; }
    .hero-stat strong { margin-top: 0; font-size: 16px; }
    .cal-head h3 { font-size: 16px; }
    .cal-sum { padding: 7px 8px; }
    .cal-sum strong { font-size: 12.5px; }
}
