:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --danger: #f87171;
    --border: #334155;
    --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand { font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--text); }
.nav-links { display: flex; align-items: center; gap: 1rem; }
.nav-links a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.nav-links a:hover { color: var(--text); }

.container { max-width: 760px; margin: 0 auto; padding: 1rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

h1 { font-size: 1.25rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }

.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.row { display: flex; gap: 0.5rem; align-items: stretch; }
.row input { flex: 1; }

label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }

input, select {
    width: 100%;
    padding: 0.7rem 0.75rem;
    font-size: 1rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    appearance: none;
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

button { cursor: pointer; font-size: 1rem; font-family: inherit; }

.primary {
    padding: 0.8rem 1rem;
    background: var(--accent-strong);
    color: #06283d;
    font-weight: 600;
    border: none;
    border-radius: 10px;
}
.primary:hover { background: var(--accent); }

.link { background: none; border: none; color: var(--muted); padding: 0.25rem 0.5rem; }
.link:hover { color: var(--text); }
.link.danger:hover { color: var(--danger); }
.inline { display: inline; margin: 0; }

.error { color: var(--danger); margin: 0 0 0.75rem; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* Login */
.login-card { max-width: 360px; margin: 3rem auto 0; }
.login-card h1 { text-align: center; }

/* Expense list */
.expense-list { list-style: none; margin: 0; padding: 0; }
.expense-list li {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "main del" "meta del";
    gap: 0.1rem 0.5rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--border);
}
.expense-list li:last-child { border-bottom: none; }
.exp-main { grid-area: main; display: flex; gap: 0.6rem; align-items: baseline; }
.exp-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.exp-category { color: var(--muted); }
.exp-meta { grid-area: meta; font-size: 0.82rem; color: var(--muted); display: flex; gap: 0.6rem; }
.expense-list .danger { grid-area: del; align-self: center; }

/* Categories */
.category-list { list-style: none; margin: 1rem 0; padding: 0; }
.category-list li {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.6rem 0; border-bottom: 1px solid var(--border);
}
.category-list li.category-group {
    color: var(--muted); font-size: 0.8rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
    padding: 0.9rem 0 0.3rem; border-bottom: none;
}
.category-list li.child span { padding-left: 1rem; }

/* Report */
.report-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.report-head h1 { margin: 0; }
.report-head select { width: auto; }

.table-scroll { overflow-x: auto; margin-top: 1rem; -webkit-overflow-scrolling: touch; }
table.report { border-collapse: collapse; width: 100%; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
table.report th, table.report td { padding: 0.5rem 0.6rem; text-align: left; white-space: nowrap; }
table.report thead th { color: var(--muted); border-bottom: 1px solid var(--border); font-weight: 600; }
table.report .num { text-align: right; }
table.report tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }
table.report .zero { color: var(--muted); }
table.report tfoot td { border-top: 2px solid var(--border); font-weight: 700; }
.total-col { font-weight: 700; }

.sticky-col {
    position: sticky;
    left: 0;
    background: var(--surface);
    z-index: 1;
}
table.report tbody tr:nth-child(even) .sticky-col { background: #20304a; }

/* Bulk add (spreadsheet) */
.banner {
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: 0.6rem 0.9rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.bulk-toolbar {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
    margin: 0.75rem 0 1rem;
}
.bulk-toolbar label { font-size: 0.8rem; }
.bulk-toolbar .link { padding: 0.6rem 0.4rem; }

kbd {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 0.05rem 0.35rem;
    font-size: 0.8rem;
}

table.sheet { border-collapse: collapse; width: 100%; }
table.sheet th {
    text-align: left;
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
    padding: 0.3rem 0.4rem;
    white-space: nowrap;
}
table.sheet td { padding: 2px; }
table.sheet input, table.sheet select {
    padding: 0.55rem 0.5rem;
    border-radius: 7px;
    min-width: 8rem;
}
table.sheet .amount-col input { min-width: 6rem; font-variant-numeric: tabular-nums; }
table.sheet .remove-row { padding: 0.4rem 0.5rem; }
