/* ============================================================
   BarsWeb - handgeschriebenes CSS, kein Framework.
   Light/Dark Mode über CSS-Variablen: das data-theme-Attribut auf
   <html> wird vor dem Rendern per Inline-Script im Layout gesetzt.
   Regel: im restlichen CSS NIE feste Farbwerte, immer var(--...).
   ============================================================ */

:root,
:root[data-theme="light"] {
  color-scheme: light;

  --paper: #eef2f3;
  --surface: #ffffff;
  --surface-2: #e5eaec;
  --ink: #16232a;
  --ink-muted: #566169;
  --line: rgba(22, 35, 42, 0.12);
  --line-strong: rgba(22, 35, 42, 0.22);

  --accent: #2f66e0;
  --accent-hover: #2454c8;
  --accent-strong: rgba(47, 102, 224, 0.28);
  --accent-ink: #ffffff;
  --accent-2: #2f6e68;
  --card-glow: rgba(47, 102, 224, 0.10);

  --success: #2e7d5b;
  --success-bg: #e3f3ea;
  --danger: #b3452f;
  --danger-bg: #fbeae4;

  --role-admin: #6a4bd4;
  --role-admin-bg: #ece7fa;
  --role-friend: #2f6e68;
  --role-friend-bg: #e2f0ee;
  --role-public: #5f6f6f;
  --role-public-bg: #e8edec;

  /* Diagramm-Farben (Sub Tracker). Feste Slot-Reihenfolge, CVD-geprüft gegen
     die Kartenfläche (validate_palette: PASS auf #ffffff und #152224).
     Slot 0 = neutrales Grau, reserviert für "Sonstiges". */
  --chart-0: #7c8a8e;
  --chart-1: #2a78d6;
  --chart-2: #1baf7a;
  --chart-3: #eda100;
  --chart-4: #008300;
  --chart-5: #4a3aa7;
  --chart-6: #e34948;
  --chart-7: #e87ba4;
  --chart-8: #eb6834;

  --shadow: 0 1px 2px rgba(22, 35, 42, 0.06), 0 8px 24px rgba(22, 35, 42, 0.07);
  --radius: 14px;

  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --paper: #0d1618;
    --surface: #152224;
    --surface-2: #1c2c2e;
    --ink: #e9f0f0;
    --ink-muted: #93a3a5;
    --line: rgba(233, 240, 240, 0.12);
    --line-strong: rgba(233, 240, 240, 0.2);

    --accent: #5b8cf5;
    --accent-hover: #6f9bff;
    --accent-strong: rgba(91, 140, 245, 0.32);
    --accent-ink: #ffffff;
    --accent-2: #57b0a6;
    --card-glow: rgba(150, 180, 255, 0.08);

    --success: #57c08a;
    --success-bg: #163329;
    --danger: #e38468;
    --danger-bg: #3a2018;

    --role-admin: #a892e8;
    --role-admin-bg: #231f36;
    --role-friend: #57b0a6;
    --role-friend-bg: #16302d;
    --role-public: #9bacac;
    --role-public-bg: #1c2a2b;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --paper: #0d1618;
  --surface: #152224;
  --surface-2: #1c2c2e;
  --ink: #e9f0f0;
  --ink-muted: #93a3a5;
  --line: rgba(233, 240, 240, 0.12);
  --line-strong: rgba(233, 240, 240, 0.2);

  --accent: #5b8cf5;
  --accent-hover: #6f9bff;
  --accent-strong: rgba(91, 140, 245, 0.32);
  --accent-ink: #ffffff;
  --accent-2: #57b0a6;
  --card-glow: rgba(150, 180, 255, 0.08);

  --success: #57c08a;
  --success-bg: #163329;
  --danger: #e38468;
  --danger-bg: #3a2018;

  --role-admin: #a892e8;
  --role-admin-bg: #231f36;
  --role-friend: #57b0a6;
  --role-friend-bg: #16302d;
  --role-public: #9bacac;
  --role-public-bg: #1c2a2b;

  /* Diagramm-Farben: gleiche Hues, für die dunkle Fläche gestuft (validiert). */
  --chart-0: #6d7a7d;
  --chart-1: #3987e5;
  --chart-2: #199e70;
  --chart-3: #c98500;
  --chart-4: #008300;
  --chart-5: #9085e9;
  --chart-6: #e66767;
  --chart-7: #d55181;
  --chart-8: #d95926;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.35);
}

