/* ==========================================================================
   TrackRefs Design System — "Warm Precision"
   Pures CSS, keine Toolchain. Tokens als Custom Properties, Dark Mode via
   [data-theme="dark"]. Tenant-Branding überschreibt ausschließlich --brand-*.
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  /* Neutrale, warme Grauskala */
  --n-0: #ffffff;
  --n-25: #fcfbfa;
  --n-50: #f7f5f2;
  --n-100: #efece7;
  --n-200: #e2ddd5;
  --n-300: #cbc4b8;
  --n-400: #a89f91;
  --n-500: #857c6e;
  --n-600: #635b4f;
  --n-700: #453f37;
  --n-800: #2d2822;
  --n-900: #1c1815;

  /* System-Akzent (Backend). Tenant-Branding setzt --brand-* im Portal um. */
  --brand-500: #e8613c;
  --brand-600: #d14e2a;
  --brand-700: #b03f20;
  --brand-50: #fdf0eb;
  --brand-100: #fbdfd4;
  --brand-contrast: #ffffff;

  --ok-500: #3d9970;
  --ok-50: #e9f6f0;
  --warn-500: #d99a26;
  --warn-50: #fbf3e2;
  --danger-500: #cc4747;
  --danger-50: #fbecec;
  --info-500: #4776cc;
  --info-50: #ecf1fb;

  --bg: var(--n-50);
  --bg-elevated: var(--n-0);
  --bg-sunken: var(--n-100);
  --text: var(--n-800);
  --text-muted: var(--n-500);
  --text-faint: var(--n-400);
  --border: var(--n-200);
  --border-strong: var(--n-300);

  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  --shadow-sm: 0 1px 2px rgb(28 24 21 / 0.05);
  --shadow: 0 1px 3px rgb(28 24 21 / 0.06), 0 4px 12px rgb(28 24 21 / 0.05);
  --shadow-lg: 0 4px 8px rgb(28 24 21 / 0.06), 0 12px 32px rgb(28 24 21 / 0.12);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;
  --topbar-h: 61px;   /* haelt .topbar und den sticky-Offset von .subnav synchron */

  --transition: 150ms cubic-bezier(0.3, 0, 0.2, 1);
  color-scheme: light;
}

[data-theme="dark"] {
  --n-0: #211d19;
  --n-25: #262220;
  --n-50: #1c1815;
  --n-100: #2d2822;
  --n-200: #3a342c;
  --n-300: #4c453b;
  --n-400: #6e6557;
  --n-500: #948a7a;
  --n-600: #b3aa9b;
  --n-700: #d4cdc2;
  --n-800: #ece8e1;
  --n-900: #f7f5f2;

  --bg: #171412;
  --bg-elevated: #211d19;
  --bg-sunken: #12100e;
  --border: #322d26;
  --border-strong: #453f37;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow: 0 1px 3px rgb(0 0 0 / 0.35), 0 4px 12px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 4px 8px rgb(0 0 0 / 0.4), 0 12px 32px rgb(0 0 0 / 0.5);

  --brand-50: #3a231b;
  --brand-100: #4d2b1f;
  --ok-50: #1d3329;
  --warn-50: #3b3019;
  --danger-50: #3d2020;
  --info-50: #1f2a40;
  color-scheme: dark;
}

/* ---------- Reset & Basis ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link, var(--brand-600)); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
small, .text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
strong { font-weight: 600; }
::selection { background: var(--brand-100); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent;
  font-weight: 560; font-size: 14px; line-height: 1.2; cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap; user-select: none; text-decoration: none !important;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--btn-bg, var(--brand-600)); color: var(--btn-fg, var(--brand-contrast)); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--btn-bg-hover, var(--brand-700)); }
.btn-secondary { background: var(--bg-elevated); border-color: var(--border-strong); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { border-color: var(--n-400); background: var(--n-25); }
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-sunken); color: var(--text); }
.btn-danger { background: var(--danger-500); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: var(--radius-xs); }
.btn-lg { padding: 12px 22px; font-size: 15px; border-radius: var(--radius); }
.btn .spinner { width: 14px; height: 14px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg, var(--bg-elevated));
  color: var(--card-fg, inherit);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--space-6); }
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.card-header h2, .card-header h3 { margin: 0; }
/* Gedaempfte Texte und Trennlinien folgen einer eigenen Kartenfarbe mit. */
.card .muted, .card .hint { color: var(--card-muted, var(--text-muted)); }
.card .label { color: var(--card-fg, var(--text)); }
.card-header, .card-footer { border-color: var(--card-border, var(--border)); }
.card-body { padding: var(--space-6); }
.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--n-25);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  display: flex; justify-content: flex-end; gap: var(--space-3);
}

