/* ---------------------------------------------------------------------------
   Vertriebs-Cockpit - Gestaltung nach der Corporate Identity von medinorum.de

   Farben, Schrift und Formensprache sind der Website entnommen:
     Grün      #33c780 / #1fa968 / #2bae6f
     Mint      #e8f7ef
     Ink       #1a1f2e
     Flächen   #fafdf9 / #f4faf6 / #ffffff
     Schrift   Plus Jakarta Sans
     Radien    10 / 14 / 16 px, Pillen 999px

   Die Schrift liegt lokal unter /fonts. Sie wird bewusst NICHT von Google
   geladen: das wäre eine Datenübertragung an Dritte bei jedem Seitenaufruf.
--------------------------------------------------------------------------- */

@font-face {
  font-family: 'Plus Jakarta Sans';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('/fonts/PlusJakartaSans-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Plus Jakarta Sans';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('/fonts/PlusJakartaSans-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light;

  --green: #33c780;
  --green-deep: #1fa968;
  --green-mid: #2bae6f;
  --mint: #e8f7ef;
  --mint-deep: #d8ecdf;

  --ink: #1a1f2e;
  --ink-soft: rgba(26, 31, 46, 0.72);
  --ink-mute: rgba(26, 31, 46, 0.52);

  --bg: #fafdf9;
  --bg-alt: #f4faf6;
  --surface: #ffffff;
  --border: rgba(26, 31, 46, 0.10);
  --border-soft: rgba(26, 31, 46, 0.06);

  --clay: #c26a5e;
  --clay-soft: #fbeeeb;
  --clay-line: #f0d5cf;
  --clay-bg: #fdf6f4;
  --warn: #b07b3a;
  --warn-bg: #fdf6ec;
  --warn-line: #f0dfc4;

  /* Milchglas-Flaechen (Anmeldekarte, Kopfleiste) und der dunkle
     Meldungsstreifen. Eigene Variablen, weil sie sich im dunklen Schema
     NICHT einfach umkehren lassen. */
  --glass: rgba(255, 255, 255, 0.86);
  --glass-line: rgba(255, 255, 255, 0.9);
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --toast-bg: #1a1f2e;
  --toast-ink: #ffffff;
  --backdrop: rgba(26, 31, 46, 0.42);

  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 16px;

  --shadow-sm: 0 1px 2px rgba(26, 31, 46, 0.04), 0 1px 3px rgba(26, 31, 46, 0.05);
  --shadow-md: 0 4px 16px rgba(26, 31, 46, 0.07);
  --shadow-green: 0 4px 14px rgba(51, 199, 128, 0.30);

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --topbar-h: 60px;
}

/* ---------------------------------------------------------------------------
   Dunkles Schema
Gesetzt wird das Attribut von /theme.js, noch bevor gezeichnet wird.
   Hier stehen NUR Farben - Abstaende, Radien und Schatten-Geometrie bleiben
   gleich. Wer eine neue Farbe braucht, legt sie oben als Variable an und
   ueberschreibt sie hier; feste Farbwerte in Regeln unten sind der Grund,
   warum Dinge im Dunkeln unlesbar werden.

   Das Gruen wird leicht aufgehellt: #33c780 auf dunklem Grund wirkt matt und
   reisst den Kontrast zur Schrift nicht mehr. Weisse Schrift auf Gruen bleibt
   in beiden Schemata weiss - dort aendert sich nichts.
--------------------------------------------------------------------------- */
:root[data-theme='dark'] {
  color-scheme: dark;

  --green: #3ad78d;
  --green-deep: #45e09a;
  --green-mid: #3fda93;
  --mint: #16332a;
  --mint-deep: #1e4636;

  --ink: #e9eef4;
  --ink-soft: rgba(233, 238, 244, 0.74);
  --ink-mute: rgba(233, 238, 244, 0.56);

  --bg: #10151c;
  --bg-alt: #161d26;
  --surface: #1a222c;
  --border: rgba(233, 238, 244, 0.15);
  --border-soft: rgba(233, 238, 244, 0.08);

  --clay: #e59485;
  --clay-soft: #33211e;
  --clay-line: #4d332d;
  --clay-bg: #2a1c1a;
  --warn: #d9ad6b;
  --warn-bg: #2a2218;
  --warn-line: #4a3b24;

  --glass: rgba(26, 34, 44, 0.86);
  --glass-line: rgba(233, 238, 244, 0.10);
  --topbar-bg: rgba(16, 21, 28, 0.92);
  /* Der Meldungsstreifen bleibt dunkel, nur etwas heller als die Seite -
     sonst muesste auch seine weisse Schrift umgedreht werden. */
  --toast-bg: #2b3644;
  --toast-ink: #ffffff;
  --backdrop: rgba(0, 0, 0, 0.6);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-green: 0 4px 14px rgba(58, 215, 141, 0.22);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--green-deep);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================== Anmeldung */

/* Das Logo ist eine einfarbige Form. Als CSS-Maske laesst es sich in jeder
   CI-Farbe darstellen - weiss auf gruen in der Marke, gruen als Wasserzeichen. */
.logo-mask {
  -webkit-mask: url('/assets/medinorum-logo.png') center / contain no-repeat;
  mask: url('/assets/medinorum-logo.png') center / contain no-repeat;
  background-color: currentColor;
}

.login-wrap {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 20px;
  overflow: hidden;
  background:
    radial-gradient(900px 600px at 82% 8%, rgba(51, 199, 128, 0.13) 0%, transparent 58%),
    radial-gradient(760px 520px at 12% 92%, rgba(51, 199, 128, 0.10) 0%, transparent 60%),
    linear-gradient(168deg, var(--surface) 0%, var(--bg) 45%, var(--bg-alt) 100%);
}

/* Grosses, sehr blasses Logo im Hintergrund */
.login-watermark {
  position: absolute;
  right: -8vw;
  bottom: -12vh;
  width: min(640px, 68vw);
  aspect-ratio: 241 / 256;
  color: var(--green);
  opacity: 0.055;
  pointer-events: none;
  -webkit-mask: url('/assets/medinorum-logo.png') center / contain no-repeat;
  mask: url('/assets/medinorum-logo.png') center / contain no-repeat;
  background-color: currentColor;
}

.login-card {
  position: relative;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-line);
  box-shadow:
    0 1px 2px rgba(26, 31, 46, 0.04),
    0 12px 34px rgba(26, 31, 46, 0.09),
    0 0 0 1px var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  width: min(420px, 100%);
}

.login-mark {
  width: 52px; height: 52px;
  border-radius: 15px;
  background: linear-gradient(145deg, var(--green) 0%, var(--green-deep) 100%);
  margin-bottom: 20px;
  box-shadow: var(--shadow-green);
  position: relative;
}
/* Das Logo weiss in die gruene Kachel */
.login-mark::after {
  content: '';
  position: absolute;
  inset: 11px;
  color: #fff;
  -webkit-mask: url('/assets/medinorum-logo.png') center / contain no-repeat;
  mask: url('/assets/medinorum-logo.png') center / contain no-repeat;
  background-color: currentColor;
}

.login-foot {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  font-size: 12.5px;
  color: var(--ink-mute);
  line-height: 1.45;
}

.login-card h1 { margin: 0 0 2px; font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.login-card p.sub { margin: 0 0 26px; color: var(--ink-mute); font-size: 14px; font-weight: 500; }

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 600; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.field input:focus {
  outline: none;
  border-color: var(--green);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(51, 199, 128, 0.14);
}

/* ================================================================= Knöpfe */

.btn {
  background: linear-gradient(145deg, var(--green) 0%, var(--green-deep) 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 11px 18px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  min-height: 42px;
  transition: transform 0.12s var(--ease), box-shadow 0.15s var(--ease), filter 0.15s var(--ease);
}
.btn:hover { filter: brightness(1.05); box-shadow: var(--shadow-green); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; box-shadow: none; }

.btn.ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  font-weight: 600;
}
.btn.ghost:hover { background: var(--bg-alt); border-color: var(--green); box-shadow: none; filter: none; }

.btn.wide { width: 100%; }
.btn.small { padding: 7px 13px; font-size: 13px; min-height: 36px; }

.error-msg {
  color: var(--clay);
  font-size: 13px;
  margin-top: 14px;
  min-height: 19px;
  font-weight: 500;
}
/* Direkt unter dem Feld, zu dem sie gehoert - und ohne Platzhalterhoehe,
   damit das Formular nicht dauerhaft eine leere Zeile mitschleppt. */
.error-msg.unter-feld { margin-top: 7px; min-height: 0; }
.error-msg.unter-feld:empty { display: none; }

/* Feld, das die Anmeldung abgelehnt hat. */
.field input.ungueltig {
  border-color: var(--clay);
  background: var(--clay-bg);
}
.field input.ungueltig:focus {
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-soft);
}

/* ================================================================= Layout */

.app { display: none; }
.app.visible { display: block; }

header.topbar {
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--topbar-h);
}

