:root {
  --bg: #f3f4f9;
  --bg-accent: #eef0fb;
  --surface: #ffffff;
  --surface-2: #f7f7fc;
  --border: #e6e7f0;
  --text: #171923;
  --muted: #6b7080;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0ff;
  --primary-soft-text: #4338ca;
  --green: #059669;
  --green-soft: #e7f9f1;
  --red: #dc2626;
  --red-soft: #fdecec;
  --amber: #d97706;
  --amber-soft: #fef6e7;
  --shadow-sm: 0 1px 2px rgba(23, 25, 35, .05);
  --shadow-md: 0 6px 20px -6px rgba(23, 25, 35, .12), 0 2px 6px -2px rgba(23, 25, 35, .06);
  --shadow-lg: 0 20px 45px -12px rgba(23, 25, 35, .22);
  --radius-sm: 9px;
  --radius: 14px;
  --radius-lg: 20px;
  --ease: cubic-bezier(.2, .7, .3, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016; --bg-accent: #14161f;
    --surface: #191b24; --surface-2: #14161f;
    --border: #2a2d3a; --text: #eceef4; --muted: #969bb0;
    --primary: #6366f1; --primary-dark: #818cf8; --primary-soft: #23253a; --primary-soft-text: #a5b4fc;
    --green: #34d399; --green-soft: #10261f;
    --red: #f87171; --red-soft: #2a1618;
    --amber: #fbbf24; --amber-soft: #2a2113;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 6px 24px -8px rgba(0,0,0,.55), 0 2px 6px -2px rgba(0,0,0,.4);
    --shadow-lg: 0 24px 55px -12px rgba(0,0,0,.65);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", "Inter", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Icons */
.icon-wrap { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.icon-wrap svg { display: block; }
.icon-badge {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 34px; height: 34px; border-radius: 10px; background: var(--primary-soft); color: var(--primary);
}
.icon-badge.sm { width: 26px; height: 26px; border-radius: 8px; }
.app { display: flex; min-height: 100vh; }

/* Topbar (nur Telefon-Breite) */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: none; color: var(--text);
  cursor: pointer; padding: 0; flex-shrink: 0; transition: background .15s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); }
.topbar {
  display: none; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 10px;
}
.topbar-brand { font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(5, 6, 10, .45); z-index: 39;
  opacity: 0; transition: opacity .2s var(--ease);
}
.sidebar-close { display: none; margin-left: auto; }

/* Sidebar */
.sidebar {
  width: 252px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
}
.brand { font-weight: 700; font-size: 17px; padding: 4px 8px 22px; display: flex; gap: 10px; align-items: center; letter-spacing: -.01em; }
.brand-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; color: #fff;
  background: linear-gradient(145deg, var(--primary), var(--primary-dark));
  box-shadow: var(--shadow-sm);
}
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: var(--radius-sm); color: var(--text);
  text-decoration: none; font-weight: 500; font-size: 14px; transition: background .15s var(--ease), color .15s var(--ease), transform .1s var(--ease);
}
.nav-icon { display: inline-flex; width: 20px; flex-shrink: 0; opacity: .75; color: var(--muted); transition: color .15s var(--ease), opacity .15s var(--ease); }
#nav a:hover { background: var(--surface-2); }
#nav a:active { transform: scale(.98); }
#nav a.active { background: var(--primary-soft); color: var(--primary-soft-text); font-weight: 600; }
#nav a.active .nav-icon { opacity: 1; color: var(--primary-soft-text); }
#nav a:hover .nav-icon { color: var(--text); opacity: 1; }
#nav a:focus { outline: none; }
#nav a:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 18px 11px 7px; font-weight: 700; }
.sidebar-foot {
  margin-top: auto; padding: 12px 11px 4px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
#current-user { font-size: 12.5px; color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.unauth .sidebar, body.unauth .topbar { display: none; }
@media (min-width: 641px) and (max-width: 820px) { .sidebar-foot { flex-direction: column; align-items: stretch; } #current-user { text-align: center; } }

/* Main */
.view { flex: 1; padding: 32px 40px 60px; width: 100%; animation: fade-in .25s var(--ease); }
@media (max-width: 900px) { .view { padding: 20px 16px 48px; } }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.loading { color: var(--muted); padding: 60px; text-align: center; font-weight: 500; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 26px; gap: 16px; flex-wrap: wrap; }
h1 { font-size: 25px; margin: 0; letter-spacing: -.02em; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 14px; font-weight: 650; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm); transition: box-shadow .2s var(--ease), transform .2s var(--ease);
}
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 820px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

/* Tablet (z.B. iPad Hochformat): Sidebar wird zur schmalen Icon-Leiste */
@media (min-width: 641px) and (max-width: 820px) {
  .sidebar { width: 68px; }
  .brand-text, .nav-label, .nav-sep { display: none; }
  .brand { justify-content: center; padding-right: 0; }
  #nav a { justify-content: center; }
}

/* Telefon: Sidebar wird zum ausklappbaren Drawer, eigene Topbar mit Menü-Button */
@media (max-width: 640px) {
  .topbar { display: flex; }
  .app { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40; width: min(84vw, 300px);
    transform: translateX(-100%); transition: transform .22s var(--ease); box-shadow: var(--shadow-lg);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; opacity: 1; }
  .sidebar-close { display: inline-flex; }
  .view { padding: 16px 14px 44px; }
}

/* Stat tiles */
.stat { display: flex; flex-direction: column; gap: 8px; position: relative; overflow: hidden; }
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat .icon { margin-bottom: 4px; }
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: .01em; }
.stat .value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .value.neg { color: var(--red); }
.stat .value.pos { color: var(--green); }
.stat.hero { background: linear-gradient(150deg, var(--primary), var(--primary-dark)); border: none; color: #fff; }
.stat.hero .label { color: rgba(255,255,255,.8); }
.stat.hero .value { color: #fff; }
.stat.hero .value.neg { color: #fecaca; }
.stat.hero .icon { background: rgba(255,255,255,.2); color: #fff; }

/* Quick-access Kacheln (Schnellzugriff) */
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.quick-tile {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 20px 12px;
  text-decoration: none; color: var(--text); font-weight: 600; font-size: 13.5px; text-align: center;
}
.quick-tile .icon-badge { width: 42px; height: 42px; border-radius: 12px; }
.quick-tile:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

/* Abschnitts-Überschrift mit Icon */
.section-head { display: flex; align-items: center; gap: 8px; }
.section-head .icon-wrap { color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 13.5px; cursor: pointer; text-decoration: none;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease), box-shadow .15s var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--border), var(--text) 8%); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(150deg, var(--primary), var(--primary-dark)); border-color: transparent; color: #fff; box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--primary), transparent 35%); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: color-mix(in srgb, var(--red), transparent 60%); }
.btn.sm { padding: 8px 13px; font-size: 12.5px; min-height: 36px; }
.btn:disabled { opacity: .6; cursor: default; transform: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.75px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: var(--surface-2); }

/* Spaltenbreite per Drag anpassen (Maus/Touch/Stift) -- breiter unsichtbarer
   Trefferbereich fürs Tablet, schmale sichtbare Trennlinie in der Mitte. */
.col-resize-handle {
  position: absolute; top: 0; right: -8px; bottom: 0; width: 16px; cursor: col-resize;
  touch-action: none; z-index: 2; display: flex; justify-content: center;
}
.col-resize-handle::after {
  content: ''; width: 2px; height: 100%; background: transparent; transition: background .12s var(--ease);
}
.col-resize-handle:hover::after, .col-resize-handle.active::after { background: var(--primary); }
thead tr:first-child th:first-child { border-top-left-radius: var(--radius); }
thead tr:first-child th:last-child { border-top-right-radius: var(--radius); }
tbody tr { transition: background .12s var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; background: var(--surface-2); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); font-weight: 500; }

/* Badges */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .01em; background: var(--surface-2); border: 1px solid var(--border); }
.badge.g { background: #f1ecfe; color: #6d28d9; border-color: #e2d6fd; }
.badge.h { background: #e5edff; color: #1d4ed8; border-color: #d3e0ff; }
.badge.unit { background: var(--green-soft); color: var(--green); border-color: transparent; }
.badge.income { background: var(--green-soft); color: var(--green); border-color: transparent; }
.badge.expense { background: var(--red-soft); color: var(--red); border-color: transparent; }
.badge.muted { color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .badge.g { background: #2a2145; color: #d8b4fe; border-color: #3a2e5c; }
  .badge.h { background: #16233f; color: #93c5fd; border-color: #21335a; }
}

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field label { font-size: 12.5px; font-weight: 650; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
input, select, textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  color: var(--text); font-size: 16px; font-family: inherit; width: 100%; transition: border-color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
/* font-size 16px ist Absicht: verhindert Auto-Zoom beim Fokussieren auf iPad/iPhone Safari */
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--border), var(--text) 15%); }
input:focus, select:focus, textarea:focus { outline: none; background: var(--surface); border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary), transparent 78%); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .form-row, .form-row-3 { grid-template-columns: 1fr; } }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 16px; background: var(--surface-2); }
legend { font-weight: 700; padding: 0 6px; font-size: 13px; color: var(--primary-soft-text); }

