/* Kontobuch — Ledger-Ästhetik: Papier, Tinte, Tannengrün. */

:root {
  --paper: #f4f0e4;
  --card: #fffdf6;
  --card-dim: #faf6ea;
  --ink: #202a24;
  --ink-dim: #5f6961;
  --ink-faint: #8b938c;
  --line: #d8d0b8;
  --line-soft: #e7e1cd;
  --brand: #175b3e;
  --brand-deep: #0e4530;
  --brand-wash: #e3ead9;
  --in: #157a4a;
  --in-wash: #e2efe2;
  --out: #ae3b2c;
  --out-wash: #f6e6de;
  --gold: #a8852b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(32, 42, 36, 0.06), 0 8px 24px -18px rgba(32, 42, 36, 0.35);
  --font-ui: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --font-mono: "Spline Sans Mono", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { color-scheme: only light; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Feines Papierkorn über allem */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.13 0 0 0 0 0.16 0 0 0 0 0.14 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 550; letter-spacing: -0.01em; }
h2 { font-size: 21px; margin: 0 0 4px; }
h3 { font-size: 16.5px; margin: 0 0 10px; }

a { color: var(--brand); }

/* ---------------------------------------------------------------- Topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(to bottom, var(--brand-deep), var(--brand));
  color: #f2eedd;
  border-bottom: 3px double rgba(242, 238, 221, 0.5);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 26px;
  min-height: 54px;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  font-size: 21px;
  color: #f6f2e2;
  text-decoration: none;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.brand .tick { color: #c9b45c; }

.nav { display: flex; gap: 2px; flex-wrap: wrap; }

.nav a {
  color: rgba(242, 238, 221, 0.78);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.nav a.active { color: var(--brand-deep); background: #ecd9a0; }

.topbar-spacer { flex: 1; }

.btn-logout {
  background: none;
  border: 1px solid rgba(242, 238, 221, 0.35);
  color: rgba(242, 238, 221, 0.85);
  font: inherit;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.btn-logout:hover { border-color: #fff; color: #fff; }

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

main { max-width: 1180px; margin: 0 auto; padding: 26px 20px 80px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head .sub { color: var(--ink-dim); font-size: 13px; margin: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 860px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}

.block { margin-top: 22px; }

/* Karten in einer Grid-Reihe: gleiche Höhe, Inhalt spaltig, Button unten bündig */
.grid > .card { display: flex; flex-direction: column; }
.grid > .card > .btn { margin-top: auto; align-self: flex-start; }

/* Kacheln */
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 16px 11px;
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--ink-faint);
}
.stat.stat-in::after { background: var(--in); }
.stat.stat-out::after { background: var(--out); }
.stat.stat-balance::after { background: var(--gold); }
.stat .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-dim);
}
.stat .value {
  font-family: var(--font-mono);
  font-size: 23px;
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.stat .hint { font-size: 12px; color: var(--ink-faint); margin-top: 1px; }

/* ---------------------------------------------------------------- Tabellen */

.table-wrap { overflow-x: auto; }

table.ledger { width: 100%; border-collapse: collapse; font-size: 13.5px; }

table.ledger th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  padding: 7px 10px;
  border-bottom: 2px solid var(--ink);
  white-space: nowrap;
  user-select: none;
}
table.ledger th.sortable { cursor: pointer; }
table.ledger th.sortable:hover { color: var(--brand); }
table.ledger th .arrow { font-size: 9px; margin-left: 3px; }

table.ledger td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
table.ledger tbody tr:hover td { background: var(--card-dim); }
table.ledger tr.clickable { cursor: pointer; }

table.ledger td.num, table.ledger th.num { text-align: right; }
td.num, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.amount-in { color: var(--in); }
.amount-out { color: var(--out); }
.amount-neg { color: var(--out); }
.muted { color: var(--ink-faint); }
.small { font-size: 12px; }

table.ledger tfoot td {
  border-top: 2px solid var(--ink);
  border-bottom: none;
  font-weight: 600;
  padding-top: 8px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge-in { background: var(--in-wash); color: var(--in); }
.badge-out { background: var(--out-wash); color: var(--out); }
.badge-plain { background: var(--brand-wash); color: var(--brand-deep); }
.badge-archived { background: #e8e4d5; color: var(--ink-dim); }

.empty {
  color: var(--ink-faint);
  font-size: 13.5px;
  padding: 22px 10px;
  text-align: center;
  font-style: italic;
}

/* ---------------------------------------------------------------- Formulare */

label.field { display: block; margin-bottom: 11px; }
label.field span.lbl {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  margin-bottom: 3px;
}

input[type="text"], input[type="date"], input[type="search"], input[type="password"],
input[type="number"], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
}
textarea { resize: vertical; min-height: 54px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}
input.amount { font-family: var(--font-mono); text-align: right; }

.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; min-width: 0; }