/* ---------- Basis ---------- */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  text-wrap: balance;
  letter-spacing: -0.015em;
  margin: 0 0 0.6rem;
}
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }

a { color: var(--accent); }

code, .mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.muted { color: var(--ink-muted); }

.eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin: 0 0 0.6rem;
}

.container {
  max-width: 68rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ---------- Navigation ---------- */

.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.navbar-inner {
  max-width: 68rem;
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--ink);
}
.nav-links {
  display: flex;
  gap: 1.4rem;
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}
.nav-link {
  position: relative;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink-muted);
  padding: 0.3rem 0.05rem;
  transition: color 0.2s ease;
}
.nav-link::after {
  content: "";
  position: absolute;
  left: 0; right: 100%;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  transition: right 0.28s cubic-bezier(.2, .8, .2, 1);
}
.nav-link:hover { color: var(--ink); }
.nav-link:hover::after { right: 0; }

/* Nur-Admin-Einträge in der Leiste: rote Pill-Umrandung, passend zu
   .card-admin auf der Topics-Übersicht. */
.nav-link-admin {
  border: 1px solid color-mix(in srgb, var(--danger) 75%, transparent);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.nav-link-admin:hover { border-color: var(--danger); }
/* Der Unterstrich-Effekt der normalen Links passt nicht in eine Pill. */
.nav-link-admin::after { display: none; }

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-left: auto;
}
.user-menu { position: relative; }
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--ink-muted);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid transparent;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.user-menu:hover .user-pill,
.user-menu:focus-within .user-pill {
  color: var(--ink);
  border-color: var(--line);
}
.user-caret { width: 0.7rem; height: 0.7rem; transition: transform 0.25s ease; }
.user-menu:hover .user-caret,
.user-menu:focus-within .user-caret { transform: rotate(180deg); }

.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 10rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  z-index: 20;
}
/* Unsichtbare Brücke über die 6px-Lücke, damit der Hover nicht abreißt. */
.user-dropdown::before {
  content: "";
  position: absolute;
  top: -6px; left: 0; right: 0;
  height: 6px;
}
.user-menu:hover .user-dropdown,
.user-menu:focus-within .user-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.dropdown-item {
  display: block;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--ink);
  text-decoration: none;
  transition: background 0.15s ease;
}
.dropdown-item:hover { background: var(--surface-2); }

.theme-toggle {
  width: 2.1rem; height: 2.1rem;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}
.theme-toggle:hover { background: var(--surface-2); transform: rotate(-8deg); }
.theme-toggle svg { width: 1.05rem; height: 1.05rem; }

/* ---------- Buttons ---------- */

