/* Ledger — one stylesheet, no build step (AssetMapper serves it as is). */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e2e5ea;
    --text: #17202e;
    --muted: #677285;
    --accent: #2f5bea;
    --accent-soft: #e8eefe;
    --in: #11865a;
    --in-soft: #e3f5ec;
    --out: #17202e;
    --danger: #c33a32;
    --danger-soft: #fbeae9;
    --warning: #9a6200;
    --warning-soft: #fdf2dc;
    --success: #11865a;
    --success-soft: #e3f5ec;
    --sidebar: #111827;
    --sidebar-text: #c9d0dc;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1117;
        --surface: #161b22;
        --surface-2: #1c232d;
        --border: #2a323d;
        --text: #e6e9ee;
        --muted: #8e99a8;
        --accent: #6d8dff;
        --accent-soft: #1d2747;
        --in: #3fcf8e;
        --in-soft: #12301f;
        --out: #e6e9ee;
        --danger: #f2716a;
        --danger-soft: #3a1a18;
        --warning: #f0b44c;
        --warning-soft: #3a2b10;
        --success: #3fcf8e;
        --success-soft: #12301f;
        --sidebar: #0a0d12;
        --shadow: none;
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 var(--font);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
pre { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: .75rem; border-radius: 8px; overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Layout ---------- */

.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 1.25rem .75rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 0 .5rem; color: #fff; font-weight: 700; font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand__mark { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #4f7bff, #23c49b); display: grid; place-items: center; font-size: 15px; }
.brand small { display: block; font-weight: 400; color: var(--sidebar-text); font-size: 11.5px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7b8494; padding: .75rem .65rem .3rem; }
.nav a {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .45rem .65rem; border-radius: 7px; color: var(--sidebar-text); font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a[aria-current="page"] { background: rgba(255, 255, 255, .1); color: #fff; }
.nav__count { font-size: 11.5px; font-weight: 600; background: rgba(255, 255, 255, .1); border-radius: 999px; padding: 0 .5rem; min-width: 1.6rem; text-align: center; }
.nav__count--alert { background: #f59e0b; color: #1c1300; }

.sidebar__user { margin-top: auto; padding: .75rem .65rem 0; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 13px; }
.sidebar__user strong { color: #fff; display: block; }
.sidebar__user a { color: var(--sidebar-text); }

.main { min-width: 0; padding: 1.75rem 2rem 4rem; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-header p { margin: .25rem 0 0; color: var(--muted); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.grid { display: grid; gap: 1rem; }
.grid--accounts { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid--2 { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.stack { display: flex; flex-direction: column; gap: 1rem; }

/* ---------- Cards ---------- */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card__header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); }
.card__body { padding: 1.1rem; }
.card__body > :last-child { margin-bottom: 0; }

.account-card { padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .35rem; color: inherit; }
.account-card:hover { text-decoration: none; border-color: var(--accent); }
.account-card__top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.account-card__name { font-weight: 600; }
.account-card__balance { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

.stat { display: flex; flex-direction: column; gap: .1rem; }
.stat__value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- Badges & amounts ---------- */

.badge {
    display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap;
    font-size: 11.5px; font-weight: 600; line-height: 1; padding: .3rem .5rem; border-radius: 999px;
    background: var(--surface-2); color: var(--muted);
}
.badge--currency { font-family: var(--mono); letter-spacing: .02em; background: var(--accent-soft); color: var(--accent); }
.badge--missing { background: var(--warning-soft); color: var(--warning); }
.badge--attached { background: var(--success-soft); color: var(--success); }
.badge--not_required { background: var(--surface-2); color: var(--muted); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.amount--in { color: var(--in); }
.amount--out { color: var(--out); }
.amount--void { text-decoration: line-through; color: var(--muted); }
.amount--lg { font-size: 2rem; letter-spacing: -.02em; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    font: inherit; font-weight: 550; line-height: 1.2; white-space: nowrap;
    padding: .5rem .85rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn--danger { color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); }
.btn--sm { padding: .3rem .55rem; font-size: 12.5px; border-radius: 7px; }
.btn--ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.inline-form { display: inline; margin: 0; }

/* ---------- Forms ---------- */

.form { display: flex; flex-direction: column; gap: 1rem; max-width: 560px; }
.form-row { display: flex; flex-direction: column; gap: .35rem; }
.form-row label { font-weight: 550; }
.form-row--check { flex-direction: row; flex-wrap: wrap; align-items: center; gap: .5rem; }
.form-row--check .form-help { flex-basis: 100%; margin-top: -.2rem; padding-left: 1.6rem; }
.form-help { color: var(--muted); font-size: 12.5px; }
.form-errors { list-style: none; margin: 0; padding: 0; color: var(--danger); font-size: 12.5px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=number], select, textarea {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem; width: 100%;
}
input[type=checkbox] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); margin: 0; }
textarea { resize: vertical; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.form-actions { display: flex; gap: .5rem; align-items: center; }

.filters {
    display: grid; gap: .6rem; align-items: end;
    grid-template-columns: minmax(200px, 2fr) repeat(auto-fit, minmax(140px, 1fr));
    padding: .9rem 1rem; margin-bottom: 1rem;
}
.filters .form-row label { font-size: 12px; color: var(--muted); font-weight: 550; }
.filters__reset { align-self: end; }

/* ---------- Movement list ---------- */

.totals { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.totals__item { padding: .65rem .9rem; display: flex; gap: 1.1rem; align-items: center; font-size: 13px; }
.totals__item .amount { font-size: 14px; }

.tx-list { overflow: hidden; }
.tx-head, .tx-row {
    display: grid; align-items: center; gap: .75rem;
    grid-template-columns: 92px minmax(0, 1fr) 150px 140px 130px;
    padding: .65rem 1.1rem;
}
.tx-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.tx-row { border-bottom: 1px solid var(--border); position: relative; transition: background .12s; }
.tx-row--compact { grid-template-columns: 92px minmax(0, 1fr) 140px 110px; }
.tx-row:last-child { border-bottom: 0; }
.tx-row:hover { background: var(--surface-2); }
.tx-row--over { background: var(--accent-soft) !important; outline: 2px dashed var(--accent); outline-offset: -4px; }
.tx-row--busy { opacity: .6; pointer-events: none; }
.tx-row__date { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.tx-row__main { min-width: 0; }
.tx-row__title { font-weight: 600; color: var(--text); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-row__title:hover { color: var(--accent); }
.tx-row__sub { display: flex; gap: .4rem; align-items: center; color: var(--muted); font-size: 12.5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tx-row__amount { text-align: right; }
.tx-row__amount .bill { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.tx-row__docs { display: flex; justify-content: flex-end; align-items: center; gap: .4rem; }
.tx-row__upload { display: flex; justify-content: flex-end; }
.tx-row__upload form { margin: 0; }
.tx-row__upload input[type=file] { display: none; }

.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: .25rem; }

/* ---------- Detail page ---------- */

.detail-hero { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; align-items: flex-start; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.doc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.doc-item { display: flex; align-items: center; gap: .75rem; padding: .65rem 0; border-bottom: 1px solid var(--border); }
.doc-item:last-child { border-bottom: 0; }
.doc-item__icon {
    flex: none; width: 36px; height: 44px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border);
    display: grid; place-items: center; font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--muted); font-family: var(--mono);
}
.doc-item__icon--pdf { color: #d0372d; }
.doc-item__body { flex: 1; min-width: 0; }
.doc-item__name { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.doc-item__actions { display: flex; gap: .25rem; flex: none; }

.dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem; text-align: center;
    border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.4rem 1rem; color: var(--muted);
    cursor: pointer; transition: border-color .12s, background .12s; margin: 0;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone--over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone--busy { opacity: .6; pointer-events: none; }
.dropzone input[type=file] { display: none; }
.dropzone strong { color: var(--text); }

.preview { width: 100%; height: 640px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
img.preview { height: auto; max-height: 640px; object-fit: contain; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); padding: .55rem 1.1rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: .65rem 1.1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table .ellipsis { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Flashes ---------- */

.flashes { position: fixed; top: 1rem; right: 1rem; z-index: 50; display: flex; flex-direction: column; gap: .5rem; width: min(420px, calc(100vw - 2rem)); }
.flash {
    display: flex; gap: .75rem; align-items: flex-start; justify-content: space-between;
    padding: .75rem .9rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
    box-shadow: 0 8px 24px rgba(16, 24, 40, .14); animation: flash-in .18s ease-out;
}
.flash--success { border-left: 4px solid var(--success); }
.flash--error { border-left: 4px solid var(--danger); }
.flash--warning { border-left: 4px solid var(--warning); }
.flash--leaving { opacity: 0; transform: translateY(-6px); transition: all .2s; }
.flash__close { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 0; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } }

.notice { padding: .8rem 1rem; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 1rem; }
.notice--warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.notice--error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.notice--success { background: var(--success-soft); border-color: transparent; color: var(--success); }

.steps { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .6rem; }

/* ---------- Pagination ---------- */

.pagination { display: flex; gap: .25rem; justify-content: center; padding: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span { min-width: 2rem; padding: .3rem .55rem; border-radius: 7px; text-align: center; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.pagination a:hover { text-decoration: none; background: var(--surface-2); }
.pagination .current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* Turbo: a frame being reloaded */
turbo-frame[busy] { opacity: .55; transition: opacity .15s; }
turbo-frame { display: block; }

/* ---------- Login ---------- */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth__card { width: min(400px, 100%); padding: 2rem; }
.auth__card .brand { color: var(--text); padding: 0; margin-bottom: 1.5rem; }
.auth__card .brand small { color: var(--muted); }

/* ---------- Small screens ---------- */

@media (max-width: 980px) {
    .grid--2 { grid-template-columns: 1fr; }
    .tx-head { display: none; }
    .tx-row, .tx-row--compact { grid-template-columns: 1fr auto; grid-template-areas: "main amount" "date docs"; gap: .3rem .75rem; }
    .tx-row__main { grid-area: main; }
    .tx-row__amount { grid-area: amount; }
    .tx-row__date { grid-area: date; }
    .tx-row__docs { grid-area: docs; }
    .tx-row__upload { display: none; }
}

@media (max-width: 760px) {
    /* The menu keeps its height on short pages; the page takes the rest. */
    .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .sidebar { position: static; height: auto; padding: .75rem 1rem; gap: .5rem; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .nav__label, .sidebar__user { display: none; }
    .main { padding: 1.25rem 1rem 3rem; }
    .filters { grid-template-columns: 1fr 1fr; }
    .filters .form-row:first-child { grid-column: 1 / -1; }
    .totals__item { flex: 1 1 100%; flex-wrap: wrap; gap: .35rem 1rem; }
}

/* Tables become one block per row on a phone: each cell with its column name. */
@media (max-width: 640px) {
    .table--stack, .table--stack tbody { display: block; }
    .table--stack thead { display: none; }
    .table--stack tr { display: flex; flex-direction: column; gap: .35rem; padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
    .table--stack tr:last-child { border-bottom: 0; }
    /* Label on the left, the cell's content (one or more lines) on the right. */
    .table--stack td { display: block; padding: 0; border: 0; text-align: right; max-width: none; white-space: normal; overflow-wrap: anywhere; }
    .table--stack td[data-label]::before { content: attr(data-label); float: left; margin-right: 1rem; color: var(--muted); font: 12px/1.7 var(--font); }
    /* The row's title (first cell, or marked) comes first, without a label. */
    .table--stack td:first-child:not([data-label]), .table--stack .table__title { order: -1; display: block; text-align: left; font-weight: 600; }
    .table--stack .table__title .muted { font-weight: 400; }
    /* Buttons last, on the right. */
    .table--stack td:last-child:not([data-label]):not(:first-child) { margin-top: .2rem; }
    .table--stack td[colspan] { display: block; }
}

/* Invoice data read from a document */
.invoice-line { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; font-size: 12.5px; margin-top: .3rem; }
.invoice-line:empty { display: none; }
.badge--invoice { background: var(--accent-soft); color: var(--accent); }
.badge--reading { background: var(--surface-2); color: var(--muted); }
.badge--auto { background: var(--success-soft); color: var(--success); }
.mono { font-family: var(--mono); }
.spinner { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* Inbox: suggested movements */
.suggestions { display: flex; flex-direction: column; gap: .35rem; margin-top: .6rem; }
.suggestion { display: flex; align-items: center; gap: .6rem; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.suggestion__body { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: .1rem .6rem; align-items: baseline; }
.suggestion__label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.suggestion__why { color: var(--muted); font-size: 12px; }
.inbox-item { padding: .9rem 0; border-bottom: 1px solid var(--border); }
.inbox-item:last-child { border-bottom: 0; }
.inbox-item__head { display: flex; align-items: center; gap: .75rem; }
.inbox-item__more { margin: .6rem 0 0 calc(36px + .75rem); }
.mail-address { font-family: var(--mono); background: var(--surface-2); padding: .1rem .4rem; border-radius: 6px; user-select: all; }
.amount-mismatch { color: var(--warning); font-size: 12.5px; margin-top: .25rem; }
@media (max-width: 640px) {
    .inbox-item__more { margin-left: 0; }
    .suggestion { flex-wrap: wrap; }
}

/* Phone capture page */
.capture-bar { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; background: var(--sidebar); color: var(--sidebar-text); }
.capture-bar .brand { padding: 0; }
.capture-bar a { color: var(--sidebar-text); font-weight: 500; }
.capture { max-width: 520px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.capture h1 { margin-bottom: 1rem; }
.capture__form { display: flex; flex-direction: column; gap: .9rem; }
.capture__shoot {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem;
    min-height: 168px; border-radius: 16px; background: var(--accent); color: #fff; font-size: 18px; font-weight: 600;
    cursor: pointer; box-shadow: 0 6px 18px rgba(47, 91, 234, .25); -webkit-tap-highlight-color: transparent;
}
.capture__shoot:active { filter: brightness(.95); }
.capture__icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: rgba(255, 255, 255, .18); }
.capture__pick { justify-content: center; padding: .8rem; }
.capture__form--busy .capture__shoot { opacity: .7; pointer-events: none; }
.capture__form--busy .capture__icon svg { animation: spin 1.2s linear infinite; }
.capture__recent { margin-top: 2rem; }
.capture__recent h2 { font-size: 15px; margin-bottom: .25rem; }
.capture .form-row select, .capture .form-row input { width: 100%; font-size: 16px; }

/* Settings → Automation: AI providers */
.ai-settings { max-width: none; }
.ai-provider { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0; display: flex; flex-direction: column; gap: .8rem; }
.ai-provider legend { font-weight: 600; padding: 0 .35rem; }
