/* Pocketcredit – mobile-first Design-System.
   Farben aus der validierten Referenzpalette (Blau = Fortschritt/Akzent,
   Statusfarben nur mit Icon + Label). */

:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #cde2fb;
  --track: #e1e0d9;
  --good: #0ca30c;
  --good-text: #006300;
  --warn: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 1px 3px rgba(11, 11, 11, 0.06), 0 4px 16px rgba(11, 11, 11, 0.05);
  --radius: 16px;
  --radius-s: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hairline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-soft: #10304f;
    --track: #2c2c2a;
    --good-text: #0ca30c;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
}

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--hairline);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 1.15rem; font-weight: 600; letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none;
}
.brand b { color: var(--accent); font-weight: 700; }
.brand-icon { width: 26px; height: 26px; color: var(--accent); }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 96px);
}

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: flex-end;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--hairline);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; min-height: 48px;
  color: var(--muted); text-decoration: none; font-size: 0.68rem; font-weight: 500;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }
.tab-new-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; margin-top: -18px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; box-shadow: var(--shadow);
}
.tab-new-btn svg { width: 22px; height: 22px; }
.tab-icon-wrap { position: relative; display: inline-flex; }
.badge {
  position: absolute; top: -4px; right: -8px;
  min-width: 17px; height: 17px; padding: 0 4px;
  background: var(--critical); color: #fff;
  border-radius: 999px; font-size: 0.62rem; font-weight: 700;
  display: grid; place-items: center; line-height: 1;
}

/* ---------- Karten & Typografie ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 1.05rem; letter-spacing: -0.01em; }
.card h3 { margin: 0 0 6px; font-size: 0.95rem; }

.page-title { margin: 6px 0 4px; font-size: 1.45rem; letter-spacing: -0.02em; }
.page-sub { margin: 0 0 16px; color: var(--ink-2); font-size: 0.92rem; }
.section-title {
  margin: 20px 0 10px; font-size: 0.8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.mono-num { font-variant-numeric: tabular-nums; }

/* Hero-Karte (Kredit-Detail) */
.hero {
  background: linear-gradient(135deg, var(--accent), #4a3aa7);
  color: #fff; border: none;
}
.hero .muted, .hero .small { color: rgba(255, 255, 255, 0.75); }
.hero-amount { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }

/* ---------- Fortschrittsbalken ---------- */
.progress { margin: 10px 0 4px; }
.progress-track {
  height: 10px; border-radius: 999px; background: var(--track); overflow: hidden;
}
.hero .progress-track { background: rgba(255, 255, 255, 0.25); }
.progress-fill {
  height: 100%; border-radius: 999px; background: var(--accent);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  min-width: 0;
}
.progress-fill.done { background: var(--good); }
.hero .progress-fill { background: #fff; }
.progress-meta {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 6px; font-size: 0.82rem; color: var(--ink-2);
}
.hero .progress-meta { color: rgba(255, 255, 255, 0.85); }
.progress-meta b { color: inherit; }

/* ---------- Statistik-Kacheln ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s); padding: 12px 14px;
}
.stat .label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.stat .value { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; margin-top: 2px; }
.stat .sub { font-size: 0.78rem; color: var(--ink-2); }

/* ---------- Status-Chips (immer Icon + Text) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; line-height: 1.4;
  background: var(--surface-2); color: var(--ink-2);
}
.chip svg { width: 13px; height: 13px; flex-shrink: 0; }
.chip.good { background: color-mix(in srgb, var(--good) 14%, var(--surface)); color: var(--good-text); }
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: color-mix(in srgb, var(--warn) 60%, var(--ink)); }
.chip.serious { background: color-mix(in srgb, var(--serious) 16%, var(--surface)); color: color-mix(in srgb, var(--serious) 70%, var(--ink)); }
.chip.critical { background: color-mix(in srgb, var(--critical) 14%, var(--surface)); color: var(--critical); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; width: 100%;
  border: none; border-radius: var(--radius-s);
  background: var(--accent); color: var(--accent-ink);
  font-size: 1rem; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none;
  transition: filter 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.secondary {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border);
}
.btn.ghost { background: transparent; color: var(--accent); border: none; }
.btn.danger { background: transparent; color: var(--critical); border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent); }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: 0.88rem; width: auto; }
.btn svg { width: 18px; height: 18px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Formulare ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block; margin-bottom: 5px;
  font-size: 0.82rem; font-weight: 600; color: var(--ink-2);
}
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink);
  font-size: 1rem; font-family: inherit;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.field .hint { margin-top: 4px; font-size: 0.78rem; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input-suffix { position: relative; }
.input-suffix span {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 0.95rem; pointer-events: none;
}

.check {
  display: flex; gap: 10px; align-items: flex-start;
  margin-bottom: 12px; font-size: 0.88rem; color: var(--ink-2);
  cursor: pointer;
}
.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); flex-shrink: 0; }

/* ---------- Listen ---------- */
.list { margin: 0; padding: 0; list-style: none; }
.list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--hairline);
}
.list li:last-child { border-bottom: none; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; font-size: 0.92rem; }
.list .sub { font-size: 0.8rem; color: var(--muted); }
.list .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Kredit-Karte in der Übersicht */
.loan-card { display: block; text-decoration: none; color: inherit; }
.loan-card:active { filter: brightness(0.97); }
.loan-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.loan-card-head .who { font-size: 0.8rem; color: var(--muted); }

/* ---------- Zahlungswege ---------- */
.paybox {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-s); background: var(--surface-2);
  margin-bottom: 10px;
}
.paybox .grow { flex: 1; min-width: 0; }
.paybox .label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.paybox .val { font-weight: 600; font-size: 0.92rem; word-break: break-all; font-variant-numeric: tabular-nums; }
.paybox .btn { flex-shrink: 0; }

