/* Heylo Web */
:root {
  --g1: #0a9f4f; --g2: #06785f; --lime: #7ed321; --yellow: #f7c531; --blue: #34b7f1;
  --bg: #eef3f0; --panel: #fff; --line: #e3ebe6; --text: #1c2a24; --muted: #6b7c74;
  --mine: #d5f7df; --theirs: #fff; --chatbg: #e9f0eb; --hover: #f3f7f5; --active: #e2efe7; --red: #c62828;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b110e; --panel: #16201b; --line: #24302a; --text: #e6eee9; --muted: #93a69c;
    --mine: #075c38; --theirs: #24302a; --chatbg: #0f1613; --hover: #1d2823; --active: #24332b;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1em; font-size: 14px; }

/* ---------- Kopplung ---------- */
.pair { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(160deg, var(--lime) -30%, var(--g1) 30%, var(--g2) 100%); }
.pair-card { background: var(--panel); border-radius: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.2); padding: 36px; display: flex; gap: 40px;
  max-width: 900px; width: 100%; align-items: center; flex-wrap: wrap; }
.pair-text { flex: 1 1 320px; }
.pair-text h1 { margin: 8px 0 4px; font-size: 28px; }
.pair-text ol { padding-left: 20px; line-height: 2; }
.pair-logo { width: 72px; height: 72px; border-radius: 18px; }
.pair-qr { flex: 0 0 auto; text-align: center; margin: auto; }
.qr { width: 280px; height: 280px; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 12px;
  border: 1px solid var(--line); position: relative; }
.qr svg { width: 100%; height: 100%; }
.qr.expired::after { content: "Neu laden"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.9); color: var(--g1); font-weight: 600; cursor: pointer; border-radius: 12px; }
.admin-link { margin-top: 18px; color: rgba(255,255,255,.75); font-size: 13px; text-decoration: none; }
.admin-link:hover { color: #fff; text-decoration: underline; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--line); border-top-color: var(--g1); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout ---------- */
.app { display: flex; height: 100%; max-width: 1600px; margin: 0 auto; background: var(--panel); box-shadow: 0 0 20px rgba(0,0,0,.08); }
.sidebar { width: 380px; min-width: 280px; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); }
.chat { flex: 1; display: flex; flex-direction: column; position: relative; background: var(--chatbg); min-width: 0; }

.side-head, .chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-height: 62px;
  background: linear-gradient(120deg, var(--g1), var(--g2)); color: #fff; }