/* ---------- Einrichtungs-Box (Sidebar, ueber dem Dashboard-Link) ----------
   Bewusst kein .nav-link: die Einrichtung ist eine Aufgabe, kein Menuepunkt. */
.setup-nav {
  display: block; margin-bottom: var(--space-3);
  padding: 11px 12px 10px;
  border-radius: var(--radius);
  background: var(--brand-600);
  color: var(--brand-contrast);
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), transform var(--transition);
}
.setup-nav:hover { background: var(--brand-700); text-decoration: none; }
.setup-nav:active { transform: translateY(1px); }
.setup-nav.is-active { background: var(--brand-700); box-shadow: inset 0 0 0 1.5px rgb(255 255 255 / 0.45); }
.setup-nav:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.setup-nav-top { display: flex; align-items: center; gap: var(--space-2); font-size: 13.5px; }
.setup-nav-title { font-weight: 600; }
.setup-nav-percent { margin-left: auto; font-weight: 680; font-variant-numeric: tabular-nums; }
.setup-nav-bar {
  display: block; height: 4px; margin: 8px 0 6px;
  border-radius: 999px; background: rgb(255 255 255 / 0.28); overflow: hidden;
}
.setup-nav-bar > span { display: block; height: 100%; border-radius: 999px; background: #fff; }
.setup-nav-hint { display: block; font-size: 12px; opacity: 0.85; }

/* ---------- Einrichtungs-Box (Dashboard) ---------- */
/* Statischer Schein - bewusst ohne Animation. */
.setup-card {
  border-color: color-mix(in srgb, var(--brand-500) 55%, var(--border));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand-500) 22%, transparent),
              0 0 32px -6px color-mix(in srgb, var(--brand-500) 75%, transparent);
}
.setup-head { display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap; }
.setup-title { margin: 0; font-size: 17px; }
/* Fortschrittsring: conic-gradient statt SVG, --p ist der Prozentwert */
.setup-ring {
  flex: none; width: 62px; height: 62px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--brand-600) calc(var(--p) * 1%), var(--bg-sunken) 0);
}
.setup-ring span {
  width: 48px; height: 48px; border-radius: 50%; background: var(--bg-elevated);
  /* flex statt grid: sonst landet das %-Zeichen als eigenes Item unter der Zahl */
  display: flex; align-items: baseline; justify-content: center; gap: 1px;
  font-size: 15px; font-weight: 680; font-variant-numeric: tabular-nums;
}
.setup-ring small { font-size: 10px; font-weight: 560; color: var(--text-muted); }
.setup-steps {
  display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4);
  margin-top: var(--space-5); padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  font-size: 13.5px;
}
.setup-step { display: flex; align-items: center; gap: 7px; }
.setup-step.is-done { color: var(--text-muted); text-decoration: line-through; }
.setup-step.is-done svg { color: var(--ok-500); }
.setup-dot { color: var(--text-faint); }

/* ---------- Stat-Karten ---------- */
.stat {
  display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-5) var(--space-6);
}
.stat-label { font-size: 12.5px; font-weight: 560; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.stat-value { font-size: 26px; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-delta { font-size: 12.5px; font-weight: 560; }
.stat-delta.up { color: var(--ok-500); }
.stat-delta.down { color: var(--danger-500); }

/* ---------- Formulare ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: var(--space-4); }
/* Nebeneinander im Grid: kein Stapel-Abstand, sonst verschobene Höhen */
.grid > .field { margin-top: 0; }
.label { font-size: 13px; font-weight: 580; color: var(--text); }
.hint { font-size: 12.5px; color: var(--text-muted); }
.error { font-size: 12.5px; color: var(--danger-500); }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px;
  background: var(--field-bg, var(--bg-elevated));
  color: var(--field-fg, inherit);
  border: 1px solid var(--field-border, var(--border-strong));
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 18%, transparent);
}
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger-500); }
.input::placeholder, .textarea::placeholder { color: var(--field-placeholder, var(--text-faint)); }
.textarea { min-height: 110px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23857c6e' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.checkbox { display: inline-flex; gap: var(--space-3); align-items: flex-start; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--brand-600); }

/* Switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--n-300); transition: background var(--transition); cursor: pointer;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}
.switch input:checked + .track { background: var(--brand-600); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brand-500); outline-offset: 2px; }

/* ---------- Auszahlungs-Detaildialog ---------- */
.payout-detail { display: grid; grid-template-columns: 1fr auto; gap: var(--space-6); align-items: start; }
.detail-label {
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint); margin-bottom: var(--space-2);
}
.detail-amount { font-size: 22px; font-weight: 680; font-variant-numeric: tabular-nums; margin-top: var(--space-3); }
@media (max-width: 620px) {
  .payout-detail { grid-template-columns: 1fr; }
}

