:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --panel-2: #eef2f1;
  --line: #dde3e1;
  --text: #17201e;
  --muted: #5f6d69;
  --accent: #2f6b3a;
  --accent-ink: #ffffff;
  --accent-soft: #dcebdf;
  --mine: #e0f0e3;
  --theirs: #ffffff;
  --bot: #f3ecff;
  --danger: #b42318;
  --warn: #9a6700;
  --badge: #e5484d;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .06);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1413; --panel: #151d1b; --panel-2: #1c2624; --line: #2a3633; --text: #e6eeec; --muted: #93a39f;
    --accent: #7cc68a; --accent-ink: #0b2410; --accent-soft: #1f3a25; --mine: #1d3523; --theirs: #1c2624; --bot: #261f36;
    --danger: #ff6b5f; --warn: #e3b341; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1413; --panel: #151d1b; --panel-2: #1c2624; --line: #2a3633; --text: #e6eeec; --muted: #93a39f;
  --accent: #7cc68a; --accent-ink: #0b2410; --accent-soft: #1f3a25; --mine: #1d3523; --theirs: #1c2624; --bot: #261f36;
  --danger: #ff6b5f; --warn: #e3b341; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Knöpfe & Felder ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: .55em 1em; min-height: 42px; font-weight: 550; text-align: center;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.small { min-height: 32px; padding: .25em .7em; font-size: .9em; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: transparent; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }
.field { display: grid; gap: .3em; margin: 0 0 .9em; }
.field label { font-size: .88em; color: var(--muted); font-weight: 550; }
.field .hint { font-size: .82em; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=search], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: .6em .75em; min-height: 44px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.error { color: var(--danger); font-size: .92em; min-height: 1.2em; margin: .3em 0; }