.btn {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.2;
  border-radius: 10px;
  padding: 0.62rem 1.15rem;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
  transition: transform 0.18s cubic-bezier(.2, .8, .2, 1), box-shadow 0.25s ease,
              background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 1px 2px rgba(22, 35, 42, 0.08);
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 10px 22px -6px var(--accent-strong);
}
/* Leichter Lichtstreif-Sweep beim Hover (nur Primär-Buttons). */
.btn-primary::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.22) 50%, transparent 65%);
  transform: translateX(-120%);
  pointer-events: none;
  z-index: 1;
  transition: transform 0s;
}
.btn-primary:hover::after {
  transform: translateX(120%);
  transition: transform 0.65s cubic-bezier(.2, .8, .2, 1);
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn-ghost:hover {
  background: var(--surface-2);
  transform: translateY(-1px);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}
.btn-danger:hover {
  background: var(--danger-bg);
  transform: translateY(-2px);
  box-shadow: 0 10px 20px -8px color-mix(in srgb, var(--danger) 40%, transparent);
}

.btn-sm { padding: 0.42rem 0.8rem; font-size: 0.82rem; }
.btn-block { width: 100%; }

/* ---------- Formulare ---------- */

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin: 0.7rem 0 0.3rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
textarea,
select {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
textarea {
  width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-strong);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  margin-top: 0.9rem;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.3rem 0 0;
}

/* ---------- Karten ---------- */

.card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.3rem 1.4rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.card-muted { opacity: 0.75; box-shadow: none; }

/* Nur-Admin-Karten: rote Umrandung als Erinnerung, dass andere Rollen
   diese Karte nicht sehen. */
.card-admin { border-color: color-mix(in srgb, var(--danger) 75%, transparent); }
.card-admin[data-glow]:hover { border-color: var(--danger); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1.1rem;
}
.card-grid .card { margin-bottom: 0; }

/* Karten mit Cursor-Beleuchtung (data-glow, dezentes Licht folgt der Maus). */
.card[data-glow]::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(300px circle at var(--x, 50%) var(--y, 0%), var(--card-glow), transparent 60%);
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}
.card[data-glow] {
  transition: transform 0.25s cubic-bezier(.2, .8, .2, 1), border-color 0.25s ease, box-shadow 0.25s ease;
}
.card[data-glow]:hover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
}
.card[data-glow]:hover::before { opacity: 1; }
.card > * { position: relative; z-index: 1; }
.card p { color: var(--ink-muted); }
.card .btn { margin-top: 0.9rem; }

/* ---------- Hero / Startseite ---------- */

.hero { padding: 1.5rem 0 1rem; }
.hero h1 { font-size: clamp(1.8rem, 3vw, 2.4rem); }
.hero p { color: var(--ink-muted); max-width: 34rem; }
.hero-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

/* ---------- Auth-Box ---------- */

.auth-box {
  max-width: 26rem;
  margin: 1.5rem auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}
.auth-box form { display: flex; flex-direction: column; }
.auth-box .btn-block { margin-top: 1.2rem; }
.auth-alt {
  margin-top: 1.25rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

/* ---------- Nutzer-Liste (Admin) ---------- */

.user-list { display: flex; flex-direction: column; gap: 0.6rem; }
.user-item {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  transition: transform 0.2s cubic-bezier(.2, .8, .2, 1), border-color 0.2s ease, box-shadow 0.2s ease;
}
.user-item:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}
.user-avatar {
  flex: none;
  width: 2.5rem; height: 2.5rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  font-weight: 700;
}
.user-avatar.role-admin { color: var(--role-admin); background: var(--role-admin-bg); }
.user-avatar.role-friend { color: var(--role-friend); background: var(--role-friend-bg); }
.user-avatar.role-public { color: var(--role-public); background: var(--role-public-bg); }

.user-meta { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 0.95rem; }
.user-email {
  font-size: 0.82rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-right {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ---------- Badges & Status ---------- */

.role-badge, .badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.18rem 0.65rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-muted);
  white-space: nowrap;
}
.role-admin { color: var(--role-admin); background: var(--role-admin-bg); }
.role-friend { color: var(--role-friend); background: var(--role-friend-bg); }
.role-public { color: var(--role-public); background: var(--role-public-bg); }
.badge-ok { color: var(--success); background: var(--success-bg); }
.badge-blocked { color: var(--danger); background: var(--danger-bg); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-muted);
}
.status-dot {
  display: inline-block;
  width: 0.5rem; height: 0.5rem;
  border-radius: 999px;
  background: currentColor;
}
.status.is-ok { color: var(--success); }
.status.is-blocked { color: var(--danger); }

