/* WLAN-Chat – Oberfläche. Dunkel im Stil der Apps-Seite, hell nach Systemeinstellung. Keine Webfonts (Systemschrift). */
:root {
  --bg: #0A1030; --bg2: #0E1640; --panel: #131C4A; --line: #222D63; --line2: #3A4894;
  --text: #EAEDFF; --muted: #9AA3D3; --dim: #6F79B0;
  --cyan: #5FE3F0; --magenta: #FF5AD1; --amber: #FFC65C; --green: #5BE0A0; --red: #FF7C8C;
  --me: #14506E; --me-text: #F2FCFF; --them: #131C4A; --shade: rgba(3, 6, 22, .62);
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #F2F4FB; --bg2: #FFFFFF; --panel: #FFFFFF; --line: #DCE1F3; --line2: #B8C1E4;
    --text: #141A3A; --muted: #58628F; --dim: #7C86AF;
    --cyan: #0A7F90; --magenta: #B3157F; --amber: #A66A00; --green: #0E8A55; --red: #C3283C;
    --me: #D4F1F6; --me-text: #0C2A33; --them: #FFFFFF; --shade: rgba(20, 26, 58, .45);
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  height: 100vh; height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
a { color: var(--cyan); }
.fine { margin: 10px 0 0; color: var(--muted); font-size: .8125rem; line-height: 1.45; }
.center { text-align: center; justify-content: center; }
.err { margin: 8px 0 0; color: var(--red); font-size: .9rem; }
.only-browser { }
@media (display-mode: standalone) { .only-browser { display: none !important; } }

.app { position: relative; height: 100vh; height: 100dvh; max-width: 760px; margin: 0 auto; overflow: hidden; }
@media (min-width: 761px) { .app { border-inline: 1px solid var(--line); } }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; padding: 0 18px; margin: 10px 0 0;
  border: 1px solid var(--line2); border-radius: 999px;
  background: transparent; color: var(--text); font-weight: 600;
  transition: background-color .15s, border-color .15s, transform .08s;
}
.btn:hover { border-color: var(--cyan); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.primary:hover { background: var(--cyan); border-color: var(--cyan); }
.btn.danger { color: var(--red); border-color: transparent; }
.btn.small { width: auto; min-height: 40px; padding: 0 16px; font-size: .9rem; }
.btn svg { width: 18px; height: 18px; flex: none; }
.link { border: 0; background: none; padding: 6px 2px; color: var(--cyan); font-weight: 600; font-size: .9rem; text-decoration: underline; text-underline-offset: 3px; }
.icon {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; color: var(--text);
}
.icon:hover { background: var(--panel); }
.icon svg { width: 22px; height: 22px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.row .btn { margin-top: 0; }

/* ---------- Willkommen ---------- */
.welcome { overflow-y: auto; padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom)); }
.welcome-inner { width: 100%; max-width: 420px; margin: auto; text-align: center; }
.logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: 0 8px 28px rgba(0, 0, 0, .35); }
.logo.small { width: 56px; height: 56px; border-radius: 14px; }
.welcome h1 { margin: 18px 0 8px; font-size: 2.1rem; line-height: 1.1; letter-spacing: -.02em; font-weight: 800; }
.lead { margin: 0 0 22px; color: var(--muted); }
.welcome form { text-align: left; }
.welcome label { display: block; margin-bottom: 6px; color: var(--muted); font-size: .875rem; font-weight: 600; }
input[type="text"], input:not([type]), textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line2); border-radius: 12px;
  background: var(--bg2); color: var(--text);
}
input:focus, textarea:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cyan) 25%, transparent); }
.offline-state { margin: 18px 0 4px; color: var(--muted); font-size: .8125rem; }
.offline-state.ok { color: var(--green); }
.welcome-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin-top: 6px; }
.back { display: inline-block; margin-top: 22px; font-size: .875rem; }

/* ---------- Chat: Kopfzeile ---------- */
.bar {
  display: flex; align-items: center; gap: 4px; flex: none;
  padding: max(8px, env(safe-area-inset-top)) 8px 8px 12px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
.who { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; border: 0; background: none; padding: 4px 6px; border-radius: 12px; text-align: left; }
.who:hover { background: var(--panel); }
.who-text { display: flex; flex-direction: column; min-width: 0; }
.who-text strong { font-size: 1.05rem; line-height: 1.2; }
.who-text small { color: var(--muted); font-size: .8125rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 12px; height: 12px; flex: none; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 4px color-mix(in srgb, var(--amber) 22%, transparent); transition: background-color .3s, box-shadow .3s; }
.dot.on { background: var(--green); box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 22%, transparent); }
.banner {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 12px;
  padding: 8px 14px; background: color-mix(in srgb, var(--amber) 14%, var(--bg)); color: var(--text);
  border-bottom: 1px solid color-mix(in srgb, var(--amber) 35%, transparent); font-size: .8125rem;
}