/* ---------- Dropzone (Datei-Upload) ---------- */
.dropzone {
  position: relative;
  border: 2px dashed var(--border-strong); border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  padding: var(--space-8) var(--space-6);
  transition: border-color var(--transition), background var(--transition);
}
.dropzone.is-over { border-color: var(--brand-500); background: var(--brand-50); }
.dropzone:focus-within { outline: 2px solid var(--brand-500); outline-offset: 2px; }
/* Liegt unsichtbar ueber der Flaeche: Klick ueberall oeffnet den Dateidialog. */
.dropzone-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}
.dropzone-body { display: flex; align-items: center; justify-content: center; gap: var(--space-4); text-align: left; }
.dropzone-body svg { width: 26px; height: 26px; color: var(--text-faint); flex-shrink: 0; }

/* Name in der Werbemittel-Liste: klicken zum Umbenennen */
.name-edit {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: none; border: none; padding: 2px 6px; margin-left: -6px;
  border-radius: var(--radius-xs); cursor: pointer; color: inherit; text-align: left;
}
.name-edit svg { width: 14px; height: 14px; color: var(--text-faint); opacity: 0; transition: opacity var(--transition); }
.name-edit:hover { background: var(--bg-sunken); }
.name-edit:hover svg, .name-edit:focus-visible svg { opacity: 1; }
.name-edit:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 1px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 580; line-height: 1.5;
  background: var(--bg-sunken); color: var(--text-muted);
}
.badge-ok { background: var(--ok-50); color: var(--ok-500); }
.badge-warn { background: var(--warn-50); color: var(--warn-500); }
.badge-danger { background: var(--danger-50); color: var(--danger-500); }
.badge-info { background: var(--info-50); color: var(--info-500); }
.badge-brand { background: var(--brand-50); color: var(--brand-600); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; padding: 11px var(--space-4);
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
  white-space: nowrap; background: var(--n-25);
}
.table td { padding: 13px var(--space-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--transition); }
.table-hover tbody tr:hover { background: var(--n-25); cursor: pointer; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Navigation / App-Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: var(--space-5) var(--space-3);
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 0 var(--space-3) var(--space-5); }
.sidebar-logo img { height: 26px; }
.sidebar-logo .name { font-weight: 700; font-size: 15.5px; letter-spacing: -0.01em; }
/* Payoutly-Wortmarke: dunkle Schrift im hellen Theme, helle im dunklen */
.payoutly-logo { display: inline-flex; align-items: center; }
.payoutly-logo img { height: var(--logo-h, 30px); width: auto; display: block; }
.payoutly-logo .logo-dark { display: none; }
[data-theme="dark"] .payoutly-logo .logo-light { display: none; }
[data-theme="dark"] .payoutly-logo .logo-dark { display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section { margin-top: var(--space-5); padding: 0 var(--space-3); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px var(--space-3); border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 530; font-size: 14px;
  transition: background var(--transition), color var(--transition);
  text-decoration: none !important;
}
/* Als <button> (Nutzer-Menü, Template-Liste): Browser-Rahmen und -Hintergrund weg */
button.nav-link { border: 0; background: none; cursor: pointer; text-align: left; width: 100%; }
.nav-link:hover { background: var(--bg-sunken); color: var(--text); }
.nav-link.active { background: var(--brand-50); color: var(--brand-600); font-weight: 600; }
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-link .nav-badge { margin-left: auto; background: var(--brand-50); color: var(--brand-600); }
.sidebar-footer { margin-top: auto; padding: var(--space-3); border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-4) var(--space-8);
  min-height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}

