/* ==========================================================================
   Wohnung Dashboard — Design
   Farbwelt bewusst warm gehalten (Papier/Terracotta), damit es sich eher
   nach Wohnzimmer als nach Buchhaltungssoftware anfühlt.
   ========================================================================== */

:root {
  /* Muss dem Theme folgen, sonst zeichnet der Browser Checkboxen, Auswahlfelder
     und Datumsauswahl im Systemmodus — also dunkel auf heller Seite. */
  color-scheme: light;

  --bg: #f4f2ee;
  --panel: #faf9f6;
  --card: #ffffff;
  --ink: #1b1a18;
  --muted: #6c6a64;
  --faint: #98968d;
  --border: #e6e2da;
  --border2: #d6d1c7;

  --accent: #b5502f;
  --accent-soft: #f8ece7;
  --accent-ink: #8d3d23;

  --green: #3d6b16;
  --green-soft: #eaf2dd;
  --blue: #175b9e;
  --blue-soft: #e6f0fa;
  --amber: #8a5709;
  --amber-soft: #faeed8;
  --red: #a52a2a;
  --red-soft: #fbeaea;
  --purple: #4b41a0;
  --purple-soft: #eeedfd;
  --teal: #0f6b54;
  --teal-soft: #e0f4ed;

  --shadow-sm: 0 1px 2px rgba(28, 24, 18, 0.05);
  --shadow: 0 2px 10px rgba(28, 24, 18, 0.07);
  --shadow-lg: 0 12px 40px rgba(28, 24, 18, 0.18);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --nav-w: 232px;
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #15140f;
  --panel: #1d1c18;
  --card: #23221d;
  --ink: #eceae3;
  --muted: #a5a298;
  --faint: #75736a;
  --border: #302e27;
  --border2: #3e3b32;

  --accent: #e08a6b;
  --accent-soft: #2d2019;
  --accent-ink: #eda182;

  --green: #9ac95c;
  --green-soft: #1d2411;
  --blue: #6aa9ea;
  --blue-soft: #10202f;
  --amber: #e9a944;
  --amber-soft: #2b2210;
  --red: #ea8a8a;
  --red-soft: #2a1413;
  --purple: #a9a1ea;
  --purple-soft: #1c1a30;
  --teal: #5fcda7;
  --teal-soft: #0b241d;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* Zahlen tabellarisch — Beträge sollen untereinander fluchten */
.num, .kpi-val, td.num, .betrag { font-variant-numeric: tabular-nums; }

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

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

.app { display: flex; min-height: 100vh; }

.nav {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 22px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { padding: 0 10px 18px; }
.brand-title { font-size: 16px; font-weight: 650; letter-spacing: -0.2px; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg); color: var(--ink); }
.nav-item.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav-item .ico { font-size: 15px; width: 18px; text-align: center; flex: 0 0 18px; }
.nav-item .badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 650;
  background: var(--accent);
  color: #fff;
  padding: 1px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}
.nav-item .badge.quiet { background: var(--border2); color: var(--muted); }

.nav-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--faint); }
.nav-foot .who { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; color: var(--muted); }
.nav-tools { display: flex; gap: 6px; flex-wrap: wrap; }

.main { flex: 1; min-width: 0; padding: 26px 30px 80px; }
.main-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.main-head h1 { font-size: 24px; font-weight: 650; letter-spacing: -0.4px; }
.main-head .lead { color: var(--muted); font-size: 13.5px; margin-top: 3px; max-width: 62ch; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Mobile Navigation */
.topbar { display: none; }

/* ---------- Bausteine --------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.card > h2, .card > .card-head h2 { font-size: 15px; font-weight: 650; letter-spacing: -0.15px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .hint { font-size: 12.5px; color: var(--muted); font-weight: 400; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.kpi-lbl { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; }
.kpi-val { font-size: 25px; font-weight: 650; line-height: 1.15; margin-top: 7px; letter-spacing: -0.6px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.accent { background: var(--accent-soft); border-color: transparent; }
.kpi.accent .kpi-val { color: var(--accent-ink); }
.kpi.warn { background: var(--amber-soft); border-color: transparent; }
.kpi.warn .kpi-val { color: var(--amber); }
.kpi.good { background: var(--green-soft); border-color: transparent; }
.kpi.good .kpi-val { color: var(--green); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 20px;
  background: var(--border); color: var(--muted); white-space: nowrap;
}
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.purple { background: var(--purple-soft); color: var(--purple); }
.pill.teal { background: var(--teal-soft); color: var(--teal); }
.pill.accent { background: var(--accent-soft); color: var(--accent-ink); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }

.avatar {
  width: 24px; height: 24px; border-radius: 50%; flex: 0 0 24px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
}
.avatar.sm { width: 19px; height: 19px; flex-basis: 19px; font-size: 9.5px; }

/* ---------- Buttons & Formular ------------------------------------------ */

.btn {
  border: 1px solid var(--border2);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.06s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.pri:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg); color: var(--ink); }
