/* ===== Haushaltsbuch – Design-Grundlage ===== */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #1e2a32;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(15, 30, 40, .07), 0 4px 14px rgba(15, 30, 40, .05);

  --primary: #0f766e;        /* Petrol */
  --primary-soft: #e0f2f0;
  --info: #0369a1;
  --info-soft: #e0f0fa;

  --good: #15803d;
  --good-soft: #e3f4e8;
  --warn: #b45309;
  --warn-soft: #fdf0dd;
  --bad: #b91c1c;
  --bad-soft: #fde7e7;

  --radius: 14px;
  --radius-sm: 9px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[data-theme="dark"] {
  --bg: #10171d;
  --surface: #1a232b;
  --surface-2: #22303a;
  --text: #e6edf3;
  --text-muted: #8fa3b3;
  --border: #2c3a46;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --primary: #2dd4bf;
  --primary-soft: #143733;
  --info: #38bdf8;
  --info-soft: #12303f;
  --good: #4ade80;
  --good-soft: #14301c;
  --warn: #fbbf24;
  --warn-soft: #3a2c10;
  --bad: #f87171;
  --bad-soft: #3b1a1a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.5;
}
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--text-muted); }
.small { font-size: .84rem; }
a { color: var(--primary); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* ===== Layout ===== */
.app { min-height: 100dvh; }
.main {
  padding: 14px 14px calc(84px + env(safe-area-inset-bottom));
  max-width: 1080px;
  margin: 0 auto;
}
.view { animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.sidebar { display: none; }

/* Mobile Bottom-Nav */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 40;
}
.bottomnav button {
  flex: 1; max-width: 90px;
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .68rem; color: var(--text-muted);
  padding: 4px 2px; border-radius: var(--radius-sm);
  font-family: inherit;
  min-height: 44px; /* Touch-Mindestgröße */
}
.bottomnav button .nav-ico { font-size: 1.25rem; line-height: 1; }
.bottomnav button.active { color: var(--primary); font-weight: 600; }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(74px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 1.7rem;
  border: none; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  z-index: 41; line-height: 1;
}
.fab:active { transform: scale(.95); }

/* Desktop */
@media (min-width: 960px) {
  .app { display: grid; grid-template-columns: 230px 1fr; }
  .bottomnav, .fab { display: none; }
  .sidebar {
    display: flex; flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 18px 12px;
    position: sticky; top: 0; height: 100dvh;
  }
  .sidebar-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; padding: 4px 10px 18px; }
  .brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); }
  .sidebar-links { display: flex; flex-direction: column; gap: 2px; flex: 1; }
  .sidebar-links button {
    display: flex; align-items: center; gap: 10px;
    background: none; border: none; cursor: pointer; font-family: inherit;
    font-size: .92rem; color: var(--text); text-align: left;
    padding: 9px 10px; border-radius: var(--radius-sm);
  }
  .sidebar-links button:hover { background: var(--surface-2); }
  .sidebar-links button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
  .sidebar-footer { padding-top: 10px; }
  .main { padding: 22px 28px 40px; }
}

