:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --tile: #eeeef3;
  --sep: rgba(0, 0, 0, 0.09);
  --ink: #000000;
  --ink2: #6c6c70;
  --ink3: #8e8e93;
  --accent: #e5254b;
  --on-accent: #ffffff;
  --in: #ffffff;
  --good: #1f9d4d;
  --danger: #d70015;
  --backdrop: rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --tile: #2c2c2e;
    --sep: rgba(255, 255, 255, 0.09);
    --ink: #ffffff;
    --ink2: #98989f;
    --ink3: #636366;
    --accent: #ff375f;
    --in: #2c2c2e;
    --good: #30d158;
    --danger: #ff453a;
    --backdrop: rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.fill { fill: currentColor; stroke: none; }

/* ---------- Layout ---------- */
#app { height: 100dvh; display: grid; grid-template-columns: minmax(330px, 390px) 1fr; }
#app.auth { display: block; overflow-y: auto; }
.side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--sep); padding-top: env(safe-area-inset-top); }
.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; padding-top: env(safe-area-inset-top); }
@media (max-width: 760px) {
  #app { display: block; }
  .side, .main { height: 100dvh; border: 0; }
  .main { display: none; }
  #app.chat-open .side { display: none; }
  #app.chat-open .main { display: flex; }
}

/* ---------- Seitenleiste ---------- */
.side-head { padding: 14px 20px 6px; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin: 0; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--ink); background: var(--surface); }
.icon-btn:hover { background: var(--tile); }
.icon-btn.plain { background: none; }
.icon-btn.plain:hover { background: var(--tile); }
.icon-btn.accent { background: var(--accent); color: var(--on-accent); }
.row-gap { display: flex; gap: 8px; }
.search { margin: 10px 20px 8px; }
.search input, .field input, .field textarea, .field select { width: 100%; border: 0; border-radius: 12px; background: var(--tile); padding: 11px 14px; outline: none; }
.search input { background: var(--surface); }
.search input::placeholder, .field input::placeholder, textarea::placeholder { color: var(--ink3); }
.list { flex: 1; overflow-y: auto; padding: 4px 12px calc(16px + env(safe-area-inset-bottom)); }
.card { background: var(--surface); border-radius: 22px; overflow: hidden; }
.list-section { font-size: 13px; color: var(--ink2); padding: 14px 10px 6px; font-weight: 600; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; position: relative; }
.item + .item::before { content: ''; position: absolute; top: 0; left: 70px; right: 0; border-top: 1px solid var(--sep); }
.item:hover, .item.active { background: var(--tile); }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--tile); color: var(--ink2); display: grid; place-items: center; font-size: 18px; font-weight: 600; flex: none; text-transform: uppercase; }
.item:hover .avatar, .item.active .avatar { background: var(--surface); }
.avatar.sm { width: 36px; height: 36px; font-size: 15px; }
.item-body { min-width: 0; flex: 1; }
.item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.item-name { font-weight: 600; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-time { font-size: 12px; color: var(--ink2); font-variant-numeric: tabular-nums; flex: none; }
.item-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.item-prev { font-size: 14px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 600; display: grid; place-items: center; font-variant-numeric: tabular-nums; flex: none; }
.empty { text-align: center; color: var(--ink2); padding: 48px 28px; font-size: 15px; line-height: 1.45; }
.empty strong { display: block; color: var(--ink); font-size: 20px; letter-spacing: -0.02em; margin-bottom: 6px; }

/* ---------- Chat ---------- */
.placeholder { margin: auto; text-align: center; color: var(--ink2); padding: 24px; }
.placeholder strong { display: block; font-size: 22px; letter-spacing: -0.02em; color: var(--ink); margin-bottom: 6px; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--sep); background: var(--bg); }
.chat-head .back { display: none; }
@media (max-width: 760px) { .chat-head .back { display: grid; } }
.chat-title { min-width: 0; flex: 1; text-align: left; }
.chat-title b { display: block; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title span { display: block; font-size: 13px; color: var(--ink2); min-height: 17px; }
.chat-title span.live { color: var(--accent); }
.msgs { flex: 1; overflow-y: auto; padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 2px; }
.day { align-self: center; font-size: 12px; color: var(--ink2); font-weight: 600; margin: 14px 0 8px; }
.sys { align-self: center; font-size: 13px; color: var(--ink2); margin: 8px 24px; text-align: center; }
.row { display: flex; flex-direction: column; max-width: min(78%, 560px); }
.row.own { align-self: flex-end; align-items: flex-end; }
.row.in { align-self: flex-start; align-items: flex-start; }
.row:not(.cont) { margin-top: 8px; }
.who { font-size: 12px; font-weight: 600; color: var(--ink2); margin: 0 12px 2px; }
.bubble { position: relative; padding: 8px 12px 7px; border-radius: 20px; background: var(--in); line-height: 1.35; font-size: 16px; letter-spacing: -0.005em; overflow-wrap: anywhere; white-space: pre-wrap; cursor: pointer; user-select: text; }
.own .bubble { background: var(--accent); color: var(--on-accent); }
.bubble .meta { display: block; text-align: right; font-size: 11px; opacity: 0.65; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: normal; }
.bubble.media { padding: 4px; }
.bubble.media .meta { padding: 0 8px 3px; }
.bubble.deleted { background: none; border: 1px solid var(--sep); color: var(--ink2); font-style: italic; cursor: default; }
.bubble img.pic { display: block; max-width: min(100%, 300px); max-height: 340px; width: auto; height: auto; border-radius: 16px; cursor: zoom-in; }
.expired { padding: 10px 12px; font-size: 14px; opacity: 0.8; font-style: italic; }
.quote { border-left: 3px solid color-mix(in srgb, currentColor 45%, transparent); padding: 1px 0 1px 8px; margin: 0 0 5px; font-size: 13px; opacity: 0.85; white-space: normal; }
.quote b { display: block; font-weight: 600; }
.quote span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.status { align-self: flex-end; font-size: 12px; color: var(--ink2); margin: 3px 6px 0; }
.file { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; padding: 4px 6px 4px 4px; min-width: 190px; white-space: normal; }
.file .ficon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, currentColor 14%, transparent); }
.file b { display: block; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.file small { font-size: 12px; opacity: 0.7; }
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 3px 6px 3px 3px; white-space: normal; }
.voice .play { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, currentColor 16%, transparent); color: inherit; }
.voice .track { flex: 1; height: 4px; border-radius: 2px; background: color-mix(in srgb, currentColor 22%, transparent); overflow: hidden; }
.voice .track i { display: block; height: 100%; width: 0; background: currentColor; border-radius: 2px; }
.voice time { font-size: 12px; font-variant-numeric: tabular-nums; opacity: 0.75; min-width: 34px; text-align: right; }
.pending { align-self: flex-end; width: 240px; margin-top: 8px; background: var(--in); border-radius: 18px; padding: 10px 12px; font-size: 14px; }
.pending .bar { height: 4px; border-radius: 2px; background: var(--tile); margin-top: 8px; overflow: hidden; }
.pending .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.more-btn { align-self: center; font-size: 14px; color: var(--accent); font-weight: 600; padding: 8px 14px; }