/* Zweite Menue-Spalte (Setup / Einstellungen) */
.content { flex: 1; display: flex; min-width: 0; }
.content > .page { flex: 1; min-width: 0; }
.subnav {
  width: 210px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-6) var(--space-3);
  border-right: 1px solid var(--border);
  position: sticky; top: var(--topbar-h); align-self: flex-start;
  max-height: calc(100vh - var(--topbar-h)); overflow-y: auto;
}
.subnav .nav-section { margin-top: 0; margin-bottom: var(--space-2); }

.page { padding: var(--space-8); max-width: 1200px; width: 100%; margin: 0 auto; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }
.page-header .sub { color: var(--text-muted); margin-top: 4px; }

/* ---------- Auth-Layout ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: var(--space-6);
  background: var(--page-bg,
    radial-gradient(1200px 500px at 20% -10%, var(--brand-50), transparent 60%) var(--bg));
}
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { display: flex; justify-content: center; margin-bottom: var(--space-6); }
.auth-wordmark { font-size: 22px; font-weight: 700; }

/* ---------- Vorlagen-Auswahl + Vorschau (Backend → Branding) ---------- */
.tpl-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.tpl-option {
  padding: 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-elevated); cursor: pointer; text-align: center;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.tpl-option:hover { border-color: var(--brand-500); }
.tpl-option.is-active { border-color: var(--brand-600); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand-500) 25%, transparent); }
.tpl-option:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.tpl-label { display: block; font-size: 11.5px; font-weight: 560; margin-top: 6px; color: var(--text-muted); }
.tpl-option.is-active .tpl-label { color: var(--brand-600); }
/* Schemaskizze: farbige Flaeche = Marke, helle Flaeche = Formular */
.tpl-sketch { display: block; height: 42px; border-radius: var(--radius-xs); overflow: hidden; background: var(--bg-sunken); }
.tpl-sketch .tpl-brand { display: block; background: var(--brand-500); }
.tpl-sketch .tpl-form { display: block; background: var(--n-300); border-radius: 2px; }
.tpl-centered { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.tpl-centered .tpl-brand { width: 16px; height: 4px; border-radius: 2px; }
.tpl-centered .tpl-form { width: 26px; height: 20px; }
.tpl-split { display: grid; grid-template-columns: 1fr 1fr; }
.tpl-split .tpl-brand { height: 100%; }
.tpl-split .tpl-form { width: 22px; height: 22px; margin: 10px auto; }
.tpl-hero { display: flex; flex-direction: column; }
.tpl-hero .tpl-brand { height: 16px; }
.tpl-hero .tpl-form { width: 26px; height: 18px; margin: -4px auto 0; }

/* Fuer Screenreader sichtbar, visuell versteckt (versteckte Datei-Inputs). */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.color-swatch {
  width: 42px; height: 34px; flex: none; padding: 2px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-elevated);
}

/* Bild-Upload: Vorschau auf gedaempftem Grund, damit auch weisse Logos
   sichtbar sind, und mit voller Hoehe statt gequetscht. */
.upload-preview { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.upload-thumb {
  display: flex; align-items: center; justify-content: center;
  min-width: 108px; height: calc(var(--thumb-h, 56px) + 16px);
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--bg-sunken); border: 1px solid var(--border);
}
.upload-thumb img { max-height: var(--thumb-h, 56px); max-width: 200px; width: auto; object-fit: contain; }
.upload-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
/* Label als Button: das Dateifeld darin ist per .sr-only versteckt. */
.upload-actions label.btn { cursor: pointer; }

/* Vorschau-Frame: rendert die Seite in Desktop-Breite und skaliert sie herunter,
   sonst greift im schmalen Frame der Mobile-Breakpoint und die Vorschau zeigt
   ein anderes Layout als die Live-Seite. */
