/* components.css - Das UI-Kit: alle Bedienelemente des Support-Systems,
   vollstaendig custom gestaltet (kein Browser-Standard-Look) und
   ausschliesslich ueber Theme-Variablen eingefaerbt. Verhalten der
   komplexeren Komponenten (Select, Datepicker, Modal, Toast, Menu)
   liefert /public/js/ui.js. Musterseite: /styleguide. */

/* =============================== Buttons =============================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 1.05rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn.secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn.ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn.ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.btn.danger.secondary {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}
.btn.danger.secondary:hover { background: var(--danger-soft); }

.btn.sm { padding: 0.3rem 0.7rem; font-size: var(--fs-xs); }

.btn.icon {
  padding: 0.45rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
}
.btn.icon svg { width: 1.15rem; height: 1.15rem; }

/* ========================= Formular-Grundlagen ========================= */
.field { display: block; }
.field + .field { margin-top: 0.95rem; }
/* In Zeilen/Rastern stehen Felder NEBENEINANDER - kein vertikaler Abstand
   (M6-Feedback: Labels/Inputs sassen sonst versetzt, "nicht in Linie") */
.row > .field + .field,
.grid > .field + .field { margin-top: 0; }
.field > .label {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: var(--fs-sm);
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.field > .label .opt {
  font-weight: 450;
  color: var(--text-faint);
  font-size: var(--fs-xs);
}
.field > .hint {
  margin-top: 0.35rem;
  font-size: var(--fs-xs);
  color: var(--text-faint);
}
.field.invalid .input,
.field.invalid .textarea,
.field.invalid .select-btn {
  border-color: var(--danger);
}
.field.invalid > .hint { color: var(--danger); }

/* Text-Eingaben: abgerundet, eigene Flaechen-/Randfarbe, weicher Fokus */
.input,
.textarea {
  width: 100%;
  padding: 0.55rem 0.85rem;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  appearance: none;
}
.input::placeholder,
.textarea::placeholder { color: var(--text-faint); }
.input:hover,
.textarea:hover { border-color: var(--border-strong); }
.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
  background: var(--surface);
}
.input:disabled,
.textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.textarea {
  min-height: 6.5rem;
  resize: vertical;
  line-height: 1.5;
}