.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 15px; white-space: nowrap;
  letter-spacing: -0.01em;
  background: none; border: none; padding: 0; cursor: pointer;
  color: inherit;
}
.brand:hover .brand-text { color: var(--green-deep); }
.brand-sub { color: var(--ink-mute); font-weight: 500; }
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--green) 0%, var(--green-deep) 100%);
  flex-shrink: 0;
  position: relative;
}
.brand-mark::after {
  content: '';
  position: absolute;
  inset: 6px;
  color: #fff;
  -webkit-mask: url('/assets/medinorum-logo.png') center / contain no-repeat;
  mask: url('/assets/medinorum-logo.png') center / contain no-repeat;
  background-color: currentColor;
}
.brand span { color: var(--ink-mute); font-weight: 500; }

nav.tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
nav.tabs::-webkit-scrollbar { display: none; }

nav.tabs button {
  background: none;
  border: none;
  padding: 8px 13px;
  cursor: pointer;
  color: var(--ink-mute);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  border-radius: 999px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
  min-height: 38px;
}
nav.tabs button:hover { color: var(--ink); background: var(--bg-alt); }
nav.tabs button.active { color: var(--green-deep); background: var(--mint); }

.topbar-right { display: flex; align-items: center; gap: 10px; font-size: 13px; }

/* Zahnrad für Konto und Passwort */
.icon-knopf {
  width: 36px; height: 36px; flex-shrink: 0;
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: pointer; color: var(--ink-soft);
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease), background 0.15s var(--ease);
}
.icon-knopf:hover { border-color: var(--green); color: var(--green-deep); background: var(--bg-alt); }
.icon-knopf svg { width: 19px; height: 19px; display: block; }

/* Prüfliste im Passwort-Dialog */
.pw-regeln {
  list-style: none; margin: -8px 0 16px; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.pw-regeln li {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-mute); font-weight: 500;
}
.pw-regeln li.ok { color: var(--green-deep); }
.pw-haken { width: 13px; display: inline-block; font-weight: 700; }
.field-hint.warnung { color: var(--clay); font-weight: 600; }
dialog input[type="password"] {
  width: 100%; padding: 11px 13px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-alt); font-weight: 500;
  font-size: 16px; /* verhindert das automatische Zoomen auf iOS */
}
dialog input[type="password"]:focus {
  outline: none; border-color: var(--green); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(51, 199, 128, 0.14);
}
.who { text-align: right; line-height: 1.25; }
.who strong { display: block; font-weight: 700; font-size: 13px; }
.who span { color: var(--ink-mute); font-size: 12px; font-weight: 500; }

.burger { display: none; }

main { padding: 22px 20px 60px; max-width: 1520px; margin: 0 auto; }

/* =============================================================== Werkzeug */

.toolbar {
  display: flex;
  gap: 9px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.toolbar select, .toolbar input[type="date"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600;
  font-size: 14px;
  min-height: 40px;
  cursor: pointer;
}
.toolbar select:focus, .toolbar input[type="date"]:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(51, 199, 128, 0.14);
}
.toolbar label { color: var(--ink-mute); font-size: 13px; font-weight: 600; }
.spacer { flex: 1; }