.reply-bar { display: flex; align-items: center; gap: 10px; margin: 0 12px; padding: 8px 12px; background: var(--surface); border-radius: 16px 16px 0 0; border-left: 3px solid var(--accent); font-size: 13px; }
.reply-bar div { flex: 1; min-width: 0; }
.reply-bar b { display: block; color: var(--accent); }
.reply-bar span { display: block; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
.composer .box { flex: 1; min-width: 0; background: var(--surface); border-radius: 22px; display: flex; align-items: flex-end; padding: 0 4px 0 14px; }
.composer textarea { flex: 1; min-width: 0; border: 0; outline: none; background: none; resize: none; padding: 11px 0; max-height: 140px; line-height: 1.3; }
.composer .icon-btn { background: none; color: var(--ink2); width: 40px; height: 40px; }
.composer .icon-btn:hover { background: var(--tile); }
.composer .send { background: var(--accent); color: var(--on-accent); width: 40px; height: 40px; flex: none; }
.composer .send:hover { background: var(--accent); filter: brightness(1.08); }
.rec { flex: 1; display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 22px; padding: 4px 4px 4px 16px; height: 48px; }
.rec .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s ease-in-out infinite; }
.rec time { font-variant-numeric: tabular-nums; flex: 1; font-weight: 600; }
@keyframes blink { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .rec .dot { animation: none; } }