.btn {
  display: inline-block;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 15px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  letter-spacing: 0.01em;
}
.btn:hover { border-color: var(--ink-dim); }
.btn-primary { background: var(--brand); border-color: var(--brand-deep); color: #f4f1e2; }
.btn-primary:hover { background: var(--brand-deep); }
.btn-in { background: var(--in); border-color: var(--in); color: #fff; }
.btn-in:hover { filter: brightness(0.92); }
.btn-out { background: var(--out); border-color: var(--out); color: #fff; }
.btn-out:hover { filter: brightness(0.92); }
.btn-danger { color: var(--out); border-color: var(--out); background: #fff; }
.btn-danger:hover { background: var(--out-wash); }
.btn-sm { font-size: 12px; padding: 4px 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 5px;
  border-radius: 5px;
  color: var(--ink-dim);
}
.icon-btn:hover { background: var(--brand-wash); color: var(--brand-deep); }
.icon-btn.danger:hover { background: var(--out-wash); color: var(--out); }

/* Segment-Umschalter (Übersicht: Zusammenfassung / Nach Konten) */
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.seg button {
  border: none;
  background: transparent;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink-dim);
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--brand); color: #f4f1e2; }

/* Filterleiste */
.filterbar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  margin-bottom: 16px;
}
.filterbar label.field { margin: 0; }
.filterbar .field input, .filterbar .field select { width: auto; min-width: 130px; }
.filterbar .quick { display: flex; gap: 5px; flex-wrap: wrap; }

/* Buchen-Karten */
.book-card { border-top: 4px solid var(--line); }
.book-card.in { border-top-color: var(--in); }
.book-card.out { border-top-color: var(--out); }
.book-card h3 { display: flex; align-items: center; gap: 8px; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 30px 20px;
  text-align: center;
  color: var(--ink-dim);
  cursor: pointer;
  background: var(--card-dim);
}
.dropzone.dragover { border-color: var(--brand); background: var(--brand-wash); color: var(--brand-deep); }
.dropzone .big { font-size: 26px; display: block; margin-bottom: 4px; }

/* Verteilungsschlüssel */
.dist-list { display: flex; flex-direction: column; gap: 6px; }
.dist-row { display: flex; gap: 8px; align-items: center; }
.dist-row input.pct { width: 90px; text-align: right; font-family: var(--font-mono); }
.dist-sum { font-size: 12.5px; color: var(--ink-dim); margin-top: 8px; }
.dist-sum.bad { color: var(--out); font-weight: 600; }

.bar {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: var(--line-soft);
  margin: 6px 0 2px;
}
.bar span { height: 100%; }

/* ---------------------------------------------------------------- Modal */

dialog.modal {
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 24px 70px -20px rgba(32, 42, 36, 0.5);
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  background: var(--card);
  color: var(--ink);
}
dialog.modal.modal-wide { width: min(880px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(32, 42, 36, 0.45); }
table.batch-table input { padding: 4px 8px; font-size: 13px; }
table.batch-table input.amount { width: 110px; }
table.batch-table input[type="date"] { width: 150px; }
.modal-head {
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px 18px; max-height: 65vh; overflow-y: auto; }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Toast */
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink);
  color: #f4f1e2;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
  max-width: 360px;
}
.toast.error { background: var(--out); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* CSV-Vorschau */
.csv-preview-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.csv-preview { border-collapse: collapse; font-size: 12.5px; min-width: 100%; }
table.csv-preview th { background: var(--card-dim); padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.csv-preview th select { font-size: 12px; padding: 3px 5px; margin-bottom: 4px; width: auto; max-width: 150px; }
table.csv-preview th .colname { display: block; font-weight: 600; color: var(--ink-dim); font-size: 11px; }
table.csv-preview td { padding: 4px 8px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }

/* Login */
body.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    radial-gradient(1100px 500px at 50% -10%, rgba(23, 91, 62, 0.16), transparent 60%),
    var(--paper);
}
.login-card {
  width: min(380px, calc(100vw - 40px));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 34px 30px 28px;
  text-align: center;
}
.login-card .brand-big {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  font-size: 34px;
  color: var(--brand-deep);
  margin: 0 0 2px;
}
.login-card .brand-big .tick { color: var(--gold); }
.login-card .tagline { color: var(--ink-dim); font-size: 13px; margin: 0 0 24px; }
.login-error {
  background: var(--out-wash);
  color: var(--out);
  font-size: 13px;
  border-radius: 7px;
  padding: 8px 12px;
  margin-bottom: 14px;
}

.rule { border: none; border-top: 1px solid var(--line-soft); margin: 14px 0; }

.doc-text-view {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--card-dim);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 12px;
  max-height: 45vh;
  overflow-y: auto;
}

.import-result { margin-top: 14px; }
.error-list { font-size: 12.5px; color: var(--out); max-height: 160px; overflow-y: auto; margin: 6px 0 0; padding-left: 18px; }

@media (max-width: 720px) {
  .topbar-inner { padding: 8px 14px; gap: 10px; }
  .topbar-spacer { display: none; }
  .brand { font-size: 18px; }
  .nav a { padding: 5px 9px; }
  main { padding: 18px 14px 60px; }
  .form-row { flex-direction: column; gap: 0; }
}