.stand {
  font-size: 12.5px;
  color: var(--ink-mute);
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.stand::before {
  content: '';
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(51, 199, 128, 0.18);
}

/* ================================================================= Karten */

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.kpi { position: relative; overflow: hidden; }
.kpi .label {
  color: var(--ink-mute); font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.kpi .value {
  font-size: 27px; font-weight: 800; margin-top: 7px;
  letter-spacing: -0.03em; line-height: 1.15;
}
.kpi .hint { color: var(--ink-mute); font-size: 12.5px; margin-top: 5px; font-weight: 500; }

/* Info-Punkt an der Kachel: „woher kommt diese Zahl?" */
.info-punkt {
  width: 16px; height: 16px; margin-left: 6px;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--ink-mute);
  font-size: 10px; font-weight: 800; line-height: 1;
  cursor: pointer; display: inline-grid; place-items: center;
  vertical-align: middle; position: relative;
  font-family: Georgia, 'Times New Roman', serif;
}
.info-punkt::before { content: ''; position: absolute; inset: -8px; }
.info-punkt:hover { border-color: var(--green); color: var(--green-deep); }

/* Herkunfts-Dialog */
.hk-liste { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.hk-zeile { display: flex; flex-direction: column; gap: 2px; }
.hk-titel {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-mute);
}
.chip.aus { cursor: default; background: var(--surface); color: var(--ink-mute); font-weight: 500; }
.chip.aus:hover { border-color: var(--border); }

.panel { margin-bottom: 20px; }
.panel h2 {
  font-size: 15.5px; font-weight: 700; margin: 0 0 15px;
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  letter-spacing: -0.01em;
}
.panel h2 .note { font-weight: 500; color: var(--ink-mute); font-size: 12.5px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* =============================================================== Tabellen */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 11px; text-align: right; border-bottom: 1px solid var(--border-soft); }
th:first-child, td:first-child { text-align: left; }
th {
  color: var(--ink-mute); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.045em;
  white-space: nowrap; cursor: pointer; user-select: none;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  border-bottom: 1px solid var(--border);
}
th:hover { color: var(--ink); }
th.sorted { color: var(--green-deep); }
tbody tr { transition: background 0.12s var(--ease); }
tbody tr:hover { background: var(--bg-alt); }
tbody tr.clickable { cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }

/* Namen nie umbrechen - sonst rutscht der Nachname auf dem Handy in eine
   zweite Zeile und die Tabelle wird unruhig. Lieber waagerecht scrollen. */
td.name {
  font-weight: 700;
  white-space: nowrap;
}
td.name > span { display: inline-flex; align-items: center; white-space: nowrap; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }

.rank {
  display: inline-grid; place-items: center;
  width: 23px; height: 23px; border-radius: 50%;
  background: var(--bg-alt); border: 1px solid var(--border);
  font-size: 11px; font-weight: 800; margin-right: 9px;
  flex-shrink: 0;
}
.rank.top1 { background: linear-gradient(145deg, var(--green), var(--green-deep)); color: #fff; border-color: transparent; }
.rank.top2 { background: var(--mint); color: var(--green-deep); border-color: var(--mint-deep); }
.rank.top3 { background: var(--mint); color: var(--green-mid); border-color: var(--mint-deep); }

/* Negativ-Ranking: Platz 1 ist hier der schlechteste. Dieselbe Formensprache
   wie oben, nur in Ton — damit sofort klar ist, dass die Richtung eine
   andere ist und man hier nach UNTEN will. */
.rank.flop1 { background: linear-gradient(145deg, #d4796b, var(--clay)); color: #fff; border-color: transparent; }
.rank.flop2 { background: var(--clay-soft); color: var(--clay); border-color: var(--clay-line); }
.rank.flop3 { background: var(--clay-soft); color: var(--clay); border-color: var(--clay-line); }
.rank.flop { background: var(--bg-alt); color: var(--ink-mute); }
.rank.leer { background: none; border-style: dashed; color: var(--ink-mute); font-weight: 500; }

/* inline-flex, NICHT flex: ein Block wuerde die Zelle voll ausfuellen und
   sich links festsetzen - das "text-align: right" der Tabelle wirkt nur auf
   Inline-Inhalte. Genau daran hing der Score frueher links neben seiner
   Spalte statt buendig unter der Ueberschrift. */
.score-cell {
  display: inline-flex; align-items: center; gap: 9px;
  vertical-align: middle;
}
.score-bar {
  width: 48px; height: 6px; border-radius: 3px;
  background: var(--border); overflow: hidden; flex-shrink: 0;
}
.score-bar i {
  display: block; height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--green), var(--green-deep));
}
.score-bar.rot { background: var(--clay-soft); }
.score-bar.rot i { background: linear-gradient(90deg, #d4796b, var(--clay)); }

.pos { color: var(--green-deep); }
.neg { color: var(--clay); }
.dim { color: var(--ink-mute); }

/* ================================================================= Funnel */

.funnel { display: flex; flex-direction: column; gap: 7px; }
.funnel-row {
  display: grid; grid-template-columns: minmax(150px, 230px) 1fr minmax(96px, auto);
  align-items: center; gap: 13px;
}
/* Statusnamen aus dem CRM sind teils lang ("02 ✅ Erstgespräch durchgeführt").
   Sie dürfen die Zeile nicht auf zwei Zeilen sprengen — sonst stehen die
   Balken versetzt und die Liste wirkt unruhig. Vollständig steht der Name
   im Tooltip. */
.funnel-row .fname {
  font-size: 13.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.funnel-bar {
  background: var(--bg-alt); border-radius: 7px; height: 28px;
  overflow: hidden; border: 1px solid var(--border-soft);
}
.funnel-bar i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--green-deep), var(--green));
  border-radius: 6px;
  transition: width 0.4s var(--ease);
}
.funnel-val { font-size: 13px; text-align: right; color: var(--ink-mute); font-weight: 500; }
.funnel-val b { color: var(--ink); font-weight: 700; }

/* =============================================================== Diagramm */

/* Der Rahmen kennt seine Breite; das SVG wird darin 1:1 in Bildschirmpunkten
   gezeichnet (siehe charts.js chartHost). Dadurch ist die Achsenschrift in
   jeder Kachelgröße gleich groß und gut lesbar. */
.chart-wrap { width: 100%; min-height: 120px; }
.chart-box { width: 100%; }
.chart { display: block; max-width: 100%; }
.chart .gridline { stroke: var(--border-soft); stroke-width: 1; }
.chart .gridline.null { stroke: var(--border); stroke-width: 1.4; }
.chart .lbl {
  fill: var(--ink-mute); font-size: 11px; font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.chart .achse-einheit { font-size: 10px; font-weight: 600; }
.chart .bar { fill: url(#barGradient); transition: opacity 0.12s var(--ease); }
.chart .bar:hover { opacity: 0.78; }
.chart .bar.peak { fill: var(--green-deep); }
.chart .bar.neg { fill: var(--clay); }

/* Werte an den Datenpunkten - damit die Zahl direkt ablesbar ist */
.chart .bar-value {
  fill: var(--ink);
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.chart .bar-value.peak { fill: var(--green-deep); }

/* Kopfzeile des Diagramms: Kennzahl wählen, Summe und Mittel ablesen */
.chart-head {
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap; margin-bottom: 12px;
}
.chart-select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 700; font-size: 14.5px;
  min-height: 38px; cursor: pointer;
  letter-spacing: -0.01em;
}
.chart-select:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(51, 199, 128, 0.14);
}
.chart-summary {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 13px; color: var(--ink-mute); font-weight: 500;
  margin-left: auto;
}
.chart-summary b { color: var(--ink); font-weight: 700; }

/* Kleines Auswahlfeld neben dem Kennzahl-Wähler (Auflösung) */
.chart-mini {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600; font-size: 13px;
  min-height: 38px; cursor: pointer;
  color: var(--ink-soft);
}
.chart-mini:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(51, 199, 128, 0.14);
}

/* Segment-Schalter: Balken / Linie */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.seg button {
  border: none; background: none; cursor: pointer;
  padding: 7px 13px; font-size: 13px; font-weight: 600;
  color: var(--ink-mute); min-height: 36px;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
}
.seg button + button { border-left: 1px solid var(--border-soft); }
.seg button:hover { color: var(--ink); background: var(--bg-alt); }
.seg button.on { background: var(--mint); color: var(--green-deep); }

/* Liniendiagramm */
.chart .line {
  fill: none;
  stroke: var(--green-deep);
  stroke-width: 2.4;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart .area { fill: rgba(51, 199, 128, 0.14); }
.chart .dot { fill: var(--green-deep); stroke: var(--surface); stroke-width: 1.4; }
.chart .dot.peak { fill: var(--ink); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: rgba(51, 199, 128, 0.07); }

/* Rechte-Schaltfläche in der Nutzertabelle */
.perm-btn {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 30px;
}
.perm-btn:hover { border-color: var(--green); background: var(--surface); }
.perm-sep { color: var(--ink-mute); }
.perm-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green); flex-shrink: 0;
}

.field-hint {
  margin: 5px 0 0; font-size: 12.5px; color: var(--ink-mute); line-height: 1.4;
}
dialog .field { margin-bottom: 18px; }

.legend {
  display: flex; gap: 16px; font-size: 12.5px;
  color: var(--ink-mute); margin-top: 10px; flex-wrap: wrap; font-weight: 500;
}

/* =============================================================== Hinweise */

.banner {
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 13px 16px;
  margin-bottom: 12px;
  font-size: 13.5px;
  line-height: 1.5;
}
.banner strong { display: block; margin-bottom: 4px; font-weight: 700; }
.banner.info { border-left-color: var(--green); background: var(--bg-alt); }
.banner.demo {
  border-left-color: var(--clay);
  background: var(--clay-bg);
  display: flex; align-items: center; gap: 12px;
}

.empty { color: var(--ink-mute); text-align: center; padding: 44px 20px; font-weight: 500; }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700;
  background: var(--mint); color: var(--green-deep);
}

.back-link {
  background: none; border: none; color: var(--green-deep);
  cursor: pointer; padding: 6px 0; font-weight: 700; font-size: 14px;
  margin-bottom: 10px; min-height: 38px;
}
.back-link:hover { text-decoration: underline; }

/* ================================================================ Dialoge */

dialog {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  padding: 26px;
  width: min(430px, 92vw);
  box-shadow: 0 16px 48px rgba(26, 31, 46, 0.18);
}
dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
dialog h3 { margin: 0 0 18px; font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
dialog h4 {
  margin: 0 0 10px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-mute);
}

/* Abschnitte im Einstellungsfenster - durch eine Linie getrennt, damit
   "Darstellung" und "Passwort ändern" nicht als ein Formular gelesen werden. */
.einstell-block + .einstell-block {
  margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border-soft);
}
dialog select {
  width: 100%; padding: 11px 13px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-alt); font-weight: 500;
}
.dialog-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 22px; }