/* ---------- Auth ---------- */
.auth-wrap { max-width: 400px; margin: 0 auto; padding: calc(56px + env(safe-area-inset-top)) 24px 40px; }
.auth-wrap .eyebrow { margin-bottom: 4px; }
.auth-wrap h1 { margin-bottom: 6px; }
.lead { color: var(--ink2); font-size: 15px; line-height: 1.45; margin: 0 0 22px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border-radius: 12px; padding: 3px; margin-bottom: 18px; }
.seg button { padding: 8px; border-radius: 10px; font-weight: 600; font-size: 15px; color: var(--ink2); }
.seg button.on { background: var(--tile); color: var(--ink); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--ink2); margin: 0 4px 6px; font-weight: 500; }
.field small { display: block; font-size: 12px; color: var(--ink3); margin: 6px 4px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 14px 18px; border-radius: 14px; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 16px; }
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: var(--tile); color: var(--ink); }
.btn.danger { background: none; color: var(--danger); }
.btn.sm { width: auto; padding: 8px 14px; font-size: 14px; border-radius: 12px; }
.err { color: var(--danger); font-size: 14px; margin: 0 4px 12px; min-height: 0; }
.link { color: var(--accent); font-size: 14px; font-weight: 500; padding: 10px 4px; }
.center { text-align: center; }
.code-box { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 24px; font-weight: 600; letter-spacing: 0.04em; text-align: center; background: var(--surface); border-radius: 18px; padding: 22px 12px; margin: 8px 0 16px; user-select: all; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; margin: 14px 2px; color: var(--ink2); }
.check input { margin-top: 3px; accent-color: var(--accent); }

/* ---------- Sheets ---------- */
.backdrop { position: fixed; inset: 0; background: var(--backdrop); display: flex; align-items: flex-end; justify-content: center; z-index: 20; animation: fade 0.15s ease-out; }
.sheet { background: var(--bg); width: 100%; max-width: 520px; max-height: 92dvh; border-radius: 22px 22px 0 0; display: flex; flex-direction: column; animation: rise 0.2s ease-out; }
@media (min-width: 761px) { .backdrop { align-items: center; } .sheet { border-radius: 22px; max-height: 86dvh; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .backdrop, .sheet { animation: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 22px; }
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-body > * + * { margin-top: 12px; }
.sheet-body .card + .card { margin-top: 12px; }
.pad { padding: 16px; }
.pad > * + * { margin-top: 12px; }
.line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; width: 100%; text-align: left; position: relative; }
.line + .line::before { content: ''; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--sep); }
button.line:hover { background: var(--tile); }
.line .l { min-width: 0; }
.line .l b { display: block; font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.line .l small { display: block; color: var(--ink2); font-size: 13px; margin-top: 1px; }
.line .r { color: var(--ink2); font-size: 14px; flex: none; }
.line.red b { color: var(--danger); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent); margin-left: 6px; vertical-align: 1px; }
.hint { color: var(--ink2); font-size: 13px; line-height: 1.4; margin: 6px 6px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--tile); border-radius: 14px; padding: 5px 6px 5px 11px; font-size: 14px; }
.chip button { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: var(--ink2); }
.qr { display: block; margin: 4px auto 12px; border-radius: 16px; background: #fff; max-width: 100%; }
.linkbox { font-size: 13px; color: var(--ink2); background: var(--tile); border-radius: 12px; padding: 10px 12px; overflow-wrap: anywhere; user-select: all; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.92); z-index: 40; display: grid; place-items: center; cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 14px; z-index: 60; max-width: 90vw; text-align: center; }
.menu { position: fixed; z-index: 30; min-width: 170px; background: var(--surface); border-radius: 16px; box-shadow: 0 0 0 1px var(--sep), 0 12px 40px rgba(0, 0, 0, 0.3); overflow: hidden; }
.menu button { display: block; width: 100%; text-align: left; padding: 12px 16px; font-size: 15px; }
.menu button + button { border-top: 1px solid var(--sep); }
.menu button:hover { background: var(--tile); }
.menu button.red { color: var(--danger); }

/* Sheets: eigene Fläche, damit sie sich vom abgedunkelten Hintergrund abheben */
.sheet { background: var(--surface); box-shadow: 0 0 0 1px var(--sep); }
.sheet .card { background: var(--tile); }
.sheet .item:hover, .sheet button.line:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.sheet .linkbox { background: var(--surface); }
.sheet .code-box { background: var(--tile); }
.sheet .field input, .sheet .field textarea, .sheet .field select { background: var(--tile); }
.sheet .card .field input { background: var(--surface); }
.sheet .btn.ghost { background: var(--tile); }
.sheet .card .btn.ghost { background: var(--surface); }
.sheet .chip { background: var(--tile); }
.sheet .hint.pad { padding: 14px 16px; margin: 0; }
.line .l small, .card.pad .hint { margin-left: 0; }
.card.pad > div > .hint { margin: 2px 0 0; }
