:root {
  --bg: #05070d;
  --panel: #0c1220;
  --panel-2: #131b2e;
  --panel-3: #0f1626;
  --border: #1c2740;
  --text: #eaf0fb;
  --text-dim: #8a96b3;
  --green: #34d399;
  --red: #f2536b;
  --amber: #f2b84b;
  --cyan: #22d3ee;
  --accent: #3b82f6;
  --accent-2: #8b7ce0;
  --radius: 16px;
  --glow: 0 0 0 1px rgba(34,211,238,.35), 0 0 40px rgba(34,211,238,.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: radial-gradient(1200px 800px at 15% -10%, #0b1730 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Grid-/Flex-Kinder dürfen unter ihre Inhaltsbreite schrumpfen, sonst
   sprengen breite Kinder (Tabellen, Sankey-/Chart-Container) die Spalte. */
.dash-grid > *, .two-col > *, .grid > *, .card, .content, .app-shell > * {
  min-width: 0;
}

/* ---------------- App frame (glow border, wie im Referenzdesign) ---------------- */
.app-frame {
  margin: 18px;
  border-radius: 28px;
  border: 1px solid rgba(34,211,238,.35);
  box-shadow: var(--glow);
  overflow: hidden;
  background: var(--bg);
}

.app-shell { display: flex; min-height: calc(100vh - 36px); }

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #0a0f1c 0%, #070b14 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.02rem;
  margin-bottom: 26px;
  padding: 0 8px;
  color: var(--text);
}

.sidebar .brand svg { flex-shrink: 0; }

.sidebar nav { display: flex; flex-direction: column; gap: 3px; }

.sidebar a {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text-dim);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  letter-spacing: .01em;
}

.sidebar a svg { flex-shrink: 0; opacity: .85; }

.sidebar a:hover { background: var(--panel-2); color: var(--text); }
.sidebar a.active {
  background: linear-gradient(90deg, rgba(59,130,246,.22), rgba(34,211,238,.08));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(59,130,246,.35);
}
.sidebar a.active svg { opacity: 1; }

.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

/* ---------------- Content ---------------- */
.content { flex: 1; padding: 26px 30px 40px; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: .02em;
}
.topbar .subtitle {
  color: var(--text-dim);
  font-size: 0.76rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-top: 2px;
}

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  position: relative;
}
.icon-btn + .icon-btn { margin-left: 8px; }
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--red);
}

h1 { font-size: 1.5rem; margin: 0 0 20px; }
h2 { font-size: 1rem; margin: 0 0 14px; font-weight: 600; letter-spacing: .01em; }

.dash-grid {
  display: grid;
  grid-template-columns: 2.2fr 1fr;
  gap: 18px;
  align-items: start;
}
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-3) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.card-head .title {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim);
}
.card-head .title svg { color: var(--cyan); }
.card-head .badge {
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(52,211,153,.14); color: var(--green);
}
.card-head .badge.negative { background: rgba(242,83,107,.14); color: var(--red); }

.card .label { color: var(--text-dim); font-size: 0.78rem; }
.card .value { font-size: 1.7rem; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; }
.card .value.positive { color: var(--green); }
.card .value.negative { color: var(--red); }
.card .sub { color: var(--text-dim); font-size: 0.8rem; margin-top: 4px; }

.legend-list { display: flex; flex-direction: column; gap: 9px; margin-top: 6px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-row .name { color: var(--text-dim); flex: 1; }
.legend-row .pct { font-weight: 700; }

.progress-bar { background: var(--panel-2); border-radius: 8px; height: 9px; overflow: hidden; margin-top: 10px; }
.progress-bar > div { height: 100%; background: linear-gradient(90deg, var(--amber), #ff8a4c); }
.progress-bar.blue > div { background: linear-gradient(90deg, var(--accent), var(--cyan)); }
.progress-bar.green > div { background: linear-gradient(90deg, var(--green), var(--cyan)); }

.debt-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.debt-row:last-child { border-bottom: none; }
.debt-row .icon-chip {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--panel-2); display: inline-flex; align-items: center; justify-content: center;
  margin-right: 10px; color: var(--amber);
}
.debt-row .name-wrap { display: flex; align-items: center; flex: 1; }
.debt-row .amount { color: var(--red); font-weight: 600; }

.activity-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.activity-row:last-child { border-bottom: none; }
.activity-row .icon-chip {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--panel-2); display: inline-flex; align-items: center; justify-content: center;
  color: var(--cyan); flex-shrink: 0;
}
.activity-row .meta { flex: 1; min-width: 0; }
.activity-row .meta .desc { font-size: 0.86rem; font-weight: 600; }
.activity-row .meta .date { font-size: 0.74rem; color: var(--text-dim); margin-top: 1px; }
.activity-row .amt { font-weight: 700; font-size: 0.86rem; white-space: nowrap; }

.mini-panel + .mini-panel { margin-top: 18px; }

/* Ausklappbarer Card-Abschnitt (z.B. "Neue Schuld eintragen") */
details.collapsible { padding: 0; }
details.collapsible > summary {
  padding: 20px;
  margin-bottom: 0;
  cursor: pointer;
  list-style: none;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::after {
  content: '▾';
  color: var(--text-dim);
  font-size: 0.7rem;
  margin-left: 10px;
  transition: transform .15s ease;
}
details.collapsible[open] > summary::after { transform: rotate(180deg); }
details.collapsible > summary:hover .title { color: var(--text); }
details.collapsible > form { padding: 0 20px 20px; }
.mini-panel .row-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.mini-panel .row-between .val-pill {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 3px 10px; font-size: 0.78rem; font-weight: 700; color: var(--cyan);
}
input[type=range] {
  -webkit-appearance: none;
  width: 100%; height: 4px; border-radius: 4px;
  background: var(--panel-2);
  margin: 8px 0 4px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--cyan); cursor: pointer;
  box-shadow: 0 0 10px rgba(34,211,238,.6);
}
.range-labels { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--text-dim); }

