/* ============================================================ Treffpunkt */
:root {
  --bg: #f4f1ea;
  --surface: #fbfaf7;
  --surface-2: #efebe3;
  --hover: #ebe6dc;
  --ink: #23211d;
  --muted: #857e73;
  --line: #e3ddd1;
  --accent: #2e5e4e;
  --accent-ink: #f7f5ef;
  --accent-soft: #dde8e1;
  --mine: #2e5e4e;
  --mine-ink: #f6f4ee;
  --theirs: #ffffff;
  --theirs-line: #e6e0d5;
  --warm: #d9a57b;
  --danger: #b04a32;
  --danger-soft: #f6e2db;
  --shadow: 0 1px 2px rgba(40, 32, 20, .06), 0 8px 30px rgba(40, 32, 20, .08);
  --radius: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412;
    --surface: #1b1a18;
    --surface-2: #23221f;
    --hover: #2a2925;
    --ink: #ece7dd;
    --muted: #9b9488;
    --line: #2e2c28;
    --accent: #8fc4ad;
    --accent-ink: #12201a;
    --accent-soft: #22322b;
    --mine: #2f5a4b;
    --mine-ink: #eef3ee;
    --theirs: #24231f;
    --theirs-line: #2f2d29;
    --warm: #d9a57b;
    --danger: #e3866b;
    --danger-soft: #3a231c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141412; --surface: #1b1a18; --surface-2: #23221f; --hover: #2a2925;
  --ink: #ece7dd; --muted: #9b9488; --line: #2e2c28; --accent: #8fc4ad; --accent-ink: #12201a;
  --accent-soft: #22322b; --mine: #2f5a4b; --mine-ink: #eef3ee; --theirs: #24231f;
  --theirs-line: #2f2d29; --danger: #e3866b; --danger-soft: #3a231c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ Logo */
.mark { position: relative; width: 44px; height: 30px; display: inline-block; }
.mark span { position: absolute; top: 0; width: 30px; height: 30px; border-radius: 50%; }
.mark span:first-child { left: 0; background: var(--accent); }
.mark span:last-child { right: 0; background: var(--warm); opacity: .85; mix-blend-mode: multiply; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .mark span:last-child { mix-blend-mode: screen; opacity: .7; } }
.mark.sm { width: 24px; height: 16px; margin-right: 9px; vertical-align: -2px; }
.mark.sm span { width: 16px; height: 16px; }
.mark.lg { width: 74px; height: 50px; }
.mark.lg span { width: 50px; height: 50px; }

.brand, .brand-sm { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; }

/* ------------------------------------------------------------ Buttons & Felder */
.btn {
  border: 0; border-radius: 999px; padding: 11px 20px; font-weight: 600;
  background: var(--surface-2); color: var(--ink); transition: background .15s, transform .05s, opacity .15s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: transparent; color: var(--ink); transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.accent { background: var(--accent); color: var(--accent-ink); }
.icon-btn.accent:hover { filter: brightness(1.07); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; }
.field input, .input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ------------------------------------------------------------ Anmeldung */
.auth { min-height: 100%; display: grid; place-items: center; padding: 40px 16px; }
.auth-inner { width: 100%; max-width: 380px; text-align: center; }
.auth .brand { font-size: 40px; margin: 18px 0 4px; }
.tagline { color: var(--muted); margin: 0 0 28px; }
.tabs { display: inline-flex; background: var(--surface-2); padding: 4px; border-radius: 999px; margin-bottom: 16px; }
.tabs button { border: 0; background: transparent; padding: 8px 18px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.card { background: var(--surface); border-radius: 22px; padding: 24px; box-shadow: var(--shadow); text-align: left; }
.auth .reg { display: none; }
.auth.register .reg { display: block; }
.hint { font-size: 13px; color: var(--muted); margin: -6px 2px 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 0; margin: 0 2px 12px; }
.error:empty { display: none; }
.fineprint { color: var(--muted); font-size: 13px; margin: 18px 10px 0; }

/* ------------------------------------------------------------ Layout */
.app { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.side { min-width: 0; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 12px 20px; }
.brand-sm { font-size: 21px; }

.list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.item {
  min-width: 0;
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border: 0;
  border-radius: 14px; background: transparent; text-align: left; transition: background .12s;
}
.item:hover { background: var(--surface-2); }
.item.on { background: var(--accent-soft); }
.item .txt { flex: 1; min-width: 0; }
.item .row { display: flex; align-items: baseline; gap: 8px; }
.item .nm { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .tm { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.item .pv { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.item .badge {
  background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: grid; place-items: center;
}
.item.unread .nm, .item.unread .pv { color: var(--ink); }

.side-empty { padding: 30px 24px; text-align: center; color: var(--muted); flex: 1; }

.me {
  display: flex; align-items: center; gap: 10px; margin: 8px; padding: 10px 12px; border: 0;
  border-radius: 14px; background: transparent; text-align: left;
}
.me:hover { background: var(--surface-2); }
.me-name { flex: 1; font-weight: 600; }
.me .dots { color: var(--muted); }
.me .dots circle { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------ Avatare */
.avatar {
  --av: #cfc6b8;
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: var(--av); color: #2a2620; font-weight: 700; font-size: 16px; user-select: none;
}
.avatar.group { border-radius: 14px; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.xs { width: 26px; height: 26px; font-size: 11px; }
.avatar.lg { width: 72px; height: 72px; font-size: 28px; }

/* ------------------------------------------------------------ Chat */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.welcome { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.welcome h2 { font-family: var(--serif); color: var(--ink); font-weight: 600; font-size: 26px; margin: 18px 0 6px; }
.welcome p { margin: 0; }

.offline {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5;
  background: var(--ink); color: var(--bg); font-size: 13px; padding: 6px 14px; border-radius: 999px;
}

.chat-head {
  display: flex; align-items: center; gap: 6px; padding: 10px 16px; min-height: 66px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.chat-head .back { display: none; }
.chat-title {
  display: flex; align-items: center; gap: 12px; border: 0; background: transparent;
  padding: 6px 10px 6px 6px; border-radius: 14px; text-align: left; min-width: 0;
}
.chat-title:hover { background: var(--surface-2); }
.titles { display: flex; flex-direction: column; min-width: 0; }
.titles .name { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.titles .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scroll { flex: 1; overflow-y: auto; min-height: 0; }
.messages { max-width: 760px; margin: 0 auto; padding: 18px 18px 8px; display: flex; flex-direction: column; }

.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 4px 12px; border-radius: 999px; margin: 18px 0 10px; }
.notice { align-self: center; text-align: center; font-size: 13px; color: var(--muted); max-width: 440px; margin: 10px 0 14px; }
.notice.warn { color: var(--danger); background: var(--danger-soft); padding: 10px 14px; border-radius: 14px; }

.msg { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; max-width: 78%; }
.msg.cont { margin-top: 3px; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar { visibility: hidden; }
.msg.last .avatar { visibility: visible; }
.msg.mine .avatar { display: none; }
.msg.dm .avatar { display: none; }
.bubble {
  background: var(--theirs); border: 1px solid var(--theirs-line); padding: 8px 13px 6px;
  border-radius: var(--radius); border-bottom-left-radius: 6px; min-width: 0;
}
.msg.cont .bubble { border-top-left-radius: 6px; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-ink); border-color: transparent; border-radius: var(--radius); border-bottom-right-radius: 6px; }
.msg.mine.cont .bubble { border-top-right-radius: 6px; }
.bubble .who { font-size: 12.5px; font-weight: 700; margin-bottom: 1px; }
.bubble .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.bubble .meta { font-size: 11px; opacity: .6; text-align: right; margin-top: 2px; user-select: none; }
.msg.pending .bubble { opacity: .6; }
.msg.bad .bubble { font-style: italic; color: var(--muted); }

.composer { padding: 10px 16px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.composer-inner {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 26px; padding: 6px 6px 6px 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .03); transition: border-color .15s, box-shadow .15s;
}
.composer-inner:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; border: 0; outline: none; background: transparent; resize: none;
  padding: 9px 0; max-height: 160px; line-height: 1.4;
}
.send {
  width: 40px; height: 40px; border-radius: 50%; border: 0; flex-shrink: 0; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); transition: transform .1s, opacity .15s;
}
.send:active { transform: scale(.94); }
.send:disabled { opacity: .35; cursor: default; }

/* ------------------------------------------------------------ Dialoge */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 20; background: rgba(20, 18, 14, .38);
  display: grid; place-items: center; padding: 16px; animation: fade .15s ease;
}
.sheet {
  width: 100%; max-width: 420px; max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--surface); border-radius: 24px; padding: 24px; box-shadow: var(--shadow);
  animation: rise .18s ease;
}
.sheet h3 { font-family: var(--serif); font-weight: 600; font-size: 22px; margin: 0 0 4px; }
.sheet .lead { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.sheet .center { text-align: center; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.sheet .stack { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.sheet .section { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }

.pick { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.pick button, .pick .row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px; border: 0;
  border-radius: 12px; background: transparent; text-align: left;
}
.pick button:hover { background: var(--surface-2); }
.pick .nm { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pick .small { font-size: 13px; color: var(--muted); font-weight: 400; }
.check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center;
  color: transparent; transition: all .12s; flex-shrink: 0;
}
.check svg { width: 14px; height: 14px; stroke-width: 3; }
.pick .sel .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.verified { color: var(--accent); font-size: 13px; font-weight: 600; }

.code {
  font: 600 22px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .06em;
  background: var(--surface-2); border-radius: 16px; padding: 16px; text-align: center; margin: 16px 0;
  word-spacing: .3em;
}
.linkbox { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-weight: 600; word-break: break-all; margin: 8px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px;
  transition: opacity .2s, transform .2s; z-index: 30; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

/* ------------------------------------------------------------ Handy */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .chat { display: none; }
  .app.in-chat .side { display: none; }
  .app.in-chat .chat { display: flex; }
  .chat-head { padding: 8px 8px; min-height: 60px; }
  .chat-head .back { display: grid; }
  .msg { max-width: 88%; }
  .messages { padding: 14px 12px 6px; }
  .composer { padding: 8px 10px 10px; }
  .sheet-wrap { place-items: end center; padding: 0; }
  .sheet { border-radius: 24px 24px 0 0; max-height: 88dvh; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Feinschliff */
.sheet .center .avatar { margin: 0 auto; }
.code { font-size: 19px; white-space: nowrap; letter-spacing: .04em; word-spacing: .2em; }
body { overflow-x: hidden; }
