:root {
  --brand: #D9682A; --brand-dark: #B5501B; --brand-soft: #FDE7D3;
  --bg: #FFFFFF; --bg-alt: #F6F1EB; --chat-bg: #F3ECE3; --text: #241D18; --muted: #7C7067;
  --line: #E8DFD5; --in: #FFFFFF; --out: #FFDDBE; --ok: #2E9E5B; --danger: #D0392B; --read: #1B8FD6;
  --shadow: 0 1px 2px rgba(36, 29, 24, .14);
  --top: env(safe-area-inset-top, 0px); --bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191512; --bg-alt: #221C18; --chat-bg: #120F0D; --text: #F3EBE4; --muted: #A3968B;
    --line: #322A24; --in: #272019; --out: #6E3A14; --brand-soft: #3A2414; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.hidden { display: none !important; }
#app { height: 100%; }
#app.boot { display: grid; place-items: center; background: var(--bg); }
#app.boot img { border-radius: 22px; }

/* Icons & Buttons */
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ibtn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: inherit; flex: none; }
.ibtn:active { background: rgba(127, 127, 127, .2); }
.btn { display: block; width: 100%; padding: 13px 18px; border-radius: 12px; background: var(--brand); color: #fff; font-weight: 600; text-align: center; }
.btn:active { background: var(--brand-dark); }
.btn[disabled] { opacity: .55; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field textarea { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-alt); }
.hint { font-size: 13px; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

/* Onboarding */
.welcome { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(28px + var(--top)) 24px calc(28px + var(--bottom)); background: linear-gradient(180deg, var(--brand-soft), var(--bg) 46%); }
.welcome .card { width: 100%; max-width: 400px; }
.welcome img { width: 104px; height: 104px; border-radius: 24px; display: block; margin: 0 auto 14px; box-shadow: 0 8px 24px rgba(181, 80, 27, .3); }
.welcome h1 { text-align: center; margin: 0; font-size: 32px; letter-spacing: -.5px; }
.welcome .tag { text-align: center; color: var(--muted); margin: 6px 0 26px; }
.welcome .facts { list-style: none; padding: 0; margin: 22px 0 0; font-size: 13px; color: var(--muted); }
.welcome .facts li { padding-left: 22px; position: relative; margin-bottom: 6px; }
.welcome .facts li::before { content: "🔒"; position: absolute; left: 0; font-size: 12px; }
details.adv { margin-bottom: 14px; }
details.adv summary { color: var(--muted); font-size: 13px; cursor: pointer; margin-bottom: 8px; }

/* Shell */
.shell { height: 100%; display: flex; background: var(--bg); }
.pane { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.list-pane { width: 100%; }
.chat-pane { width: 100%; display: none; background: var(--chat-bg); }
.shell.show-chat .list-pane { display: none; }
.shell.show-chat .chat-pane { display: flex; }
@media (min-width: 820px) {
  .list-pane { width: 360px; flex: none; border-right: 1px solid var(--line); }
  .chat-pane, .shell.show-chat .list-pane { display: flex; }
  .chat-pane { flex: 1; }
  .only-mobile { display: none !important; }
}
.bar { display: flex; align-items: center; gap: 4px; padding: calc(6px + var(--top)) 6px 6px; background: var(--brand); color: #fff; flex: none; min-height: calc(56px + var(--top)); }
.bar h1 { font-size: 20px; margin: 0 0 0 8px; flex: 1; display: flex; align-items: center; gap: 10px; }
.bar h1 img { width: 30px; height: 30px; border-radius: 8px; }
.bar .who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left; color: inherit; padding: 4px; border-radius: 10px; }
.bar .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .who small { display: block; font-size: 12.5px; opacity: .88; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 17px; }
.conn { font-size: 12.5px; text-align: center; padding: 4px; background: #5c5148; color: #fff; }
.search { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; padding: 9px 14px; border-radius: 20px; border: 0; background: var(--bg-alt); }

/* Avatare */
.av { width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 19px; overflow: hidden; position: relative; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.sm { width: 38px; height: 38px; font-size: 15px; }
.av.lg { width: 108px; height: 108px; font-size: 42px; margin: 0 auto; }
.dot { position: absolute; }
.online-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid var(--bg); margin: -12px 0 0 36px; flex: none; position: relative; }

/* Chatliste */
.chats { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chat-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.chat-item:active, .chat-item.active { background: var(--bg-alt); }
.chat-item .mid { flex: 1; min-width: 0; }
.chat-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .prev { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .right { text-align: right; flex: none; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.badge { background: var(--brand); color: #fff; border-radius: 11px; min-width: 22px; height: 22px; padding: 0 6px; display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; }
.empty { padding: 48px 28px; text-align: center; color: var(--muted); }
.empty img { width: 72px; border-radius: 18px; opacity: .9; margin-bottom: 12px; }
.fab { position: absolute; right: 18px; bottom: calc(18px + var(--bottom)); width: 58px; height: 58px; border-radius: 18px; background: var(--brand); color: #fff; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0, 0, 0, .28); }
.list-pane { position: relative; }
.menu { position: absolute; right: 8px; top: calc(52px + var(--top)); background: var(--bg); color: var(--text); border-radius: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, .28); z-index: 5; overflow: hidden; min-width: 200px; }
.menu button { display: block; width: 100%; text-align: left; padding: 14px 18px; }
.menu button:active { background: var(--bg-alt); }

/* Nachrichten */
.msgs { flex: 1; overflow-y: auto; padding: 10px 10px 6px; display: flex; flex-direction: column; gap: 3px; -webkit-overflow-scrolling: touch; }
.e2e-note { align-self: center; background: var(--brand-soft); color: var(--text); font-size: 12.5px; padding: 7px 12px; border-radius: 10px; margin: 4px 16px 10px; text-align: center; max-width: 420px; }
.sys { align-self: center; background: var(--bg); color: var(--muted); font-size: 12.5px; padding: 4px 10px; border-radius: 9px; margin: 5px 0; box-shadow: var(--shadow); text-align: center; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--bg); padding: 3px 10px; border-radius: 9px; margin: 8px 0 4px; box-shadow: var(--shadow); }
.msg { max-width: min(82%, 560px); padding: 6px 9px 5px; border-radius: 12px; background: var(--in); align-self: flex-start; box-shadow: var(--shadow); position: relative; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg .sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; }
.msg .meta { float: right; font-size: 11px; color: var(--muted); margin: 6px 0 -2px 10px; display: flex; align-items: center; gap: 3px; }
.msg .meta .icon { width: 15px; height: 15px; }
.msg .meta .read { color: var(--read); }
.msg .meta .failed { color: var(--danger); }
.msg .media { display: block; max-width: 100%; width: 260px; border-radius: 9px; margin-bottom: 3px; background: var(--bg-alt); min-height: 80px; object-fit: cover; max-height: 340px; }
.msg audio { width: 240px; max-width: 100%; display: block; }
.msg .filebox { display: flex; align-items: center; gap: 10px; padding: 6px 4px; text-align: left; color: inherit; width: 100%; }
.msg .filebox .fi { width: 40px; height: 40px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; }
.msg .filebox b { display: block; font-weight: 600; font-size: 14.5px; }
.msg .filebox small { color: var(--muted); }
.more { align-self: center; color: var(--brand); padding: 8px; font-size: 14px; }

/* Eingabe */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 6px 8px calc(6px + var(--bottom)); background: var(--bg); border-top: 1px solid var(--line); flex: none; }
.composer textarea { flex: 1; resize: none; border: 0; background: var(--bg-alt); border-radius: 22px; padding: 11px 16px; max-height: 130px; min-height: 44px; }
.composer .send { background: var(--brand); color: #fff; }
.composer .rec { flex: 1; display: flex; align-items: center; gap: 10px; padding: 0 12px; min-height: 44px; color: var(--danger); font-variant-numeric: tabular-nums; }
.composer .rec i { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.left-note { padding: 14px; text-align: center; color: var(--muted); background: var(--bg); border-top: 1px solid var(--line); font-size: 14px; }
.placeholder { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 30px; }
.placeholder img { width: 110px; border-radius: 26px; margin-bottom: 14px; }

/* Dialoge */
#overlay:empty { display: none; }
#overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 480px; max-height: 92%; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 8px 20px calc(22px + var(--bottom)); }
@media (min-width: 620px) { #overlay { align-items: center; } .sheet { border-radius: 20px; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; position: sticky; top: -8px; background: var(--bg); padding: 8px 0; z-index: 1; }
.sheet h2 { margin: 0; font-size: 19px; }
.sheet .center { text-align: center; margin-bottom: 16px; }
.sheet .center h3 { margin: 10px 0 0; }
.sheet .stack { display: grid; gap: 10px; margin-top: 16px; }
.safety { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--bg-alt); border-radius: 12px; padding: 12px; text-align: center; letter-spacing: 1px; font-size: 15px; line-height: 1.8; }
.row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.row .grow { flex: 1; min-width: 0; }
.row small { color: var(--muted); display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { background: var(--brand-soft); border-radius: 16px; padding: 5px 10px; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.pick { display: flex; align-items: center; gap: 12px; width: 100%; padding: 7px 0; text-align: left; }
.pick input { width: 20px; height: 20px; accent-color: var(--brand); }
.avatar-edit { position: relative; width: 108px; margin: 0 auto; display: block; }
.avatar-edit .cam { position: absolute; right: -4px; bottom: -4px; width: 38px; height: 38px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; border: 3px solid var(--bg); }
.viewer { position: fixed; inset: 0; background: #000; z-index: 30; display: flex; flex-direction: column; }
.viewer .vbar { display: flex; justify-content: space-between; color: #fff; padding: calc(6px + var(--top)) 6px 6px; }
.viewer img, .viewer video { flex: 1; min-height: 0; width: 100%; object-fit: contain; }

/* Anruf */
#call:empty { display: none; }
#call { position: fixed; inset: 0; z-index: 40; background: #1b1512; color: #fff; display: flex; flex-direction: column; align-items: center; }
#call video.remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
#call video.local { position: absolute; right: 14px; top: calc(14px + var(--top)); width: 104px; height: 150px; object-fit: cover; border-radius: 14px; z-index: 2; background: #000; box-shadow: 0 4px 14px rgba(0, 0, 0, .5); transform: scaleX(-1); }
#call video.local.back { transform: none; }
#call .info { position: relative; z-index: 1; text-align: center; margin-top: calc(64px + var(--top)); text-shadow: 0 1px 6px rgba(0, 0, 0, .7); }
#call .info h2 { margin: 14px 0 4px; font-size: 26px; }
#call .info p { margin: 0; opacity: .85; }
#call .info .lock { font-size: 12.5px; opacity: .7; margin-top: 8px; }
#call .controls { position: absolute; bottom: calc(34px + var(--bottom)); left: 0; right: 0; z-index: 2; display: flex; justify-content: center; gap: 18px; }
#call .cbtn { width: 62px; height: 62px; border-radius: 50%; background: rgba(255, 255, 255, .2); color: #fff; display: grid; place-items: center; }
#call .cbtn.on { background: #fff; color: #1b1512; }
#call .cbtn.red { background: var(--danger); }
#call .cbtn.green { background: var(--ok); }
#call.has-video .info .av { display: none; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--bottom)); background: #2b2420; color: #fff; padding: 10px 16px; border-radius: 22px; font-size: 14px; z-index: 50; max-width: 86%; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: .96; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

#call:not(:empty) ~ #toast { bottom: calc(130px + var(--bottom)); }
.welcome .dl { margin-top: 18px; text-decoration: none; }