.credentials {
  background: var(--mint);
  border: 1px solid var(--mint-deep);
  border-radius: var(--radius);
  padding: 14px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13.5px;
  margin-top: 14px;
  word-break: break-all;
  white-space: pre-wrap;
  font-weight: 600;
}

/* Auswahlfelder in Tabellen kompakt halten */
td select {
  padding: 5px 9px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); font-size: 13px; max-width: 190px;
}
.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }

/* ===========================================================================
   Modulauswahl (Startseite nach der Anmeldung)
   =========================================================================== */

.launchpad { padding: 8px 0 20px; }

.launch-head { margin-bottom: 22px; }
.launch-head h1 {
  font-size: 25px; font-weight: 800; margin: 0 0 4px; letter-spacing: -0.025em;
}
.launch-head p { margin: 0; color: var(--ink-mute); font-size: 14.5px; }

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  max-width: 940px;
}

.module-card {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.12s var(--ease);
  min-height: 132px;
}
.module-card:hover {
  border-color: var(--green);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.module-icon {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--mint); color: var(--green-deep);
  display: grid; place-items: center; margin-bottom: 12px;
}
.module-icon svg { width: 21px; height: 21px; }
.module-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.module-sub { font-size: 13.5px; color: var(--ink-mute); font-weight: 500; }
.module-flag {
  position: absolute; top: 14px; right: 14px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 999px; padding: 2px 8px;
}

