/* =====================================================================
   Victoris CRM — Design-System
   Professioneller Agentur-Look. Marke zentral über Tokens austauschbar.
   ===================================================================== */
:root {
  /* Marke (hier später echte Firmenfarben eintragen) */
  --brand:        #0b5cff;
  --brand-600:    #0a4fd8;
  --brand-050:    #eaf1ff;
  --ink:          #0f1b2d;
  --ink-2:        #33455c;
  --muted:        #6b7c93;
  --line:         #e3e9f1;
  --line-2:       #eef2f7;
  --surface:      #ffffff;
  --surface-2:    #f6f8fb;
  --surface-3:    #eef2f7;
  --bg:           #f1f4f9;

  /* Status-Farben (Pipeline) */
  --st-cold:      #5f7d99;
  --st-warm:      #e07b39;
  --st-erst:      #6366f1;
  --st-qual:      #0ea5e9;
  --st-vertrag:   #f59e0b;
  --st-laufen:    #10b981;
  --st-abschluss: #64748b;

  /* Semantik */
  --danger:       #dc2626;
  --danger-bg:    #fdecec;
  --warn:         #b45309;
  --warn-bg:      #fef3e2;
  --ok:           #067647;
  --ok-bg:        #e6f6ee;

  --radius:       12px;
  --radius-sm:    8px;
  --shadow-sm:    0 1px 2px rgba(16,27,45,.06), 0 1px 3px rgba(16,27,45,.05);
  --shadow-md:    0 10px 30px rgba(16,27,45,.12);
  --shadow-lg:    0 24px 60px rgba(16,27,45,.22);
  --sidebar-w:    244px;
  --font:         "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink);
  background: var(--bg); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; color: var(--ink); letter-spacing: -.01em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; justify-content: center;
  padding: .5rem .9rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer; background: var(--surface-3); color: var(--ink-2);
  transition: background .15s, box-shadow .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { background: var(--line); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.94); }
.btn.sm { padding: .32rem .6rem; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
  width: 30px; height: 30px; border-radius: 7px; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }

/* ---------- Inputs ---------- */
.input, select.input, textarea.input {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font: inherit; color: var(--ink); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-050);
}
textarea.input { resize: vertical; min-height: 62px; }
label.fld { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: .3rem; }
.field { margin-bottom: .85rem; }
.chk { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ---------- Badges / Pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .35rem; padding: .18rem .5rem;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--ink-2);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-Cold { color: var(--st-cold); background: color-mix(in srgb, var(--st-cold) 14%, white); }
.st-Warm { color: var(--st-warm); background: color-mix(in srgb, var(--st-warm) 15%, white); }
.st-Erstkontakt { color: var(--st-erst); background: color-mix(in srgb, var(--st-erst) 12%, white); }
.st-Qualifizierung { color: var(--st-qual); background: color-mix(in srgb, var(--st-qual) 12%, white); }
.st-Vertrag { color: var(--st-vertrag); background: color-mix(in srgb, var(--st-vertrag) 15%, white); }
.st-Am-Laufen { color: var(--st-laufen); background: color-mix(in srgb, var(--st-laufen) 14%, white); }
.st-Abgeschlossen { color: var(--st-abschluss); background: color-mix(in srgb, var(--st-abschluss) 14%, white); }
.prio-Hoch { color: var(--danger); background: var(--danger-bg); }
.prio-Mittel { color: var(--warn); background: var(--warn-bg); }
.prio-Niedrig { color: var(--muted); background: var(--surface-3); }
.pill-over { color: var(--danger); background: var(--danger-bg); }
.pill-due { color: var(--warn); background: var(--warn-bg); }

/* =====================================================================
   Login / 2FA / Setup — zentrierte Karte
   ===================================================================== */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(1200px 500px at 80% -10%, color-mix(in srgb, var(--brand) 16%, transparent), transparent),
    var(--bg);
}
.auth-card {
  width: min(400px, 94vw); background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-md); padding: 2rem 1.9rem; border: 1px solid var(--line-2);
}
.brand-mark {
  width: 44px; height: 44px; border-radius: 11px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 22px; margin-bottom: 1rem;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 40%, transparent);
}
.auth-card h1 { font-size: 1.25rem; }
.auth-card .sub { color: var(--muted); margin: .2rem 0 1.3rem; }
.auth-card .field:last-of-type { margin-bottom: 1.2rem; }
.auth-error { background: var(--danger-bg); color: var(--danger); padding: .6rem .75rem; border-radius: 8px; font-size: 12.5px; margin-bottom: 1rem; }
.auth-note { background: var(--warn-bg); color: var(--warn); padding: .6rem .75rem; border-radius: 8px; font-size: 12.5px; margin-bottom: 1rem; }

