:root {
  --bg: #f4f4f6;
  --bg-card: #ffffff;
  --text: #111827;
  --text-dim: #6b7280;
  --accent: #7c3aed;
  --accent-text: #ffffff;
  --border: #e5e7eb;
  --danger: #dc2626;
  --income: #16a34a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-card: #1a1d24;
    --text: #f3f4f6;
    --text-dim: #9ca3af;
    --accent: #8b5cf6;
    --border: #2b2f38;
    --danger: #f87171;
    --income: #4ade80;
  }
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  max-width: 420px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 16px) 20px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100dvh;
  gap: 16px;
  text-align: center;
}
.login-logo { font-size: 56px; }
.login-wrap h1 { font-size: 24px; }
#login-form { display: flex; flex-direction: column; gap: 8px; text-align: left; }
#login-form label { font-size: 13px; color: var(--text-dim); margin-top: 8px; }

/* ---------- Layout ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
#header-title { font-size: 20px; font-weight: 700; }
#btn-logout {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  padding: 8px 0;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 20px calc(env(safe-area-inset-bottom) + 96px);
}

h2 { font-size: 15px; color: var(--text-dim); margin: 24px 0 8px; font-weight: 600; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

/* ---------- Inputs ---------- */
input[type="text"], input[type="password"], input[type="date"] {
  width: 100%;
  font-size: 17px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn-primary {
  width: 100%;
  margin-top: 12px;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 14px;
  cursor: pointer;
}
.btn-primary:active { opacity: 0.85; }
.btn-small { width: auto; margin-top: 0; padding: 12px 18px; }

.error { color: var(--danger); font-size: 14px; margin: 8px 0; }

/* ---------- Eingabe ---------- */
.amount-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
#amount {
  flex: 1;
  font-size: 40px;
  font-weight: 700;
  border: none;
  background: none;
  padding: 4px 0;
  text-align: right;
}
#amount:focus { outline: none; }
.currency { font-size: 28px; color: var(--text-dim); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip.selected { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }

.form-rows { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; align-items: center; gap: 12px; }
.form-row label { width: 64px; font-size: 14px; color: var(--text-dim); flex-shrink: 0; }

/* ---------- Listen ---------- */
.expense-list, .summary-list, .admin-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.expense-list li, .summary-list li, .admin-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
}
.exp-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.exp-main { flex: 1; min-width: 0; }
.exp-cat { font-size: 15px; font-weight: 600; }
.exp-sub { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-amount { font-weight: 700; font-size: 16px; white-space: nowrap; }
.btn-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 4px 6px;
  cursor: pointer;
}

/* ---------- Übersicht ---------- */
.month-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.month-nav button {
  width: 44px;
  height: 44px;
  font-size: 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text);
}
#month-label { font-size: 17px; font-weight: 600; }

.balance-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.balance-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.total-label { color: var(--text-dim); font-size: 15px; }
#total-amount, .income-amount { font-size: 17px; font-weight: 600; }
.income-amount, .amount-positive { color: var(--income); }
.amount-negative { color: var(--danger); }
.balance-diff {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
#balance-amount { font-size: 28px; font-weight: 700; }

.segmented {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 12px;
}
.segmented button {
  flex: 1;
  padding: 10px 0;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 9px;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
}
.segmented button.active { background: var(--accent); color: var(--accent-text); }

#chart-wrap { display: flex; justify-content: center; padding: 20px; margin-bottom: 12px; }
#chart-wrap svg { width: min(65vw, 260px); height: auto; }
#chart-wrap .empty { color: var(--text-dim); padding: 24px 0; }

.summary-list .pct { color: var(--text-dim); font-size: 14px; margin-left: 6px; }

/* ---------- Admin ---------- */
.admin-form { display: flex; gap: 8px; align-items: center; padding: 12px; }
.admin-form input[type="color"] {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: none;
  padding: 2px;
  flex-shrink: 0;
}
.user-form { flex-wrap: wrap; }
.user-form input[type="text"], .user-form input[type="password"] { flex: 1 1 100%; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  flex: 1;
}
.checkbox-label input { width: 20px; height: 20px; }
.badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
}

/* ---------- Tabbar ---------- */
#tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 8px 0 max(env(safe-area-inset-bottom), 8px);
}
#tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 0;
  cursor: pointer;
}
#tabbar button .icon { font-size: 22px; line-height: 1; }
#tabbar button.active { color: var(--accent); font-weight: 600; }
