:root {
    --ink: #1c1915;
    --muted: #5e584e;
    --paper: #f3eee4;
    --card: #fffdf8;
    --line: #e3d9c8;
    --send: #1d6b43;
    --send-bg: #e7f4ec;
    --receive: #8d3d32;
    --receive-bg: #f8ece8;
    --focus: #1f4d3a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font: 14px/1.4 "Segoe UI", sans-serif;
}

h1, h2, p { margin: 0; }

.wrap {
    width: min(960px, calc(100% - 32px));
    margin: 0 auto;
}

.top {
    background: #24382e;
    color: #f7f3ea;
    padding: 22px 0 18px;
}

.top h1 {
    font-size: 1.15rem;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.bar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-top: 6px;
}

.brand {
    color: #d9e4db;
    font-size: 0.85rem;
}

nav {
    display: flex;
    align-items: center;
    gap: 14px;
}

nav a,
button.link {
    color: #f7f3ea;
    text-decoration: none;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: pointer;
}

nav a[aria-current="page"] {
    text-decoration: underline;
    text-underline-offset: 4px;
}

main { padding: 22px 0 48px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    margin-top: 14px;
}

.card h2 {
    font-size: 0.95rem;
    margin-bottom: 12px;
}

.narrow { max-width: 420px; margin-left: auto; margin-right: auto; }

.summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.summary p,
.stack label,
.entry-form label,
.import-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.summary p {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
}

.summary span,
label {
    color: var(--muted);
    font-size: 0.82rem;
}

.summary strong {
    color: var(--ink);
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
}

.stack { display: grid; gap: 12px; }

input[type="text"],
input[type="password"],
input[type="date"],
input[type="file"],
select {
    width: 100%;
    border: 1px solid #d4c9b6;
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    padding: 9px 10px;
    font: inherit;
}

input:focus {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

button,
.button {
    border: 0;
    border-radius: 8px;
    padding: 9px 14px;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    background: #ece4d6;
    color: var(--ink);
}

button.primary,
.send-btn {
    background: var(--send);
    color: #fff;
}

.receive-btn {
    background: var(--receive);
    color: #fff;
}

.entry-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
}

.entry-form label { flex: 1 1 140px; }
.entry-form .field-date { flex: 0 0 7.4rem; width: 7.4rem; }
.entry-form .field-amount { flex: 0 0 6.2rem; width: 6.2rem; }
.entry-form .field-name { flex: 1 1 18rem; }
.actions { display: flex; gap: 8px; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: end;
    gap: 12px 20px;
    margin-bottom: 14px;
}

.filters,
.file-actions,
.import-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: end;
}

.filters label { width: 8.2rem; }
.filters select { width: 100%; }

.file-actions { margin-left: auto; }

.import-form input[type="file"] { width: 12.5rem; }

.hint, .empty { color: var(--muted); margin-top: 10px; }

.flash {
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.flash.ok { background: var(--send-bg); color: var(--send); }
.flash.err { background: var(--receive-bg); color: var(--receive); }

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

th, td {
    text-align: left;
    padding: 8px 6px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

th { color: var(--muted); font-size: 0.82rem; font-weight: 650; }
.num { text-align: right; white-space: nowrap; }
.send { color: var(--send); }
.receive { color: var(--receive); }

.text-btn {
    background: transparent;
    color: var(--receive);
    padding: 4px 0;
}

.entries-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.entries-bar h2 { margin-bottom: 0; }

.edit-controls { position: relative; display: flex; align-items: center; gap: 8px; }

.edit-toggle {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.edit-field,
.edit-only,
.edit-close {
    display: none;
}

.edit-open,
.edit-close {
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
}

.edit-open { background: #ece4d6; }
.edit-close { color: var(--muted); }
.save-btn {
    background: var(--send);
    color: #fff;
    padding: 6px 10px;
}

.col-date { width: 7.6rem; white-space: nowrap; }
.col-amount { width: 6.4rem; }
.col-actions { width: 4.5rem; text-align: right; }

.ledger:has(.edit-toggle:checked) .view,
.ledger:has(.edit-toggle:checked) .edit-open { display: none; }
.ledger:has(.edit-toggle:checked) .edit-close { display: inline; }
.ledger:has(.edit-toggle:checked) .edit-field { display: block; }
.ledger:has(.edit-toggle:checked) .edit-only { display: inline-block; }

td .edit-field { width: 100%; min-width: 0; padding: 6px 8px; }

button.link:focus,
button:focus,
.button:focus {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

@media (max-width: 720px) {
    .toolbar { flex-direction: column; align-items: stretch; }
    .filters { width: 100%; }
    .filters label { flex: 1 1 7rem; width: auto; }
    .file-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        margin-left: 0;
        width: 100%;
    }
    .file-actions > a:first-of-type { grid-column: 1; grid-row: 1; }
    .file-actions > a:last-of-type { grid-column: 2; grid-row: 1; }
    .file-actions > .button { text-align: center; }
    .import-form {
        grid-column: 1 / -1;
        grid-row: 2;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
    }
    .import-form input[type="file"] { width: 100%; min-width: 0; }
}

@media (max-width: 520px) {
    .summary { grid-template-columns: 1fr; }
    .bar { align-items: flex-start; flex-direction: column; }
    .top h1 { font-size: 1.05rem; }
    .entry-form .field-date,
    .entry-form .field-amount { flex: 1 1 7rem; width: auto; }
    .actions { width: 100%; }
    .actions button { flex: 1; }
    th, td { padding: 8px 4px; }
    .col-date { width: auto; }
    .ledger:has(.edit-toggle:checked) table { min-width: 40rem; }
}
