:root {
    --bg: #e4e1d9;
    --paper: #f5f3ed;
    --ink: #191b1b;
    --muted: #686c67;
    --line: #d3d0c7;
    --side: #242727;
    --side-text: #c6c9c6;
    --accent: #f2b705;
    --accent-ink: #191b1b;
    --gold: #f2b705;
    --coal: #242727;
    --neg: #b91c1c;
    --pos: #178c55;
    --warn: #8a6500;
    --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: var(--bg);
    display: grid;
    grid-template-columns: 240px 1fr;
}

a { color: var(--ink); text-decoration: none; }
a:hover { color: #8a6500; }
h1, h2, h3 {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0;
}
h1 { font-size: 1.85rem; line-height: 1.1; }
h2 { font-size: 1.15rem; }

.sidebar {
    background: var(--side);
    color: var(--side-text);
    min-height: 100vh;
    padding: 1.5rem 1rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: sticky;
    top: 0;
}
.brand {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    color: #f5f3ed;
}
.brand:hover { color: #f5f3ed; }
.brand-name {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}
.brand-name strong {
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    line-height: 1.1;
}
.brand small, .brand-name small {
    display: block;
    color: #979b97;
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.brand-logo {
    height: 2.75rem;
    width: auto;
    display: block;
    object-fit: contain;
    border-radius: 6px;
    background: #111313;
}
.brand-mark {
    width: 2.4rem;
    height: 2.4rem;
    display: grid;
    place-items: center;
    background: var(--gold);
    color: var(--ink);
    font-weight: 800;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.2rem; }
.sidebar nav a {
    color: var(--side-text);
    padding: 0.65rem 0.75rem;
    border-left: 2px solid transparent;
    display: flex;
    flex-direction: column;
}
.sidebar nav a small { color: #8e928e; font-size: 0.72rem; }
.sidebar nav a.active {
    border-left-color: var(--gold);
    color: #fff;
    background: #191c1b;
}
.sidebar nav a:hover { color: #fff; }
.sidebar-foot {
    margin-top: auto;
    font-size: 0.75rem;
    color: #8e928e;
    line-height: 1.4;
}
.sidebar-user {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.75rem 0.75rem 0;
    border-top: 1px solid #343735;
}
.sidebar-user a { color: #f5f3ed; }
.sidebar-user a:hover { color: var(--gold); }
.sidebar-user small { display: block; color: #8e928e; font-size: 0.72rem; }
.sidebar-logout { color: #8e928e; padding-left: 0; justify-content: flex-start; }

.auth-body {
    display: grid;
    place-items: center;
    grid-template-columns: 1fr;
    min-height: 100vh;
    background: var(--coal);
}
.auth-wrap { width: min(26rem, calc(100% - 2rem)); padding: 2rem 0; }
.auth-brand { margin-bottom: 1.25rem; }
.auth-card.panel {
    background: #fff;
    border: 0;
    padding: 2.5rem;
    box-shadow: 0 20px 60px #292d2812;
}
.auth-card .lede { margin-bottom: 1rem; }
.auth-card .eyebrow { color: #8a6500; }

.main { padding: 2rem 2.25rem 4rem; max-width: 1120px; }
.page-head {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    align-items: flex-end;
    margin-bottom: 1.75rem;
}
.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--muted);
    margin: 0 0 0.4rem;
}
.lede { color: var(--muted); max-width: 40rem; margin: 0.6rem 0 0; }

.kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}
.kpis article, .panel {
    background: var(--paper);
    border: 1px solid var(--line);
    padding: 1rem 1.1rem;
}
.kpis .kpi-link { color: inherit; display: block; }
.kpis .kpi-link:hover strong { color: #8a6500; }
.kpis p, .panel header p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.kpis strong { display: block; font-size: 1.45rem; margin: 0.35rem 0 0.15rem; }
.kpis small { color: var(--muted); display: block; }
.kpis .kpi-delta.good { color: var(--pos); }
.kpis .kpi-delta.bad { color: var(--neg); }

.month-nav { display: flex; gap: 0.4rem; align-items: flex-end; }
.month-nav select { min-width: 16rem; }
.month-nav .btn[aria-disabled] { opacity: 0.35; pointer-events: none; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.subhead { font-size: 0.95rem; margin: 1.25rem 0 0.35rem; }
.subhead + .caption { margin-top: 0; margin-bottom: 0.65rem; }
.callout {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
    padding: 0.7rem 1rem;
    margin: 0 0 1rem;
    font-size: 0.9rem;
}

.neg { color: var(--neg); }
.pos { color: var(--pos); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.8rem; }

.grid-2 { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 1rem; margin-bottom: 1rem; }
.panel header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.9rem;
}
.panel.flush { padding: 0; overflow: hidden; }
.panel.flush header, .panel.flush .padded { padding: 1rem 1.1rem; }

.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.7rem; }
.bar { height: 6px; background: #ede8dc; margin-top: 0.25rem; }
.bar span { display: block; height: 100%; }
.bar-link { display: block; color: inherit; border-radius: 2px; }
.bar-link:hover .bar span { filter: brightness(0.92); }
.bar-link:hover strong { color: #8a6500; }
.bar-meta { display: grid; grid-template-columns: 10px 1fr auto auto auto; gap: 0.5rem; align-items: center; font-size: 0.88rem; }
.bar-meta b { min-width: 7.5rem; text-align: right; }
.bar-share { color: var(--muted); min-width: 2.4rem; text-align: right; font-variant-numeric: tabular-nums; }
.transfer-item .bar-meta { grid-template-columns: 10px 1fr auto auto; }
.transfer-split {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.78rem;
    margin-top: 0.2rem;
}
.transfer-split a:hover { text-decoration: underline; }
.transfer-item .bar { margin-top: 0.15rem; }
.transfer-item .bar-out { background: var(--neg); }
.transfer-item .bar-in { background: var(--pos); }
.dot { width: 8px; height: 8px; display: inline-block; }
.share { display: grid; grid-template-columns: 1fr 3.2rem; gap: 0.5rem; align-items: center; min-width: 8rem; }
.share .bar { height: 4px; background: #ede8dc; }
.share .bar span { display: block; height: 100%; background: var(--accent); }
.share.in .bar span { background: var(--pos); }
tfoot th { font-weight: 600; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 0.9rem; }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 140px; }
.spark-col {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 1px;
    height: 100%;
}
.spark-exp, .spark-inc { display: block; width: 50%; min-height: 1px; }
.spark-exp { background: #b91c1c; }
.spark-inc { background: var(--gold); }
.caption { font-size: 0.75rem; color: var(--muted); margin: 0.75rem 0 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td strong { display: block; }
td small { display: block; margin-top: 0.15rem; }
.compact td { padding: 0.55rem 0.85rem; }

.pill {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background: color-mix(in srgb, var(--pill, #f2b705) 18%, white);
    color: var(--ink);
    border: 1px solid color-mix(in srgb, var(--pill, #f2b705) 42%, white);
    font-size: 0.78rem;
}
.pill-ghost { background: transparent; color: var(--muted); border-color: var(--line); }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--ink);
    background: transparent;
    color: var(--ink);
    padding: 0.7rem 0.95rem;
    font: inherit;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #ffd03b; border-color: #ffd03b; }
.btn-danger { background: #fff; border-color: var(--neg); color: var(--neg); }
.btn-ghost { border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.inline { display: flex; gap: 0.6rem; align-items: end; flex-wrap: wrap; }
.inline label, .form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.8rem; color: var(--muted); }
select, input, textarea {
    font: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    padding: 0.45rem 0.55rem;
    outline: none;
}
select:focus, input:focus, textarea:focus { border-color: #9c7500; }
.filters { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input[type="search"] { flex: 1; min-width: 12rem; }
.check { display: flex; flex-direction: row !important; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; }
.cat-select { max-width: 16rem; }
.memory-table input.mem-field {
    width: 100%;
    min-width: 9rem;
}

.drop {
    background: var(--paper);
    border: 1px dashed #b8b09f;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.drop-label { cursor: pointer; }
.drop-label span { display: block; color: var(--muted); }
#ofx { position: absolute; width: 1px; height: 1px; opacity: 0; }

.preview-card { margin-bottom: 1.25rem; }
.preview-card .kpis { margin-bottom: 0.75rem; }
.preview-card .callout { margin: 0 0 0.75rem; }
.preview-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }
.month-split {
    list-style: none;
    margin: 0.75rem 0 1rem;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}
.month-split li {
    border: 1px solid var(--line);
    padding: 0.35rem 0.55rem;
    font-size: 0.82rem;
    display: flex;
    gap: 0.5rem;
}

.flash { padding: 0.75rem 1rem; margin-bottom: 1rem; border: 1px solid var(--line); }
.flash-ok { background: #fff1b0; border-color: #f2b705; }
.flash-error { background: #fef2f2; border-color: #fecaca; }

.empty {
    background: var(--paper);
    border: 1px solid var(--line);
    padding: 2.5rem;
    max-width: 36rem;
}
.form { display: flex; flex-direction: column; gap: 0.75rem; }
.sql-layout { align-items: start; }
.sql-input {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.85rem;
    min-height: 12rem;
    width: 100%;
    resize: vertical;
}
.sql-examples, .sql-tables {
    list-style: none;
    margin: 0.4rem 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.sql-fill {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    padding: 0.35rem 0;
    font: inherit;
    color: #8a6500;
    cursor: pointer;
}
.sql-tables .sql-fill { color: inherit; }
.sql-tables .sql-fill small { color: var(--muted); }
.sql-fill:hover { text-decoration: underline; }
.sql-scroll { overflow: auto; max-height: 28rem; }
.sql-result td.mono { font-size: 0.78rem; word-break: break-word; }
.form small { color: var(--muted); }
.steps { margin: 0; padding-left: 1.1rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.6rem; }
.steps strong { color: var(--ink); }
.inline-edit { display: flex; gap: 0.4rem; align-items: center; }
.inline-edit input[name="name"] { min-width: 12rem; }
.category-table tr[id^="row-cat-"] { scroll-margin-top: 1.25rem; }
.category-table tr.is-saved td {
    background: #fff1b0;
}
.category-table .js-cat-save.is-saved {
    border-color: #8a6500;
    color: #8a6500;
}
.category-table .group-row td {
    background: #efe9dc;
    font-size: 0.72rem;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0.55rem 0.75rem;
}
.category-table textarea[name="keywords"] {
    width: 100%;
    min-width: 14rem;
    min-height: 3.2rem;
    resize: vertical;
}
.category-table .row-actions {
    display: flex;
    gap: 0.35rem;
    justify-content: flex-end;
    align-items: center;
    white-space: nowrap;
}

.status { padding: 0.35rem 0.7rem; border: 1px solid var(--line); font-size: 0.8rem; }
.status.ok { background: #fff1b0; }
.status.bad { background: #fef2f2; }

#ai-overlay {
    position: fixed;
    inset: 0;
    background: rgb(36 39 39 / 0.72);
    display: grid;
    place-items: center;
    z-index: 20;
}
#ai-overlay[hidden] { display: none; }
.ai-card {
    background: var(--paper);
    padding: 1.75rem;
    width: min(28rem, 92vw);
    border: 1px solid var(--line);
}
.progress { height: 6px; background: var(--line); margin-top: 1rem; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.25s linear; }
.progress.is-wait span { width: 30%; animation: load 1.2s infinite; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(350%); } }
.ai-meta, .ai-pct { font-size: 0.8rem; color: var(--muted); margin: 0.45rem 0 0; }
.ai-hint { font-size: 0.78rem; margin: 0.55rem 0 0; }
.ai-log {
    list-style: none;
    margin: 0.9rem 0 0;
    padding: 0;
    max-height: 9rem;
    overflow: auto;
    font-size: 0.82rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.ai-log li { border-bottom: 1px solid var(--line); padding-bottom: 0.3rem; }
.ai-log strong { display: inline; }
.ai-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.ai-card.is-error #ai-status { color: var(--neg); }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}
.chat-shell { display: flex; flex-direction: column; min-height: 28rem; padding: 0; }
.chat-log {
    flex: 1;
    overflow: auto;
    max-height: 62vh;
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.chat-msg { border: 1px solid var(--line); padding: 0.85rem 1rem; background: #fff; }
.chat-msg.is-user { background: #f5f0e6; }
.chat-who { margin: 0 0 0.35rem; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.chat-body { margin: 0; }
.chat-table { margin-top: 0.75rem; max-height: 18rem; }
.chat-actions { margin: 0.65rem 0 0; }
.chat-sql { margin-top: 0.65rem; font-size: 0.85rem; }
.chat-sql pre {
    margin: 0.4rem 0 0;
    padding: 0.7rem;
    background: #1c1917;
    color: #e7e5e4;
    overflow: auto;
    font-size: 0.78rem;
    white-space: pre-wrap;
}
.chat-form {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 0.9rem 1.1rem 1.1rem;
    border-top: 1px solid var(--line);
}
.chat-input { flex: 1; min-width: 12rem; margin: 0; }
.chat-input textarea { width: 100%; resize: vertical; min-height: 3.2rem; }
.chat-form #chat-status { flex-basis: 100%; margin: 0; }

.pager {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: flex-end;
    padding: 0.85rem 1.1rem;
    font-size: 0.9rem;
}

.lede a { color: #8a6500; }
.dre-wrap { overflow-x: auto; }
.dre-table { min-width: 44rem; }
.dre-table th.num, .dre-table td.num { width: 8.5rem; }
.dre-table .is-group td {
    font-weight: 650;
    background: #f7f4ee;
}
.dre-table .is-leaf td { color: #3f3a32; }
.dre-table .is-leaf td:first-child { padding-left: 1.85rem; font-weight: 400; }
.dre-table .is-total td {
    font-weight: 650;
    border-top: 2px solid var(--ink);
    background: #f3efe6;
}
.dre-table .is-result td {
    border-bottom: 2px solid var(--ink);
    background: color-mix(in srgb, var(--accent) 10%, white);
}
.dre-table a { color: inherit; }
.dre-table a:hover { text-decoration: underline; color: #8a6500; }
.dre-prefix { color: var(--muted); font-weight: 500; margin-right: 0.35rem; }
.dre-share, .dre-delta { display: block; font-size: 0.75rem; margin-top: 0.12rem; font-weight: 400; }
.dre-delta.good { color: var(--pos); }
.dre-delta.bad { color: var(--neg); }
.dre-notes { margin-top: 1rem; }
.dre-notes + .dre-notes { margin-top: 1rem; }
.bank-switch {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0.7rem 0 0;
}
.bank-switch a {
    border: 1px solid var(--line);
    padding: 0.28rem 0.7rem;
    font-size: 0.82rem;
    color: var(--muted);
    background: #fff;
}
.bank-switch a.active {
    border-color: var(--gold);
    background: var(--gold);
    color: var(--ink);
    font-weight: 800;
}
.bank-switch a:hover { border-color: var(--ink); color: var(--ink); }

@media (max-width: 960px) {
    body { grid-template-columns: 1fr; }
    .auth-body { grid-template-columns: 1fr; }
    .sidebar { min-height: auto; position: static; }
    .kpis, .grid-2 { grid-template-columns: 1fr; }
    .page-head { flex-direction: column; align-items: flex-start; }
}
