:root {
  --bg: #f5f5f4; --surface: #ffffff; --surface-2: #f0efed; --text: #1c1917; --muted: #6b6560;
  --border: #e2dfdb; --accent: #c8102e; --accent-ink: #ffffff; --accent-soft: #fbe9ec;
  --ok: #15803d; --warn: #b45309; --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141210; --surface: #1d1a18; --surface-2: #26221f; --text: #f2efec; --muted: #a39d97;
    --border: #36312d; --accent: #e3344f; --accent-soft: #3a1a20; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .r { text-align: right; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 18px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 20px 0 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; } .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 9px 14px; border-radius: 10px; font: inherit; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; } .btn.block { width: 100%; } .btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; font-size: 20px; color: var(--text); cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
input, textarea, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* Login */
.screen { height: 100%; }
#login { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 16px; }
.brand { display: flex; gap: 12px; align-items: center; }
.logo { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 24px; }

/* App */
#app { display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .title { flex: 1; display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.topbar .title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.token-badge { background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 4px 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.token-badge.leer { background: #fde68a; color: #92400e; }
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 250px; border-right: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--surface); }
.chat-liste { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-liste button { text-align: left; background: none; border: 0; color: var(--text); padding: 8px 10px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-liste button:hover, .chat-liste button.aktiv { background: var(--surface-2); }
#btn-menu { display: none; }
@media (max-width: 760px) {
  #btn-menu { display: block; }
  .sidebar { position: fixed; inset: 49px auto 0 0; z-index: 5; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.offen { transform: none; }
}

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.nachrichten { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: min(760px, 92%); padding: 11px 14px; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.fehler { align-self: center; background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.msg .meta { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.msg table { border-collapse: collapse; margin: 6px 0; } .msg td, .msg th { border: 1px solid var(--border); padding: 3px 8px; }
.willkommen { margin: auto; text-align: center; max-width: 560px; }
.vorschlaege { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 99px; padding: 8px 14px; cursor: pointer; font: inherit; font-size: 14px; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.status { display: flex; gap: 8px; align-items: center; padding: 6px 18px; color: var(--muted); font-size: 13px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.eingabe { display: flex; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--border); background: var(--surface); }
.eingabe textarea { resize: none; max-height: 160px; }

/* Dialog */
.dialog { border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(640px, calc(100% - 32px)); max-height: 86vh; background: var(--surface); color: var(--text); }
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; }
.tabs { display: flex; gap: 4px; padding: 10px 18px 0; }
.tab { background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--muted); font: inherit; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-color: var(--accent); }
.tab-panel { padding: 16px 18px 20px; }
.zugang { display: flex; flex-direction: column; gap: 10px; box-shadow: none; }
.zugang-head { display: flex; justify-content: space-between; align-items: center; }
.z-felder { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.token-gross { font-size: 32px; font-weight: 700; color: var(--accent); }
.pakete { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.paket { border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.paket strong { display: block; } .paket.aktiv { border-color: var(--accent); }
.tabelle { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabelle th, .tabelle td { padding: 6px; border-bottom: 1px solid var(--border); text-align: left; }
.tabelle .r { text-align: right; } .plus { color: var(--ok); }

/* Admin */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.scroll-x { overflow-x: auto; }

.foto-btn { display: grid; place-items: center; padding: 0 10px; font-size: 18px; margin: 0; }
.anhang { display: flex; gap: 8px; padding: 8px 16px 0; background: var(--surface); border-top: 1px solid var(--border); }
.anhang .vorschau { position: relative; }
.anhang img { height: 56px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.anhang button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); font-size: 11px; cursor: pointer; }
.fb { display: inline-flex; gap: 2px; margin-left: 8px; vertical-align: middle; }
.fb button { background: none; border: 0; cursor: pointer; font-size: 13px; opacity: .45; padding: 0 3px; }
.fb button:hover, .fb button.gewaehlt { opacity: 1; }
.token-badge.niedrig { background: #fef3c7; color: #92400e; }
.live { margin: 0 16px 8px; align-self: flex-start; }
.live img { width: min(360px, 80vw); border-radius: 10px; border: 1px solid var(--border); display: block; }
.msg.angebot { max-width: min(860px, 96%); white-space: normal; display: flex; flex-direction: column; gap: 8px; }
.msg.angebot .tabelle td, .msg.angebot .tabelle th { white-space: nowrap; }
.msg.angebot .tabelle td:nth-child(3) { white-space: normal; }
.neu-btn { display: block; margin-top: 8px; font-size: 13px; padding: 5px 12px; }

/* Ausbaustufe 2 */
.einrichtung { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.einrichtung h2 { margin: 0; }
.hinweis { background: var(--accent-soft); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.check input { margin-top: 3px; width: auto; }
.badge.fehler { background: var(--accent-soft); color: var(--accent); }
.kontext { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: 13px; }
.kontext .icon-btn { font-size: 13px; padding: 2px 6px; }
.mic-btn.aktiv { background: #c8102e; color: #fff; }
