/* HomeBudget — plain CSS */
:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --pos: #16a34a;
    --neg: #dc2626;
    --warn: #d97706;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111827; --card: #1f2937; --text: #e5e7eb; --muted: #9ca3af;
        --border: #374151; --primary: #3b82f6; --primary-dark: #2563eb;
        --pos: #22c55e; --neg: #f87171; --warn: #fbbf24;
    }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }
.topbar { display: flex; align-items: center; gap: 1.5rem; background: var(--card); border-bottom: 1px solid var(--border); padding: 0 1.25rem; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); padding: .9rem 0; }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { color: var(--muted); padding: .5rem .75rem; border-radius: 6px; }
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.active { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); font-weight: 600; }
.nav .nav-user { margin-left: auto; }
.nav-toggle { display: none; background: none; border: 0; font-size: 1.4rem; color: var(--text); cursor: pointer; margin-left: auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.grid-2.tight { gap: .75rem; margin: 0; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }
.card.narrow { max-width: 560px; }
.auth-card { max-width: 380px; margin: 4rem auto; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.kpi { display: flex; flex-direction: column; gap: .25rem; margin: 0; }
.kpi strong { font-size: 1.5rem; }
.summary-row { display: flex; flex-wrap: wrap; gap: .5rem 2rem; margin: 0 0 1rem; padding: .75rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.summary-row strong { margin-left: .35rem; }

/* Forms */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]):not([type=color]), select, textarea {
    width: 100%; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
input[type=color] { width: 3rem; height: 2.2rem; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; }
.form-stack { display: flex; flex-direction: column; gap: .85rem; }
.form-stack label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; }
.form-stack label.check, label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
.form-stack small { font-weight: 400; }
[hidden] { display: none !important; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .85rem; }
.filters > * { width: auto !important; flex: 0 1 auto; }
.filters input[type=search] { flex: 1 1 180px; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.segmented label { flex-direction: row !important; font-weight: 500; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { padding: .45rem 1rem; cursor: pointer; color: var(--muted); }
.segmented label + label span { border-left: 1px solid var(--border); }
.segmented input:checked + span { background: var(--primary); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -2px; }

/* Buttons */
.btn { display: inline-block; padding: .5rem .9rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card); cursor: pointer; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn.link, button.link { border: 0; background: none; color: var(--primary); padding: 0; cursor: pointer; }
.btn.link { padding: .5rem .5rem; }
.danger { color: var(--neg) !important; }
form.inline { display: inline; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: color-mix(in srgb, var(--primary) 4%, transparent); }
.table tfoot th { color: var(--text); font-size: .95rem; text-transform: none; border-bottom: 0; }
.table.small { font-size: .85rem; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions > * + * { margin-left: .6rem; }
tr.inactive td { opacity: .55; }
.budget-input { max-width: 120px; text-align: right; margin-left: auto; display: block; }
.progress-col { width: 30%; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.badge { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.remembered-hint { font-weight: 400; margin-left: .25rem; }
.badge-default { color: var(--primary); border-color: color-mix(in srgb, var(--primary) 35%, transparent); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.swatch { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .45rem; vertical-align: middle; }

.cleared-toggle { border: 1px solid var(--border); background: none; border-radius: 50%; width: 1.6rem; height: 1.6rem; cursor: pointer; color: var(--muted); line-height: 1; padding: 0; }
.cleared-toggle.on { background: var(--pos); border-color: var(--pos); color: #fff; }

.bulk-bar { display: flex; gap: .5rem; align-items: center; margin-bottom: .75rem; padding: .5rem .75rem; background: color-mix(in srgb, var(--primary) 8%, transparent); border-radius: 6px; }
.bulk-bar select { width: auto !important; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; }
.month-nav { display: flex; gap: .35rem; }

/* Progress bars */
.progress { height: .6rem; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: .45rem; border: 1px solid var(--border); }
.progress span { display: block; height: 100%; background: var(--pos); }
.progress.warn span { background: var(--warn); }
.progress.over span { background: var(--neg); }

/* Category bars on dashboard */
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.bars li { display: grid; grid-template-columns: 8rem 1fr 6rem; gap: .6rem; align-items: center; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: .75rem; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }
#trend-chart { width: 100%; display: block; }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--muted); margin-top: .5rem; }
.dot { display: inline-block; width: .65rem; height: .65rem; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.pos-bg { background: var(--pos); } .neg-bg { background: var(--neg); }

/* Flash messages */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash-success { background: color-mix(in srgb, var(--pos) 10%, var(--card)); border-color: color-mix(in srgb, var(--pos) 35%, transparent); }
.flash-error { background: color-mix(in srgb, var(--neg) 10%, var(--card)); border-color: color-mix(in srgb, var(--neg) 35%, transparent); }
.flash-info { background: color-mix(in srgb, var(--primary) 8%, var(--card)); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }

/* Installer */
.install-card { max-width: 620px; margin: 2.5rem auto; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .9rem 1rem 1rem; margin: 0; display: flex; flex-direction: column; gap: .85rem; }
legend { font-weight: 600; padding: 0 .35rem; }
.host-port { grid-template-columns: 1fr 7rem; }
.install-log { margin: 0 0 1rem; padding-left: 1.2rem; color: var(--muted); }
textarea.code { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; background: var(--bg); padding: .05rem .3rem; border-radius: 4px; }

/* Responsive */
@media (max-width: 900px) {
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2 { grid-template-columns: 1fr; }
    .grid-2 > .card { margin-bottom: 0; }
}
@media (max-width: 720px) {
    .nav-toggle { display: block; }
    .topbar { flex-wrap: wrap; }
    .nav { display: none; flex-direction: column; width: 100%; padding-bottom: .75rem; }
    body.nav-open .nav { display: flex; }
    .nav .nav-user { margin-left: 0; }
    .container { padding: .85rem; }
    .kpis { gap: .75rem; }
    .kpi strong { font-size: 1.2rem; }
    .bars li { grid-template-columns: 6rem 1fr 5rem; }
    .grid-2.tight { grid-template-columns: 1fr 1fr; }
}
.actions .add-another { margin-left: auto; }
.summary-balance { margin-left: auto; }
.summary-balance strong { font-size: 1.1rem; }
.btn-danger { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--neg) 85%, #000); }
