/* =========================================================================
   Finanzen – iOS-inspiriertes Design
   System-Font (San Francisco auf iPhone), gruppierte Listen, Tab-Bar,
   große Titel, Dark Mode, Safe-Areas. Signature: die Topf-Karten.
   ========================================================================= */

:root {
  color-scheme: light dark;

  /* Marke & Semantik */
  --brand:        #0E8A6B;
  --brand-2:      #12A57F;
  --income:       #34C759;
  --expense:      #FF3B30;
  --warning:      #FF9F0A;
  --info:         #0A84FF;

  /* Flächen (Light) */
  --bg:           #F2F2F7;
  --bg-elevated:  #FFFFFF;
  --card:         #FFFFFF;
  --card-2:       #F2F2F7;
  --fill:         rgba(120,120,128,0.12);
  --fill-2:       rgba(120,120,128,0.08);

  /* Text */
  --label:        #1C1C1E;
  --label-2:      #3C3C43;
  --secondary:    #8A8A8E;
  --tertiary:     #C7C7CC;
  --separator:    rgba(60,60,67,0.20);
  --separator-strong: rgba(60,60,67,0.29);

  /* Maße */
  --radius-card:  16px;
  --radius-tile:  14px;
  --radius-sm:    10px;
  --tap:          44px;
  --pad:          16px;

  --shadow-card:  0 1px 2px rgba(0,0,0,0.04), 0 6px 20px rgba(0,0,0,0.04);
  --nav-blur:     saturate(180%) blur(20px);

  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);

  --num: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --sys: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #000000;
    --bg-elevated:  #1C1C1E;
    --card:         #1C1C1E;
    --card-2:       #2C2C2E;
    --fill:         rgba(120,120,128,0.24);
    --fill-2:       rgba(120,120,128,0.16);
    --label:        #FFFFFF;
    --label-2:      #EBEBF5;
    --secondary:    #98989F;
    --tertiary:     #48484A;
    --separator:    rgba(84,84,88,0.40);
    --separator-strong: rgba(84,84,88,0.60);
    --brand:        #16B892;
    --brand-2:      #24C7A2;
    --expense:      #FF453A;
    --shadow-card:  0 1px 2px rgba(0,0,0,0.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--sys);
  background: var(--bg);
  color: var(--label);
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 17px; }
a { color: var(--brand); text-decoration: none; }

.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- App-Gerüst ---------- */
#app { min-height: 100%; }
.screen {
  min-height: 100vh;
  padding-bottom: calc(64px + var(--sab) + 12px); /* Platz für Tab-Bar */
}
.hidden { display: none !important; }

/* ---------- Navigationsleiste / Großer Titel ---------- */
.nav {
  position: sticky; top: 0; z-index: 30;
  padding-top: var(--sat);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: var(--nav-blur);
  -webkit-backdrop-filter: var(--nav-blur);
}
.nav-bar {
  height: 44px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--pad); gap: 8px;
}
.nav-title-compact { font-size: 17px; font-weight: 600; opacity: 0; transition: opacity .2s; }
.nav.scrolled .nav-title-compact { opacity: 1; }
.nav.scrolled { border-bottom: 0.5px solid var(--separator); }
.nav-action {
  color: var(--brand); background: none; border: 0; font-size: 17px; padding: 6px 8px;
  min-width: 40px; display: inline-flex; align-items: center; gap: 6px; border-radius: 10px;
}
.nav-action:active { opacity: .5; }
.nav-action.icon { justify-content: center; }
.large-title {
  font-size: 34px; font-weight: 700; letter-spacing: 0.37px;
  padding: 4px var(--pad) 8px;
}