/* Eingabe mit Symbol/Zusatz (z. B. Auge fuer Passwort, Suche) */
.input-group { position: relative; }
.input-group .input { padding-right: 2.6rem; }
.input-group .input-addon {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 2.5rem;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  background: none;
  border: 0;
  cursor: pointer;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.input-group .input-addon:hover { color: var(--text); }
.input-group .input-addon svg { width: 1.1rem; height: 1.1rem; }

/* ========================= Custom Select ========================= */
/* ui.js ersetzt <select class="ui-select"> durch diese Struktur;
   das native Element bleibt (unsichtbar) fuer Formular-Submit erhalten. */
.select { position: relative; }
.select > select {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}
.select-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.55rem 0.85rem;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.select-btn:hover { border-color: var(--border-strong); }
.select.open .select-btn,
.select-btn:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.select-btn .placeholder { color: var(--text-faint); }
.select-btn .caret {
  flex: none;
  width: 1rem;
  height: 1rem;
  color: var(--text-faint);
  transition: transform 0.15s ease;
}
.select.open .select-btn .caret { transform: rotate(180deg); }

.select-menu {
  position: absolute;
  z-index: 60;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 16rem;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.3rem;
  display: none;
}
.select.open .select-menu { display: block; }
.select-opt {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  cursor: pointer;
  color: var(--text);
}
.select-opt:hover,
.select-opt.hover { background: var(--surface-hover); }
.select-opt.selected {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.select-opt.selected::after {
  content: "";
  margin-left: auto;
  width: 0.9rem;
  height: 0.9rem;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* ==================== Checkbox / Radio / Schalter ==================== */
.checkbox,
.radio {
  /* relative: verankert das absolut positionierte (unsichtbare) Input im
     Label - sonst haengt es am Seiten-Root und sprengt bei Tabellen im
     Scroller die Seitenbreite (M6-Feedback, Mobile-Overflow) */
  position: relative;
  display: inline-flex;
  align-items: flex-start;
  gap: 0.55rem;
  cursor: pointer;
  font-size: var(--fs-sm);
  line-height: 1.4;
  user-select: none;
}
.checkbox input,
.radio input,
.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.checkbox .box,
.radio .box {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.1rem;
  border: 1.5px solid var(--input-border);
  background: var(--input-bg);
  display: grid;
  place-items: center;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.checkbox .box { border-radius: 0.35rem; }
.radio .box { border-radius: var(--radius-full); }
.checkbox:hover .box,
.radio:hover .box { border-color: var(--border-strong); }
.checkbox input:focus-visible + .box,
.radio input:focus-visible + .box,
.switch input:focus-visible + .track {
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.checkbox .box::after {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  transform: scale(0);
  transition: transform 0.12s ease;
  background: var(--accent-contrast);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
}
.checkbox input:checked + .box {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox input:checked + .box::after { transform: scale(1); }
.radio .box::after {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: var(--radius-full);
  background: var(--accent);
  transform: scale(0);
  transition: transform 0.12s ease;
}
.radio input:checked + .box { border-color: var(--accent); }
.radio input:checked + .box::after { transform: scale(1); }

/* Schalter (an/aus) */
.switch {
  position: relative; /* verankert das unsichtbare Input (s. .checkbox) */
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  font-size: var(--fs-sm);
  user-select: none;
}
.switch .track {
  flex: none;
  width: 2.5rem;
  height: 1.4rem;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1.5px solid var(--input-border);
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  border-radius: var(--radius-full);
  background: var(--text-faint);
  transition: left 0.15s ease, background 0.15s ease;
}
.switch input:checked + .track {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked + .track::after {
  left: calc(100% - 1rem - 2px);
  background: var(--accent-contrast);
}

/* ===================== Chips, Badges, Ampeln, Timer ===================== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.18rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: 600;
  background: color-mix(in srgb, var(--chip-c, var(--accent)) 15%, transparent);
  color: var(--chip-c, var(--accent));
  border: 1px solid color-mix(in srgb, var(--chip-c, var(--accent)) 30%, transparent);
  white-space: nowrap;
}
.chip .x {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  margin-left: 0.1rem;
  opacity: 0.7;
}
.chip .x:hover { opacity: 1; }

/* Status-Punkt (Ampel) */
.dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: var(--radius-full);
  background: var(--dot-c, var(--text-faint));
}
.dot.ok { --dot-c: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.warn { --dot-c: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.error { --dot-c: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot.pulse { animation: dot-pulse 1.6s ease-in-out infinite; }
@keyframes dot-pulse {
  50% { opacity: 0.45; }
}

/* Level-Badges (0 Admin / 1 Redaktion / 2 Plattform / 3 Sysadmin) */
.badge-level {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.16rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge-level::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: var(--radius-full);
  background: currentColor;
}
.badge-level.l0 { color: var(--level-0); background: var(--level-0-soft); }
.badge-level.l1 { color: var(--level-1); background: var(--level-1-soft); }
.badge-level.l2 { color: var(--level-2); background: var(--level-2-soft); }
.badge-level.l3 { color: var(--level-3); background: var(--level-3-soft); }

/* Timer-Pille (Zeitampel; Farbe via --ms-Token) */
.timer {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.18rem 0.65rem;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--timer-c, var(--ms-normal));
  background: color-mix(in srgb, var(--timer-c, var(--ms-normal)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--timer-c, var(--ms-normal)) 30%, transparent);
  white-space: nowrap;
}
.timer::before {
  content: "";
  width: 0.85rem;
  height: 0.85rem;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 3' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 3' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
}
.timer.normal { --timer-c: var(--ms-normal); }
.timer.elevated { --timer-c: var(--ms-elevated); }
.timer.warning { --timer-c: var(--ms-warning); }
.timer.alarm { --timer-c: var(--ms-alarm); }
.timer.alarm { animation: dot-pulse 1.2s ease-in-out infinite; }
.timer.paused { opacity: 0.75; }
.timer.paused::before {
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M10 5v14M15 5v14'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M10 5v14M15 5v14'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Dringlichkeit */
.urgency {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: var(--fs-xs);
  font-weight: 650;
  color: var(--urg-c, var(--urg-normal));
  white-space: nowrap;
}
.urgency.normal { --urg-c: var(--urg-normal); }
.urgency.urgent { --urg-c: var(--urg-urgent); }
.urgency.immediate { --urg-c: var(--urg-immediate); }

/* ========================= Hinweise (Alerts) ========================= */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  border: 1px solid;
}
.alert.ok { color: var(--ok); background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.alert.error { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert.warn { color: var(--warn); background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alert.info { color: var(--info); background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); }

/* ============================== Tabellen ============================== */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.table th {
  text-align: left;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 650;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-hover); }
/* Kompakte Variante fuer spaltenreiche Einstellungs-Tabellen (M5-Feedback:
   der "Test"-Button der Ziel-Tabelle lag unsichtbar im Scroll-Bereich) */
.table.compact th { padding: 0.6rem 0.45rem; }
.table.compact td { padding: 0.5rem 0.45rem; }

/* Ticket-Listenzeile (Vorschau des M1-Layouts):
   Level-Farbmarkierung am linken Rand + dezente Einfaerbung der Zeile */
.ticket-row {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.35rem 1rem;
  padding: 0.8rem 1rem 0.8rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(to right, color-mix(in srgb, var(--row-c, transparent) 9%, transparent), transparent 45%),
    var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.ticket-row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--row-c, var(--border-strong));
}
.ticket-row:hover { border-color: var(--border-strong); }
a.ticket-row { color: inherit; }
a.ticket-row:hover { color: inherit; }
.ticket-row.l0 { --row-c: var(--level-0); }
.ticket-row.l1 { --row-c: var(--level-1); }
.ticket-row.l2 { --row-c: var(--level-2); }
.ticket-row.l3 { --row-c: var(--level-3); }
.ticket-row + .ticket-row { margin-top: 0.6rem; }
.ticket-row .t-head {
  grid-column: 1;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}
.ticket-row .t-no {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-faint);
}
.ticket-row .t-subject {
  font-weight: 650;
  font-size: var(--fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ticket-row .t-meta {
  grid-column: 3;
  grid-row: 1 / span 2;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.ticket-row .t-preview {
  grid-column: 1 / span 2;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ticket-row .t-from {
  color: var(--text-faint);
  font-size: var(--fs-xs);
  white-space: nowrap;
}
.ticket-row .t-attach {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  color: var(--text-faint);
  font-size: var(--fs-xs);
}
.ticket-row .t-attach svg { width: 0.9rem; height: 0.9rem; }

/* ============================ Dialog / Modal ============================ */
dialog.modal {
  margin: auto; /* zentriert - der globale Reset entfernt sonst die UA-Zentrierung */
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  padding: 0;
  width: min(92vw, 34rem);
  max-height: 85vh;
}
dialog.modal.wide { width: min(94vw, 52rem); }
dialog.modal::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(3px);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: var(--fs-md); }
.modal-body {
  padding: 1.15rem 1.25rem;
  overflow-y: auto;
  max-height: calc(85vh - 8.5rem);
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* =============================== Toasts =============================== */
.toast-stack {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-width: min(92vw, 23rem);
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--toast-c, var(--accent));
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  animation: toast-in 0.18s ease;
}
.toast.ok { --toast-c: var(--ok); }
.toast.error { --toast-c: var(--danger); }
.toast.info { --toast-c: var(--info); }
.toast .x {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0 0 0 0.4rem;
  font-size: var(--fs-md);
  line-height: 1;
}
.toast .x:hover { color: var(--text); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

/* ================================ Tabs ================================ */
.tabs {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.25rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.tab {
  padding: 0.35rem 0.9rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 550;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* =============================== Avatare =============================== */
.avatar {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-grid;
  place-items: center;
  font-size: var(--fs-xs);
  font-weight: 700;
  overflow: hidden;
  flex: none;
  border: 1px solid var(--border);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 4rem; height: 4rem; font-size: var(--fs-md); }

/* ========================= Dropdown-Menue ========================= */
.menu { position: relative; }
.menu-panel {
  position: absolute;
  z-index: 70;
  top: calc(100% + 8px);
  right: 0;
  min-width: 13rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.35rem;
  display: none;
}
.menu.open .menu-panel { display: block; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}
.menu-item:hover { background: var(--surface-hover); color: var(--text); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-sep { height: 1px; background: var(--border); margin: 0.35rem 0.3rem; }
.menu-head {
  padding: 0.5rem 0.65rem 0.35rem;
  font-size: var(--fs-xs);
  color: var(--text-faint);
}

/* ======================= Notification-Glocke (M4) ======================= */
.btn.bell { position: relative; }
.bell-badge {
  position: absolute;
  top: -0.3rem;
  right: -0.3rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.25rem;
  border-radius: var(--radius-full);
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  line-height: 1;
}
.menu-panel.notif-panel { min-width: 21rem; max-width: 24rem; }
#notif-list { max-height: 21rem; overflow-y: auto; }
.notif-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  align-items: flex-start;
  white-space: normal;
}
.notif-item .notif-title { font-weight: 600; font-size: var(--fs-sm); line-height: 1.35; }
.notif-item .notif-meta { font-size: var(--fs-xs); color: var(--text-faint); }

/* ========================= Theme-Dreifach-Switch ========================= */
.theme-switch {
  position: relative;
  display: inline-flex;
  padding: 0.2rem;
  gap: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}
.theme-switch .thumb {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease;
}
.theme-switch[data-active="bb"] .thumb { transform: translateX(0); }
.theme-switch[data-active="dark"] .thumb { transform: translateX(1.9rem); }
.theme-switch[data-active="light"] .thumb { transform: translateX(3.8rem); }
.theme-switch .seg {
  position: relative;
  z-index: 1;
  width: 1.9rem;
  height: 1.9rem;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  border-radius: var(--radius-full);
  padding: 0;
}
.theme-switch .seg svg { width: 1.05rem; height: 1.05rem; }
.theme-switch .seg:hover { color: var(--text); }
.theme-switch .seg.active { color: var(--accent); }

/* ============================ Datepicker ============================ */
.dp-wrap { position: relative; }
.dp {
  position: absolute;
  z-index: 60;
  top: calc(100% + 6px);
  left: 0;
  width: 17.5rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.75rem;
  display: none;
}
.dp.open { display: block; }
.dp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}
.dp-title {
  font-size: var(--fs-sm);
  font-weight: 650;
  text-transform: capitalize;
}
.dp-nav {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
.dp-nav:hover { background: var(--surface-hover); color: var(--text); }
.dp-nav svg { width: 1rem; height: 1rem; }
.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.dp-dow {
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--text-faint);
  font-weight: 650;
  padding: 0.25rem 0;
}
.dp-day {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: var(--fs-xs);
  cursor: pointer;
  padding: 0;
}
.dp-day:hover { background: var(--surface-hover); }
.dp-day.other { color: var(--text-faint); opacity: 0.5; }
.dp-day.today { box-shadow: inset 0 0 0 1.5px var(--border-strong); }
.dp-day.selected,
.dp-day.range-end {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
}
.dp-day.in-range { background: var(--accent-soft); color: var(--accent); border-radius: 0; }
.dp-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

/* ==================== Welcome-Page: Kennzahlen-Badges ==================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 1rem;
}
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 1.05rem 1.2rem;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--stat-c, var(--accent)) 10%, transparent), transparent 55%),
    var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--stat-c, var(--accent));
  border-radius: var(--radius-lg);
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.stat-card:hover { border-color: var(--stat-c, var(--accent)); color: inherit; transform: translateY(-1px); }
.stat-card .n {
  font-size: 1.7rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  color: var(--stat-c, var(--accent));
  line-height: 1.15;
}
.stat-card .k { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 550; }

/* ==================== Ticket-Seiten (Liste + Detail) ==================== */

/* Status-Chips (Farben je Status) */
.chip.st-neu { --chip-c: var(--info); }
.chip.st-in_bearbeitung { --chip-c: var(--accent); }
.chip.st-warten_kunde { --chip-c: var(--text-muted); }
.chip.st-erledigt { --chip-c: var(--ok); }
.chip.st-spam { --chip-c: var(--danger); }
.chip.st-unklar { --chip-c: var(--warn); }

/* Filter-/Sortier-Leiste der Ticket-Liste */
.tickets-toolbar {
  display: flex;
  gap: 0.7rem 0.8rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.9rem;
}
.tickets-toolbar .field { margin: 0; flex: 0 1 auto; min-width: 9.5rem; }
.tickets-toolbar .field.grow { flex: 1 1 14rem; }
.tickets-toolbar .label { margin-bottom: 0.3rem; font-size: var(--fs-xs); color: var(--text-faint); }

/* Nachrichten-Verlauf in der Detailansicht */
.msg {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}
.msg + .msg { margin-top: 0.85rem; }
.msg-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.95rem;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.msg-head .who { font-weight: 650; color: var(--text); }
.msg-head .when { margin-left: auto; color: var(--text-faint); white-space: nowrap; }
.msg-body {
  padding: 0.95rem;
  font-size: var(--fs-sm);
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.msg-body p + p { margin-top: 0.6rem; }
/* Formatierte Kunden-Mails (bereinigtes HTML) */
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 {
  margin: 0.9rem 0 0.4rem;
  font-size: var(--fs-md);
}
.msg-body ul, .msg-body ol { margin: 0.5rem 0 0.5rem 1.4rem; }
.msg-body li + li { margin-top: 0.2rem; }
.msg-body a { text-decoration: underline; }
.msg-body blockquote {
  margin: 0.6rem 0;
  padding: 0.4rem 0.9rem;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}
.msg-body pre, .msg-body code { font-family: var(--font-mono); font-size: 0.85em; }
.msg-body pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  overflow-x: auto;
}
.msg-body table { border-collapse: collapse; margin: 0.6rem 0; max-width: 100%; }
.msg-body th, .msg-body td {
  border: 1px solid var(--border-strong);
  padding: 0.3rem 0.6rem;
  font-size: var(--fs-xs);
  text-align: left;
}
.msg-body img { max-width: 100%; border-radius: var(--radius-sm); }
.msg-body hr { border: 0; border-top: 1px solid var(--border); margin: 0.8rem 0; }
.msg.out {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
}
.msg.note {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
  background: color-mix(in srgb, var(--warn) 5%, var(--surface));
}

/* Anhaenge: Bild-Thumbnails + Datei-Chips (Klick -> PopUp, Konzept 7.6) */
.msg-atts {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0 0.95rem 0.95rem;
}
.att-thumb {
  width: 74px;
  height: 74px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  object-fit: cover;
  cursor: zoom-in;
  background: var(--surface-2);
  transition: border-color 0.15s ease;
}
.att-thumb:hover { border-color: var(--accent); }
.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: var(--fs-xs);
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
}
.att-chip:hover { border-color: var(--accent); }
.att-chip svg { width: 1rem; height: 1rem; color: var(--text-faint); flex: none; }
.att-chip .sz { color: var(--text-faint); }

/* Lightbox-/PDF-Inhalt im PopUp */
.modal-body img.att-full { max-width: 100%; max-height: 65vh; margin: 0 auto; border-radius: var(--radius-sm); }
.modal-body iframe.att-pdf { width: 100%; height: 65vh; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }

/* Ticket-Detail: Kopf mit Timern */
.ticket-head {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
}
.timer-stats {
  display: flex;
  gap: 1.4rem;
  flex-wrap: wrap;
}
.timer-stats .ts {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.timer-stats .ts .k {
  font-size: var(--fs-xs);
  color: var(--text-faint);
}
.timer-stats .ts .v {
  font-family: var(--font-mono);
  font-weight: 650;
  font-size: var(--fs-md);
}

/* Farb-Auswahl (Admin-Einstellungen) */
input[type="color"].color-swatch {
  width: 2.3rem;
  height: 2.3rem;
  padding: 2px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  cursor: pointer;
}
input[type="color"].color-swatch::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"].color-swatch::-webkit-color-swatch { border: 0; border-radius: 0.3rem; }

/* ======================= Filter-Chips (aktive Filter) ======================= */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.8rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: var(--fs-xs);
}
.filter-bar .filter-label {
  font-weight: 700;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

/* ====================== Rich-Text-Editor (M5) ======================
   BBEditor (public/js/editor.js): Toolbar + contenteditable-Flaeche im
   Stil der Textarea; ab M6 auch Grundlage des FAQ-Editors. */
.rte {
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--input-bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.rte:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.rte-toolbar {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.rte-toolbar .rte-btn { width: 1.9rem; height: 1.9rem; }
.rte-toolbar .rte-btn svg { width: 1.05rem; height: 1.05rem; }
.rte-toolbar .rte-btn.active {
  background: var(--accent-soft, rgba(127, 127, 127, 0.18));
  color: var(--accent);
}
.rte-sep {
  width: 1px;
  height: 1.2rem;
  background: var(--border);
  margin: 0 0.35rem;
}
.rte-area {
  min-height: 9rem;
  max-height: 24rem;
  overflow-y: auto;
  padding: 0.55rem 0.85rem;
  font-size: var(--fs-sm);
  color: var(--text);
  outline: none;
  word-break: break-word;
}
.rte-area:empty::before,
.rte-area[data-empty="1"]::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
  pointer-events: none;
}
.rte-area p { margin: 0 0 0.55rem; }
.rte-area p:last-child { margin-bottom: 0; }
.rte-area ul, .rte-area ol { margin: 0.35rem 0 0.55rem 1.4rem; }
.rte-area a { color: var(--accent); text-decoration: underline; }
.rte-area blockquote {
  margin: 0.4rem 0;
  padding: 0.2rem 0 0.2rem 0.8rem;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}
.rte[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }

/* ====================== Logos je Theme (M5) ====================== */
.topbar-logo img.logo-mark { object-fit: contain; }
.topbar-logo img.logo-full {
  height: 2.1rem;
  max-width: 15rem;
  object-fit: contain;
}
.auth-logo img.logo-mark { object-fit: contain; }
.auth-logo img.logo-full {
  height: 2.6rem;
  max-width: 18rem;
  object-fit: contain;
}
.logo-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 4.5rem;
  height: 2.6rem;
  padding: 0.25rem 0.5rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
}
.logo-preview img { max-height: 2rem; max-width: 8rem; object-fit: contain; }
.logo-preview svg { width: 1.7rem; height: 1.7rem; color: var(--accent); }

/* Ueberfaellig-Markierung (Retention, Konzept 4.2) */
.chip.overdue { --chip-c: var(--danger, #ff5c5c); }

/* Info-Button (Blauton) - z. B. "Test" in der Notification-Ziel-Tabelle
   (M5-Feedback: der Ghost-Button wirkte wie blosser Text) */
.btn.info {
  background: var(--info-soft);
  color: var(--info);
  border-color: var(--info);
}
.btn.info:hover {
  background: var(--info);
  color: #fff;
  border-color: var(--info);
}

/* Danger Zone (M5-Feedback, Muster Statistik-Server): rote Karte fuer den
   Test-Daten-Reset auf der Aufbewahrungs-Seite */
.card.danger-zone { border: 1px solid var(--danger); }
.card.danger-zone .card-title { color: var(--danger); }

/* Rich-Text-Editor: FAQ-Erweiterungen (M6) */
.rte-source {
  width: 100%;
  min-height: 12rem;
  border: 0;
  outline: none;
  resize: vertical;
  padding: 0.55rem 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--fs-xs);
  line-height: 1.55;
  color: var(--text);
  background: var(--input-bg);
  border-radius: 0 0 var(--radius) var(--radius);
}
.rte-area img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  display: block;
  margin: 0.4rem 0;
}

/* FAQ-Verwaltung (M6) */
.faq-entry { cursor: grab; }
.faq-entry.dragging { opacity: 0.45; }
.faq-entry .faq-body-preview {
  max-height: 6.5rem;
  overflow: hidden;
  position: relative;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.faq-entry .faq-body-preview::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 2rem;
  background: linear-gradient(transparent, var(--surface));
}
.faq-entry .drag-handle {
  color: var(--text-faint);
  cursor: grab;
  flex: none;
}
.faq-preview-frame {
  width: 100%;
  height: min(70vh, 42rem);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
}
