* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; overflow: hidden; background: #0f1115; color: #e9edef;
  font: 18px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Login */
body.login { align-items: center; justify-content: center; }
#f { display: flex; flex-direction: column; align-items: center; gap: 16px; width: min(360px, 90vw); }
#f input, #f button { width: 100%; padding: 14px 16px; border-radius: 12px; border: 0; }
#f input { background: #1f242c; }
#f button { background: #25d366; color: #0b1a10; font-weight: 600; cursor: pointer; }
#err { color: #ff8a80; min-height: 1.4em; margin: 0; }

/* Liste */
#side { width: 380px; flex: 0 0 380px; display: flex; flex-direction: column; border-right: 1px solid #222831; background: #12151b; }
#side > header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; font-size: 20px; }
#state { margin-left: auto; font-size: 13px; color: #8696a0; }
#chats { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#chats li { display: flex; gap: 12px; align-items: center; padding: 10px 16px; cursor: pointer; }
#chats li.on { background: #1f242c; }
#chats li:active { background: #262c35; }
.pic { width: 52px; height: 52px; border-radius: 50%; flex: 0 0 52px; background: #2a3039 center/cover; display: grid; place-items: center; font-weight: 600; color: #aeb9c1; }
.meta { flex: 1; min-width: 0; }
.row1, .row2 { display: flex; gap: 8px; align-items: baseline; }
.name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time { font-size: 13px; color: #8696a0; }
.last { flex: 1; font-size: 15px; color: #8696a0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: #25d366; color: #0b1a10; font-size: 13px; font-weight: 700; border-radius: 12px; padding: 1px 8px; }
li.unread .time { color: #25d366; }

/* Chat */
#main { flex: 1; display: flex; min-width: 0; position: relative; }
#empty { margin: auto; color: #8696a0; }
#link { margin: auto; text-align: center; max-width: 520px; padding: 24px; }
#link p { color: #aeb9c1; }
#qr { width: 300px; height: 300px; background: #fff; border-radius: 12px; padding: 12px; }
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chat > header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #12151b; border-bottom: 1px solid #222831; font-size: 20px; }
#cpic { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; background: #2a3039; }
#back { display: none; border: 0; background: none; padding: 0 4px; cursor: pointer; }
#msgs { flex: 1; overflow-y: auto; padding: 10px 4%; display: flex; flex-direction: column; gap: 4px; }
.m { position: relative; max-width: 70%; padding: 6px 10px 7px; border-radius: 9px; line-height: 1.3; background: #1f2c34; align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; }
.m.me { background: #005c4b; align-self: flex-end; }
.m .who { font-size: 14px; font-weight: 600; color: #53bdeb; }
/* Uhrzeit rechts in der letzten Zeile, wie bei WhatsApp. */
.m .foot { position: absolute; right: 9px; bottom: 6px; font-size: 12px; color: #aebac1; line-height: 1; white-space: nowrap; }
.m .spacer { display: inline-block; width: 44px; }
.m.me .spacer { width: 62px; }
.m .ack.read { color: #53bdeb; }
.m img, .m video { display: block; max-width: 100%; max-height: 300px; border-radius: 6px; margin: 2px 0 2px; cursor: pointer; }
.m a { color: #53bdeb; }
.day { align-self: center; font-size: 13px; color: #8696a0; background: #1a1f26; border-radius: 8px; padding: 2px 10px; margin: 6px 0; }

#compose { display: flex; gap: 8px; padding: 10px 12px; background: #12151b; align-items: center; }
#compose input#text { flex: 1; padding: 14px 16px; border-radius: 24px; border: 0; background: #1f242c; outline: none; }
#compose button, #attach { width: 52px; height: 52px; flex: 0 0 52px; border-radius: 50%; border: 0; background: #1f242c; cursor: pointer; display: grid; place-items: center; font-size: 22px; }
#send { background: #25d366 !important; color: #0b1a10; }
#mic.rec { background: #e53935 !important; }
#compose.recording #text { color: #ff8a80; }

#viewer { position: fixed; inset: 0; background: rgb(0 0 0 / .92); display: grid; place-items: center; z-index: 10; }
#viewer img { max-width: 96vw; max-height: 96vh; }

#toast {
  position: fixed; top: 16px; right: 16px; z-index: 20; max-width: 420px; display: flex; gap: 12px; align-items: center;
  padding: 12px 16px; border-radius: 14px; background: rgb(38 42 50 / .92); box-shadow: 0 6px 24px rgb(0 0 0 / .4); cursor: pointer;
}
#toast .t { min-width: 0; }
#toast .t div:last-child { color: #c3cbd1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 800px) {
  #side { width: 100%; flex: 1 1 100%; border: 0; }
  #main { display: none; }
  body.open #side, body.linking #side { display: none; }
  body.open #main, body.linking #main { display: flex; }
  #back { display: block; }
  .m { max-width: 85%; }
}

#compose svg, #back svg { display: block; }
/* Im Tesla-Wrapper sitzt unten rechts dessen Dreieck (31 px): Platz lassen. */
.embedded #compose { padding-right: 52px; }

/* Sprachnachricht, nah an WhatsApp. */
.m:has(.voice) { padding: 8px 12px 8px 8px; }
.m:not(.me):has(.voice) { padding: 8px 8px 8px 12px; }
.voice { display: flex; align-items: center; gap: 6px; width: 340px; max-width: 100%; }
.vav { position: relative; flex: 0 0 52px; }
.vav .pic { width: 52px; height: 52px; flex: none; font-size: 16px; }
.vmic { position: absolute; right: -4px; bottom: -2px; color: #53bdeb; display: block; line-height: 0; filter: drop-shadow(0 0 2px rgb(0 0 0 / .6)); }
.m.me .vmic { color: #e9edef; }
.vplay { border: 0; background: none; color: #e9edef; padding: 0; width: 46px; height: 46px; flex: 0 0 46px; display: grid; place-items: center; cursor: pointer; }
.m:not(.me) .vplay { color: #aebac1; }
.vright { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-top: 14px; }
.voice .wave { position: relative; height: 26px; display: flex; align-items: center; gap: 2px; cursor: pointer; margin-left: 6px; }
.voice .wave i { flex: 1; max-width: 3px; min-width: 2px; border-radius: 2px; background: rgb(255 255 255 / .45); }
.m:not(.me) .voice .wave i { background: rgb(255 255 255 / .3); }
.voice .wave i.on { background: #e9edef; }
.m:not(.me) .voice .wave i.on { background: #25d366; }
.voice .knob { position: absolute; top: 50%; left: 0; width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; border-radius: 50%; background: #e9edef; pointer-events: none; }
.m:not(.me) .voice .knob { background: #25d366; }
.voice .vtime { font-size: 13px; color: #aebac1; margin: 4px 0 0 0; height: 14px; }
.m:has(.voice) .foot { bottom: 9px; right: 12px; }
.m:not(.me):has(.voice) .foot { right: 72px; }
.m.pending { opacity: .7; }
/* Ohne Text (Sprachnachricht, Bild, Video): Uhrzeit bekommt eine eigene
   schmale Zeile unter dem Inhalt. */
.m:not(:has(.txt)):not(:has(.voice)) { padding-bottom: 20px; }