.me, .peer { flex: 1; min-width: 0; }
.me-name, .peer-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-address, .peer-address { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: transparent; border: 0; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: inherit; flex: 0 0 auto; }
.icon-btn:hover { background: rgba(255,255,255,.18); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.composer .icon-btn { color: var(--muted); }
.composer .icon-btn:hover { background: var(--hover); }
.back { display: none; }

.avatar { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff;
  font-weight: 700; font-size: 18px; flex: 0 0 auto; border: 2px solid rgba(255,255,255,.4); }
.chats .avatar { width: 48px; height: 48px; border: 0; }
.avatar { overflow: hidden; position: relative; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar.clickable { cursor: pointer; }
.avatar.clickable:hover { filter: brightness(1.1); }
.avatar.big { width: 160px; height: 160px; font-size: 64px; border: 0; }
.avatar-preview { display: flex; justify-content: center; margin: 14px 0; }

.search { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; padding: 9px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; outline: none; }
.conn { background: #fff3c4; color: #5a4500; padding: 8px 14px; font-size: 13px; }

.chats { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chats li { display: flex; gap: 12px; padding: 10px 14px; cursor: pointer; align-items: center; border-bottom: 1px solid var(--line); }
.chats li:hover { background: var(--hover); }
.chats li.active { background: var(--active); }
.chats .c-main { flex: 1; min-width: 0; }
.chats .c-top, .chats .c-bottom { display: flex; align-items: center; gap: 8px; }
.chats .c-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chats .c-time { font-size: 12px; color: var(--muted); }
.chats .c-time.unread { color: var(--g1); font-weight: 600; }
.chats .c-last { flex: 1; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--g1); color: #fff; border-radius: 12px; min-width: 22px; height: 22px; padding: 0 6px; font-size: 12px;
  display: flex; align-items: center; justify-content: center; font-weight: 600; }
.chats .none { padding: 30px 20px; text-align: center; color: var(--muted); cursor: default; border: 0; display: block; }

.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: 20px; }
.empty img { width: 110px; height: 110px; border-radius: 26px; opacity: .9; }
.empty h2 { color: var(--text); margin-bottom: 4px; }

/* ---------- Nachrichten ---------- */
.messages { flex: 1; overflow-y: auto; padding: 14px 6%; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 10px; margin: 10px 0; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.row { display: flex; }
.row.out { justify-content: flex-end; }
.bubble { max-width: min(560px, 75%); background: var(--theirs); border-radius: 4px 14px 14px 14px; padding: 6px 9px 4px; box-shadow: 0 1px 1px rgba(0,0,0,.08); position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.row.out .bubble { background: var(--mine); border-radius: 14px 4px 14px 14px; }
.bubble.media { padding: 4px 4px 3px; }
.bubble .text { white-space: pre-wrap; line-height: 1.38; }
.bubble.media .text { padding: 4px 6px 0; }
.bubble a { color: #1a63c9; }
@media (prefers-color-scheme: dark) { .bubble a { color: #8ab4f8; } }
.meta { display: flex; justify-content: flex-end; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); margin-top: 2px; padding: 0 4px; user-select: none; }
.tick { font-size: 12px; letter-spacing: -3px; padding-right: 3px; }
.tick.read { color: var(--blue); }
.tick.err { color: var(--red); letter-spacing: 0; cursor: pointer; }
.thumb { display: block; border-radius: 10px; max-width: 100%; width: 330px; max-height: 420px; object-fit: cover; background: rgba(0,0,0,.06); cursor: zoom-in; }
video.thumb { cursor: default; background: #000; object-fit: contain; }
.file { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: rgba(0,0,0,.05); border-radius: 10px; min-width: 240px; text-decoration: none; color: inherit; }
.file:hover { background: rgba(0,0,0,.09); }
.file svg { width: 34px; height: 34px; fill: var(--g1); flex: 0 0 auto; }
.file .f-name { font-weight: 500; word-break: break-all; }
.file .f-size { font-size: 12px; color: var(--muted); }
.file > div { flex: 1 1 auto; }
.file .f-dl { flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 17px; color: var(--g1); background: rgba(0,0,0,.06); }
.file:hover .f-dl { background: rgba(0,0,0,.12); }
.bubble .dl { display: inline-block; margin: 6px 6px 2px; font-size: 13px; color: var(--g1); text-decoration: none; font-weight: 500; }
.bubble .dl:hover { text-decoration: underline; }
.progress { height: 4px; background: rgba(0,0,0,.1); border-radius: 2px; margin: 6px 4px 2px; overflow: hidden; }
.progress > div { height: 100%; background: var(--g1); width: 0; transition: width .2s; }
.more { align-self: center; margin: 6px; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 22px; padding: 10px 16px; font: inherit; max-height: 160px;
  background: var(--bg); color: var(--text); outline: none; line-height: 1.35; }
.send-btn { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--g1); color: #fff; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.send-btn svg { width: 22px; height: 22px; fill: #fff; }
.send-btn:hover { background: var(--g2); }

.drop { position: absolute; inset: 0; background: rgba(10,159,79,.85); color: #fff; font-size: 22px; font-weight: 600; display: flex; align-items: center; justify-content: center; z-index: 5; pointer-events: none; }

/* ---------- Dialoge ---------- */
.dlg { border: 0; border-radius: 16px; padding: 22px; width: min(420px, 92vw); background: var(--panel); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.dlg::backdrop { background: rgba(0,0,0,.4); }
.dlg h3 { margin: 0 0 6px; }
.dlg input { width: 100%; padding: 11px; border-radius: 10px; border: 1px solid var(--line); font: inherit; background: var(--bg); color: var(--text); margin-top: 8px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.btn { background: var(--g1); color: #fff; border: 0; padding: 9px 16px; border-radius: 10px; }
.btn.secondary { background: var(--bg); color: var(--text); }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; z-index: 20; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; }
.lightbox-dl { position: absolute; top: 16px; right: 20px; color: #fff; background: rgba(255,255,255,.15); padding: 8px 14px; border-radius: 8px; text-decoration: none; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 30; max-width: 90vw; }

/* ---------- Schmale Bildschirme ---------- */
@media (max-width: 760px) {
  .sidebar { width: 100%; border: 0; }
  .chat { display: none; }
  .app.in-chat .sidebar { display: none; }
  .app.in-chat .chat { display: flex; }
  .back { display: flex; }
  .messages { padding: 10px; }
  .bubble { max-width: 85%; }
  .pair-card { padding: 22px; gap: 20px; }
  .qr { width: 240px; height: 240px; }
}

/* Ende-zu-Ende-Verschlüsselung */
.e2e-badge { margin-left: auto; border: 0; background: rgba(10,159,79,.12); color: var(--g2); border-radius: 14px; padding: 5px 11px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.e2e-badge.off { background: rgba(200,120,0,.14); color: #9a5b00; }
.e2e-banner { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: #fff4d6; color: #6b4a00; font-size: 14px; border-bottom: 1px solid rgba(0,0,0,.06); }
.e2e-banner span { flex: 1; }
.e2e-banner .icon-btn { width: 28px; height: 28px; font-size: 14px; }
.e2e-note { margin: 6px 10px; padding: 8px 10px; border-radius: 8px; background: #fff4d6; color: #6b4a00; font-size: 13px; }
.meta .lock { font-size: 11px; opacity: .75; }
.bubble .enc-err { font-style: italic; color: var(--muted); padding: 6px 8px 0; }
.bubble .unverified { font-size: 12px; color: #9a5b00; padding: 2px 8px 0; }
.enc-media { position: relative; cursor: pointer; display: block; min-width: 200px; min-height: 120px; background: rgba(0,0,0,.08); border-radius: 10px; overflow: hidden; }
.enc-media img { display: block; width: 100%; height: auto; filter: blur(0); }
.enc-media .play { position: absolute; inset: 0; display: grid; place-items: center; font-size: 42px; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.5); }
.enc-media .hint { position: absolute; left: 8px; bottom: 6px; font-size: 12px; color: #fff; background: rgba(0,0,0,.45); padding: 2px 7px; border-radius: 8px; }
.sn-number { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 20px; letter-spacing: 1px; line-height: 1.6; text-align: center; background: var(--bg); padding: 12px; border-radius: 10px; margin: 10px 0; white-space: pre; }