/* Rücksprung zur Modulauswahl */
.tab-back {
  font-size: 15px !important;
  padding: 8px 11px !important;
  color: var(--ink-mute);
  flex-shrink: 0;
}

/* ===========================================================================
   Filter
   =========================================================================== */

.filter-toggle.active {
  border-color: var(--green);
  background: var(--mint);
  color: var(--green-deep);
}

.filter-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.filter-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.filter-field.wide { grid-column: 1 / -1; }
.filter-field label {
  font-size: 11.5px; font-weight: 700; color: var(--ink-mute);
  text-transform: uppercase; letter-spacing: 0.045em;
}
.filter-field select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-alt); font-size: 13.5px; font-weight: 500; min-height: 38px;
  max-width: 100%;
}
.filter-field select:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(51, 199, 128, 0.14);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; min-height: 34px;
  transition: all 0.12s var(--ease);
}
.chip:hover { border-color: var(--green); }
.chip.on {
  background: var(--green-deep); color: #fff; border-color: var(--green-deep);
}

/* Aktive Filter als sichtbare, einzeln entfernbare Chips */
.active-filters {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  margin: -8px 0 18px;
}
.active-filters-label {
  font-size: 12px; font-weight: 700; color: var(--ink-mute);
  text-transform: uppercase; letter-spacing: 0.045em;
}
.chip.removable { display: inline-flex; align-items: center; gap: 7px; }
.chip .chip-x { font-size: 11px; opacity: 0.75; }
.chip.removable:hover .chip-x { opacity: 1; }

.inline-toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.inline-toolbar label { color: var(--ink-mute); font-size: 13px; font-weight: 600; }
.inline-toolbar select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-weight: 600; font-size: 13.5px; min-height: 38px;
}

/* ===========================================================================
   Mein Cockpit (persoenliches Dashboard)
   =========================================================================== */

.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;
}