.btn.danger { color: var(--red); border-color: var(--border2); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.icon { padding: 6px 9px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  font: inherit;
  font-size: 14px;
  padding: 8px 11px;
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--ink);
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
input[type='checkbox'] { width: auto; accent-color: var(--accent); }
input[type='color'] { padding: 2px; height: 36px; }
input[type='file'] { border: 1px dashed var(--border2); background: var(--panel); cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field .help { font-size: 11.5px; color: var(--faint); line-height: 1.4; }
.field.wide { grid-column: 1 / -1; }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check > label { font-size: 13.5px; color: var(--ink); font-weight: 450; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 13px; }
.fields.narrow { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.inline-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 13px; }
.inline-toolbar .spacer { flex: 1; }
.search { max-width: 260px; }

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

.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 0 10px 8px; white-space: nowrap; border-bottom: 1px solid var(--border);
}
th.num, td.num { text-align: right; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel); }
tr.done td { opacity: 0.5; }
tr.done .t-title { text-decoration: line-through; }
td .t-title { font-weight: 550; }
td .t-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
tfoot td { font-weight: 650; border-top: 2px solid var(--border); border-bottom: 0; padding-top: 12px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: 0; transition: opacity 0.12s; }
tr:hover .row-actions,
.item:hover .row-actions,
.check-row:hover .row-actions,
.card:hover > .card-head .row-actions,
.row-actions:focus-within { opacity: 1; }
/* Ohne Hover (Touch) sind die Knöpfe dauerhaft sichtbar, sonst kämen Amalia und
   Johannes am Handy nie ans Bearbeiten heran. */
@media (hover: none) { .row-actions { opacity: 1; } }

/* ---------- Listen ------------------------------------------------------ */

.list { display: flex; flex-direction: column; gap: 9px; }
.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r);
  padding: 11px 14px;
}
.item.flat { background: transparent; border-color: transparent; padding: 8px 0; border-bottom: 1px solid var(--border); border-radius: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 550; font-size: 14px; }
.item .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item .s.wrap { white-space: normal; }
.item.warn { border-color: var(--amber); background: var(--amber-soft); }
.item.urgent { border-color: var(--red); background: var(--red-soft); }
.item.ok { border-left: 3px solid var(--green); }

