/* FinanzCoach – Mobile-first PWA */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f3f3f0;
  --card: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --income: #006300;
  --expense: #b3261e;
  --s1: #2a78d6; --s2: #008300; --s3: #e87ba4; --s4: #eda100;
  --s5: #1baf7a; --s6: #eb6834; --s7: #4a3aa7; --s8: #e34948;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --nav-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --card: #1e1e1c;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255,255,255,0.10);
    --accent: #3987e5;
    --income: #0ca30c;
    --expense: #e66767;
    --s1: #3987e5; --s2: #008300; --s3: #d55181; --s4: #c98500;
    --s5: #199e70; --s6: #d95926; --s7: #9085e9; --s8: #e66767;
  }
}

html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

header.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px calc(10px);
  background: var(--page);
  border-bottom: 1px solid var(--border);
}
header.topbar h1 { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
header.topbar h1 span { color: var(--accent); }
.iconbtn {
  background: none; border: none; font-size: 21px; cursor: pointer; color: var(--text-primary);
  padding: 6px 8px; border-radius: 10px;
}
.iconbtn:active { background: var(--grid); }

main { max-width: 640px; margin: 0 auto; padding: 14px 14px 24px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; font-weight: 700; color: var(--text-secondary); margin-bottom: 10px; }
.card h2 .sub { font-weight: 400; color: var(--muted); font-size: 13px; }

/* Stat-Kacheln */
.stat-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.stat .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat .value { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.stat .value.pos { color: var(--income); }
.stat .value.neg { color: var(--expense); }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav .label { font-weight: 700; font-size: 17px; text-transform: capitalize; }
.month-nav button { background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  font-size: 16px; padding: 6px 14px; cursor: pointer; color: var(--text-primary); }

/* Listen */
.tx { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--grid); cursor: pointer; }
.tx:last-child { border-bottom: none; }
.tx .cat-ico { font-size: 20px; width: 36px; height: 36px; border-radius: 10px; background: var(--page);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.tx .mid { flex: 1; min-width: 0; }
.tx .who { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .what { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx .amt.pos { color: var(--income); }

.pill-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.pill { border: 1px solid var(--border); background: var(--card); color: var(--text-primary);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; white-space: nowrap; cursor: pointer; }
.pill.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

input[type=text], input[type=password], input[type=number], input[type=search], select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); color: var(--text-primary); font-size: 16px;
}
button.primary {
  width: 100%; padding: 13px; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 16px; border: none; border-radius: 12px; cursor: pointer;
}
button.primary:disabled { opacity: 0.5; }
button.secondary {
  width: 100%; padding: 12px; background: var(--card); color: var(--text-primary);
  font-weight: 600; font-size: 15px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer;
}

/* Bottom-Navigation */
nav.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
nav.bottom a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted); font-size: 10.5px; font-weight: 600;
}
nav.bottom a .ico { font-size: 21px; }
nav.bottom a.active { color: var(--accent); }

/* Charts */
.chart-wrap { overflow-x: auto; }
svg text { font-family: inherit; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: var(--text-secondary); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18); display: none; max-width: 240px;
}
.tooltip b { display: block; }

/* Budget-Balken */
.budget-row { margin-bottom: 12px; }
.budget-row .head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.budget-row .bar { background: var(--grid); border-radius: 6px; height: 10px; overflow: hidden; }
.budget-row .bar > div { height: 100%; border-radius: 6px; }

/* Hinweise (Insights) */
.tip { border-left: 4px solid var(--muted); border-radius: 4px 12px 12px 4px; background: var(--card);
  padding: 12px 14px; margin-bottom: 10px; border-top: 1px solid var(--border);
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.tip b { display: block; margin-bottom: 3px; font-size: 14.5px; }
.tip p { font-size: 13.5px; color: var(--text-secondary); }
.tip.critical { border-left-color: var(--critical); }
.tip.warn { border-left-color: var(--warning); }
.tip.info { border-left-color: var(--s1); }
.tip.good { border-left-color: var(--good); }
.tip .lvl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* Verträge */
.contract { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--grid); }
.contract:last-child { border-bottom: none; }
.contract .mid { flex: 1; min-width: 0; }
.contract .name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contract .meta { font-size: 12.5px; color: var(--muted); }
.contract .cost { text-align: right; }
.contract .cost .m { font-weight: 700; font-variant-numeric: tabular-nums; }
.contract .cost .y { font-size: 12px; color: var(--muted); }
.contract.inactive { opacity: 0.5; }

/* Coach-Chat */
.chat-box { display: flex; flex-direction: column; gap: 10px; min-height: 45vh; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-input { position: sticky; bottom: calc(var(--nav-h) + 8px); display: flex; gap: 8px; margin-top: 12px; }
.chat-input input { flex: 1; }
.chat-input button { width: 52px; border-radius: 12px; border: none; background: var(--accent); color: var(--accent-ink);
  font-size: 19px; cursor: pointer; }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

/* Login */
.login-wrap { max-width: 380px; margin: 10vh auto 0; padding: 0 20px; }
.login-wrap .logo { text-align: center; font-size: 44px; margin-bottom: 8px; }
.login-wrap h1 { text-align: center; font-size: 24px; margin-bottom: 4px; }
.login-wrap p { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.login-wrap form > * { margin-bottom: 12px; }
.error { color: var(--critical); font-size: 14px; text-align: center; margin-top: 8px; }

.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hidden { display: none !important; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 18px);
  background: var(--text-primary); color: var(--page); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 60; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

/* Modal (Kategorie wählen) */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 40; display: flex; align-items: flex-end; }
.modal { background: var(--page); width: 100%; max-height: 80vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.modal h3 { margin-bottom: 12px; }
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cat-opt { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--card); cursor: pointer; font-size: 13.5px; }
.cat-opt.sel { border-color: var(--accent); outline: 2px solid var(--accent); }
.check-row { display: flex; align-items: center; gap: 10px; margin: 14px 2px; font-size: 14.5px; }
.check-row input { width: 20px; height: 20px; }

@media (min-width: 700px) {
  .stat-row { grid-template-columns: repeat(3, 1fr); }
  nav.bottom { max-width: 640px; left: 50%; transform: translateX(-50%); border: 1px solid var(--border);
    border-radius: 18px 18px 0 0; }
}