.dash-kopf { margin-top: 4px; }
.dash-title { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.dash-title strong { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; }
.muted-inline { color: var(--ink-mute); font-size: 12.5px; font-weight: 500; }
.dash-aktionen { display: inline-flex; gap: 8px; flex-wrap: wrap; }

/* --------------------------------------------------------- Cockpit-Leiste */

.cockpit-bar {
  display: flex; gap: 4px; align-items: center;
  overflow-x: auto; scrollbar-width: none;
  padding: 2px 0 10px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 4px;
}
.cockpit-bar::-webkit-scrollbar { display: none; }
.cockpit-tab {
  background: none; border: 1px solid transparent; border-radius: 999px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
  font-weight: 600; font-size: 13.5px; color: var(--ink-mute);
  min-height: 38px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.cockpit-tab:hover { background: var(--bg-alt); color: var(--ink); }
.cockpit-tab.active {
  background: var(--mint); color: var(--green-deep); border-color: var(--mint-deep);
}
.cockpit-fest { opacity: 0.55; margin-left: 5px; }
.cockpit-neu {
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: 999px; width: 38px; height: 38px; flex-shrink: 0;
  cursor: pointer; color: var(--ink-mute); font-size: 17px; line-height: 1;
}
.cockpit-neu:hover { border-color: var(--green); color: var(--green-deep); }

/* ------------------------------------------------------------ Kachelraster */

.widget-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  align-items: start;
}
.widget { margin: 0; min-width: 0; position: relative; }
.widget.w-s { grid-column: span 3; }
.widget.w-d { grid-column: span 4; }
.widget.w-m { grid-column: span 6; }
.widget.w-l { grid-column: span 12; }
.widget.hoch .widget-body { min-height: 360px; }

.widget-body { min-width: 0; }

.widget-head {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 12px; flex-wrap: nowrap;
}
.widget-head h3 {
  margin: 0; font-size: 14.5px; font-weight: 700; letter-spacing: -0.01em;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.widget-tools { display: inline-flex; gap: 2px; margin-left: auto; flex-shrink: 0; }

/* Anfasser. touch-action nur HIER - stünde es auf der Kachel oder gar auf
   dem Raster, ließe sich die Seite auf dem Handy nicht mehr scrollen. */
.griff, .groesse, .menue-knopf {
  position: relative;
  border: 1px solid transparent; border-radius: 8px;
  background: none; cursor: pointer; color: var(--ink-mute);
  display: inline-grid; place-items: center;
  touch-action: none;
  -webkit-touch-callout: none;
  transition: background 0.12s var(--ease), border-color 0.12s var(--ease), color 0.12s var(--ease);
}
/* Trefferfläche auf ~46px vergrößern, ohne das Aussehen zu ändern */
.griff::before, .groesse::before, .menue-knopf::before {
  content: ''; position: absolute; inset: -9px;
}
.griff, .menue-knopf { width: 28px; height: 28px; }
.griff { cursor: grab; }
.griff:active { cursor: grabbing; }
.griff:hover, .menue-knopf:hover { background: var(--bg-alt); border-color: var(--border); color: var(--ink); }
.dots6 svg, .dots3 svg { fill: currentColor; display: block; }

.groesse {
  position: absolute; right: 4px; bottom: 4px;
  width: 26px; height: 26px;
  color: var(--ink-mute); font-size: 13px;
  opacity: 0; pointer-events: none;
}
.widget-grid.bearbeiten .groesse { opacity: 0.75; pointer-events: auto; cursor: nwse-resize; }
.widget-grid.bearbeiten .groesse:hover { opacity: 1; color: var(--green-deep); background: var(--bg-alt); }
.groesse-pfeile { transform: rotate(90deg); display: block; font-weight: 700; }

.widget-grid.bearbeiten .widget {
  border-style: dashed;
  border-color: var(--mint-deep);
}

/* Kachel während des Ziehens: hängt am body, folgt dem Zeiger */
.widget.wird-gezogen {
  position: fixed !important;
  z-index: 200;
  margin: 0;
  pointer-events: none;
  box-shadow: 0 18px 42px rgba(26, 31, 46, 0.22);
  border-style: solid;
  border-color: var(--green);
  opacity: 0.96;
  transform-origin: center;
}
.widget-platzhalter {
  border: 2px dashed var(--green);
  border-radius: var(--radius-xl);
  background: rgba(51, 199, 128, 0.06);
}
.widget-platzhalter.w-s { grid-column: span 3; }
.widget-platzhalter.w-d { grid-column: span 4; }
.widget-platzhalter.w-m { grid-column: span 6; }
.widget-platzhalter.w-l { grid-column: span 12; }

body.raster-geste { user-select: none; -webkit-user-select: none; }

.widget-kpi .kpi-inner .value {
  font-size: 27px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.15;
}
.widget-kpi .kpi-inner .hint { color: var(--ink-mute); font-size: 12.5px; margin-top: 5px; font-weight: 500; }

/* Rückmeldung beim Ändern der Größe - unter 760px sehen „Halb" und „Voll"
   sonst identisch aus und der Anfasser wirkt wirkungslos. */
.groesse-hinweis {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-ink); border-radius: 999px;
  padding: 8px 16px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; z-index: 300;
  transition: opacity 0.18s var(--ease);
}
.groesse-hinweis.an { opacity: 0.94; }

/* ------------------------------------------------------- Negativ-Ansichten */

/* Alles, was einen Rückstand zeigt, trägt denselben Ton: rot heißt hier
   "hier ist etwas offen", nicht "hier ist etwas kaputt". */
.card.kpi.negativ {
  border-color: var(--clay-line);
  background: linear-gradient(180deg, var(--clay-soft) 0%, var(--surface) 62%);
}
.card.kpi.negativ .value { color: var(--clay); }

.banner.negativ {
  border-left-color: var(--clay);
  background: var(--clay-soft);
}

.panel.negativ { border-color: var(--clay-line); }
.panel.negativ > h2 { color: var(--clay); }
.panel.negativ th.sorted { color: var(--clay); }
.panel.negativ tbody tr:hover { background: var(--clay-soft); }
.panel.negativ tbody tr:nth-child(-n+3) td.name { font-weight: 800; }

.ehrung-spalte.negativ .ehrung-titel { color: var(--clay); border-bottom-color: var(--clay-line); }
.ehrung-spalte.negativ .ehrung-wert { color: var(--clay); }

/* -------------------------------------------------- Bestenliste (Ehrungen) */

.board-seg { margin-bottom: 18px; }

.ehrung-monat h2 .note { font-weight: 500; }
.ehrung-spalten {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}
.ehrung-spalte { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.ehrung-titel {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-mute);
  padding-bottom: 6px; border-bottom: 1px solid var(--border-soft);
}
.ehrung-platz {
  display: grid; grid-template-columns: 23px 1fr auto;
  align-items: center; gap: 9px;
  font-size: 13.5px;
}
/* Platz 2 und 3 treten bewusst zurück - Platz 1 soll ins Auge fallen */
.ehrung-platz.weiter { font-size: 12.5px; color: var(--ink-soft); }
.ehrung-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ehrung-platz.weiter .ehrung-name { font-weight: 500; }
.ehrung-wert { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ehrung-platz.weiter .ehrung-wert { font-weight: 600; }

/* ------------------------------------------------------------ Kachel-Menü */

.kachel-menue {
  position: fixed; z-index: 250;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 34px rgba(26, 31, 46, 0.16);
  padding: 6px;
  min-width: 190px;
  max-height: 70vh; overflow-y: auto;
}
.km-eintrag {
  display: block; width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  padding: 9px 11px; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: var(--ink);
  min-height: 40px;
}
.km-eintrag.klein { font-size: 13px; font-weight: 500; min-height: 34px; padding: 6px 11px; }
.km-eintrag:hover { background: var(--bg-alt); }
.km-eintrag.gefahr { color: var(--clay); }
.km-eintrag.gefahr:hover { background: var(--clay-bg); }
.km-trenner { height: 1px; background: var(--border-soft); margin: 5px 0; }
.km-titel {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-mute); padding: 6px 11px 3px;
}

.undo-streifen {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-ink);
  border-radius: 999px; padding: 9px 10px 9px 18px;
  display: flex; align-items: center; gap: 12px;
  font-size: 13.5px; font-weight: 500; z-index: 300;
  box-shadow: 0 10px 28px rgba(26, 31, 46, 0.28);
  max-width: calc(100vw - 24px);
}
.undo-streifen .btn { background: rgba(255, 255, 255, 0.16); border: none; color: #fff; }
.undo-streifen .btn:hover { background: rgba(255, 255, 255, 0.26); box-shadow: none; }

/* ------------------------------------------------- Assistent Widget-Auswahl */

/* Ebenfalls nur im geöffneten Zustand — siehe Hinweis bei .frame-dialog. */
dialog.dlg-wide[open] { display: flex; flex-direction: column; }
dialog.dlg-wide {
  width: min(760px, 94vw);
  max-height: min(88vh, 820px);
  padding: 0;
  overflow: hidden;
}
.wz { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.wz-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.wz-head strong { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; }
.wz-back, .wz-close {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  width: 32px; height: 32px; cursor: pointer; color: var(--ink-soft);
  display: grid; place-items: center; font-size: 14px; flex-shrink: 0;
}
.wz-back:hover, .wz-close:hover { background: var(--bg-alt); border-color: var(--green); }
.wz-body {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px; min-height: 0;
}
.wz-hint { margin: 0 0 14px; color: var(--ink-mute); font-size: 13.5px; }
.wz-fuss {
  display: flex; gap: 9px; justify-content: flex-end;
  padding: 14px 18px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); flex: 0 0 auto;
  background: var(--surface);
}

.wz-gallery {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px;
}
.wcard {
  display: flex; flex-direction: column; gap: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  cursor: pointer; text-align: left; padding: 0;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.12s var(--ease);
}
.wcard:hover { border-color: var(--green); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.wcard-vis {
  position: relative; display: block;
  background: var(--bg-alt); border-bottom: 1px solid var(--border-soft);
  padding: 12px; min-height: 104px;
}
.wcard-badge {
  position: absolute; top: 7px; right: 7px;
  font-size: 9.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--ink-mute);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 7px;
}
.wcard-txt { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px 14px; }
.wcard-name { font-weight: 700; font-size: 14.5px; }
.wcard-desc { font-size: 12.5px; color: var(--ink-mute); line-height: 1.45; }

/* Miniaturen in der Galerie */
.mini { pointer-events: none; }
.mini .funnel { gap: 4px; }
.mini .funnel-row { grid-template-columns: minmax(64px, 84px) 1fr auto; gap: 7px; }
.mini .funnel-row .fname { font-size: 10.5px; }
.mini .funnel-bar { height: 13px; border-radius: 4px; }
.mini .funnel-val { font-size: 10.5px; }
.mini-svg svg { width: 100%; height: auto; display: block; }
.mini-kpi { display: flex; flex-direction: column; gap: 2px; padding: 6px 2px; }
.mini-label {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-mute);
}
.mini-wert { font-size: 24px; font-weight: 800; letter-spacing: -0.03em; }
.mini-hint { font-size: 11px; color: var(--ink-mute); }