/* ---------- Gruppierte Listen (inset) ---------- */
.group { margin: 18px var(--pad) 0; }
.group-header {
  font-size: 13px; color: var(--secondary); text-transform: uppercase;
  letter-spacing: 0.4px; padding: 0 4px 8px; font-weight: 600;
}
.group-footer { font-size: 13px; color: var(--secondary); padding: 8px 4px 0; }
.list {
  background: var(--card); border-radius: var(--radius-card);
  overflow: hidden; box-shadow: var(--shadow-card);
}
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px var(--pad); min-height: var(--tap);
  border-bottom: 0.5px solid var(--separator);
  background: var(--card); position: relative;
}
.row:last-child { border-bottom: 0; }
.row.tappable:active { background: var(--fill-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-size: 17px; color: var(--label); }
.row .subtitle { font-size: 13px; color: var(--secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .value { font-size: 17px; color: var(--label); white-space: nowrap; }
.chevron { color: var(--tertiary); margin-left: 2px; flex: none; }

/* ---------- Icon-Kachel (App-Icon-Look) ---------- */
.tile {
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  display: grid; place-items: center; color: #fff;
  background: var(--brand);
}
.tile.lg { width: 52px; height: 52px; border-radius: 12px; }
.tile svg { width: 20px; height: 20px; }
.tile.lg svg { width: 28px; height: 28px; }
.tile img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 13px 18px; font-size: 17px; font-weight: 600;
  background: var(--fill); color: var(--label); width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { opacity: .6; }
.btn svg { width: 18px; height: 18px; flex: none; }
.nav-action svg { width: 22px; height: 22px; }
.chevron svg { width: 15px; height: 15px; display: block; }
.chip .dot svg { width: 13px; height: 13px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.tinted { background: color-mix(in srgb, var(--brand) 15%, transparent); color: var(--brand); }
.btn.danger { background: color-mix(in srgb, var(--expense) 15%, transparent); color: var(--expense); }
.btn.plain { background: none; color: var(--brand); }
.btn.sm { padding: 8px 14px; font-size: 15px; width: auto; }
.btn-row { display: flex; gap: 10px; padding: 16px var(--pad) 0; }

/* ---------- Hero: Vermögen ---------- */
.hero {
  margin: 8px var(--pad) 0; padding: 22px; border-radius: 22px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; box-shadow: 0 10px 30px color-mix(in srgb, var(--brand) 35%, transparent);
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(255,255,255,0.18), transparent 70%);
}
.hero .label { font-size: 14px; opacity: .85; }
.hero .amount { font-family: var(--num); font-size: 40px; font-weight: 700; margin-top: 2px; letter-spacing: -0.5px; }
.hero-own { font-size: 13px; opacity: .92; margin-top: 6px; background: rgba(255,255,255,0.14);
  display: inline-block; padding: 4px 10px; border-radius: 12px; }
.warn-list { border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent); }
.hero .meta { display: flex; gap: 18px; margin-top: 14px; font-size: 13px; }
.hero .meta b { font-family: var(--num); font-weight: 700; display: block; font-size: 16px; }
.hero .meta .dot { opacity: .85; }

/* ---------- Topf-Karten (Signature) ---------- */
.pots-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px var(--pad) 0; }
.pot-card {
  background: var(--card); border-radius: var(--radius-tile); padding: 14px;
  box-shadow: var(--shadow-card); border: 0.5px solid var(--separator);
  display: flex; flex-direction: column; gap: 10px; min-height: 118px; position: relative;
}
.pot-card:active { transform: scale(0.98); transition: transform .1s; }
.pot-card .top { display: flex; align-items: center; justify-content: space-between; }
.pot-card .name { font-size: 14px; color: var(--secondary); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pot-card .amount { font-family: var(--num); font-size: 22px; font-weight: 700; }
.pot-card .sub { font-size: 12px; color: var(--secondary); }
.bar { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 3px; background: var(--brand); transition: width .4s ease; }
.bar.over > span { background: var(--expense); }

/* ---------- Transaktionszeile ---------- */
.tx-amount.in  { color: var(--income); }
.tx-amount.out { color: var(--label); }
.tx-badge {
  font-size: 11px; padding: 2px 7px; border-radius: 20px; font-weight: 600;
  background: var(--fill); color: var(--secondary);
}
.tx-badge.open { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning); }
.tx-badge.internal { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); }

/* ---------- Segmented control ---------- */
.segmented {
  display: flex; background: var(--fill); border-radius: 10px; padding: 2px; margin: 12px var(--pad) 0;
}
.segmented button {
  flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: var(--secondary);
}
.segmented button.active {
  background: var(--brand); color: #fff;
  box-shadow: 0 1px 4px color-mix(in srgb, var(--brand) 50%, transparent);
}

/* ---------- Tab-Bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding-bottom: var(--sab);
  background: color-mix(in srgb, var(--bg-elevated) 82%, transparent);
  backdrop-filter: var(--nav-blur); -webkit-backdrop-filter: var(--nav-blur);
  border-top: 0.5px solid var(--separator);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.tabbar button {
  border: 0; background: none; padding: 7px 0 4px; display: flex; flex-direction: column;
  align-items: center; gap: 3px; color: var(--secondary); font-size: 10px; position: relative;
}
.tabbar button.active { color: var(--brand); }
.tabbar button svg { width: 26px; height: 26px; }
.tabbar .badge {
  position: absolute; top: 4px; right: calc(50% - 20px); min-width: 17px; height: 17px;
  background: var(--expense); color: #fff; border-radius: 9px; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; padding: 0 4px;
}

/* ---------- Sheet / Modal ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 50;
  opacity: 0; transition: opacity .25s; display: flex; align-items: flex-end;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  background: var(--bg); width: 100%; max-height: 92vh; border-radius: 14px 14px 0 0;
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  padding-bottom: calc(var(--sab) + 16px); overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.sheet-backdrop.show .sheet { transform: translateY(0); }
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--tertiary);
  margin: 8px auto 4px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px var(--pad) 8px; }
.sheet-head h2 { font-size: 18px; margin: 0; font-weight: 700; }
.sheet-body { padding: 0 var(--pad); }

/* ---------- Formulare ---------- */
.field { margin-top: 14px; }
.field label { display: block; font-size: 13px; color: var(--secondary); margin: 0 4px 6px; font-weight: 600; }
.input, .select, textarea.input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 0.5px solid var(--separator);
  background: var(--card); color: var(--label); outline: none;
}
.input:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.amount-input { font-family: var(--num); font-size: 40px; font-weight: 700; text-align: center;
  border: 0; background: none; width: 100%; color: var(--label); padding: 20px 0; }
