/* =========================================================================
   FinanzManager – Stylesheet
   Mobile-first, CSS-Variablen, Hell/Dunkel-Theme.
   ========================================================================= */

:root {
  --indigo: #4f46e5;
  --indigo-600: #4338ca;
  --green: #16a34a;
  --red: #ef4444;
  --orange: #f97316;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0,0,0,.12);
  --transition: .18s ease;
}

/* Dunkles Theme (Standard) */
html[data-theme="dark"] {
  --bg: #0f172a;
  --bg-2: #111c33;
  --card: #1e293b;
  --card-2: #243049;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --input-bg: #0f172a;
}

/* Helles Theme */
html[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-2: #e8eef6;
  --card: #ffffff;
  --card-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --input-bg: #ffffff;
  --shadow: 0 10px 30px rgba(15,23,42,.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

a { color: var(--indigo); cursor: pointer; }

/* ----------------------------- Buttons --------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .55rem .9rem; border: 1px solid transparent; border-radius: var(--radius-sm);
  font-size: .92rem; font-weight: 600; cursor: pointer; background: var(--card-2);
  color: var(--text); transition: var(--transition); text-decoration: none;
}
.btn:hover { filter: brightness(1.07); }
.btn-primary { background: var(--indigo); color: #fff; }
.btn-primary:hover { background: var(--indigo-600); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger  { background: var(--red); color: #fff; }
.btn-ghost   { background: transparent; border-color: var(--border); }
.btn-block   { width: 100%; justify-content: center; }
.btn-sm      { padding: .35rem .6rem; font-size: .82rem; }
.btn-icon    { padding: .4rem .55rem; background: transparent; }

/* ----------------------------- Auth ------------------------------------ */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1rem; background: radial-gradient(1200px 600px at 20% -10%, #312e81, transparent),
                            radial-gradient(1000px 600px at 100% 110%, #0e7490, transparent), var(--bg);
}
.auth-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2rem; width: 100%; max-width: 420px; box-shadow: var(--shadow);
}
.auth-brand { font-size: 1.6rem; font-weight: 800; }
.auth-sub { color: var(--muted); font-size: .92rem; margin-top: .4rem; }
.auth-tabs { display: flex; gap: .5rem; margin: 1.4rem 0 1rem; background: var(--card-2);
  padding: .3rem; border-radius: var(--radius-sm); }
.auth-tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: .55rem;
  border-radius: 7px; font-weight: 600; cursor: pointer; }
.auth-tab.active { background: var(--indigo); color: #fff; }
.auth-form label { display: block; margin: .8rem 0 .3rem; font-weight: 600; font-size: .85rem; }
.auth-hint { margin-top: 1rem; font-size: .85rem; color: var(--muted); }

input, select, textarea {
  width: 100%; padding: .6rem .7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text);
  font-size: .95rem; font-family: inherit; transition: var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(79,70,229,.18);
}
input[type="color"] { padding: .2rem; height: 42px; }

.form-error { color: var(--red); font-size: .85rem; margin: .6rem 0; min-height: 1em; }

/* ----------------------------- App-Layout ------------------------------ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1.1rem .8rem; position: sticky; top: 0;
  height: 100vh;
}
.sidebar-brand { font-weight: 800; font-size: 1.2rem; padding: .3rem .5rem 1.2rem;
  display: flex; gap: .4rem; align-items: center; }
.nav { display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.nav-link { padding: .6rem .7rem; border-radius: var(--radius-sm); color: var(--text);
  text-decoration: none; font-weight: 500; font-size: .92rem; transition: var(--transition); }
.nav-link:hover { background: var(--card-2); }
.nav-link.active { background: var(--indigo); color: #fff; }
.sidebar-footer { display: flex; flex-direction: column; gap: .4rem; padding-top: .8rem;
  border-top: 1px solid var(--border); }
.user-email { font-size: .76rem; color: var(--muted); text-align: center; word-break: break-all; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg);
  z-index: 5; }
.topbar h1 { font-size: 1.25rem; margin: 0; flex: 1; }
.topbar-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.hamburger { display: none; background: transparent; border: 0; font-size: 1.4rem;
  color: var(--text); cursor: pointer; }

.content { padding: 1.4rem; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ----------------------------- Karten / Grid --------------------------- */
.grid { display: grid; gap: 1rem; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.2rem; box-shadow: var(--shadow);
}
.card h2, .card h3 { margin-top: 0; }
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem; }