/* Stufe 2: Vorschau links, Einstellungen rechts */
.wz2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.wz2-vorschau {
  background: var(--bg-alt); border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg); padding: 14px;
  position: sticky; top: 0; min-height: 140px;
}
.wz2-marke {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-mute); margin-bottom: 8px;
}
.wz2-vorschau .value { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; }
.wz2-vorschau .hint { font-size: 12px; color: var(--ink-mute); margin-top: 4px; }
.wz2-form { display: flex; flex-direction: column; gap: 2px; }
.wz2-form .field { margin-bottom: 14px; }

.wz-mehr { border-top: 1px solid var(--border-soft); padding-top: 12px; margin-top: 4px; }
.wz-mehr > summary {
  cursor: pointer; font-weight: 700; font-size: 13.5px;
  list-style: none; display: flex; align-items: center; gap: 8px;
  padding: 6px 0; min-height: 36px;
}
.wz-mehr > summary::-webkit-details-marker { display: none; }
.wz-mehr > summary::before { content: '▸'; color: var(--ink-mute); transition: transform 0.15s var(--ease); }
.wz-mehr[open] > summary::before { transform: rotate(90deg); }

/* Kennzahl-Wähler */
.metrik-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 11px 13px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-alt); cursor: pointer; font-weight: 600; font-size: 14px;
  min-height: 44px;
}
.metrik-btn:hover { border-color: var(--green); background: var(--surface); }
.metrik-fmt { font-size: 11.5px; color: var(--ink-mute); font-weight: 600; }
.metrik-picker { display: flex; flex-direction: column; gap: 12px; }
.metrik-suche {
  width: 100%; padding: 11px 13px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-alt);
  font-size: 16px; /* 16px verhindert das automatische Zoomen auf iOS */
}
.metrik-suche:focus {
  outline: none; border-color: var(--green); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(51, 199, 128, 0.14);
}
.metrik-liste { display: flex; flex-direction: column; gap: 1px; }
.mg-titel {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-mute);
  padding: 12px 4px 4px;
}
.mrow {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; background: none; border: none;
  padding: 10px 11px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 500; min-height: 42px;
}
.mrow:hover { background: var(--bg-alt); }
.mrow.on { background: var(--mint); color: var(--green-deep); font-weight: 700; }

.dialog-sub {
  margin: 22px 0 10px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.045em; color: var(--ink-mute);
}
dialog input[type="text"], dialog input[type="search"] {
  width: 100%; padding: 11px 13px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-alt); font-weight: 500;
}
dialog input[type="text"]:focus {
  outline: none; border-color: var(--green); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(51, 199, 128, 0.14);
}
.btn.ghost.gefahr { color: var(--clay); }
.btn.ghost.gefahr:hover { border-color: var(--clay); }

/* ===========================================================================
   Score-Aufschluesselung
   =========================================================================== */

.score-btn {
  border: none; background: none; padding: 0; cursor: pointer;
  font: inherit; font-weight: 600;
}
.score-btn:hover .score-bar i { filter: brightness(1.12); }
.score-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

.score-table td, .score-table th { font-size: 13px; }
.score-table tr.dim { color: var(--ink-mute); }
.score-table tr.score-total td {
  border-top: 2px solid var(--border);
  border-bottom: none;
  font-size: 14px;
}

/* ===========================================================================
   Schulungsprogramm
   =========================================================================== */

.lesson-list { display: flex; flex-direction: column; gap: 2px; }

.lesson {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s var(--ease);
}
.lesson:hover { background: var(--bg-alt); }
.lesson input[type="checkbox"] {
  width: 17px; height: 17px; accent-color: var(--green-deep);
  cursor: pointer; flex-shrink: 0;
}
.lesson-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lesson-title { font-size: 14px; font-weight: 500; }
.lesson-desc { font-size: 12.5px; line-height: 1.45; color: var(--ink-mute); }
.lesson.done .lesson-title { color: var(--ink-mute); text-decoration: line-through; }
.lesson-meta { font-size: 12.5px; color: var(--ink-mute); white-space: nowrap; }
.lesson-link {
  font-size: 13px; font-weight: 600; color: var(--green-deep);
  text-decoration: none; white-space: nowrap;
}
.lesson-link:hover { text-decoration: underline; }

/* ===========================================================================
   Werkzeuge
   =========================================================================== */

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}
.tool-card {
  display: flex; flex-direction: column; gap: 3px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-alt);
  text-decoration: none; color: inherit;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.tool-card:hover { border-color: var(--green); background: var(--surface); }
.tool-card { text-align: left; cursor: pointer; font: inherit; color: inherit; }
.tool-icon { font-size: 20px; margin-bottom: 4px; }
.tool-title { font-weight: 700; font-size: 14.5px; }
.tool-sub { font-size: 13px; color: var(--ink-mute); }

/* --------------------------------- Fenster für eingebettete Fremdformulare */