/* ---------- Tabelle (z. B. Einladungscodes) ---------- */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}
th, td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  font-weight: 600;
  background: var(--surface-2);
}
tbody tr { transition: background 0.18s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.inline-form {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  margin: 0;
}

/* ---------- Meldungen ---------- */

.alert {
  padding: 0.7rem 1rem;
  border-radius: 10px;
  margin-bottom: 1.25rem;
  border: 1px solid transparent;
  font-size: 0.92rem;
}
.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}
.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

/* ---------- Toasts (kurze Popups, verschieben den Inhalt nicht) ---------- */

.toast-container {
  position: fixed;
  top: 4.5rem;
  right: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: 22rem;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: toast-in 0.28s cubic-bezier(.2, .8, .2, 1);
}
.toast.is-leaving {
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast-success {
  background: var(--success-bg);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 32%, transparent);
}
.toast-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---------- Profil-Seite ---------- */

.profile-card { max-width: 34rem; }
.profile-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1.1rem;
  margin-bottom: 1.1rem;
  border-bottom: 1px solid var(--line);
}
.profile-avatar {
  flex: none;
  width: 3.6rem; height: 3.6rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--ink-muted);
}
.profile-name { font-weight: 700; font-size: 1.15rem; margin-bottom: 0.3rem; }

.data-list { display: flex; flex-direction: column; gap: 0.1rem; margin: 0; }
.data-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}
.data-row:last-child { border-bottom: none; }
.data-row dt { color: var(--ink-muted); font-size: 0.9rem; }
.data-row dd { margin: 0; font-weight: 500; text-align: right; }

/* ---------- Settings-/Topic-Liste ---------- */

.settings-list { display: flex; flex-direction: column; gap: 0.6rem; max-width: 38rem; }
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1.1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.settings-item:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.settings-title { font-weight: 600; }

/* ---------- Topic-Steuerung (zwei Umschalter pro Topic) ---------- */

