/* =========================================================================
   Abo-Tracker — elegantes, seriöses Farb- und Layout-System
   Light/Dark über prefers-color-scheme. Diagrammfarben (--series-*) sind
   CVD-geprüft (dataviz-Validator) für die jeweilige Fläche.
   ========================================================================= */

:root {
  /* Flächen & Text */
  --bg: #edeae3;            /* Seitenhintergrund (warmes Greige) */
  --surface: #ffffff;       /* Karten */
  --surface-2: #f3f1ea;     /* Insets, Balken-Spur */
  --border: #e3dfd5;        /* Haarlinie */
  --border-strong: #d6d1c4;
  --text: #1b2333;          /* tiefes Tinten-Navy */
  --muted: #6c7484;
  --muted-2: #9aa0ac;

  /* Marke / Akzente */
  --primary: #223a5e;       /* tiefes Navy */
  --primary-hover: #2e4d78;
  --on-primary: #f7f9fc;
  --accent: #a97e22;        /* zurückhaltendes Gold */
  --danger: #a83a3a;
  --success: #1f7a4d;

  --hero-from: #223a5e;
  --hero-to: #35507a;

  --shadow-sm: 0 1px 2px rgba(20, 28, 46, 0.05);
  --shadow: 0 6px 24px -12px rgba(20, 28, 46, 0.22);
  --radius: 14px;
  --radius-sm: 9px;

  /* Kategorische Diagrammpalette — LIGHT (Validator: worst adj. CVD ΔE 24.7) */
  --series-1: #2f5aa8;  /* blau    */
  --series-2: #c8901f;  /* gold    */
  --series-3: #0a8a74;  /* teal    */
  --series-4: #c0552f;  /* rost    */
  --series-5: #7a3f9e;  /* pflaume */
  --series-6: #5e8c2a;  /* oliv    */
  --series-7: #c85a86;  /* rosé    */
  --series-8: #1f8a44;  /* grün    */

  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1220;
    --surface: #18202e;
    --surface-2: #212b3b;
    --border: #2a3444;
    --border-strong: #354052;
    --text: #e9edf4;
    --muted: #97a1b2;
    --muted-2: #6b7688;

    --primary: #3f5f9e;
    --primary-hover: #4d70b4;
    --on-primary: #f7f9fc;
    --accent: #d4a13f;
    --danger: #e07373;
    --success: #3fae74;

    --hero-from: #1c2c47;
    --hero-to: #2c4368;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 10px 30px -14px rgba(0, 0, 0, 0.6);

    /* Diagrammpalette — DARK (Validator: worst adj. CVD ΔE 26.9, ≥3:1) */
    --series-1: #5b8ae0;
    --series-2: #b8851f;
    --series-3: #1f9e86;
    --series-4: #d0663c;
    --series-5: #a878d8;
    --series-6: #79a038;
    --series-7: #d06f96;
    --series-8: #35a256;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: var(--font-serif); font-weight: 600; letter-spacing: 0.01em; }

/* ------------------------------- Topbar -------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.75rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.1) blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-emblem {
  display: inline-grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--hero-from), var(--hero-to));
  color: #fff;
  font-family: var(--font-serif);
  font-size: 1.02rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.brand-word { font-family: var(--font-serif); font-size: 1.16rem; font-weight: 600; letter-spacing: 0.02em; }
.topnav { display: flex; align-items: center; gap: 0.6rem; }
.topnav .user { color: var(--muted); font-size: 0.86rem; margin-right: 0.25rem; }

.container { max-width: 1000px; margin: 0 auto; padding: 1.75rem 1.5rem 2.5rem; }
.footer {
  text-align: center;
  color: var(--muted-2);
  font-size: 0.82rem;
  padding: 2.5rem 1rem 3rem;
  letter-spacing: 0.02em;
}

/* ------------------------------- Buttons ------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.58rem 1.05rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(0.5px); }
.btn-small { padding: 0.4rem 0.8rem; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; border-color: var(--border-strong); color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: var(--danger); }
.inline { display: inline; margin: 0; }

/* ------------------------------ Stat-Tiles ----------------------------- */
.stats {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 1.1rem;
  margin-bottom: 1.4rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.3rem 1.4rem;
  box-shadow: var(--shadow-sm);
}
.stat-card.highlight {
  background: linear-gradient(140deg, var(--hero-from), var(--hero-to));
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.stat-card.highlight .stat-label { color: rgba(255, 255, 255, 0.75); }
.stat-value {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-card.highlight .stat-value { font-size: 2.1rem; }

/* ------------------------------- Panels -------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.6rem;
  margin-bottom: 1.4rem;
  box-shadow: var(--shadow-sm);
}
.panel h2 { margin: 0 0 1.2rem; font-size: 1.18rem; }
.panel h2 .muted { font-size: 0.9rem; font-weight: 400; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }
.panel-actions { display: flex; gap: 0.55rem; }
.empty { padding: 1.5rem 0; color: var(--muted); }

/* --------------------------- Donut & Legende --------------------------- */
.chart-layout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2rem;
  align-items: center;
}
.donut-wrap { position: relative; width: 210px; height: 210px; }
.donut { display: block; width: 210px; height: 210px; }
.donut .track { fill: none; stroke: var(--surface-2); }
.donut .seg { fill: none; stroke-linecap: butt; }
.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.donut-total { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.donut-sub { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin-top: 0.15rem; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.1rem; }
.legend li {
  display: grid;
  grid-template-columns: 14px 1fr auto auto;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.2rem;
  border-bottom: 1px solid var(--border);
}
.legend li:last-child { border-bottom: none; }
.swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--c, var(--muted)); }
.legend-name { color: var(--text); font-size: 0.92rem; }
.legend-amount { color: var(--text); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.legend-pct { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; min-width: 2.6em; text-align: right; }

/* Farbzuordnung nach Slot (Donut-Segment: stroke, Swatch: background) */
.slot-1 { --c: var(--series-1); } .slot-2 { --c: var(--series-2); }
.slot-3 { --c: var(--series-3); } .slot-4 { --c: var(--series-4); }
.slot-5 { --c: var(--series-5); } .slot-6 { --c: var(--series-6); }
.slot-7 { --c: var(--series-7); } .slot-8 { --c: var(--series-8); }
.donut .seg.slot-1, .donut .seg.slot-2, .donut .seg.slot-3, .donut .seg.slot-4,
.donut .seg.slot-5, .donut .seg.slot-6, .donut .seg.slot-7, .donut .seg.slot-8 { stroke: var(--c); }

/* -------------------------------- Tabelle ------------------------------ */
.table-wrap { overflow-x: auto; }
table.subs { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.subs th, table.subs td { padding: 0.75rem 0.65rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.subs thead th {
  color: var(--muted);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
table.subs tbody tr:last-child td { border-bottom: none; }
table.subs td.num, table.subs th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.subs tr.inactive { opacity: 0.5; }
.sub-name { font-weight: 600; }
.badge {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.08rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  vertical-align: middle;
}
td.actions { display: flex; gap: 0.4rem; justify-content: flex-end; }

/* --------------------------- Auth & Formulare -------------------------- */
.auth-card, .form-card {
  max-width: 430px;
  margin: 3rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.2rem;
  box-shadow: var(--shadow);
}
.form-card { max-width: 580px; }
.auth-card h1, .form-card h1 { margin-top: 0; margin-bottom: 1.3rem; font-size: 1.5rem; }

.stack { display: flex; flex-direction: column; gap: 1.05rem; }
.stack label, .form-card label {
  display: flex; flex-direction: column; gap: 0.4rem;
  font-size: 0.82rem; color: var(--muted); font-weight: 600;
  letter-spacing: 0.01em;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
label.checkbox { flex-direction: row; align-items: center; gap: 0.55rem; color: var(--text); }

input, select, textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.62rem 0.72rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
label.checkbox input { width: auto; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 0.4rem; }

/* -------------------------------- Alerts ------------------------------- */
.alert { padding: 0.8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem; font-size: 0.9rem; border: 1px solid transparent; }
.alert-error { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert-info { background: color-mix(in srgb, var(--primary) 10%, transparent); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 28%, transparent); }

.muted { color: var(--muted); }
.center { text-align: center; }
small.muted { font-weight: 400; }

/* ------------------------------ Responsive ----------------------------- */
@media (max-width: 720px) {
  .stats { grid-template-columns: 1fr; }
  .chart-layout { grid-template-columns: 1fr; justify-items: center; gap: 1.4rem; }
  .legend { width: 100%; }
  .row { grid-template-columns: 1fr; }
  .container { padding: 1.25rem 1rem 2rem; }
  .topbar { padding: 0.75rem 1rem; }
}