.stat { display: flex; flex-direction: column; gap: .25rem; }
.stat-label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }
.stat .icon { font-size: 1.4rem; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-muted { color: var(--muted); }

/* ----------------------------- Tabellen -------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: .65rem .7rem; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .03em; }
table.data tr:hover td { background: var(--card-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .55rem;
  border-radius: 999px; font-size: .78rem; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.pill { padding: .15rem .5rem; border-radius: 6px; font-size: .76rem; font-weight: 600;
  background: var(--card-2); color: var(--muted); }

/* ----------------------------- Kalender -------------------------------- */
.cal-controls { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin-bottom: 1rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { text-align: center; font-size: .78rem; font-weight: 700; color: var(--muted);
  padding: .3rem 0; }
.cal-cell { background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  min-height: 96px; padding: .4rem; display: flex; flex-direction: column; gap: .25rem;
  font-size: .76rem; }
.cal-cell.empty { background: transparent; border: 0; }
.cal-cell.today { border-color: var(--indigo); box-shadow: 0 0 0 2px rgba(79,70,229,.3); }
.cal-cell.neg { background: color-mix(in srgb, var(--red) 14%, var(--card)); }
.cal-daynum { font-weight: 700; }
.cal-bal { margin-top: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-ev { display: flex; align-items: center; gap: .25rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.cal-ev .dot { width: 7px; height: 7px; flex-shrink: 0; }

/* ----------------------------- Charts ---------------------------------- */
.chart-box { position: relative; height: 300px; }

/* ----------------------------- Progress / Goals ------------------------ */
.progress { height: 12px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; transition: width .4s; }

/* ----------------------------- Modal ----------------------------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 1rem;
  z-index: 50; overflow-y: auto; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 520px; box-shadow: var(--shadow); animation: pop .15s ease; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 1.2rem; }
.modal-foot { padding: 1rem 1.2rem; border-top: 1px solid var(--border);
  display: flex; gap: .6rem; justify-content: flex-end; }
.field { margin-bottom: .9rem; }
.field label { display: block; margin-bottom: .3rem; font-weight: 600; font-size: .85rem; }
.field-row { display: flex; gap: .8rem; }
.field-row .field { flex: 1; }
.close-x { background: transparent; border: 0; font-size: 1.3rem; cursor: pointer;
  color: var(--muted); }

/* ----------------------------- Toast ----------------------------------- */
.toast-root { position: fixed; bottom: 1.2rem; right: 1.2rem; display: flex;
  flex-direction: column; gap: .5rem; z-index: 100; }
.toast { background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--indigo);
  padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); font-size: .9rem;
  min-width: 220px; animation: pop .15s ease; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }

/* ----------------------------- Diverses -------------------------------- */
.section-actions { display: flex; justify-content: flex-end; margin-bottom: 1rem; }
.empty-state { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty-state .big { font-size: 2.5rem; }
.alert { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: .9rem; }
.alert-warn { background: color-mix(in srgb, var(--orange) 18%, var(--card)); border: 1px solid var(--orange); }
.row-actions { display: flex; gap: .3rem; }
.spacer { flex: 1; }
.mt { margin-top: 1rem; }
.flex { display: flex; gap: .6rem; align-items: center; }
.wrap { flex-wrap: wrap; }

/* ----------------------------- Footer ---------------------------------- */
.legal-footer {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: 1.2rem 1rem; color: var(--muted); font-size: .82rem;
}
.legal-footer a { color: var(--muted); text-decoration: none; }
.legal-footer a:hover { color: var(--indigo); text-decoration: underline; }
.auth-card .legal-footer { margin-top: 1.2rem; padding: .6rem 0 0;
  border-top: 1px solid var(--border); }
.main .legal-footer { margin-top: auto; border-top: 1px solid var(--border); }

/* ----------------------------- Responsive ------------------------------ */
.backdrop { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%);
    transition: transform var(--transition); }
  .sidebar.open { transform: none; }
  .hamburger { display: block; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; }
  .content { padding: 1rem; }
  .cal-cell { min-height: 70px; font-size: .68rem; }
  .stat-value { font-size: 1.4rem; }
}
