:root {
    --bg: #f7f7f5;
    --fg: #1f2430;
    --muted: #6b7280;
    --accent: #2563eb;
    --danger: #b91c1c;
    --card: #ffffff;
    --border: #e5e7eb;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--fg);
}

.nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.nav .brand { font-weight: 700; margin-right: 1rem; }
.nav-spacer { flex: 1; }
.nav-user { color: var(--muted); font-size: 0.85rem; }
.nav-logout { margin: 0; }
.nav-logout button { padding: 0.25rem 0.5rem; }
.nav a { text-decoration: none; color: var(--muted); padding: 0.25rem 0.5rem; border-radius: 6px; }
.nav a.active { color: var(--accent); font-weight: 600; }

main { max-width: 860px; margin: 1.5rem auto; padding: 0 1rem; }

h1 { font-size: 1.35rem; }

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

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

form.inline { display: flex; gap: 0.5rem; align-items: end; flex-wrap: wrap; }
label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); }
input, select, textarea {
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    color: var(--fg);
    background: #fff;
}

button, .btn {
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font: inherit;
}
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.link { border: none; background: none; color: var(--accent); padding: 0; cursor: pointer; }

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.9rem; margin: 0.25rem 0; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

.month-nav { display: flex; align-items: center; gap: 1rem; }
.month-nav h1 { margin: 0; min-width: 12rem; text-align: center; }
.month-nav .btn { text-decoration: none; }
.month-picker { position: relative; }
#month-picker-btn { min-width: 12rem; }
#month-picker-pop {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 0.85rem;
    z-index: 50;
    box-shadow: 0 8px 24px rgba(31, 36, 48, 0.14);
}
#month-picker-pop[hidden] { display: none; }
.picker-year { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.5rem; font-weight: 600; }
.picker-grid { display: grid; grid-template-columns: repeat(4, minmax(3.5rem, 1fr)); gap: 0.25rem; }
.picker-month.is-viewed { background: var(--accent); border-color: var(--accent); color: #fff; }
.picker-month.is-today:not(.is-viewed) { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: #eef2ff;
    color: var(--accent);
}
.badge.archived { background: #f3f4f6; color: var(--muted); }
.badge.new { background: #dcfce7; color: #15803d; }
.badge.duplicate { background: #f3f4f6; color: var(--muted); }
.badge.skipped { background: #f3f4f6; color: var(--muted); }
.badge.error { background: #fee2e2; color: var(--danger); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.kind-col { min-width: 0; }
.kind-col h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }
.stacked { display: flex; flex-direction: column; }
.expense-list { order: 1; }
.income-list { order: 2; }
.transfer-list { order: 3; }
.transaction-section h2 { margin: 0 0 0.5rem; }
.transaction-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    text-align: left;
}
.transaction-section-toggle:hover { background: transparent; color: var(--accent); }
.transaction-section-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.collapse-chevron { transition: transform 120ms ease; }
.transaction-section-toggle[aria-expanded="false"] .collapse-chevron { transform: rotate(-90deg); }
.transaction-section-content[hidden] { display: none; }
.transaction-filters { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.filter-dropdowns { display: flex; align-items: center; gap: 0.75rem; flex-wrap: nowrap; }
.multi-filter { position: relative; flex: 0 0 auto; }
.multi-filter-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-weight: 600;
}
.multi-filter.is-open .multi-filter-trigger { border-color: var(--accent); }
.filter-chevron { color: var(--muted); }
.filter-count { color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.multi-filter-menu {
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0;
    z-index: 60;
    min-width: 15rem;
    max-width: min(22rem, calc(100vw - 3rem));
    max-height: 18rem;
    overflow-y: auto;
    padding: 0.35rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    box-shadow: 0 8px 24px rgba(31, 36, 48, 0.14);
}
.multi-filter-menu[hidden] { display: none; }
.transaction-filters .multi-filter-option {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem;
    border-radius: 5px;
    color: var(--fg);
    cursor: pointer;
}
.multi-filter-option:hover { background: var(--bg); }
.multi-filter-option input { margin: 0; accent-color: var(--accent); }
.clear-filters { margin-left: auto; }
th[aria-sort] a { color: inherit; text-decoration: none; white-space: nowrap; }
th[aria-sort] a:hover { color: var(--accent); }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 560px) {
    .filter-dropdowns { width: 100%; }
    .clear-filters { margin-left: 0; }
}

.summary { display: flex; gap: 2rem; align-items: center; }
.summary strong { font-variant-numeric: tabular-nums; }
.summary strong.positive { color: #15803d; }
.summary strong.negative { color: var(--danger); }
table caption { text-align: left; font-size: 0.85rem; padding: 0.75rem 0 0.25rem; }

main { max-width: 1180px; }
.auth-main { max-width: 440px; margin-top: 3rem; }
.auth-card form { display: grid; gap: 1rem; }
.auth-card label { margin-bottom: 0.25rem; }
.auth-card input:not([type="checkbox"]) { width: 100%; }
.auth-card .checkbox-label { display: flex; flex-direction: row; align-items: center; gap: 0.5rem; }
.page-heading { margin: 1.5rem 0 1.25rem; }
.page-heading h1 { margin: 0 0 0.35rem; }
.page-heading p { margin: 0; }
.configuration-card { max-width: 760px; padding: 1.5rem; }
.configuration-intro { margin-bottom: 1.25rem; }
.configuration-intro h2 { margin: 0 0 0.35rem; font-size: 1.05rem; }
.configuration-intro p { margin: 0; }
.configuration-form { display: grid; gap: 1.25rem; }
.currency-toggle {
    display: grid;
    grid-template-columns: 1.1rem minmax(0, 1fr);
    align-items: start;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--fg);
    cursor: pointer;
}
.currency-toggle input { width: 1rem; height: 1rem; margin: 0.15rem 0 0; accent-color: var(--accent); }
.currency-toggle-copy { display: grid; gap: 0.3rem; }
.currency-toggle-title { font-weight: 600; }
.currency-toggle-copy .muted { font-size: 0.9rem; line-height: 1.45; }
.currency-field { max-width: 26rem; gap: 0.45rem; }
.currency-field select { width: 100%; }
.configuration-actions { display: flex; justify-content: flex-end; padding-top: 0.25rem; }
.configuration-actions button { min-width: 9rem; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: 46rem; }
td.date, th.date { white-space: nowrap; }
td.desc { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a {
    text-decoration: none;
    color: var(--muted);
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    font-weight: 600;
}
.tabs a:hover { color: var(--accent); }
.tabs a.active {
    color: var(--accent);
    background: var(--card);
    border-color: var(--border);
    margin-bottom: -1px;
}
td.num.positive { color: #15803d; }
td.num.negative { color: var(--danger); }