/* Modal */
#modal-root:empty { display: none; }
.modal-overlay {
  position: fixed; inset: 0; background: color-mix(in srgb, #05060a, transparent 45%); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto; z-index: 50;
  animation: overlay-in .18s var(--ease);
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 660px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); animation: modal-in .2s var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 22px 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.x-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); width: auto; padding: 4px 8px; border-radius: 8px; transition: background .15s var(--ease), color .15s var(--ease); line-height: 1; }
.x-btn:hover { background: var(--surface-2); color: var(--text); }

/* Toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(24px) scale(.96); background: #171923; color: #fff;
  padding: 12px 20px; border-radius: 12px; opacity: 0; pointer-events: none; transition: all .3s var(--ease); z-index: 100; font-weight: 600; font-size: 13.75px;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
.toast.err { background: linear-gradient(150deg, #dc2626, #b91c1c); }

/* Photo */
.photo-thumb { width: 46px; height: 46px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); cursor: pointer; transition: transform .15s var(--ease); }
.photo-thumb:hover { transform: scale(1.08); }
.photo-preview { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); margin-top: 8px; box-shadow: var(--shadow-sm); }
.warn-banner {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--amber-soft); color: color-mix(in srgb, var(--amber), black 25%); border: 1px solid color-mix(in srgb, var(--amber), transparent 65%);
  padding: 13px 16px; border-radius: var(--radius); margin-bottom: 20px; font-weight: 500; font-size: 13.75px;
}
.warn-banner .icon-wrap { color: var(--amber); flex-shrink: 0; margin-top: 1px; }
@media (prefers-color-scheme: dark) { .warn-banner { color: var(--amber); } }
.pill-tabs { display: inline-flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.pill-tabs button { border: none; background: none; padding: 7px 15px; border-radius: 7px; cursor: pointer; font-weight: 650; font-size: 13.5px; color: var(--muted); width: auto; transition: background .15s var(--ease), color .15s var(--ease); }
.pill-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.pill-tabs button:hover:not(.active) { color: var(--text); }

/* Tabellen mit vielen Spalten (Rechnungen, Kontobuch): auf dem Handy Karten statt Zeilen */
.mobile-cards { display: none; flex-direction: column; gap: 10px; }
.mcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.mcard-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.mcard-title { font-weight: 650; font-size: 14.5px; }
.mcard-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.mcard-amount { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mcard-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.mcard-meta { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.mcard-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.mcard-foot { text-align: center; color: var(--muted); font-weight: 600; font-size: 13.5px; padding: 6px 4px 2px; }
@media (max-width: 640px) {
  .desktop-table { display: none; }
  .mobile-cards { display: flex; }
}

/* Aufgaben */
.task-row { display: flex; align-items: flex-start; gap: 12px; padding: 14px 2px; border-bottom: 1px solid var(--border); }
.task-row:last-child { border-bottom: none; }
.task-check {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--border); flex-shrink: 0; margin-top: 1px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; background: var(--surface); color: transparent;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.task-check:hover { border-color: var(--primary); }
.task-check.checked { background: var(--primary); border-color: var(--primary); color: #fff; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; font-size: 14px; }
.task-title.done { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.task-meta { display: flex; align-items: center; gap: 7px; margin-top: 5px; font-size: 12.5px; color: var(--muted); }
.task-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.task-due { margin-left: auto; flex-shrink: 0; white-space: nowrap; }
.task-actions { flex-shrink: 0; }
.count-pill { color: var(--muted); font-weight: 600; font-size: 14px; }