/* 2FA-Setup */
.qr-box { display: grid; place-items: center; padding: 1rem; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--line); }
.qr-box svg { width: 190px; height: 190px; }
.secret-chip { font-family: "SF Mono", ui-monospace, monospace; letter-spacing: 2px; background: var(--surface-3); padding: .5rem .7rem; border-radius: 8px; text-align: center; font-size: 14px; word-break: break-all; }
.recovery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin: .8rem 0; }
.recovery-grid code { background: var(--surface-3); padding: .4rem; border-radius: 6px; text-align: center; font-size: 13px; }

/* =====================================================================
   App-Layout
   ===================================================================== */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: #cdd7e4; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.1rem; font-weight: 700; color: #fff; font-size: 15px; }
.sidebar .logo .brand-mark { width: 30px; height: 30px; font-size: 16px; margin: 0; box-shadow: none; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: .5rem .6rem; overflow-y: auto; flex: 1; }
.nav-sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6b7d94; padding: .9rem .7rem .3rem; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .55rem .7rem; border-radius: 8px; color: #cdd7e4; font-weight: 550; font-size: 13.5px; cursor: pointer;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a .count { font-size: 11px; background: rgba(255,255,255,.14); padding: .05rem .4rem; border-radius: 999px; }
.nav a.active .count { background: rgba(255,255,255,.25); }
.sidebar .foot { padding: .8rem 1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar .foot .u { color: #fff; font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .8rem 1.4rem; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.05rem; }
.topbar .spacer { flex: 1; }
.search { position: relative; }
.search .input { width: 240px; padding-left: 2rem; }
.search::before { content: "⌕"; position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.content { padding: 1.4rem; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card .card-head { display: flex; align-items: center; gap: .6rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line-2); }
.card .card-head h3 { font-size: 14px; }
.card .card-body { padding: 1.1rem; }
/* Einklappbare Karten (Dashboard) */
.card.is-collapsible > .card-head { cursor: pointer; user-select: none; }
.card.is-collapsible > .card-head .chev { color: var(--muted); transition: transform .15s; }
.card.is-collapsible.collapsed > .card-head { border-bottom: 0; }
.card.is-collapsible.collapsed > .card-head .chev { transform: rotate(-90deg); }
.card.is-collapsible.collapsed > .card-body { display: none; }
.grid { display: grid; gap: 1.1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- Dashboard ---------- */
.pipeline { display: grid; grid-template-columns: repeat(5, 1fr); gap: .8rem; }
.pipe-card { border-radius: var(--radius); padding: 1rem; cursor: pointer; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s; }
.pipe-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.pipe-card .n { font-size: 1.9rem; font-weight: 750; letter-spacing: -.02em; }
.pipe-card .l { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: .4rem; }
.kpi { display: flex; flex-direction: column; gap: .1rem; }
.kpi .v { font-size: 1.5rem; font-weight: 750; }
.kpi .k { font-size: 12px; color: var(--muted); }
.stat-row { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.stat-row:last-child { border-bottom: 0; }
.action-item { display: flex; align-items: center; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.action-item:hover { background: var(--surface-2); }
.action-item:last-child { border-bottom: 0; }
.action-item .when { font-size: 12px; margin-left: auto; }
.feed-item { display: flex; gap: .6rem; padding: .45rem 0; font-size: 12.5px; color: var(--ink-2); border-bottom: 1px solid var(--line-2); }
.feed-item:last-child { border-bottom: 0; }

/* ---------- Tabelle / Listen ---------- */
.toolbar { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
table.grid-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid-tbl thead th {
  text-align: left; padding: .65rem .8rem; background: var(--surface-2); color: var(--muted);
  font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none;
}
.grid-tbl thead th:hover { color: var(--ink); }
.grid-tbl tbody td { padding: .6rem .8rem; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.grid-tbl tbody tr { cursor: pointer; }
.grid-tbl tbody tr:hover { background: var(--brand-050); }
.grid-tbl tbody tr:last-child td { border-bottom: 0; }
.dup-flag { color: var(--warn); margin-left: .3rem; }
.pager { display: flex; align-items: center; gap: .6rem; justify-content: flex-end; margin-top: .9rem; font-size: 13px; }
.progress { position: relative; height: 7px; border-radius: 999px; background: var(--surface-3); width: 90px; overflow: hidden; }
.progress > span { position: absolute; inset: 0 auto 0 0; background: var(--st-vertrag); border-radius: 999px; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* =====================================================================
   Modal / Detail-Overlay
   ===================================================================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16,27,45,.5); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 1.2rem; z-index: 100; animation: fade .18s ease;
}
.modal-overlay.closing { animation: fade .18s ease reverse; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(560px, 96vw); max-height: 92vh; background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; animation: pop .18s ease;
}
.modal-card.wide { width: min(880px, 96vw); }
.modal-card.detail { width: min(920px, 97vw); }
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { font-size: 1.05rem; flex: 1; }
.modal-body { padding: 1.2rem; overflow-y: auto; }
.modal-footer { display: flex; gap: .6rem; justify-content: flex-end; padding: .9rem 1.2rem; border-top: 1px solid var(--line-2); background: var(--surface-2); }

/* Detail-Sektionen */
.detail-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: .3rem; }
.detail-head .id { font-size: 12px; color: var(--muted); }
.section { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden; }
.section > .sec-head { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; background: var(--surface-2); cursor: pointer; font-weight: 650; font-size: 13px; }
.section > .sec-head .chev { margin-left: auto; color: var(--muted); transition: transform .15s; }
.section.collapsed > .sec-head .chev { transform: rotate(-90deg); }
/* Eingeklappt = Inhalt ausblenden. Fehlte -> Klick drehte nur den Pfeil. */
.section.collapsed > .sec-body { display: none; }
.section.collapsed > .sec-head { border-bottom: 0; }
.section .sec-body { padding: 1rem; }
.section.locked .sec-body { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 10px, #fff 10px, #fff 20px); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .55rem; }
.form-grid .field.full { grid-column: 1 / -1; }
/* Detail-/Formular-Felder als dezente Zellen — bessere Unterscheidung */
.section .form-grid .field {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: .5rem .6rem .6rem;
  margin-bottom: 0;
}
/* „Nur Ausgefülltes anzeigen" — leere Felder ausblenden (Kompakt-Modus) */
.detail-compact .form-grid .field.is-empty { display: none; }
/* Termin-Felder bleiben IMMER sichtbar (auch leer), damit man Termine eintragen kann */
.detail-compact .form-grid.termin-grid .field.is-empty { display: block; }
/* Warnhinweis (z.B. Backup läuft nicht) — muss auffallen, nicht dekorieren */
.hinweis { padding: .7rem .9rem; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: .9rem; }
.hinweis.warn { background: #fef3c7; border: 1px solid #f59e0b; color: #7c2d12; font-weight: 600; }

/* „⋯"-Menü für seltene Aktionen in der Detail-Kopfzeile */
.more-wrap { position: relative; display: inline-block; }
.more-wrap > summary { list-style: none; cursor: pointer; user-select: none; }
.more-wrap > summary::-webkit-details-marker { display: none; }
.more-menu {
  position: absolute; right: 0; top: calc(100% + .3rem); z-index: 30; min-width: 12rem;
  display: flex; flex-direction: column; padding: .3rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(16,27,45,.14);
}
.menu-item {
  text-align: left; padding: .5rem .6rem; border: 0; background: none; cursor: pointer;
  border-radius: var(--radius-sm); font: inherit; font-size: 13px; color: var(--ink);
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: #fef2f2; }

/* ToDo-Bereich */
.todo-list { display: flex; flex-direction: column; gap: .5rem; }
.todo-row { display: flex; align-items: flex-start; gap: .75rem; padding: .7rem .9rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.todo-row .chk { margin-top: .1rem; }
.todo-body { flex: 1; }
.todo-titel { font-weight: 600; color: var(--ink); }
.todo-row.is-done .todo-titel { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.todo-row.is-done { opacity: .7; }

/* Umschalter-Leiste im Detail */
.detail-tools { display: flex; align-items: center; gap: .8rem; margin: 0 0 1rem; padding: .5rem .7rem; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: .3rem .8rem; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.lock-note { display: flex; align-items: center; gap: .5rem; font-size: 12px; color: var(--warn); margin-bottom: .6rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: .7rem; padding: .4rem 0; font-size: 12.5px; }
.timeline .marker { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); margin-top: .35rem; flex: none; }

.contact-row { display: flex; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.contact-row:last-child { border-bottom: 0; }
.contact-row { align-items: center; }
.contact-row.is-abgesagt { opacity: .6; }   /* eine Absage ist Information, kein Nichts */
.tag-list { display: flex; flex-wrap: wrap; gap: .35rem; }

/* Farbpunkt = Kalenderfarbe der Person (Farbe kommt per CSSOM aus der DB).
   Die Farbe ist nie die EINZIGE Auskunft — der Name steht daneben. */
.termin-dot { display: inline-block; width: .62rem; height: .62rem; border-radius: 50%; flex: 0 0 auto; }

/* Freigabe-Matrix (Einstellungen -> Kalender-Freigaben) */
.frg-tbl th { vertical-align: bottom; }
.frg-tbl .frg-zeile { text-align: left; font-weight: 600; min-width: 210px; }
.frg-tbl td { vertical-align: middle; }
.frg-zelle { display: flex; align-items: center; gap: .3rem; }
.frg-zelle .input.sm { padding: .25rem .35rem; font-size: 12px; }
/* Die Diagonale: bewusst KEIN Steuerelement — hier gibt es nichts einzustellen. */
.frg-selbst { text-align: center; color: var(--muted); background: var(--line-2); }
.asym { color: var(--warn, #b26a00); font-weight: 700; min-width: .7rem; }

/* Multiselect (Leistungsart) */
.multi { display: flex; flex-wrap: wrap; gap: .4rem; }
.multi label { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px; cursor: pointer; }
.multi label.on { background: var(--brand-050); border-color: var(--brand); color: var(--brand-600); }
.multi input { display: none; }

/* Segmented / Tabs (Einstellungen) */
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1.2rem; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: .6rem .9rem; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Toasts ---------- */
.toast-host { position: fixed; right: 1.2rem; bottom: 1.2rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow-md); font-size: 13px; opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; max-width: 340px; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- Loader ---------- */
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; margin: 2rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; z-index: 90; width: 260px; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex !important; }
  .search .input { width: 150px; }
  .form-grid, .grid.cols-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
.menu-toggle { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80; }

/* =====================================================================
   Kalender
   Zeitraster: 1 Pixel = 1 Minute (--day-h: 1440px). Kopf und Körper teilen
   sich EINE Spalten-Vorlage (inline gesetzt) -> sie fluchten ohne JS.
   ===================================================================== */
.kal-leiste { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem; flex-wrap: wrap; }
.kal-leiste .kal-titel { font-weight: 650; font-size: 14px; margin-left: .4rem; }
.kal-seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.kal-seg button { border: 0; background: var(--surface); padding: .4rem .8rem; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.kal-seg button + button { border-left: 1px solid var(--line); }
.kal-seg button:hover { background: var(--surface-2); color: var(--ink); }
.kal-seg button.active { background: var(--brand); color: #fff; }

/* Personenfilter */
.kal-filter { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; margin-bottom: .8rem; padding: .5rem .7rem; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); }
.kal-pers { display: inline-flex; align-items: center; gap: .4rem; font-size: 12.5px; cursor: pointer; padding: .2rem .55rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.kal-pers input { width: 14px; height: 14px; accent-color: var(--brand); }
.kal-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }

.kal-banner { display: flex; align-items: center; gap: .6rem; }

/* EIN Scroller. Definite Höhe, sonst greift sticky im Kopf nicht. */
.kal-scroller {
  --kal-gutter: 54px;
  --ppm: 1;
  --day-h: 1440px;
  height: calc(100vh - 250px); min-height: 340px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.kal-head, .kal-body { display: grid; }
.kal-head {
  position: sticky; top: 0; z-index: 3;
  background: var(--surface);                 /* sticky MUSS deckend sein */
  border-bottom: 1px solid var(--line);
}
.kal-hcol { padding: .35rem .4rem; text-align: center; border-left: 1px solid var(--line-2); min-width: 0; }
.kal-hcol .kal-wt { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kal-hcol .kal-dt { font-size: 15px; font-weight: 700; display: inline-block; min-width: 24px; padding: 0 .25rem; border-radius: 999px; }
.kal-hcol.is-heute .kal-wt { color: var(--brand); }
.kal-hcol.is-heute .kal-dt { background: var(--brand); color: #fff; }
/* z-Reihenfolge: Ecke(4) > Kopf(3) > Rinne(2) > Ereignisse(1) */
.kal-corner { position: sticky; left: 0; z-index: 4; background: var(--surface); }
.kal-gutter { position: sticky; left: 0; z-index: 2; background: var(--surface); height: var(--day-h); border-right: 1px solid var(--line-2); }
.kal-hour { position: absolute; right: .45rem; transform: translateY(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.kal-col {
  position: relative; height: var(--day-h); border-left: 1px solid var(--line-2); min-width: 0; cursor: cell;
  /* Stundenlinien als Farbverlauf statt 96 DOM-Knoten je Spalte. */
  background-image:
    repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px 60px),
    repeating-linear-gradient(to bottom, var(--line-2) 0 1px, transparent 1px 15px);
}

/* Ereignisse. Eigene Termine voll gefüllt, fremde blass + Farbschiene:
   fünf gleich laute Kalender werden sonst zu Brei. */
.kal-ev {
  position: absolute; z-index: 1; overflow: hidden; border-radius: 6px;
  padding: 1px 4px; font-size: 11.5px; line-height: 1.25; cursor: pointer;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0 .3rem;
  --farbe: var(--brand);
}
.kal-ev.is-eigen { background: var(--farbe); color: #fff; }
.kal-ev.is-fremd { background: color-mix(in srgb, var(--farbe) 15%, white); color: var(--ink); border-left: 4px solid var(--farbe); }
.kal-ev .kal-zeit { font-weight: 600; opacity: .85; flex: none; }
.kal-ev .kal-titel { font-weight: 600; flex: 1 1 100%; overflow: hidden; text-overflow: ellipsis; }
/* Kurze Termine (<=30 min): eine Zeile, niemals umbrechen. */
.kal-ev.is-kurz { flex-wrap: nowrap; white-space: nowrap; }
.kal-ev.is-kurz .kal-titel { flex: 1 1 auto; }
.kal-ev.is-abgesagt { opacity: .55; text-decoration: line-through; }   /* eine Absage ist Information */
.kal-ev.is-belegt, .kal-chip.is-belegt {
  cursor: default; color: var(--muted); border-left-color: var(--muted);
  background: repeating-linear-gradient(45deg, var(--surface-3), var(--surface-3) 5px, var(--surface-2) 5px, var(--surface-2) 10px);
}
.kal-ini { flex: none; font-size: 9.5px; font-weight: 800; background: var(--farbe); color: #fff; border-radius: 999px; padding: 0 4px; line-height: 14px; }

/* Jetzt-Linie: UNTER den Ereignissen (z-index 0), damit sie nie einen Titel verdeckt. */
.kal-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 0; pointer-events: none; }
.kal-now::before { content: ""; position: absolute; left: -3px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

/* ---------- Monatsraster ---------- */
/* 6 Zeilen IMMER. minmax(0,1fr) ist Pflicht — sonst wachsen die Zellen still
   und die Chip-Arithmetik in views.kalender.js stimmt nicht mehr. */
.kal-monat {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: 30px repeat(6, minmax(0, 1fr));
  height: calc(30px + 6 * 96px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  overflow: clip;   /* clip statt hidden: hidden erzeugt einen Scroll-Container */
}
.kal-mkopf { padding: .35rem; text-align: center; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); }
.kal-zelle { display: flex; flex-direction: column; gap: 1px; padding: 2px; min-width: 0; overflow: hidden; border-top: 1px solid var(--line-2); border-left: 1px solid var(--line-2); }
.kal-zelle.is-fremd-monat { background: var(--surface-2); }
.kal-ztag { align-self: flex-start; height: 20px; line-height: 18px; padding: 0 6px; border: 0; background: none; font: inherit; font-size: 11.5px; font-weight: 650; color: var(--ink-2); border-radius: 999px; cursor: pointer; flex: none; }
.kal-ztag:hover { background: var(--surface-3); }
.kal-zelle.is-fremd-monat .kal-ztag { color: var(--muted); font-weight: 500; }
.kal-ztag.is-heute { background: var(--brand); color: #fff; }
.kal-ztag.is-heute:hover { background: var(--brand-600); }
/* Chips MÜSSEN konstant hoch sein, sonst bricht die Packungs-Arithmetik. */
.kal-chip {
  height: 18px; line-height: 18px; flex: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-radius: 4px; padding: 0 4px; font-size: 11px; cursor: pointer;
  --farbe: var(--brand);
}
.kal-chip.is-eigen { background: var(--farbe); color: #fff; }
.kal-chip.is-fremd { background: color-mix(in srgb, var(--farbe) 15%, white); color: var(--ink); border-left: 3px solid var(--farbe); }
.kal-chip.is-abgesagt { opacity: .55; text-decoration: line-through; }
.kal-mehr { height: 18px; line-height: 18px; flex: none; border: 0; background: none; padding: 0 4px; font: inherit; font-size: 11px; font-weight: 600; color: var(--muted); text-align: left; cursor: pointer; }
.kal-mehr:hover { color: var(--brand); text-decoration: underline; }

/* ---------- Dialog: Kundenauswahl ---------- */
.kal-kunde-treffer { max-height: 150px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-top: .3rem; background: var(--surface); }
.kal-kunde-treffer button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: .35rem .5rem; font: inherit; font-size: 12.5px; cursor: pointer; }
.kal-kunde-treffer button:hover { background: var(--brand-050); }
.kal-chip-sel { display: inline-flex; align-items: center; gap: .3rem; background: var(--brand-050); color: var(--brand-600); border: 1px solid var(--brand); border-radius: 999px; padding: .2rem .3rem .2rem .6rem; font-size: 12.5px; }

/* Undo-Toast links unten — die normalen Toasts sitzen rechts unten. */
.kal-toast-host { position: fixed; left: 1.2rem; bottom: 1.2rem; display: flex; flex-direction: column; gap: .5rem; z-index: 210; }
.kal-toast { display: flex; align-items: center; gap: .9rem; background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow-md); font-size: 13px; }
.kal-undo { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: #7fb0ff; cursor: pointer; }
.kal-undo:hover { text-decoration: underline; }

@media (max-width: 820px) {
  /* Sidebar wird zur Schublade -> mehr Höhe für das Raster. */
  .kal-scroller { height: calc(100vh - 210px); }
  .kal-leiste .kal-titel { order: -1; width: 100%; margin-left: 0; }
  /* Zellenhöhe bleibt bei 96px: sie steckt als ZELLE_H in der Chip-Arithmetik
     von views.kalender.js. Wer sie hier ändert, muss sie dort mitziehen. */
}

/* =====================================================================
   Persönliche Feld-Markierungen (views.detail.js)
   Die Farbe selbst kommt aus FeldfarbenRepository::FARBEN und wird per
   CSSOM gesetzt — hier steht nur, wie ein markiertes Feld sitzt.
   ===================================================================== */

/* Ohne Markierung hat .field keinen Innenabstand. Eine Tönung würde sonst
   direkt am Text kleben. Der negative Rand hält die Beschriftungen aller
   Felder trotzdem in einer Flucht — markiert oder nicht. */
.field.has-farbe {
  padding: .5rem .6rem;
  margin-left: -.6rem;
  margin-right: -.6rem;
  border-radius: var(--radius-sm);
}

.farb-wrap { position: relative; display: inline-block; margin-left: .3rem; }
.farb-wrap > summary { list-style: none; cursor: pointer; user-select: none; }
.farb-wrap > summary::-webkit-details-marker { display: none; }

/* Zurückhaltend: der Griff ist Werkzeug, nicht Inhalt. Er taucht erst auf,
   wenn man das Feld ansteuert — sonst stünden auf jeder Karte 20 „▾". */
.farb-griff {
  display: inline-block; width: 1.1rem; text-align: center;
  color: var(--muted); font-size: 11px; line-height: 1.1rem;
  border-radius: var(--radius-sm);
  opacity: 0; transition: opacity .12s, background .12s, color .12s;
}
.field:hover .farb-griff,
.farb-wrap[open] .farb-griff,
.farb-griff:focus-visible { opacity: 1; }
.farb-griff:hover, .farb-wrap[open] .farb-griff { background: var(--surface-3); color: var(--ink); }
/* Tastatur: der Griff muss auffindbar bleiben, auch ohne Maus. */
.farb-griff:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
/* Ein markiertes Feld zeigt den Griff dauerhaft — sonst findet man den
   Rückweg („keine") nur durch Raten. */
.field.has-farbe .farb-griff { opacity: .6; }

.farb-menu {
  position: absolute; left: 0; top: calc(100% + .3rem); z-index: 30;
  display: flex; align-items: center; gap: .25rem; padding: .35rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(16,27,45,.14);
}
.farb-dot {
  width: 20px; height: 20px; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: 50%;
  transition: transform .1s, border-color .1s;
}
.farb-dot:hover { transform: scale(1.15); border-color: var(--ink-2); }
.farb-dot:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.farb-keine {
  border: 0; background: none; cursor: pointer; font: inherit; font-size: 12px;
  color: var(--muted); padding: .2rem .4rem; border-radius: var(--radius-sm);
  white-space: nowrap;
}
.farb-keine:hover { background: var(--surface-3); color: var(--ink); }

/* Der frühere Ergebnis-Dialog (Radio-Liste .erg-liste/.erg-opt) ist durch die
   Knopf-Leiste ersetzt — die Regeln dazu sind mit ihm entfernt worden. */

/* =====================================================================
   Ergebnis-Leiste (views.ergebnis.js) — Kundenkarte UND Anruf-Maske
   ===================================================================== */
/* flex-wrap statt fester Spalten: die Leiste hängt an der Zahl der Codes im
   Backend. Ein Grid mit „4 Spalten" würde beim 10. Code brechen. */
.erg-leiste { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- Termin-Ergebnis (dieselbe Mechanik, anderer Katalog) ---------- */
.erg-termin { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.erg-termin-status {
  font-size: 12px; font-weight: 600; color: var(--ok);
  background: var(--ok-bg); padding: .2rem .55rem; border-radius: 999px;
}
/* Im Kalender-Dialog abgesetzt, damit die Ergebnis-Frage nicht mit den
   Formularfeldern verschwimmt. */
.kal-ergebnis {
  margin: .6rem 0 .9rem; padding: .7rem .8rem;
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
}
/* In der Terminliste der Kundenkarte: eingerückt unter die Termin-Zeile,
   damit erkennbar bleibt, zu welchem Termin die Knöpfe gehören. */
.termin-ergebnis-zeile { margin: -.3rem 0 .7rem 132px; }

/* ---------- Kunden-Kontext im Termin-Dialog ---------- */
.kal-kontext {
  margin-bottom: .9rem; padding: .7rem .8rem;
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); font-size: 13px;
}
.kal-kontext-zeile { display: flex; gap: .6rem; padding: .15rem 0; align-items: center; }
.kal-kontext-label { color: var(--muted); min-width: 116px; flex: none; }

/* ---------- Schnellerfassung Notiz/Aufgabe ---------- */
.kontext-leiste { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .6rem; }
.kontext-leiste .input { flex: 1 1 14rem; min-width: 0; }
.kontext-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.kontext-chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: .18rem .6rem; font-size: 12px; cursor: pointer;
}
.kontext-chip:hover { background: var(--surface-2); }
.kontext-chip.is-aktiv { background: var(--brand-050); border-color: var(--brand); color: var(--brand-600); font-weight: 600; }

@media (max-width: 820px) {
  /* Auf schmalen Schirmen bringt die Einrückung nichts — sie kostet nur Breite. */
  .termin-ergebnis-zeile { margin-left: 0; }
  .kal-kontext-label { min-width: 92px; }
}
.erg-btn { background: var(--surface-3); }
.erg-btn:hover:not(:disabled) { background: var(--brand-050); color: var(--brand-600); }
/* Archivierende Codes sehen anders aus — sie nehmen den Kunden aus dem Betrieb. */
.erg-btn.ist-archiv { color: var(--danger); }
.erg-btn.ist-archiv:hover:not(:disabled) { background: var(--danger-bg); color: var(--danger); }
.erg-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.erg-status {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin-top: .7rem; padding-top: .6rem; border-top: 1px solid var(--line-2);
}

/* Im Kompakt-Modus dürfen Firma/Ansprechpartner/Telefon NICHT verschwinden,
   auch wenn sie leer sind: dass die Nummer fehlt, ist am Telefon genau die
   Information, die man braucht. Gleiche Ausnahme wie beim Termin-Block. */
.detail-compact .form-grid.anruf-grid .field.is-empty { display: block; }

/* ---------- Toast mit „Rückgängig" ---------- */
/* Unten MITTIG — die normalen Toasts (UI.toast) sitzen unten rechts. */
.undo-host {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%);
  z-index: 210; display: flex; flex-direction: column; gap: .5rem;
  max-width: min(92vw, 520px);
}
.undo-toast {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: .9rem;
  background: var(--ink); color: #fff; padding: .7rem .8rem .7rem 1rem;
  border-radius: 10px; box-shadow: var(--shadow-md); font-size: 13px;
  opacity: 0; transform: translateY(10px); transition: opacity .25s, transform .25s;
}
.undo-toast.show { opacity: 1; transform: none; }
.undo-text { flex: 1; }
.undo-btn {
  flex: none; border: 1px solid rgba(255,255,255,.35); background: transparent;
  color: #fff; font: inherit; font-weight: 650; cursor: pointer;
  padding: .3rem .7rem; border-radius: var(--radius-sm); white-space: nowrap;
}
.undo-btn:hover:not(:disabled) { background: rgba(255,255,255,.14); }
.undo-btn:disabled { opacity: .6; cursor: progress; }
.undo-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
/* Ablaufbalken: zeigt, dass das Angebot endlich ist. transform statt width —
   das läuft auf dem Compositor und nicht über das Layout. */
.undo-bar {
  position: absolute; left: 0; bottom: 0; height: 2px; width: 100%;
  background: var(--brand); transform-origin: left center;
  animation: undo-ablauf 8s linear forwards;
}
@keyframes undo-ablauf { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) {
  .undo-toast { transition: none; }
  .undo-bar { animation: none; }
}

/* =====================================================================
   Anruf-Maske (views.anrufen.js)
   ===================================================================== */
.anruf-wrap { max-width: 760px; }

.anruf-kopf {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  margin-bottom: 1rem; padding-bottom: .8rem; border-bottom: 1px solid var(--line);
}
.anruf-kopf-links { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.anruf-kopf .anruf-phase { width: auto; padding: .3rem .5rem; font-size: 13px; }
.anruf-pos { white-space: nowrap; }
.anruf-zaehler { margin-left: auto; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.anruf-zaehler strong { color: var(--ink); }

.anruf-karte {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 1.4rem;
}
.anruf-identitaet { margin-bottom: 1.1rem; }
/* Die Firma trägt die Ansage — sie wird laut vorgelesen, nicht überflogen. */
.anruf-firma { font-size: 26px; font-weight: 680; letter-spacing: -.02em; line-height: 1.15; }
.anruf-person { font-size: 16px; color: var(--ink-2); margin-top: .2rem; }
.anruf-tel {
  display: inline-block; margin-top: .6rem;
  font-size: 22px; font-weight: 650; letter-spacing: .01em;
}
.anruf-tel.ist-leer { color: var(--muted); font-size: 15px; font-weight: 500; }
/* Nummer vorhanden, aber nicht eindeutig wählbar (z.B. zwei Nummern in einem
   Feld). Lesbar lassen, aber sichtbar als „nicht anklickbar" markieren — ein
   Wähl-Link würde hier einen Fremden anrufen. */
.anruf-tel.ist-unklar { color: var(--warn); font-size: 17px; font-weight: 600; }

.anruf-trenner { height: 1px; background: var(--line-2); margin: 1.1rem 0; }
.anruf-zeile { display: flex; gap: .7rem; align-items: baseline; margin-top: .7rem; }
.anruf-label { flex: none; width: 4.2rem; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.anruf-historie { font-size: 13px; color: var(--ink-2); }
.anruf-fuss { display: flex; align-items: center; gap: .6rem; }

@media (max-width: 620px) {
  .anruf-karte { padding: 1rem; }
  .anruf-firma { font-size: 21px; }
  .anruf-tel { font-size: 19px; }
  /* Label über den Wert statt daneben — 4.2rem sind hier zu viel Rand. */
  .anruf-zeile { flex-direction: column; gap: .2rem; }
  .anruf-label { width: auto; }
  .anruf-zaehler { margin-left: 0; }
}

/* =====================================================================
   Seitenblätterung (views.list.js)
   ===================================================================== */
/* .input ist 100% breit — in der Fußzeile wäre das die ganze Zeile. */
.pager select.input { width: auto; padding: .3rem .5rem; font-size: 13px; }
.seiten-sprung { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); white-space: nowrap; }
.pager .seiten-eingabe {
  width: 4.2rem; padding: .3rem .4rem; font-size: 13px;
  text-align: center; color: var(--ink);
}

@media (max-width: 720px) {
  /* Auf dem Telefon bricht die Fußzeile um, statt seitlich zu scrollen. */
  .pager { flex-wrap: wrap; justify-content: center; gap: .4rem; }
}

/* Anrede-Auswahl in der Kundenkarte (Herr / Frau / Hallo) — drei Knöpfe,
   einer aktiv. Speist die Anrede der Termin-Mail. */
.anrede-wahl { display: inline-flex; gap: .35rem; flex-wrap: wrap; }
.anrede-btn {
  padding: .32rem .7rem; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-sm); font: inherit; font-size: 13px; color: var(--ink-2);
  cursor: pointer;
}
.anrede-btn:hover { background: var(--surface-2); }
.anrede-btn.aktiv { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