/* Bleibt beim Scrollen der langen Einstellungsliste stehen. */
.preview-sticky { position: sticky; top: calc(var(--topbar-h) + var(--space-4)); }
.preview-frame {
  --preview-w: 1280px;
  --preview-h: 880px;
  --preview-scale: 0.56;
  width: 100%;
  height: calc(var(--preview-h) * var(--preview-scale));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-sunken);
}
.preview-frame iframe {
  width: var(--preview-w);
  height: var(--preview-h);
  border: 0;
  transform: scale(var(--preview-scale));
  transform-origin: top left;
}
@media (max-width: 1500px) { .preview-frame { --preview-scale: 0.44; } }

/* ---------- Portal-Vorlagen: split & hero ----------
   Auswahl unter Einstellungen → Branding, siehe App\Domain\Branding\PortalTheme. */
.auth-split { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-panel {
  display: flex; align-items: center; justify-content: flex-end;
  padding: var(--space-12) var(--space-8);
  background: var(--panel-bg, linear-gradient(160deg, var(--brand-600), var(--brand-700)));
  color: var(--panel-fg, var(--brand-contrast));
}
.auth-panel-inner { width: 100%; max-width: 420px; }
.auth-panel-logo { margin-bottom: var(--space-8); }
/* Namenszug auf farbigem Grund erbt die Kontrastfarbe des Panels */
.auth-panel .auth-wordmark, .auth-hero .auth-wordmark { color: inherit; }
.auth-panel-headline { font-size: 30px; line-height: 1.2; margin-bottom: var(--space-4); }
.auth-panel-intro { font-size: 15.5px; opacity: 0.9; }
.auth-form-col {
  display: flex; align-items: center; justify-content: flex-start;
  padding: var(--space-10) var(--space-8); background: var(--page-bg, var(--bg));
}
.auth-form-inner { width: 100%; max-width: 440px; }

.auth-hero-wrap { min-height: 100vh; background: var(--page-bg, var(--bg)); }
.auth-hero {
  padding: var(--space-12) var(--space-6) calc(var(--space-12) + 40px);
  text-align: center;
  background: var(--panel-bg, linear-gradient(160deg, var(--brand-600), var(--brand-700)));
  color: var(--panel-fg, var(--brand-contrast));
}
.auth-hero-logo { display: flex; justify-content: center; margin-bottom: var(--space-5); }
.auth-hero-headline { font-size: 30px; line-height: 1.2; max-width: 640px; margin: 0 auto var(--space-3); }
.auth-hero-intro { font-size: 15.5px; opacity: 0.9; max-width: 560px; margin: 0 auto; }
/* zieht die Karte in das Farbband hinein */
.auth-hero-body {
  width: 100%; max-width: 460px;
  margin: -40px auto 0; padding: 0 var(--space-6) var(--space-10);
}

@media (max-width: 860px) {
  .auth-split { grid-template-columns: 1fr; min-height: 0; }
  .auth-panel { justify-content: center; padding: var(--space-10) var(--space-6); }
  .auth-panel-inner { max-width: 460px; text-align: center; }
  .auth-panel-logo { display: flex; justify-content: center; }
  .auth-panel-headline, .auth-hero-headline { font-size: 24px; }
  .auth-form-col { justify-content: center; padding: var(--space-8) var(--space-6); }
}

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; z-index: 50;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 6px; display: flex; flex-direction: column;
}
.dropdown-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border: 0; background: none; text-align: left;
  border-radius: var(--radius-xs); font-size: 13.5px; color: var(--text);
  cursor: pointer; text-decoration: none !important;
}
.dropdown-item:hover { background: var(--bg-sunken); }
.dropdown-sep { height: 1px; background: var(--border); margin: 5px 4px; }