.topic-controls {
  display: flex;
  gap: 1.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.switch-field {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

/* ---------- Toggle-Switch (an/aus) ---------- */

.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 2.4rem; height: 1.4rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  position: relative;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 50%; left: 0.15rem;
  width: 1rem; height: 1rem;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transform: translateY(-50%);
  transition: transform 0.22s cubic-bezier(.2, .8, .2, 1);
}
.switch input:checked + .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked + .switch-track::after { transform: translate(1rem, -50%); }
.switch input:disabled + .switch-track { opacity: 0.7; cursor: default; }

/* ---------- Kontakt ---------- */

.contact-email {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 1.3rem;
  padding: 0.9rem 1rem;
  border-radius: 10px;
  background: var(--surface-2);
}
.contact-email .muted { font-size: 0.8rem; }

/* ---------- Segment-Umschalter (wiederverwendbare Komponente) ---------- */

.segmented {
  position: relative;
  display: inline-flex;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  gap: 2px;
}
.segmented-indicator {
  position: absolute;
  top: 4px; bottom: 4px; left: 4px;
  width: var(--seg-w, 5rem);
  transform: translateX(var(--seg-x, 0px));
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: transform 0.32s cubic-bezier(.2, .85, .25, 1), width 0.32s cubic-bezier(.2, .85, .25, 1);
}
.segmented-option {
  position: relative;
  z-index: 1;
  border: none;
  background: none;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.84rem;
  color: var(--ink-muted);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.25s ease, background 0.2s ease;
}
.segmented-option:hover:not(.is-active) {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
.segmented-option.is-active { color: var(--ink); }

/* ---------- Markets-Einträge ---------- */

.post { max-width: 44rem; }
.post-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.post-head h2 { margin-bottom: 0.4rem; }
.post-date { flex: none; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
/* Zeilenumbrüche aus dem Eintrag erhalten (Textarea-Inhalt). */
.post-content { margin: 0; white-space: pre-wrap; }

/* ---------- Sub Tracker ---------- */

.add-sub-trigger { margin: 0.5rem 0 1.4rem; }

/* Popup zentriert im Fenster. position/inset/margin zentrieren auch den
   No-JS-Fall (open-Attribut ohne showModal); mit showModal kommt der
   Backdrop dazu. */
dialog.dialog-card {
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 3rem);
  overflow: auto;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem 1.6rem;
  box-shadow: var(--shadow);
  z-index: 60;
}
dialog.dialog-card::backdrop {
  background: rgba(6, 12, 14, 0.5);
  backdrop-filter: blur(2px);
}

.sub-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1.2rem;
}
.sub-form-wide { grid-column: 1 / -1; }
.sub-form-actions { margin-top: 1.1rem; }

/* Dashboard: Diagramm | zentrale Zusammenfassung | Chronologie */
.subdash {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 1.1rem;
  margin-bottom: 1.6rem;
}
.subdash .card { margin-bottom: 0; }

.subdash-total { display: grid; place-items: center; }
.stat-hero { text-align: center; padding: 0.5rem 0; }
.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.4rem;
}
.stat-value {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 3.4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.stat-sub { margin-top: 0.45rem; font-size: 0.85rem; color: var(--ink-muted); }

/* Kuchendiagramm (Donut) + Legende. Identität hängt nie an der Farbe allein:
   die Legende trägt Label + Betrag, die Segmente sind durch Lücken getrennt. */
.donut-wrap { display: flex; align-items: center; gap: 1rem; }
.donut { width: 7rem; height: 7rem; flex: none; }
.donut-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.84rem;
}
.donut-legend li { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.legend-dot { width: 0.65rem; height: 0.65rem; border-radius: 999px; flex: none; }
/* Labels dürfen umbrechen - abgeschnittene Kategorienamen helfen niemandem. */
.legend-label { flex: 1; min-width: 0; overflow-wrap: break-word; }
.legend-value {
  color: var(--ink-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Chronologie der nächsten Abbuchungen */
.upcoming-list { list-style: none; margin: 0; padding: 0; }
.upcoming-item {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}
.upcoming-item:last-child { border-bottom: none; }
.upcoming-date { color: var(--ink-muted); font-variant-numeric: tabular-nums; flex: none; }
.upcoming-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.upcoming-days { color: var(--ink-muted); font-size: 0.78rem; white-space: nowrap; }
.upcoming-cost { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Abo-Liste: Zeile aufklappen zeigt Kategorie/Notizen/Löschen */
.sub-list-heading { margin-top: 0.4rem; }
.sub-list { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1.5rem; }
.sub-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.sub-item:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.sub-item > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
}
.sub-item > summary::-webkit-details-marker { display: none; }
.sub-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.95rem;
}
.sub-cost {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  color: var(--ink-muted);
  white-space: nowrap;
}
.sub-caret {
  width: 0.85rem;
  height: 0.85rem;
  flex: none;
  color: var(--ink-muted);
  transition: transform 0.25s ease;
}
.sub-item[open] .sub-caret { transform: rotate(180deg); }
.sub-item[open] > summary { border-bottom: 1px solid var(--line); }
.sub-details { padding: 0.7rem 1.1rem 1rem; }
.sub-meta { margin: 0 0 0.2rem; font-size: 0.85rem; }
.sub-meta strong { font-weight: 600; color: var(--ink); }
.sub-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

@media (max-width: 56rem) {
  .subdash { grid-template-columns: 1fr; }
  /* Die zentrale Zusammenfassung zuerst, wenn nichts mehr "zentral" sein kann. */
  .subdash-total { order: -1; }
}

/* ---------- Responsiv ---------- */

@media (max-width: 34rem) {
  .user-item { flex-wrap: wrap; }
  .user-right { width: 100%; justify-content: flex-start; padding-left: 3.4rem; }
  .sub-form { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