/* ===== Karten & Grids ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card h2, .card h3 { display: flex; align-items: center; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.kpi { padding: 12px 14px; margin: 0; }
.kpi .kpi-label { font-size: .78rem; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.kpi .kpi-value { font-size: 1.25rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: .76rem; color: var(--text-muted); }

.pos { color: var(--good); }
.neg { color: var(--bad); }
.warn-text { color: var(--warn); }

/* Ampel / Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .76rem; font-weight: 600;
  padding: 3px 10px; border-radius: 99px;
}
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--surface-2); color: var(--text-muted); }

/* Fortschrittsbalken */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 99px; transition: width .3s ease; }
.progress .p-good { background: var(--good); }
.progress .p-warn { background: var(--warn); }
.progress .p-bad { background: var(--bad); }
.progress .p-info { background: var(--info); }
.progress .p-primary { background: var(--primary); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: inherit; font-size: .9rem; font-weight: 600;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  padding: 9px 16px; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Segment-Auswahl (Buchungstyp) */
.segment { display: flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.segment button {
  flex: 1; border: none; background: none; cursor: pointer; font-family: inherit;
  font-size: .82rem; font-weight: 600; color: var(--text-muted);
  padding: 8px 4px; border-radius: 7px;
}
.segment button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segment button.active.seg-in { color: var(--good); }
.segment button.active.seg-out { color: var(--bad); }
.segment button.active.seg-save { color: var(--info); }

/* ===== Formulare ===== */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font-family: inherit; font-size: 1rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px;
}
input[type="checkbox"] { width: auto; }
textarea { resize: vertical; min-height: 60px; }
.amount-input { font-size: 1.5rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: .9rem; }

/* ===== Listen & Tabellen ===== */
.tx-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
  cursor: pointer; border-radius: 6px;
}
.tx-item:hover { background: var(--surface-2); }
.tx-item:last-child { border-bottom: none; }
.tx-ico {
  width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
  background: var(--surface-2);
}
.tx-body { flex: 1; min-width: 0; }
.tx-title { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: .76rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-flags { font-size: .7rem; }

table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); padding: 8px 8px; border-bottom: 1px solid var(--border); }
table.data td { padding: 8px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Filterzeile */
.filterbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filterbar input, .filterbar select { width: auto; flex: 1; min-width: 120px; padding: 8px 10px; font-size: .88rem; }
.filterbar input[type="search"] { min-width: 160px; }

/* ===== Leere Zustände ===== */
.empty {
  text-align: center; padding: 34px 18px; color: var(--text-muted);
}
.empty .empty-ico { font-size: 2.4rem; margin-bottom: 8px; }
.empty h3 { color: var(--text); }

/* ===== Kopfzeile pro View ===== */
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav button { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); cursor: pointer; padding: 6px 11px; font-size: 1rem; color: var(--text); }
.month-nav .month-label { font-weight: 700; min-width: 130px; text-align: center; }

/* ===== Banner / Toast / Modal ===== */
.offline-banner, .demo-banner {
  border-radius: var(--radius-sm); padding: 8px 14px; margin-bottom: 12px;
  font-size: .84rem; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
}
.offline-banner { background: var(--warn-soft); color: var(--warn); }
.demo-banner { background: var(--info-soft); color: var(--info); }

.toast {
  position: fixed; bottom: calc(88px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 99px; font-size: .88rem; font-weight: 600;
  z-index: 100; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
@media (min-width: 960px) { .toast { bottom: 30px; } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 26, .5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 60; animation: fadein .15s ease;
}
.modal {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto;
}
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 18px; }
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { margin: 0; }
.modal-close { background: var(--surface-2); border: none; border-radius: 50%; width: 32px; height: 32px; cursor: pointer; font-size: 1rem; color: var(--text-muted); }

/* ===== Lockscreen ===== */
.lockscreen {
  position: fixed; inset: 0; background: var(--bg); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.lock-box { text-align: center; padding: 24px; max-width: 300px; width: 100%; }
.lock-icon { font-size: 2.6rem; margin-bottom: 10px; }
.lock-box input { text-align: center; font-size: 1.4rem; letter-spacing: .3em; margin-bottom: 10px; }
.pin-error { color: var(--bad); font-size: .85rem; }

/* ===== Diagramme ===== */
.chart-wrap { overflow-x: auto; }
.chart-wrap svg { display: block; max-width: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .78rem; color: var(--text-muted); margin-top: 8px; }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

/* Budget-Zeile */
.budget-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.budget-row:last-child { border-bottom: none; }
.budget-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.budget-name { font-weight: 600; font-size: .92rem; }
.budget-nums { font-size: .8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Rücklagen */
.goal-card .goal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.goal-nums { display: flex; justify-content: space-between; font-size: .8rem; color: var(--text-muted); margin-top: 5px; font-variant-numeric: tabular-nums; }

/* Beleg-Vorschau */
.receipt-thumb { width: 54px; height: 54px; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-2); }
.receipt-full { max-width: 100%; border-radius: var(--radius-sm); }
.split-row { display: grid; grid-template-columns: 1fr 110px 36px; gap: 6px; margin-bottom: 6px; align-items: center; }

/* Hilfsklassen */
.hidden { display: none !important; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.divider { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 99px; padding: 5px 12px; font-size: .8rem; cursor: pointer; font-family: inherit;
}
.chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }

@media print {
  .sidebar, .bottomnav, .fab, .filterbar, .btn, .demo-banner, .offline-banner { display: none !important; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; color: #000; }
}
