/* ==========================================================
   Kunden-Chat – Theme (Light / Dark / Auto)
   ========================================================== */
:root {
  --bg:        #f5f7fa;
  --panel:     #ffffff;
  --panel-2:   #f0f3f7;
  --line:      #e3e8ef;
  --txt:       #1b232e;
  --muted:     #6b7685;
  --accent:    #3b6ef5;
  --accent-2:  #2b54d4;
  --mine:      #3b6ef5;
  --mine-txt:  #ffffff;
  --theirs:    #eef1f6;
  --theirs-txt:#1b232e;
  --ok:        #22c55e;
  --off:       #c2cbd6;
  --danger:    #e0524d;
  --shadow:    0 6px 24px rgba(20,30,50,.07);
  --radius:    16px;
  --radius-sm: 10px;
}
:root[data-theme="dark"] {
  --bg:        #0f141b;
  --panel:     #161d27;
  --panel-2:   #1c2531;
  --line:      #283341;
  --txt:       #e7edf4;
  --muted:     #8a97a8;
  --accent:    #4f80ff;
  --accent-2:  #6a93ff;
  --mine:      #3f6fe6;
  --mine-txt:  #ffffff;
  --theirs:    #222c39;
  --theirs-txt:#e7edf4;
  --ok:        #34d77f;
  --off:       #46556a;
  --danger:    #f0625c;
  --shadow:    0 8px 28px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0f141b; --panel:#161d27; --panel-2:#1c2531; --line:#283341;
    --txt:#e7edf4; --muted:#8a97a8; --accent:#4f80ff; --accent-2:#6a93ff;
    --mine:#3f6fe6; --mine-txt:#fff; --theirs:#222c39; --theirs-txt:#e7edf4;
    --ok:#34d77f; --off:#46556a; --danger:#f0625c; --shadow:0 8px 28px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--txt);
  -webkit-text-size-adjust: 100%;
  transition: background .2s, color .2s;
}
.muted { color: var(--muted); }
a { color: var(--accent); }

/* ---------- Theme toggle button ---------- */
.theme-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--txt);
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem; line-height: 1;
  transition: background .15s, border-color .15s, transform .1s;
}
.theme-btn:hover { background: var(--panel-2); }
.theme-btn:active { transform: scale(.92); }

/* ---------- Centered cards (login / start form / errors) ---------- */
.center {
  display: flex; min-height: 100dvh;
  align-items: center; justify-content: center;
  padding: clamp(.75rem, 3vw, 1.5rem);
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1.5rem, 5vw, 2.25rem);
  width: 100%; max-width: 440px;
  box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 .75rem; font-size: clamp(1.25rem, 4vw, 1.5rem); letter-spacing: -.01em; }

/* ---------- Form fields ---------- */
.field { display: block; margin-bottom: .85rem; }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
.field input,
.field textarea,
textarea.field-input {
  width: 100%;
  padding: .65rem .8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--txt);
  font: inherit;
}
.field input:focus,
.field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--txt);
  border-radius: var(--radius-sm); padding: .5rem .9rem; cursor: pointer;
  font: inherit; font-weight: 500; text-decoration: none;
  display: inline-flex; align-items: center; gap: .4rem;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-2); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }

/* ==========================================================
   Chat layout
   ========================================================== */