/* ---------- Protokollausgabe (Mail-Text, SMTP-Dialog) ---------- */
.logbox {
  margin: 10px 0 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Wizard ---------- */
.steps { display: flex; gap: 6px; margin: 4px 0 18px; }
.steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--track); }
.steps span.done { background: var(--accent); }

/* ---------- Unterschrift ---------- */
.sigpad-hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #9a9a9a; font-size: 0.9rem; pointer-events: none; text-align: center;
}
.sig-img { max-width: 240px; max-height: 90px; }

/* Unterschrifts-Box im Formular (öffnet das Overlay) */
.sigbox .sig-preview { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sigbox .sig-preview img {
  max-height: 72px; max-width: 65%;
  background: #fff; border: 1px solid var(--hairline);
  border-radius: 10px; padding: 4px 12px;
}

/* Dokument-Overlay (Vertrag lesen vor der Zustimmung) */
.doc-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.65);
  display: grid; place-items: center;
  padding: 12px;
}
.doc-sheet {
  background: var(--surface);
  border-radius: 18px;
  width: 100%; max-width: 640px;
  height: min(88dvh, 820px);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.doc-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}
.doc-body { flex: 1; overflow-y: auto; padding: 12px 16px; -webkit-overflow-scrolling: touch; }
.doc-foot {
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid var(--hairline);
  display: flex; flex-direction: column; gap: 8px;
  flex-shrink: 0;
}

/* Vollbild-Overlay, auf Hochformat-Handys um 90° gedreht (Querformat) */
.sig-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.65);
  display: grid; place-items: center;
}
.sig-stage {
  background: var(--surface);
  border-radius: 18px; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.sig-stage.rotated {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
}
.sig-head { font-weight: 600; font-size: 0.95rem; padding: 0 4px; }
.sig-area {
  position: relative; flex: 1; min-height: 0;
  background: #fff; border: 1.5px dashed rgba(0, 0, 0, 0.2);
  border-radius: 12px; overflow: hidden;
}
.sig-area canvas { display: block; width: 100%; height: 100%; }
.sig-baseline {
  position: absolute; left: 8%; right: 8%; bottom: 24%;
  border-bottom: 1.5px solid #c9c9c9; pointer-events: none;
}
.sig-actions { display: flex; gap: 8px; }
.sig-actions .btn { flex: 1; min-height: 44px; }

/* ---------- Vertrag ---------- */
.contract h3 { margin: 18px 0 4px; font-size: 0.92rem; }
.contract p { margin: 0 0 8px; font-size: 0.88rem; color: var(--ink-2); }
.contract .parties { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.contract .sigline { border-top: 1px solid var(--ink-2); padding-top: 6px; margin-top: 40px; font-size: 0.8rem; color: var(--muted); }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed; top: calc(env(safe-area-inset-top) + 12px);
  left: 16px; right: 16px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  max-width: 480px; width: 100%;
  padding: 12px 16px; border-radius: var(--radius-s);
  background: var(--ink); color: var(--bg);
  font-size: 0.9rem; font-weight: 500;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
}
.toast.error { background: var(--critical); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- Leerzustand ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; margin-bottom: 10px; opacity: 0.5; }

/* ---------- Auth-Screens ---------- */
.auth-wrap { max-width: 400px; margin: 8vh auto 0; }
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo .brand-icon { width: 52px; height: 52px; }
.auth-logo h1 { margin: 8px 0 4px; font-size: 1.6rem; letter-spacing: -0.02em; }
.auth-logo p { margin: 0; color: var(--ink-2); font-size: 0.92rem; }

/* ---------- Tabellen (Ratenplan) ---------- */
.plan-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.plan-table th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); font-weight: 600;
  padding: 6px 8px; border-bottom: 1px solid var(--hairline);
}
.plan-table td { padding: 9px 8px; border-bottom: 1px solid var(--hairline); font-variant-numeric: tabular-nums; }
.plan-table tr:last-child td { border-bottom: none; }
.plan-table .num { text-align: right; }

/* ---------- Admin-Bereich ---------- */
.topbar-admin {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 12px;
  color: var(--muted);
}
.topbar-admin svg { width: 22px; height: 22px; }
.topbar-admin:hover, .topbar-admin:active { color: var(--accent); background: var(--surface-2); }

.admin-nav {
  display: flex; gap: 6px; margin: 0 0 16px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.admin-nav::-webkit-scrollbar { display: none; }
.admin-nav a {
  flex-shrink: 0; padding: 8px 14px; min-height: 38px;
  display: inline-flex; align-items: center;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2);
  font-size: 0.85rem; font-weight: 600; text-decoration: none;
}
.admin-nav a.active { background: var(--accent); border-color: transparent; color: var(--accent-ink); }

.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-chips button {
  padding: 6px 12px; min-height: 34px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2);
  font-size: 0.8rem; font-weight: 600; font-family: inherit; cursor: pointer;
}
.filter-chips button.active { background: var(--accent); border-color: transparent; color: var(--accent-ink); }

/* ---------- Desktop ---------- */
@media (min-width: 700px) {
  .view { padding-top: 24px; }
  .tabbar { max-width: 640px; left: 50%; transform: translateX(-50%); border-radius: 20px 20px 0 0; border: 1px solid var(--hairline); border-bottom: none; }
}

/* ---------- Druck (Vertrag) ---------- */
@media print {
  .topbar, .tabbar, .toast-root, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .view { max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; padding: 0; }
}