.check-row { display: flex; align-items: flex-start; gap: 11px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.check-row:last-child { border-bottom: 0; }
.check-row input[type='checkbox'] { margin-top: 3px; width: 17px; height: 17px; flex: 0 0 17px; cursor: pointer; }
.check-row .grow { flex: 1; min-width: 0; }
.check-row.done .ct { text-decoration: line-through; color: var(--muted); }
.ct { font-size: 14px; font-weight: 500; }
.cs { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.45; }

.empty { text-align: center; padding: 34px 20px; color: var(--muted); font-size: 13.5px; }
.empty .big { font-size: 26px; display: block; margin-bottom: 8px; opacity: 0.5; }

/* ---------- Fortschritt ------------------------------------------------- */

.progress { height: 7px; background: var(--border); border-radius: 5px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 5px; transition: width 0.3s; }
.progress.green > div { background: var(--green); }

.split-bar { display: flex; height: 26px; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--border); }
.split-bar > div { display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 650; color: #fff; min-width: 0; overflow: hidden; }

/* ---------- Hinweisboxen ------------------------------------------------ */

.note {
  border-radius: var(--r); padding: 12px 15px; font-size: 13px; line-height: 1.5;
  background: var(--blue-soft); color: var(--blue); border: 1px solid transparent;
}
.note.amber { background: var(--amber-soft); color: var(--amber); }
.note.red { background: var(--red-soft); color: var(--red); }
.note.green { background: var(--green-soft); color: var(--green); }
.note b { font-weight: 700; }
.note + .note { margin-top: 9px; }

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

.modal-bg {
  position: fixed; inset: 0; background: rgba(20, 17, 12, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 100; backdrop-filter: blur(3px);
}
.modal-bg[hidden] { display: none; }
.modal {
  background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  width: min(620px, 100%); max-height: min(86vh, 860px); display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
.modal-head { padding: 18px 22px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-head h3 { font-size: 16px; font-weight: 650; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px 18px; border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }

/* ---------- Toast ------------------------------------------------------- */

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 9px; z-index: 200; max-width: min(380px, calc(100vw - 40px)); }
.toast {
  background: var(--ink); color: var(--bg); padding: 11px 15px; border-radius: var(--r);
  font-size: 13.5px; box-shadow: var(--shadow-lg); animation: slidein 0.2s ease-out;
}
.toast.err { background: var(--red); color: #fff; }
.toast.ok { background: var(--green); color: #fff; }
@keyframes slidein { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Sync-Anzeige ------------------------------------------------ */

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--faint); }
.sync .dot { background: var(--green); }
.sync.busy .dot { background: var(--amber); animation: pulse 1s infinite; }
.sync.err .dot { background: var(--red); }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- Dropzone ---------------------------------------------------- */

.dropzone {
  border: 2px dashed var(--border2); border-radius: var(--r); padding: 26px 20px;
  text-align: center; color: var(--muted); font-size: 13.5px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.dropzone .big { font-size: 26px; display: block; margin-bottom: 8px; }

.file-icon {
  width: 34px; height: 34px; border-radius: var(--r-sm); flex: 0 0 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent-ink);
}

/* ---------- Timeline ---------------------------------------------------- */

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding: 0 0 18px; }
.tl-item::before {
  content: ''; position: absolute; left: -21px; top: 5px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--card); border: 2px solid var(--border2);
}
.tl-item.past::before { background: var(--green); border-color: var(--green); }
.tl-item.next::before { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.tl-date { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.tl-title { font-size: 14px; font-weight: 550; margin-top: 1px; }
.tl-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- Sonstiges --------------------------------------------------- */

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border2); background: transparent; color: var(--muted);
  font: inherit; font-size: 12.5px; font-weight: 550; padding: 5px 12px;
  border-radius: 20px; cursor: pointer;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .c { opacity: 0.55; margin-left: 4px; }

.section { display: none; }
.section.on { display: block; animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.sub-head { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); font-weight: 700; margin: 22px 0 10px; }
.sub-head:first-child { margin-top: 0; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; font-size: 13.5px; align-items: baseline; }
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { font-weight: 550; text-align: right; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 650; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.rowflex { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

/* ---------- Responsiv --------------------------------------------------- */

@media (max-width: 900px) {
  .app { flex-direction: column; }

  .nav { display: none; }

  .topbar {
    display: block; position: sticky; top: 0; z-index: 50;
    background: var(--panel); border-bottom: 1px solid var(--border);
  }
  .topbar-main { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px 10px; }
  .topbar-main .brand-title { font-size: 15px; }
  .topbar-nav { display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 10px; scrollbar-width: none; }
  .topbar-nav::-webkit-scrollbar { display: none; }
  .topbar-nav .nav-item { width: auto; flex: 0 0 auto; padding: 7px 13px; font-size: 13.5px; border-radius: 20px; }
  .topbar-nav .nav-item .badge { margin-left: 4px; }

  .main { padding: 20px 16px 90px; }
  .main-head h1 { font-size: 21px; }
  .card { padding: 16px; border-radius: var(--r); }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .kpi-val { font-size: 22px; }
  .modal { max-height: 92vh; }
  .toasts { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .fields { grid-template-columns: 1fr; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
  .modal-foot .spacer { display: none; }
}

/* ---------- Druck ------------------------------------------------------- */

@media print {
  .nav, .topbar, .head-actions, .row-actions, .inline-toolbar, .btn, .toasts { display: none !important; }
  .section { display: block !important; page-break-after: always; }
  .main { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  body { background: #fff; font-size: 11pt; }
}