.chat-wrap {
  display: flex; flex-direction: column;
  height: 100dvh;
  max-width: 860px; margin: 0 auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem;
  padding: .8rem clamp(.8rem, 3vw, 1.1rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(160%) blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.chat-head .title { display: flex; flex-direction: column; min-width: 0; }
.chat-head .title strong { font-size: .98rem; letter-spacing: -.01em; }
.chat-head .title .who { font-size: .78rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .right { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: transparent;
  border: 1.5px solid var(--off); transition: border-color .3s; flex-shrink: 0;
  opacity: .7; }
.dot.on { background: transparent; border-color: var(--ok);
  box-shadow: none; opacity: .85; }

/* ---------- Messages ---------- */
.messages {
  flex: 1; overflow-y: auto;
  padding: clamp(.75rem, 3vw, 1.1rem);
  display: flex; flex-direction: column; gap: .35rem;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.msg { display: flex; max-width: 100%; }
.msg.mine { justify-content: flex-end; }
.msg + .msg.same { margin-top: -.15rem; }

.bubble {
  max-width: min(78%, 540px);
  padding: .55rem .8rem;
  border-radius: 18px;
  background: var(--theirs); color: var(--theirs-txt);
  line-height: 1.4;
  box-shadow: 0 1px 1px rgba(0,0,0,.04);
  border-bottom-left-radius: 6px;
}
.msg.mine .bubble {
  background: var(--mine); color: var(--mine-txt);
  border-bottom-left-radius: 18px; border-bottom-right-radius: 6px;
}
.bubble .meta { font-size: .68rem; opacity: .65; margin-bottom: .12rem; font-weight: 500; }
.bubble .text { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.bubble a { color: inherit; text-decoration: underline; }

/* Day separator */
.daysep { align-self: center; font-size: .7rem; color: var(--muted);
  background: var(--panel-2); padding: .2rem .7rem; border-radius: 999px; margin: .5rem 0; }

/* ---------- Composer ---------- */
.composer {
  display: flex; gap: .55rem; align-items: flex-end;
  padding: clamp(.6rem, 2.5vw, .85rem);
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding-bottom: calc(clamp(.6rem,2.5vw,.85rem) + env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1; resize: none;
  border: 1px solid var(--line); border-radius: 14px;
  padding: .6rem .8rem; font: inherit;
  background: var(--panel); color: var(--txt);
  max-height: 140px; min-height: 42px;
  line-height: 1.35;
}
.composer textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.composer button {
  border: 0; background: var(--accent); color: #fff;
  border-radius: 14px; height: 42px; padding: 0 1.15rem;
  font-weight: 600; cursor: pointer; flex-shrink: 0;
  transition: background .15s;
}
.composer button:hover { background: var(--accent-2); }
.composer button:disabled { opacity: .5; cursor: default; }

/* ==========================================================
   Admin
   ========================================================== */
.admin-grid { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }
.sidebar {
  border-right: 1px solid var(--line); overflow-y: auto;
  background: var(--panel); display: flex; flex-direction: column;
}
.sidebar h2 { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 1rem 1rem .5rem; margin: 0; }
.cust { display: block; padding: .7rem 1rem; border-bottom: 1px solid var(--line);
  cursor: pointer; text-decoration: none; color: var(--txt); transition: background .12s; }
.cust:hover { background: var(--panel-2); }
.cust.active { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.cust .nm { font-weight: 600; display: block; }
.cust .sub { font-size: .72rem; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; display: block; }

.badge { display: inline-block; font-size: .6rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; background: color-mix(in srgb, var(--accent) 18%, var(--panel));
  color: var(--accent); padding: .08rem .4rem; border-radius: 5px;
  vertical-align: middle; margin-left: .35rem; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: .6rem;
  padding: .7rem clamp(.7rem,2.5vw,1rem); border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar .ttl { min-width: 0; overflow: hidden; }
.topbar .ttl strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.token-box { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .78rem;
  background: var(--panel-2); padding: .5rem .6rem; border-radius: 8px;
  word-break: break-all; border: 1px solid var(--line); }

.menu-toggle { display: none; }

/* ==========================================================
   Responsive — small windows & phones
   ========================================================== */
@media (max-width: 760px) {
  .admin-grid { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(85vw, 320px);
    z-index: 40; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .scrim.show { display: block; }
  .chat-wrap { border-left: 0; border-right: 0; }
  .bubble { max-width: 86%; }
}
@media (max-width: 380px) {
  .bubble { max-width: 92%; }
  .composer button { padding: 0 .9rem; }
  .chat-head .title strong { font-size: .9rem; }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Anhänge ---------- */
.att-img { display: block; margin-top: .35rem; }
.att-img img { max-width: 240px; max-height: 240px; border-radius: 10px; display: block; }
.msg.mine .att-img img { margin-left: auto; }
.att-file { display: inline-flex; align-items: center; gap: .5rem; margin-top: .35rem;
  padding: .5rem .65rem; border-radius: 10px; text-decoration: none;
  background: color-mix(in srgb, var(--txt) 7%, transparent); color: inherit; max-width: 260px; }
.msg.mine .att-file { background: rgba(255,255,255,.18); }
.att-ico { font-size: 1.3rem; flex-shrink: 0; }
.att-info { display: flex; flex-direction: column; min-width: 0; }
.att-name { font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-size { font-size: .68rem; opacity: .7; }

/* ---------- Datei-Button im Composer ---------- */
.file-btn { border: 1px solid var(--line); background: var(--panel); color: var(--txt);
  border-radius: 14px; height: 42px; width: 42px; flex-shrink: 0; cursor: pointer;
  font-size: 1.15rem; display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s; }
.file-btn:hover { background: var(--panel-2); }
.file-name { font-size: .75rem; color: var(--muted); padding: 0 .4rem .35rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-wrap { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.composer { border-top: 0 !important; }

/* ---------- Login ---------- */
.login-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1.75rem, 5vw, 2.5rem);
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-logo { height: 64px; width: auto; margin-bottom: .85rem;
  object-fit: contain; }
.login-brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: -.01em; }
.login-sub { margin: .25rem 0 0; font-size: .85rem; }
.login-error {
  background: color-mix(in srgb, var(--danger) 14%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  padding: .6rem .8rem; border-radius: var(--radius-sm);
  font-size: .88rem; margin-bottom: 1rem; text-align: center;
}
.login-foot { text-align: center; font-size: .72rem; margin-top: 1.25rem;
  padding-top: 1rem; border-top: 1px solid var(--line); }

/* ---------- Sidebar Footer (Logo + Version) ---------- */
.sidebar-foot {
  margin-top: auto;
  padding: 1rem; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: .6rem;
  font-size: .72rem;
}
.sidebar-logo { height: 28px; width: auto; object-fit: contain; opacity: .9; flex-shrink: 0; }

/* ---------- Status & Filter ---------- */
.filterbar { display: flex; flex-wrap: wrap; gap: .25rem; padding: 0 .6rem .6rem; }
.filter-tab {
  font-size: .72rem; text-decoration: none; color: var(--muted);
  padding: .25rem .5rem; border-radius: 999px; border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap;
}
.filter-tab:hover { background: var(--panel-2); }
.filter-tab.on { background: color-mix(in srgb, var(--accent) 14%, var(--panel));
  color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.filter-tab .cnt { font-size: .64rem; background: var(--panel-2); color: var(--muted);
  border-radius: 999px; padding: 0 .35rem; min-width: 1.1em; text-align: center; }
.filter-tab.on .cnt { background: color-mix(in srgb, var(--accent) 25%, var(--panel)); color: var(--accent); }

.st-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0; vertical-align: middle; margin-right: .15rem; }
.st-open     { background: #f0a020; }   /* offen – gelb/orange */
.st-progress { background: var(--accent); } /* in Bearbeitung – blau */
.st-done     { background: #22c55e; }   /* abgeschlossen – grün */

.cust .sub { display: flex; align-items: center; gap: .25rem; }
.badge-arch { background: color-mix(in srgb, var(--muted) 22%, var(--panel)); color: var(--muted); }

.status-select {
  font: inherit; font-size: .82rem; padding: .35rem .5rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--txt); cursor: pointer;
}

/* ---------- Token-Link kopieren ---------- */
.token-row { display: flex; gap: .5rem; align-items: stretch; }
.token-row .token-box { flex: 1; display: flex; align-items: center; }
.copy-btn { white-space: nowrap; flex-shrink: 0; }
.copy-btn.copied { background: #22c55e; color: #fff; border-color: #22c55e; }

/* ---------- Einstellungsseite ---------- */
.settings-body { background: var(--bg); }
.settings-wrap { max-width: 720px; margin: 0 auto; padding: clamp(1rem,3vw,1.5rem);
  min-height: 100dvh; }
.settings-head { display: flex; justify-content: space-between; align-items: center;
  gap: .75rem; margin-bottom: 1.25rem; }
.settings-flash { background: color-mix(in srgb, var(--accent) 12%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent); padding: .65rem .85rem; border-radius: var(--radius-sm);
  margin-bottom: 1.25rem; font-size: .9rem; }
.settings-card { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(1.1rem,3vw,1.5rem); margin-bottom: 1.25rem;
  box-shadow: var(--shadow); }
.settings-card h2 { margin: 0 0 1rem; font-size: 1.05rem; letter-spacing: -.01em; }
.settings-card .field { margin-bottom: 1rem; }
.settings-card textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .6rem .75rem; font: inherit; background: var(--panel); color: var(--txt); resize: vertical; }
.settings-card textarea:focus, .settings-card input:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.check { display: flex; align-items: flex-start; gap: .6rem; cursor: pointer;
  font-size: .92rem; margin-bottom: .6rem; line-height: 1.35; }
.check input { margin-top: .15rem; flex-shrink: 0; }
.hint { font-size: .74rem; margin: .3rem 0 0; }
.settings-sub { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.settings-foot { display: flex; align-items: center; gap: .6rem; justify-content: center;
  font-size: .72rem; padding: 1rem 0 2rem; }

/* ---------- DSGVO-Checkbox im Startformular ---------- */
.dsgvo-check { display: flex; align-items: flex-start; gap: .55rem;
  font-size: .8rem; line-height: 1.4; color: var(--muted);
  margin: .25rem 0 1rem; cursor: pointer; }
.dsgvo-check input { margin-top: .15rem; flex-shrink: 0; }
.dsgvo-check a { color: var(--accent); }

/* ---------- Danger-Button ---------- */
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); border-color: color-mix(in srgb, var(--danger) 85%, #000); }

/* ---------- Ungelesen-Markierung ---------- */
.cust.unread .nm { font-weight: 700; }
.unread-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-right: .15rem; vertical-align: middle;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------- Suche & Unread-Badge ---------- */
.searchbar { position: relative; padding: 0 .6rem .6rem; }
.searchbar input { width: 100%; padding: .5rem .75rem; padding-right: 2rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  color: var(--txt); font: inherit; font-size: .85rem; }
.searchbar input:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.search-clear { position: absolute; right: 1.1rem; top: 50%; transform: translateY(-60%);
  color: var(--muted); text-decoration: none; font-size: .9rem; padding: .2rem; }
.search-clear:hover { color: var(--txt); }
.unread-badge { font-size: .62rem; font-weight: 700; background: var(--accent);
  color: #fff; border-radius: 999px; padding: .08rem .45rem; vertical-align: middle;
  margin-left: .35rem; letter-spacing: 0; text-transform: none; }

/* ---------- Tipp-Indikator ---------- */
.bubble.typing { display: inline-flex; gap: .25rem; align-items: center; padding: .7rem .85rem; }
.bubble.typing span { width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); opacity: .5; animation: typingBounce 1.2s infinite; }
.bubble.typing span:nth-child(2) { animation-delay: .2s; }
.bubble.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: .9; }
}
@media (prefers-reduced-motion: reduce) {
  .bubble.typing span { animation: none; }
}

/* ---------- Alt-Badge ---------- */
.badge-stale { background: color-mix(in srgb, #f0a020 25%, var(--panel)); color: #d98a00; }

/* ---------- Embed (iFrame) ---------- */
.embed-body { background: var(--panel); margin: 0; height: 100dvh; overflow: hidden; }
.embed-wrap { height: 100dvh; box-sizing: border-box; display: flex; flex-direction: column; }
.embed-form { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.embed-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: clamp(.85rem, 4vw, 1.25rem) clamp(.85rem, 4vw, 1.25rem) .5rem; }
.embed-foot { flex: 0 0 auto; padding: .75rem clamp(.85rem, 4vw, 1.25rem) 1rem;
  border-top: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; gap: .75rem; }
.embed-intro { font-size: .9rem; color: var(--muted); margin-bottom: 1rem; line-height: 1.4; }
.embed-form .field { margin-bottom: .7rem; }
.chat-wrap.embed-chat { height: 100dvh; max-width: none; border: 0; }

/* ---------- Standalone-Kontaktseite ---------- */
.kontakt-body { background: var(--bg); margin: 0; min-height: 100dvh; }
.kontakt-page { display: flex; flex-direction: column; min-height: 100dvh; }
.kontakt-head { display: flex; align-items: center; justify-content: space-between;
  padding: 1rem clamp(1rem, 4vw, 2rem); }
.kontakt-logo { height: 48px; width: auto; object-fit: contain; }
.kontakt-main { flex: 1; display: flex; align-items: center; justify-content: center;
  padding: clamp(1rem, 4vw, 2rem); }
.kontakt-card { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(1.5rem, 5vw, 2.5rem);
  width: 100%; max-width: 520px; box-shadow: var(--shadow); }
.kontakt-card h1 { margin: 0 0 .5rem; font-size: clamp(1.3rem, 4vw, 1.7rem); letter-spacing: -.01em; }
.kontakt-intro { margin: 0 0 1.5rem; font-size: .95rem; line-height: 1.5; }
.kontakt-foot { text-align: center; padding: 1.5rem; font-size: .8rem; }

/* ---------- Embed-Snippets in Einstellungen ---------- */
.embed-snippet { margin-bottom: 1.1rem; }
.embed-snippet label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .4rem; }
.embed-snippet pre { background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: .6rem .7rem; overflow-x: auto; margin: 0 0 .4rem;
  font-size: .78rem; line-height: 1.4; }
.embed-snippet code { font-family: ui-monospace, "SF Mono", Menlo, monospace; color: var(--txt); }
.settings-card code { font-family: ui-monospace, Menlo, monospace; font-size: .82em;
  background: var(--panel-2); padding: .05rem .3rem; border-radius: 4px; }

/* ---------- Admin-Online-Status (Präsenz) ---------- */
.presence { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); }
.presence-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: #9aa0a6; }
.presence[data-state="online"]  .presence-dot, .presence-dot.presence[data-state] { }
.presence[data-state="online"]  .presence-dot { background: #22c55e; box-shadow: 0 0 0 3px color-mix(in srgb, #22c55e 22%, transparent); }
.presence[data-state="recent"]  .presence-dot { background: #f0a020; }
.presence[data-state="offline"] .presence-dot { background: #9aa0a6; }
/* Standalone-Punkt (im Admin-Header, ohne Wrapper) */
.presence-dot.presence[data-state="online"]  { background: #22c55e; box-shadow: 0 0 0 3px color-mix(in srgb, #22c55e 22%, transparent); }
.presence-dot.presence[data-state="recent"]  { background: #f0a020; }
.presence-dot.presence[data-state="offline"] { background: #9aa0a6; }

.chat-head .presence { margin-top: .15rem; }
.embed-presence { padding: .5rem .85rem; border-bottom: 1px solid var(--line); background: var(--panel); }

.presence-switch { display: inline-flex; align-items: center; gap: .4rem; }
.presence-switch select { font: inherit; font-size: .78rem; padding: .3rem .45rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--txt); cursor: pointer; max-width: 190px; }
@media (max-width: 720px) {
  .presence-switch select { max-width: 120px; }
}

/* ---------- Prefill-Links ---------- */
.prefill-list { display: flex; flex-direction: column; gap: .6rem; }
.prefill-item { display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; padding: .7rem .85rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--panel-2); }
.prefill-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.prefill-info strong { font-size: .92rem; }
.prefill-info .muted { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prefill-id { font-family: ui-monospace, Menlo, monospace; font-size: .72rem;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent);
  padding: .05rem .3rem; border-radius: 4px; align-self: flex-start; }
.prefill-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.prefill-actions .btn { padding: .4rem .6rem; }

/* ---------- Abwesenheits-Hinweis ---------- */
.away-banner { display: flex; align-items: flex-start; gap: .5rem;
  padding: .7rem .9rem; font-size: .85rem; line-height: 1.4;
  background: color-mix(in srgb, #f0a020 14%, var(--panel));
  border-bottom: 1px solid color-mix(in srgb, #f0a020 35%, transparent);
  color: var(--txt); }
.away-icon { flex-shrink: 0; }
.msg.system { justify-content: center; margin: .5rem 0; }
.system-bubble { background: var(--panel-2); color: var(--muted);
  font-size: .8rem; text-align: center; max-width: 85%;
  border: 1px dashed var(--line); border-radius: 10px; padding: .6rem .85rem; }

/* ---------- Ticketnummern ---------- */
.ticket-no { font-family: ui-monospace, Menlo, monospace; font-size: .72rem;
  color: var(--muted); font-weight: 600; }
.cust.active .ticket-no { color: color-mix(in srgb, var(--accent) 70%, var(--txt)); }
.ticket-badge { display: inline-block; font-family: ui-monospace, Menlo, monospace;
  font-size: .72rem; font-weight: 700; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  padding: .1rem .4rem; border-radius: 6px; vertical-align: middle; }
.embed-ticket { padding: .4rem .85rem; font-size: .78rem; color: var(--muted);
  border-bottom: 1px solid var(--line); }

/* ---------- Embed: dezenter Scrollbalken ---------- */
.embed-body { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.embed-body::-webkit-scrollbar { width: 8px; }
.embed-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.embed-body::-webkit-scrollbar-track { background: transparent; }

/* ---------- Rechtliche Fußzeile ---------- */
.legal-footer { margin-top: 1rem; padding-top: .85rem; border-top: 1px solid var(--line);
  text-align: center; font-size: .8rem; color: var(--muted); }
.legal-footer a { color: var(--muted); text-decoration: none; }
.legal-footer a:hover { color: var(--txt); text-decoration: underline; }
.legal-footer .sep { opacity: .5; margin: 0 .25rem; }
.embed-foot .legal-footer { margin-top: .6rem; padding-top: .6rem; }
.legal-card { max-width: 640px; }
.legal-text { font-size: .92rem; line-height: 1.6; color: var(--txt); white-space: normal; }

/* ---------- Demo & Status ---------- */
.status-list { display: flex; flex-direction: column; gap: .5rem; }
.status-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: .6rem; padding: .55rem .7rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--panel-2); }
.status-ico { width: 22px; height: 22px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; color: #fff; }
.status-ok { background: #22c55e; }
.status-warn { background: #f0a020; }
.status-fail { background: #ef4444; }
.status-label { font-size: .9rem; font-weight: 600; }
.status-hint { font-size: .82rem; text-align: right; }
.snip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem .7rem; overflow-x: auto; margin: 0 0 .5rem; font-size: .78rem; line-height: 1.4; }
.snip code { font-family: ui-monospace, Menlo, monospace; color: var(--txt); }
.demo-frame-box { display: flex; justify-content: center; padding: 1rem;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.demo-frame-box iframe { width: 380px; height: 600px; max-width: 100%; border: 0;
  border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18); background: var(--panel); }
@media (max-width: 560px) {
  .status-row { grid-template-columns: auto 1fr; }
  .status-hint { grid-column: 2; text-align: left; }
}

/* ---------- Feld-Validierung ---------- */
.field.has-error input, .field.has-error textarea {
  border-color: #ef4444; box-shadow: 0 0 0 3px color-mix(in srgb, #ef4444 18%, transparent); }
.field-error { color: #ef4444; font-size: .8rem; margin: .35rem 0 0; }
.dsgvo-check.has-error span { color: #ef4444; }
.dsgvo-check.has-error input { outline: 2px solid #ef4444; outline-offset: 2px; }
/* rotes Markieren beim Browser-Check (z.B. ungültige Rufnummer) */
.field input:user-invalid, .field textarea:user-invalid {
  border-color: #ef4444; box-shadow: 0 0 0 3px color-mix(in srgb, #ef4444 18%, transparent); }

/* ---------- Platzhalter (Vorbelegung) dezent ---------- */
input::placeholder, textarea::placeholder {
  color: var(--muted); opacity: .55; }
input:focus::placeholder, textarea:focus::placeholder { opacity: .4; }

/* ---------- Markenfarben-Auswahl ---------- */
.color-row { display: flex; gap: .6rem; align-items: center; }
.color-picker { width: 48px; height: 42px; padding: 2px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--panel-2); cursor: pointer; flex: 0 0 auto; }
.color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker::-webkit-color-swatch { border: 0; border-radius: 4px; }
.color-hex { flex: 1 1 auto; font-family: ui-monospace, Menlo, monospace; }

/* Kunden-Aktionsleiste: am Desktop wie bisher (flex, umbrechend) */
.cust-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

/* ==========================================================
   Mobile Admin-Feinschliff (Topbar + Aktions-Buttons)
   ========================================================== */
@media (max-width: 560px) {
  /* Topbar kompakter: E-Mail und Flash weg, damit der Name Platz hat */
  .topbar .ttl a.muted,
  .topbar .ttl > span.muted { display: none; }
  .topbar .ttl strong { font-size: .95rem; }

  /* Topbar in zwei Zeilen: Titel oben, Steuerung darunter (kein Überlappen) */
  .topbar { flex-wrap: wrap; padding: .55rem .7rem; gap: .45rem .4rem; }
  .topbar > div:first-child { flex: 1 1 100%; min-width: 0; }
  .topbar > div:last-child { flex: 1 1 100%; justify-content: flex-end; }

  /* Präsenz-Umschalter darf jetzt breiter, da eigene Zeile */
  .presence-switch select { max-width: 150px; font-size: .82rem; padding: .4rem .5rem; }
  .presence-switch { margin-right: auto; }  /* Status links, Rest rechts */

  /* Rechte Buttongruppe kompakt */
  .topbar .btn,
  .topbar .theme-btn { padding: .4rem .6rem; }

  /* Kunden-Aktionsleiste: gleichmäßiges 2-Spalten-Raster statt unruhigem Umbruch */
  .cust-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; width: 100%; }
  .cust-actions form { display: flex; }
  .cust-actions .btn,
  .cust-actions form button,
  .cust-actions .status-select { width: 100%; justify-content: center; }
  /* Statusauswahl über die volle Breite */
  .cust-actions .status-cell { grid-column: 1 / -1; }
}

/* Sehr schmale Geräte: Aktionen einspaltig */
@media (max-width: 360px) {
  .cust-actions { grid-template-columns: 1fr; }
}

/* ---------- Nachricht löschen (Admin) ---------- */
.msg .bubble { position: relative; }
.msg-del {
  position: absolute; top: 2px; right: 2px;
  border: 0; background: transparent; cursor: pointer;
  font-size: .8rem; line-height: 1; padding: 3px 4px; border-radius: 6px;
  opacity: 0; transition: opacity .12s, background .12s; color: inherit;
}
.msg .bubble:hover .msg-del { opacity: .55; }
.msg-del:hover { opacity: 1 !important; background: rgba(239,68,68,.18); }
.deleted-msg { font-style: italic; opacity: .6; font-size: .9em; }
/* Auf Touch-Geräten (kein Hover) dauerhaft dezent zeigen */
@media (hover: none) {
  .msg-del { opacity: .4; }
}

/* ---------- Logo im Kopfbereich ---------- */
/* Chat-Kopf: Logo links neben dem Titel, alles in EINER Zeile */
.chat-head .title { display: flex; flex-direction: row; align-items: center; gap: .55rem; min-width: 0; }
.head-logo { height: 32px; width: auto; object-fit: contain; flex-shrink: 0; }
.title-text { display: flex; flex-direction: row; align-items: center; gap: .5rem; min-width: 0; }
/* Formular-Karten: Logo mittig über dem Titel */
.form-logo { display: block; height: 52px; width: auto; object-fit: contain;
  margin: 0 auto .6rem; }

/* ---------- Design-Auswahlmenü (Hell / Dunkel / System / Sonnenstand) ---------- */
.theme-menu {
  position: absolute; z-index: 9999; min-width: 190px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: .35rem;
  box-shadow: 0 12px 32px rgba(0,0,0,.22);
}
.theme-menu[hidden] { display: none; }
.theme-menu-item {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  border: 0; background: transparent; color: var(--txt);
  font-size: .95rem; font-family: inherit; text-align: left;
  padding: .6rem .7rem; border-radius: 8px; cursor: pointer;
}
.theme-menu-item:hover { background: var(--panel-2); }
.theme-menu-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.theme-menu-item .tm-icon { font-size: 1.05rem; line-height: 1; flex-shrink: 0; }