/* WICHTIG: display nur im geöffneten Zustand setzen.
   Ein geschlossenes <dialog> ist per Browser-Vorgabe display:none — ein
   pauschales "display:flex" hebelt das aus und malt das Fenster als leeren
   Kasten auf jede Seite. */
.frame-dialog[open] {
  display: flex;
  flex-direction: column;
}
.frame-dialog {
  padding: 0;
  width: min(760px, 94vw);
  height: min(860px, 88vh);
  max-width: 94vw;
  max-height: 88vh;
  border-radius: 18px;
  overflow: hidden;
}
.frame-kopf {
  display: flex; align-items: center; gap: 9px;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex: 0 0 auto;
}
.frame-kopf strong { font-size: 15px; font-weight: 700; }
.frame-koerper { position: relative; flex: 1 1 auto; min-height: 0; background: var(--bg-alt); }
.frame-koerper iframe { width: 100%; height: 100%; border: 0; display: block; }
.frame-lade {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--ink-mute); font-weight: 500;
  pointer-events: none;
}
.frame-ausweich {
  padding: 32px 24px; text-align: center;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.frame-ausweich strong { font-size: 16px; }
.frame-ausweich p { margin: 0; color: var(--ink-mute); max-width: 46ch; line-height: 1.5; }
.frame-ausweich .btn { text-decoration: none; margin-top: 6px; }

/* Auf dem Handy bildschirmfüllend - ein Formular in einer 92vw-Karte
   verschenkt genau die Breite, die Eingabefelder brauchen. */
@media (max-width: 760px) {
  .frame-dialog {
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    margin: 0; border-radius: 0;
  }
}

/* iOS scrollt sonst gelegentlich hinter dem geöffneten Fenster weiter */
body:has(dialog[open]) { overflow: hidden; }

/* ============================================================ Kleinkram === */

.page-title {
  margin: 0 0 3px; font-size: 21px; font-weight: 800; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.muted-text { color: var(--ink-mute); font-size: 13.5px; margin: 0 0 16px; }

/* ===========================================================================
   Mobil und Tablet
   =========================================================================== */

@media (max-width: 1024px) {
  .two-col { grid-template-columns: 1fr; }
  .widget.w-s, .widget-platzhalter.w-s { grid-column: span 6; }
  .widget.w-d, .widget-platzhalter.w-d { grid-column: span 6; }
  .widget.w-m, .widget-platzhalter.w-m { grid-column: span 12; }
  .wz2 { grid-template-columns: 1fr; }
  .wz2-vorschau { position: static; }
}

@media (max-width: 760px) {
  body { font-size: 14.5px; }

  header.topbar {
    flex-wrap: wrap;
    padding: 0 14px;
    gap: 10px;
    row-gap: 0;
  }

  /* Reiter rutschen in eine eigene, waagerecht scrollbare Zeile */
  nav.tabs {
    order: 3;
    flex-basis: 100%;
    border-top: 1px solid var(--border-soft);
    padding: 6px 0 8px;
    margin: 0 -14px;
    padding-left: 14px;
    padding-right: 14px;
    gap: 4px;
  }
  nav.tabs button { font-size: 13.5px; padding: 8px 12px; }

  .brand { flex: 1; font-size: 14px; }
  .brand span { display: none; }

  .who strong { font-size: 12.5px; }
  .who span { display: none; }

  main { padding: 16px 14px 48px; }

  .grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
  .card { padding: 15px; border-radius: var(--radius-lg); }
  .kpi .value { font-size: 23px; }
  .kpi .label { font-size: 11px; }

  .toolbar { gap: 8px; }
  .toolbar select, .toolbar input[type="date"] { flex: 1 1 auto; min-width: 140px; }
  .stand { order: 10; flex-basis: 100%; }

  /* Tabellen bis zum Bildschirmrand scrollen lassen */
  .table-scroll {
    margin: 0 -15px;
    padding: 0 15px;
  }
  th, td { padding: 9px 9px; font-size: 13px; white-space: nowrap; }

  /* Die Namensspalte bleibt beim Scrollen stehen, damit klar bleibt,
     zu wem die Zahlen gehören. */
  th:first-child, td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--border-soft);
  }
  tbody tr:hover td:first-child { background: var(--bg-alt); }
  th:first-child { z-index: 3; }

  .chart-head { gap: 8px; }
  .chart-select { font-size: 14px; flex: 1 1 100%; }
  .chart-summary { margin-left: 0; font-size: 12.5px; flex-basis: 100%; }
  .seg button { padding: 7px 11px; font-size: 12.5px; }
  .chart-mini { font-size: 12.5px; }

  .widget-grid { gap: 10px; }
  .widget.w-s, .widget-platzhalter.w-s { grid-column: span 6; }
  .widget.w-d, .widget.w-m, .widget.w-l,
  .widget-platzhalter.w-d, .widget-platzhalter.w-m, .widget-platzhalter.w-l { grid-column: span 12; }
  .widget-kpi .kpi-inner .value { font-size: 23px; }
  .widget.hoch .widget-body { min-height: 300px; }

  .wz-gallery { grid-template-columns: 1fr; }
  dialog.dlg-wide {
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    margin: 0; border-radius: 0;
  }

  .funnel-row {
    grid-template-columns: 1fr;
    gap: 3px;
    padding-bottom: 6px;
  }
  /* Auf dem Handy steht der Name in einer eigenen Zeile über dem Balken -
     dort darf er umbrechen, es verschiebt nichts. */
  .funnel-row .fname { font-size: 13px; white-space: normal; }
  .funnel-bar { height: 22px; }
  .funnel-val { text-align: left; font-size: 12.5px; }

  dialog { padding: 20px; border-radius: 16px; }
}

@media (max-width: 420px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .kpi .value { font-size: 21px; }
  main { padding: 14px 12px 44px; }
}

/* Bewegung reduzieren, wenn das System es verlangt */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Druck: Cockpit als Bericht ausgeben */
@media print {
  header.topbar, .toolbar, .btn, .back-link { display: none !important; }
  body { background: #fff; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ccc; }
  main { padding: 0; max-width: none; }
}
