:root {
  --bg: #f4efe6;
  --paper: #fffdf8;
  --ink: #2b2a27;
  --muted: #7a756b;
  --line: #e3dccf;
  --accent: #2f5d50;
  --accent-soft: #dfe9e4;
  --mine: #e6efe9;
  --danger: #a33a2b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1f1e; --paper: #262928; --ink: #ecebe6; --muted: #9c9a92; --line: #3a3e3c;
    --accent: #8fc1ad; --accent-soft: #2f3d38; --mine: #2c3a34; --danger: #e07a6a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); }

.bar {
  display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-top)) 12px 10px;
  border-bottom: 1px solid var(--line); background: var(--bg); flex-shrink: 0;
}
.bar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.icon-btn:active { background: var(--line); }
.icon-btn.on { background: var(--accent-soft); }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page { padding: 20px 16px calc(20px + var(--safe-bottom)); }

/* Formulare */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 18px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 18px; border-radius: 10px; background: var(--accent); color: var(--paper); font-weight: 600; }
.btn.secondary { background: var(--accent-soft); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; margin-top: 16px; }
.btn:disabled { opacity: .5; }
.tabs { display: flex; gap: 4px; background: var(--line); padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tabs button { flex: 1; padding: 8px; border-radius: 9px; font-size: 14px; }
.tabs button.active { background: var(--paper); font-weight: 600; }
.hint { font-size: 14px; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }
.brand { text-align: center; margin: 24px 0 20px; }
.brand img { width: 64px; height: 64px; border-radius: 16px; }
.brand h1 { font-size: 22px; margin: 10px 0 4px; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 18px; background: var(--bg); padding: 10px; border-radius: 8px; text-align: center; user-select: all; margin: 8px 0; }

/* Liste */
.conv { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.conv:active { background: var(--line); }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--accent-soft); color: var(--accent); flex-shrink: 0; }
.conv .body { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .name { font-weight: 600; }
.conv .time { font-size: 13px; color: var(--muted); }
.conv .preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.new .name::after { content: " · neu"; font-weight: 400; font-size: 13px; color: var(--accent); }
.section { padding: 14px 16px 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Chat */
.messages { padding: 12px 10px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.msg { max-width: 82%; align-self: flex-start; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; position: relative; }
.msg.mine { align-self: flex-end; background: var(--mine); border-color: transparent; }
.msg .who { font-size: 13px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .meta { display: flex; gap: 8px; justify-content: flex-end; align-items: center; font-size: 12px; color: var(--muted); margin-top: 4px; }
.msg .more { font-size: 16px; line-height: 1; padding: 2px 4px; color: var(--muted); }
.msg.pinned { border-color: var(--accent); }
.media-btn { display: flex; align-items: center; gap: 10px; padding: 6px 2px; min-width: 180px; }
.media-btn .play { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: var(--paper); display: grid; place-items: center; font-size: 16px; }
.msg audio { width: 240px; max-width: 100%; display: block; }
.msg video { width: 260px; max-width: 100%; border-radius: 10px; display: block; background: #000; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + var(--safe-bottom)); border-top: 1px solid var(--line); background: var(--bg); flex-shrink: 0; }
.composer textarea { flex: 1; resize: none; max-height: 140px; min-height: 42px; border-radius: 21px; padding: 10px 14px; }
.composer .icon-btn { background: var(--accent-soft); }
.composer .send { background: var(--accent); color: var(--paper); }
.ttl-chip { font-size: 12px; padding: 4px 8px; border-radius: 10px; background: var(--accent-soft); white-space: nowrap; align-self: center; }

.recording { display: flex; align-items: center; gap: 10px; flex: 1; padding: 0 8px; min-height: 42px; }
.recording .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* Video-Aufnahme */
.overlay { position: fixed; inset: 0; background: #000; z-index: 20; display: flex; flex-direction: column; }
.overlay video { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.overlay video.mirror { transform: scaleX(-1); }
.overlay .controls { display: flex; align-items: center; justify-content: space-around; padding: 18px 12px calc(18px + var(--safe-bottom)); color: #fff; }
.overlay .controls button { color: #fff; font-size: 16px; }
.overlay .top { position: absolute; top: calc(12px + var(--safe-top)); left: 0; right: 0; text-align: center; color: #fff; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px #000; }
.rec-btn { width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff !important; display: grid; place-items: center; }
.rec-btn span { width: 54px; height: 54px; border-radius: 50%; background: #e0412f; transition: all .2s; }
.rec-btn.active span { width: 28px; height: 28px; border-radius: 6px; }

/* Aktionsmenü */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--paper); width: 100%; max-width: 720px; border-radius: 18px 18px 0 0; padding: 8px 0 calc(8px + var(--safe-bottom)); }
.sheet button { display: block; width: 100%; text-align: left; padding: 14px 20px; font-size: 17px; }
.sheet button.danger { color: var(--danger); }
.sheet .title { padding: 10px 20px; font-size: 14px; color: var(--muted); }

.member-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.member-row:last-child { border-bottom: 0; }
.member-row .info { flex: 1; min-width: 0; }
.member-row .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--accent-soft); margin-left: 6px; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 40; max-width: 90%; }