.amount-input:focus { outline: none; }

/* Farbwahl / Icon-Wahl */
.swatches, .icons { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; }
.swatch.active { border-color: var(--label); transform: scale(1.08); }
.icon-opt { width: 46px; height: 46px; border-radius: 12px; background: var(--fill);
  display: grid; place-items: center; color: var(--label-2); border: 2px solid transparent; }
.icon-opt.active { border-color: var(--brand); color: var(--brand); }
.icon-opt svg { width: 24px; height: 24px; }

/* Chips (Topf-Auswahl) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 22px;
  background: var(--card); border: 0.5px solid var(--separator); color: var(--label); font-size: 15px;
}
.chip .dot { width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; color:#fff; }
.chip .dot svg { width: 13px; height: 13px; }
.chip.active { background: color-mix(in srgb, var(--brand) 14%, transparent); border-color: var(--brand); }

/* ---------- Diverses ---------- */
.center-empty { text-align: center; color: var(--secondary); padding: 60px 30px; }
.center-empty .tile { margin: 0 auto 14px; }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--fill); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 100; }
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--sab)); transform: translateX(-50%) translateY(20px);
  background: var(--label); color: var(--bg); padding: 11px 18px; border-radius: 22px; font-size: 15px;
  font-weight: 600; z-index: 200; opacity: 0; transition: all .3s; pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Login */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
  padding: 24px; padding-top: calc(var(--sat) + 24px); }
.auth .brand-mark { width: 76px; height: 76px; border-radius: 18px; margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: grid; place-items: center;
  box-shadow: 0 12px 30px color-mix(in srgb, var(--brand) 40%, transparent); }
.auth .brand-mark svg { width: 40px; height: 40px; color: #fff; }
.auth h1 { text-align: center; font-size: 26px; margin: 0 0 4px; }
.auth p.sub { text-align: center; color: var(--secondary); margin: 0 0 28px; }
.auth .card { background: var(--card); border-radius: var(--radius-card); padding: 8px 16px 16px; box-shadow: var(--shadow-card); }
.auth .err { color: var(--expense); text-align: center; font-size: 14px; margin-top: 12px; min-height: 18px; }

/* PIN */
.pin-dots { display: flex; gap: 16px; justify-content: center; margin: 24px 0; }
.pin-dot { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--brand); }
.pin-dot.filled { background: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; max-width: 300px; margin: 0 auto; }
.key { height: 74px; border-radius: 50%; background: var(--fill); border: 0; font-size: 30px; font-weight: 500;
  color: var(--label); font-family: var(--num); }
.key:active { background: var(--brand); color: #fff; }
.key.blank { background: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Breite Bildschirme (Desktop, Edge am PC, Tablets) ----------
   Die App wird als zentrierte "Telefon-Spalte" gerendert. Keine
   transform-Tricks: left/right:0 + margin:auto zentriert position:fixed
   zuverlässig in allen Browsern. */
@media (min-width: 640px) {
  body { background: color-mix(in srgb, var(--bg) 92%, var(--label) 8%); }
  .screen, .nav {
    max-width: 440px;
    margin-left: auto; margin-right: auto;
  }
  .screen {
    background: var(--bg);
    min-height: 100vh;
    box-shadow: 0 0 0 0.5px var(--separator), 0 10px 40px rgba(0,0,0,0.10);
  }
  .nav { max-width: 440px; }
  .tabbar {
    left: 0; right: 0;
    max-width: 440px;
    margin: 0 auto;
    border-left: 0.5px solid var(--separator);
    border-right: 0.5px solid var(--separator);
  }
  .sheet-backdrop { align-items: flex-end; justify-content: center; }
  .sheet {
    max-width: 440px;
    border-radius: 14px 14px 0 0;
  }
  .toast { bottom: 90px; }
}