.reminder-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.reminder-row:last-child { border-bottom: none; }
.reminder-row .icon-chip {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  background: rgba(59,130,246,.15); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
}
.reminder-row .title { font-size: 0.82rem; font-weight: 600; }
.reminder-row .sub { font-size: 0.72rem; color: var(--text-dim); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: rgba(255,255,255,.02); }

.amount-pos { color: var(--green); }
.amount-neg { color: var(--red); }

form.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 20px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.76rem; color: var(--text-dim); }
input, select, button {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}
button {
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  border: none;
  color: #04121f;
  cursor: pointer;
  font-weight: 700;
}
button:hover { filter: brightness(1.08); }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--red); color: #fff; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim); }
.tag.fix { color: var(--amber); }
.tag.variabel { color: var(--accent); }

.chart-wrap { position: relative; }
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 800px at 50% 0%, #0b1730 0%, var(--bg) 60%);
}
.login-box {
  background: var(--panel);
  border: 1px solid rgba(34,211,238,.35);
  box-shadow: var(--glow);
  border-radius: var(--radius);
  padding: 36px;
  width: 320px;
}
.login-box h1 { font-size: 1.15rem; text-align: center; }
.login-box .field { margin-bottom: 14px; }
.login-box input { width: 100%; }
.login-box button { width: 100%; margin-top: 8px; }
.error-msg { color: var(--red); font-size: 0.85rem; margin-bottom: 12px; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
.table-scroll table { min-width: 560px; }

/* ==================================================================
   Mobile (Smartphone) – Sidebar wird zur unteren Tab-Leiste,
   alles stapelt sich einspaltig, Formulare werden touch-freundlich.
   ================================================================== */
@media (max-width: 780px) {
  .app-frame { margin: 0; border-radius: 0; border: none; box-shadow: none; min-height: 100vh; }
  .app-shell { flex-direction: column; min-height: 100vh; }

  /* Schwebende Glass-Pill-Tab-Leiste im Apple-Stil: zentriert, abgerundet,
     nur Icons (keine Beschriftung), Frosted-Glass-Hintergrund. */
  .sidebar {
    position: fixed;
    bottom: max(14px, env(safe-area-inset-bottom));
    left: 16px;
    right: 16px;
    top: auto;
    width: auto;
    max-width: 460px;
    margin: 0 auto;
    height: 56px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 0 8px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 999px;
    background: rgba(20,26,42,.55);
    backdrop-filter: blur(22px) saturate(180%);
    -webkit-backdrop-filter: blur(22px) saturate(180%);
    box-shadow: 0 10px 30px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.06);
    z-index: 100;
  }
  .sidebar .brand { display: none; }
  .sidebar nav { flex: 1 1 auto; flex-direction: row; justify-content: space-around; gap: 2px; height: 100%; }
  .sidebar nav a {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    text-align: center;
    flex: 0 0 auto;
    color: var(--text-dim);
  }
  .sidebar nav a span { display: none; }
  .sidebar nav a svg { width: 20px; height: 20px; opacity: .85; }
  .sidebar nav a.active {
    background: rgba(255,255,255,.14);
    color: #fff;
    box-shadow: none;
  }
  .sidebar nav a.active svg { opacity: 1; }
  .sidebar-footer {
    border-top: none; margin-top: 0; padding-top: 0;
    padding-left: 4px;
    margin-left: 2px;
    border-left: 1px solid rgba(255,255,255,.14);
    flex: 0 0 auto;
    display: flex; align-items: center; height: 100%;
  }
  .sidebar-footer a {
    flex-direction: column; justify-content: center; align-items: center;
    gap: 0; padding: 0;
    width: 44px; height: 44px;
    border-radius: 50%;
    color: var(--text-dim);
  }
  .sidebar-footer a span { display: none; }
  .sidebar-footer a svg { width: 20px; height: 20px; opacity: .85; }

  .content { padding: 14px 14px 104px; }

  .topbar { flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
  .topbar h1 { font-size: 1.1rem; }
  .topbar .subtitle { font-size: 0.68rem; }
  .topbar-icons { display: flex; gap: 6px; }
  .icon-btn { width: 32px; height: 32px; }
  .icon-btn + .icon-btn { margin-left: 0; }

  h2 { font-size: 0.92rem; }

  .dash-grid, .two-col { grid-template-columns: 1fr !important; }
  .grid { grid-template-columns: 1fr !important; }
  .card { padding: 16px; }
  .card-head { flex-wrap: wrap; gap: 6px; }
  .card-head .title { font-size: 0.74rem; }

  form.inline-form { gap: 8px; }
  .field { flex: 1 1 100%; }
  .field input, .field select { width: 100%; }
  input, select, button { font-size: 16px; } /* verhindert Auto-Zoom auf iOS */

  .login-box { width: 88vw; max-width: 340px; padding: 26px; }

  .debt-row, .activity-row, .reminder-row { font-size: 0.8rem; }
}