/* ---------- Chat: Verlauf ---------- */
.log-wrap { position: relative; flex: 1; min-height: 0; }
.log {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 2px;
  scroll-behavior: smooth;
}
.day, .sys { align-self: center; margin: 10px 0 6px; padding: 3px 12px; border-radius: 999px; background: var(--panel); color: var(--muted); font-size: .75rem; text-align: center; }
.sys { margin: 6px 0; }
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; margin-top: 8px; }
.msg.same { margin-top: 0; }
.msg.me { justify-content: flex-end; }
.av {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: hsl(var(--h, 210) 62% 46%); color: #fff; font-size: .8125rem; font-weight: 700; text-transform: uppercase;
}
.av.gap { visibility: hidden; }
.bub {
  position: relative; max-width: min(78%, 520px); padding: 7px 12px 6px; border-radius: 18px;
  background: var(--them); border: 1px solid var(--line); border-bottom-left-radius: 6px;
}
.msg.same:not(.me) .bub { border-top-left-radius: 6px; }
.msg.me .bub { background: var(--me); color: var(--me-text); border-color: transparent; border-bottom-left-radius: 18px; border-bottom-right-radius: 6px; }
.msg.me.same .bub { border-top-right-radius: 6px; }
.who-name { display: block; margin-bottom: 1px; color: hsl(var(--h, 190) 80% 72%); font-size: .78rem; font-weight: 700; }
@media (prefers-color-scheme: light) { .who-name { color: hsl(var(--h, 190) 62% 33%); } }
.txt { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.time { display: block; margin-top: 1px; text-align: right; color: var(--muted); font-size: .6875rem; font-variant-numeric: tabular-nums; }
.msg.me .time { color: color-mix(in srgb, var(--me-text) 62%, transparent); }
.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; pointer-events: none;
}
.empty > * { pointer-events: auto; }
.empty h2 { margin: 14px 0 6px; font-size: 1.25rem; }
.empty p { margin: 0 0 6px; max-width: 34ch; color: var(--muted); }
.to-bottom {
  position: absolute; right: 14px; bottom: 12px; display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px 8px 10px; border: 1px solid var(--line2); border-radius: 999px;
  background: var(--panel); color: var(--text); font-size: .8125rem; font-weight: 600; box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
}
.to-bottom svg { width: 16px; height: 16px; }

/* ---------- Chat: Eingabe ---------- */
.composer {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom)); background: var(--bg2); border-top: 1px solid var(--line);
}
.composer textarea { flex: 1; min-height: 44px; max-height: 132px; padding: 10px 14px; resize: none; border-radius: 22px; line-height: 1.35; font-size: 16px; }
.send {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--cyan); color: #04202A; transition: transform .08s, opacity .15s;
}
.send:active { transform: scale(.92); }
.send:disabled { opacity: .35; cursor: default; }
.send svg { width: 20px; height: 20px; }

/* ---------- Sheets ---------- */
dialog.sheet {
  width: 100%; max-width: 520px; max-height: 94vh; max-height: 94dvh; padding: 0; margin: auto auto 0;
  border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0;
  background: var(--bg2); color: var(--text); overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .22s cubic-bezier(.2, .9, .3, 1); }
dialog.sheet::backdrop { background: var(--shade); backdrop-filter: blur(3px); }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) { dialog.sheet { margin: auto; border-bottom: 1px solid var(--line); border-radius: 22px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 4px 20px; flex: none; }
.sheet-head h2 { margin: 0; font-size: 1.2rem; }
.sheet-body { overflow-y: auto; padding: 6px 20px max(20px, env(safe-area-inset-bottom)); overscroll-behavior: contain; }
.hint { margin: 6px 0 12px; color: var(--muted); }

.qrbox { width: min(78vw, 330px); margin: 0 auto; padding: 8px; border-radius: 16px; background: #fff; box-shadow: 0 6px 26px rgba(0, 0, 0, .25); }
.qrbox svg { display: block; width: 100%; height: auto; }
.status { margin: 12px 0 0; text-align: center; color: var(--muted); }
.status.err { color: var(--red); }
.textcode { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.textcode summary { cursor: pointer; color: var(--cyan); font-weight: 600; font-size: .9rem; }
.textcode textarea { margin-top: 8px; font: .75rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.textcode .btn { margin-top: 8px; }

.viewfinder { position: relative; aspect-ratio: 4 / 3; border-radius: 16px; overflow: hidden; background: #000; }
.viewfinder video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.reticle { position: absolute; inset: 14% 22%; border-radius: 18px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); border: 3px solid var(--cyan); }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 20px; text-align: center; background: var(--panel); color: var(--muted); }

.spinner { width: 44px; height: 44px; margin: 28px auto 14px; border: 4px solid var(--line2); border-top-color: var(--cyan); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.members { list-style: none; margin: 4px 0 0; padding: 0; }
.members li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.members .av { width: 38px; height: 38px; }
.members .nm { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.members .st { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .8125rem; }
.members .st::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.members li.connecting .st::before { background: var(--amber); }
.members li.offline { opacity: .6; }
.members li.offline .st::before { background: var(--dim); }

.field { display: block; margin: 10px 0 6px; }
.field > span:first-child { display: block; margin-bottom: 6px; color: var(--muted); font-size: .875rem; font-weight: 600; }
.seg { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; }
.seg button { border: 0; padding: 7px 16px; border-radius: 999px; background: none; color: var(--muted); font-size: .9rem; }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--text); }
.check { display: flex; align-items: flex-start; gap: 12px; margin: 14px 0; }
.check input { flex: none; width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--cyan); }
.check b { display: block; font-weight: 600; }
.check small { display: block; color: var(--muted); font-size: .8125rem; }
.help ol, .help ul { margin: 6px 0 0; padding-left: 1.3em; }
.help li { margin: 0 0 10px; }
.help h3 { margin: 18px 0 4px; font-size: 1rem; }
.help ul { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: max(84px, calc(env(safe-area-inset-bottom) + 84px)); z-index: 50; transform: translateX(-50%);
  max-width: min(92vw, 420px); padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: .9rem; font-weight: 600; text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; scroll-behavior: auto !important; }
}