/* ---------- Benachrichtigungen (Glocke in der Topbar) ---------- */
.bell { position: relative; }
.bell-dot {
  position: absolute; top: -2px; right: -2px; min-width: 16px; height: 16px;
  padding: 0 4px; border-radius: 999px;
  background: var(--danger-500); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.notif-menu { width: min(360px, calc(100vw - 32px)); max-height: 70vh; overflow-y: auto; padding: 0; }
.notif-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: 10px 8px 10px 12px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-elevated); z-index: 1;
}
.notif-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left;
  padding: 10px 12px; border: 0; border-bottom: 1px solid var(--border);
  background: none; color: var(--text); cursor: pointer;
}
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--bg-sunken); }
.notif-item:focus-visible { outline: 2px solid var(--brand-500); outline-offset: -2px; }
/* Ungelesenes traegt einen Balken - Farbe allein waere kein Unterscheidungsmerkmal. */
.notif-item.is-open { box-shadow: inset 3px 0 0 var(--brand-600); background: var(--brand-50); }
.notif-item { text-decoration: none !important; }
.notif-title { font-weight: 600; font-size: 13.5px; }
.notif-body { font-size: 12.5px; color: var(--text-muted); }
.notif-time { font-size: 11px; color: var(--text-faint); }
.notif-empty { padding: var(--space-6); text-align: center; font-size: 13.5px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgb(28 24 21 / 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh var(--space-4) var(--space-4);
  animation: fade-in 140ms ease;
}
.modal {
  width: 100%; max-width: 520px;
  background: var(--bg-elevated); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  animation: pop-in 160ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
  max-height: 84vh; display: flex; flex-direction: column;
}
.modal .card-body { overflow-y: auto; }
.modal-backdrop[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

/* ---------- Toasts ---------- */
.toast-host { position: fixed; bottom: var(--space-6); right: var(--space-6); z-index: 100; display: flex; flex-direction: column; gap: var(--space-2); }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--n-800); color: var(--n-50);
  padding: 11px 16px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 530;
  animation: toast-in 220ms cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
[data-theme="dark"] .toast { background: var(--n-100); color: var(--n-800); }
.toast.ok::before, .toast.error::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.toast.ok::before { background: var(--ok-500); }
.toast.error::before { background: var(--danger-500); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* ---------- Empty State ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--space-2); padding: var(--space-12) var(--space-6); color: var(--text-muted);
}
.empty .icon { font-size: 30px; margin-bottom: var(--space-2); }
.empty h3 { color: var(--text); }
.empty p { max-width: 380px; }
.empty .btn { margin-top: var(--space-3); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: var(--space-6); }
.tab {
  padding: 9px 14px; margin-bottom: -1px;
  font-weight: 550; font-size: 14px; color: var(--text-muted);
  border: 0; background: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  text-decoration: none !important;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand-600); border-bottom-color: var(--brand-600); }

/* ---------- Progress / Level ---------- */
.progress { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.progress > div { height: 100%; border-radius: 999px; background: var(--brand-600); transition: width 600ms cubic-bezier(0.3, 0, 0.2, 1); }

/* ---------- Skeleton ---------- */
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--n-200) 50%, var(--bg-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Copy-Feld ---------- */
.copy-field {
  display: flex; align-items: stretch;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--bg-elevated);
}
.copy-field input { flex: 1; border: 0; padding: 9px 12px; background: transparent; font-family: var(--font-mono); font-size: 13px; min-width: 0; }
.copy-field input:focus { outline: none; }
.copy-field button {
  border: 0; border-left: 1px solid var(--border);
  padding: 0 14px; background: var(--n-25); cursor: pointer;
  font-weight: 570; font-size: 13px; color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.copy-field button:hover { background: var(--bg-sunken); color: var(--text); }
.copy-field button.copied { color: var(--ok-500); }

/* ---------- Utilities (bewusst klein gehalten) ---------- */
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); } .gap-4 { gap: var(--space-4); } .gap-6 { gap: var(--space-6); }
.grid { display: grid; gap: var(--space-5); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.mt-2 { margin-top: var(--space-2); } .mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); } .mt-8 { margin-top: var(--space-8); }
.mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); }
.w-full { width: 100%; }
.text-right { text-align: right; }
.hidden { display: none; }

.mobile-only { display: none; }
[x-cloak] { display: none !important; }

@media (max-width: 900px) {
  .mobile-only { display: inline-flex; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .sidebar { position: fixed; z-index: 60; transform: translateX(-100%); transition: transform 200ms ease; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .page { padding: var(--space-5); }
  .topbar { padding: var(--space-3) var(--space-5); }
  /* Untermenue wird zur horizontalen Leiste ueber dem Inhalt */
  .content { flex-direction: column; }
  .subnav {
    width: auto; flex-direction: row; overflow-x: auto; max-height: none;
    padding: var(--space-3) var(--space-5);
    border-right: none; border-bottom: 1px solid var(--border);
    position: static;
  }
  .subnav .nav-link { white-space: nowrap; }
  .subnav .nav-section { display: none; }
}
@media (max-width: 620px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- Spinner ---------- */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Reduzierte Bewegung respektieren */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