/* ---------- Anmeldung ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; align-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); padding: 28px 24px; }
.auth-card h1 { margin: 0 0 .2em; font-size: 1.5em; display: flex; align-items: center; gap: .4em; }
.auth-card h1 img { width: 34px; height: 34px; border-radius: 9px; }
.auth-card p.sub { margin: 0 0 1.4em; color: var(--muted); }
.tabs { display: flex; background: var(--panel-2); padding: 4px; border-radius: 12px; margin-bottom: 1.2em; }
.tabs button { flex: 1; border: 0; background: transparent; padding: .5em; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.auth-card .btn { width: 100%; }
.or { text-align: center; color: var(--muted); font-size: .85em; margin: 1em 0; display: flex; align-items: center; gap: .8em; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 320px 1fr; height: 100vh; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 10px 10px 16px; border-bottom: 1px solid var(--line); }
.side-head .title { font-weight: 700; font-size: 1.15em; flex: 1; display: flex; align-items: center; gap: .5em; min-width: 0; }
.side-head .title img { width: 28px; height: 28px; border-radius: 8px; }
.side-head .title a { color: inherit; text-decoration: none; }
.rooms { overflow-y: auto; flex: 1; padding: 6px; }
.rooms h3 { font-size: .75em; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 10px 6px; }
.room {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border-radius: 12px;
  border: 0; background: transparent; text-align: left;
}
.room:hover { background: var(--panel-2); }
.room.on { background: var(--accent-soft); }
.room .av { flex: none; }
.room .meta { flex: 1; min-width: 0; }
.room .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room .sub { font-size: .84em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--badge); color: #fff; border-radius: 999px; font-size: .75em; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; display: inline-grid; place-items: center; }
.pill { font-size: .72em; font-weight: 650; padding: .1em .55em; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.pill.warn { background: #fff3cd; color: #7a5300; }
.pill.bot { background: var(--bot); color: #6b46c1; }
.side-foot { padding: 10px; border-top: 1px solid var(--line); padding-bottom: calc(10px + var(--safe-b)); }
.side-foot .btn { width: 100%; }
.extra-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin-top: 10px; font-size: .9em; }
.extra-links a { color: var(--muted); text-decoration: none; font-weight: 600; }
.extra-links a:hover { color: var(--text); text-decoration: underline; }
.av {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .95em;
  color: #fff; background: var(--accent); user-select: none;
}
.av.sm { width: 30px; height: 30px; font-size: .78em; }
.av.av-hash { border-radius: 12px; }
.av.av-hash svg { width: 22px; height: 22px; }
.av.sm.av-hash svg { width: 16px; height: 16px; }

.req { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 6px 4px; background: var(--panel); }
.req .t { font-weight: 650; }
.req .d { font-size: .86em; color: var(--muted); margin: .2em 0 .6em; }
.req .row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Chat ---------- */
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chat-head {
  display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-t)) 8px 8px 8px;
  background: var(--panel); border-bottom: 1px solid var(--line); min-height: 60px;
}
.chat-head .back { display: none; }
.chat-head .meta { flex: 1; min-width: 0; padding-left: 4px; }
.chat-head .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .sub { font-size: .82em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msgs { flex: 1; overflow-y: auto; padding: 12px 12px 4px; overscroll-behavior: contain; }
.msgs-inner { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; }
.empty { color: var(--muted); text-align: center; margin: 15vh auto; max-width: 340px; }
.day { align-self: center; font-size: .78em; color: var(--muted); background: var(--panel); border-radius: 999px; padding: .2em .8em; margin: 14px 0 8px; box-shadow: var(--shadow); }
.sys { align-self: center; font-size: .84em; color: var(--muted); text-align: center; margin: 6px 16px; max-width: 520px; }
.msg { display: flex; gap: 8px; margin-top: 2px; max-width: min(78%, 640px); align-items: flex-end; position: relative; }
.msg.first { margin-top: 10px; }
.msg .av { visibility: hidden; }
.msg.last .av { visibility: visible; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.mine .av { display: none; }
.bubble {
  background: var(--theirs); border-radius: 16px; padding: 7px 11px 6px; box-shadow: var(--shadow);
  min-width: 60px; overflow-wrap: anywhere; position: relative;
}
.msg.mine .bubble { background: var(--mine); }
.msg.bot .bubble { background: var(--bot); }
.msg.first:not(.mine) .bubble { border-top-left-radius: 6px; }
.msg.first.mine .bubble { border-top-right-radius: 6px; }
.bubble .who { font-size: .8em; font-weight: 700; color: var(--accent); margin-bottom: 1px; display: flex; gap: .4em; align-items: center; }
.bubble .text { white-space: pre-wrap; }
.bubble .time { font-size: .7em; color: var(--muted); float: right; margin: 6px 0 -2px 10px; }
.bubble.deleted .text { font-style: italic; color: var(--muted); }
.bubble img.pic { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; margin: 2px 0 4px; cursor: zoom-in; background: var(--panel-2); }
.bubble video, .bubble audio { display: block; max-width: 100%; border-radius: 10px; margin: 2px 0 4px; }
.file-card { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--panel-2); text-decoration: none; color: inherit; margin: 2px 0 4px; }
.file-card .ic { width: 36px; height: 36px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: .7em; font-weight: 800; flex: none; text-transform: uppercase; }
.file-card .fn { font-weight: 600; word-break: break-all; }
.file-card .fs { font-size: .8em; color: var(--muted); }
.msg .tools { position: absolute; top: -12px; display: none; gap: 2px; background: var(--panel); border-radius: 999px; box-shadow: var(--shadow); padding: 2px; z-index: 2; }
.msg:not(.mine) .tools { right: -8px; }
.msg.mine .tools { left: -8px; }
.msg:hover .tools, .msg.show-tools .tools { display: flex; }
.msg .tools button { border: 0; background: transparent; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.msg .tools button:hover { background: var(--panel-2); color: var(--danger); }
.msg .tools svg { width: 16px; height: 16px; }
.typing { font-size: .84em; color: var(--muted); padding: 2px 16px 4px; min-height: 1.6em; max-width: 860px; margin: 0 auto; width: 100%; }
.typing .dots::after { content: "…"; animation: dots 1.2s steps(3, end) infinite; display: inline-block; width: 1em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1em; } }
.more { align-self: center; margin: 4px 0 10px; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 8px calc(8px + var(--safe-b)); }
.composer-inner { max-width: 860px; margin: 0 auto; display: flex; gap: 6px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 40vh; min-height: 44px; border-radius: 22px; padding: .6em 1em; line-height: 1.35; }
.composer .send { background: var(--accent); color: var(--accent-ink); }
.composer .send:hover { background: var(--accent); filter: brightness(1.08); color: var(--accent-ink); }
.composer .send:disabled { opacity: .5; }
.composer .blocked { color: var(--muted); text-align: center; padding: 8px; }
.upload-bar { max-width: 860px; margin: 0 auto 6px; font-size: .85em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.upload-bar progress { flex: 1; height: 6px; accent-color: var(--accent); }
.suggest { max-width: 860px; margin: 0 auto 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.suggest button { border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: .2em .8em; }
.dropzone { position: fixed; inset: 0; background: color-mix(in srgb, var(--accent) 18%, transparent); border: 3px dashed var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 1.3em; z-index: 50; pointer-events: none; }

/* ---------- Dialoge ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; background: var(--panel); color: var(--text);
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 16, 15, .45); }
.dlg { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.dlg-head { display: flex; align-items: center; gap: 8px; padding: 14px 10px 10px 20px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 1.15em; flex: 1; }
.dlg-body { padding: 16px 20px; overflow-y: auto; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); flex-wrap: wrap; }
.section { margin: 0 0 1.4em; }
.section h3 { font-size: .8em; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .6em; }
.list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; }
.list .item .grow { flex: 1; min-width: 0; }
.list .item .small { font-size: .82em; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); border-radius: 999px; padding: .15em .3em .15em .7em; font-size: .9em; }
.chip button { border: 0; background: transparent; width: 22px; height: 22px; border-radius: 50%; color: var(--muted); }
.note { background: var(--panel-2); border-radius: 12px; padding: 10px 12px; font-size: .9em; color: var(--muted); margin-bottom: 1em; }
.switch { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 100; display: grid; place-items: center; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lightbox .bar { position: fixed; top: calc(8px + var(--safe-t)); right: 8px; display: flex; gap: 6px; }
.lightbox .bar a, .lightbox .bar button { background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 999px; padding: .5em 1em; text-decoration: none; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6em 1.1em; border-radius: 999px; z-index: 200; box-shadow: var(--shadow); max-width: calc(100vw - 32px); text-align: center; }

/* ---------- Handy ---------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .shell .pane { display: none; }
  .shell.in-room .side { display: none; }
  .shell.in-room .pane { display: flex; }
  .chat-head .back { display: inline-grid; }
  .msg { max-width: 88%; }
  .msgs { padding: 8px 8px 4px; }
}
@media (min-width: 761px) {
  .shell:not(.in-room) .pane .chat-head, .shell:not(.in-room) .pane .composer { visibility: hidden; }
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bubble .who { filter: brightness(1.7) saturate(.8); } }
:root[data-theme="dark"] .bubble .who { filter: brightness(1.7) saturate(.8); }

/* Einladen */
.invite-box { text-align: center; padding: 1em; margin: 0 0 1em; border-radius: 14px; background: var(--accent-soft); }
.invite-box p { margin: .6em 0 .8em; }
.invite-code { font-size: 1.6em; font-weight: 700; letter-spacing: .03em; word-break: break-word; user-select: all; }
.invite-qr { display: block; width: 200px; max-width: 70%; height: auto; margin: .8em auto 0; padding: 8px; background: #fff; border-radius: 10px; image-rendering: pixelated; }
.invite-code.small-code { font-size: 1em; white-space: nowrap; }
