:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel2: #1f2c34;
  --line: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #19c37d;
  --accent2: #0f9d63;
  --me: #005c4b;
  --them: #1f2c34;
  --danger: #f15c6d;
  --read: #53bdeb;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Color Emoji", "Segoe UI Emoji", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--read); }

#app { height: 100dvh; display: flex; justify-content: center; }
.view { width: 100%; max-width: 980px; height: 100%; }
.view.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 20px; }

.brand { display: flex; align-items: center; gap: 10px; font-size: 30px; font-weight: 700; letter-spacing: -.5px; justify-content: center; }
.brand img { width: 44px; height: 44px; }

.card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 24px; text-align: center; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 50px #0008;
}
.card h2 { margin: 4px 0 0; font-size: 20px; }
.card form { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.msg { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

.btn {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 10px 16px;
  text-decoration: none; display: inline-block; text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #062a1b; font-weight: 600; }
.btn.primary:hover { background: #22d68b; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.big { padding: 14px 18px; font-size: 16px; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.field {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit;
}
.field:focus { outline: 2px solid var(--accent); border-color: transparent; }
.check { display: flex; gap: 8px; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }

.spinner {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- chat ---------- */
.view.chat { display: flex; flex-direction: column; background: var(--bg); position: relative; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--panel);
  border-bottom: 1px solid var(--line); padding-top: max(8px, env(safe-area-inset-top));
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #19c37d, #0b7a8a); font-weight: 700; color: #fff;
}
.peer { flex: 1; min-width: 0; }
.peer-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { font-size: 12.5px; color: var(--muted); }
.peer-status.online, .peer-status[data-typing] { color: var(--accent); }

.icon {
  background: transparent; border: 0; width: 42px; height: 42px; border-radius: 50%; font-size: 20px;
  display: grid; place-items: center; flex: none; text-decoration: none; color: var(--text);
}
.icon:hover { background: #ffffff12; }
.icon.small { width: 30px; height: 30px; font-size: 15px; }
.icon.on { background: #19c37d30; }
.icon.send { background: var(--accent); color: #062a1b; font-size: 18px; }
.icon.send:hover { background: #22d68b; }

.messages {
  flex: 1; overflow-y: auto; padding: 8px 4% 12px; overscroll-behavior: contain;
  background:
    radial-gradient(circle at 20% 10%, #19c37d0a 0, transparent 40%),
    radial-gradient(circle at 80% 70%, #0b7a8a0d 0, transparent 40%), var(--bg);
}
.older { text-align: center; color: var(--muted); font-size: 12.5px; padding: 8px; }
.day {
  text-align: center; margin: 14px auto 8px; font-size: 12px; color: var(--muted); background: var(--panel);
  width: fit-content; padding: 4px 12px; border-radius: 8px; text-transform: capitalize;
}
.system {
  text-align: center; margin: 10px auto; font-size: 12.5px; color: #e2c66b; background: #2b2614;
  width: fit-content; max-width: 90%; padding: 5px 12px; border-radius: 8px;
}

.m { display: flex; margin-top: 8px; }
.m.cont { margin-top: 2px; }
.m.me { justify-content: flex-end; }
.bubble {
  position: relative; max-width: min(78%, 560px); padding: 6px 9px 5px; border-radius: var(--radius);
  background: var(--them); box-shadow: 0 1px 1px #0005; word-wrap: break-word; overflow-wrap: anywhere;
  user-select: text;
}
.m.me .bubble { background: var(--me); }
.m.them:not(.cont) .bubble { border-top-left-radius: 3px; }
.m.me:not(.cont) .bubble { border-top-right-radius: 3px; }
.m.flash .bubble { animation: flash 1.2s; }
@keyframes flash { 30% { box-shadow: 0 0 0 3px var(--accent); } }

.text { white-space: pre-wrap; padding-right: 4px; }
.text.jumbo { font-size: 42px; line-height: 1.15; }
.meta { display: flex; gap: 4px; justify-content: flex-end; align-items: center; font-size: 11px; color: #ffffff99; margin-top: 2px; }
.tick { letter-spacing: -3px; padding-right: 3px; }
.tick.read { color: var(--read); }
.exp { font-size: 10px; }

.quote {
  display: flex; flex-direction: column; background: #0000002e; border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 4px 8px; margin-bottom: 4px; font-size: 13px; cursor: pointer;
}
.quote b { color: var(--accent); font-size: 12.5px; }
.quote span { color: #ffffffb3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.media { position: relative; margin: -2px -5px 2px; border-radius: 9px; overflow: hidden; cursor: pointer; min-width: 180px; }
.media img { display: block; width: 100%; max-width: 360px; max-height: 420px; object-fit: cover; }
.media-ph { width: 240px; height: 160px; display: grid; place-items: center; font-size: 44px; background: #0003; }
.play {
  position: absolute; inset: 0; margin: auto; width: 54px; height: 54px; border-radius: 50%; background: #000a;
  display: grid; place-items: center; font-size: 22px; padding-left: 4px;
}

.file {
  display: flex; align-items: center; gap: 10px; background: #0000002e; border: 0; border-radius: 9px;
  padding: 10px 12px; text-align: left; min-width: 220px; width: 100%;
}
.file-ico { font-size: 28px; }
.file-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.file-size { font-size: 12px; color: #ffffff99; }

.reacts { display: flex; gap: 3px; position: absolute; bottom: -14px; left: 8px; }
.m.me .reacts { left: auto; right: 8px; }
.react { background: var(--panel2); border: 1px solid var(--bg); border-radius: 12px; padding: 0 6px; font-size: 13px; }
.m:has(.react) { margin-bottom: 14px; }

/* ---------- composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 4px; padding: 6px 8px; background: var(--panel);
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}
#input {
  flex: 1; resize: none; border: 0; border-radius: 22px; background: var(--panel2); color: var(--text);
  padding: 11px 16px; font: inherit; max-height: 160px; line-height: 1.35; margin: 0 2px;
}
#input:focus { outline: none; }

.reply-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px 0; background: var(--panel); }
.reply-quote { flex: 1; display: flex; flex-direction: column; border-left: 3px solid var(--accent); background: var(--panel2); border-radius: 8px; padding: 5px 10px; min-width: 0; }
.reply-quote b { color: var(--accent); font-size: 13px; }
.reply-quote span { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.progress { position: relative; height: 22px; background: var(--panel2); font-size: 12px; }
.progress div { position: absolute; inset: 0 auto 0 0; background: #19c37d44; transition: width .2s; }
.progress span { position: relative; padding: 0 12px; line-height: 22px; }

.emoji-panel { background: var(--panel); border-top: 1px solid var(--line); height: 280px; display: flex; flex-direction: column; }
.emoji-tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); flex: none; }
.emoji-tabs .tab { background: none; border: 0; padding: 8px 12px; font-size: 20px; opacity: .55; border-bottom: 2px solid transparent; }
.emoji-tabs .tab.on { opacity: 1; border-bottom-color: var(--accent); }
.emoji-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); padding: 6px; align-content: start; }
.emo { background: none; border: 0; font-size: 26px; height: 44px; border-radius: 8px; }
.emo:hover { background: #ffffff14; }

/* ---------- popups / diálogos ---------- */
.popup {
  position: fixed; z-index: 50; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; min-width: 210px; box-shadow: 0 12px 32px #000a; display: flex; flex-direction: column;
}
.pop-item { background: none; border: 0; text-align: left; padding: 10px 12px; border-radius: 8px; }
.pop-item:hover { background: #ffffff12; }
.pop-item.danger { color: var(--danger); }
.pop-title { font-size: 12px; color: var(--muted); padding: 6px 12px; }
.pop-reacts { display: flex; gap: 2px; padding: 2px 2px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.pop-emoji { background: none; border: 0; font-size: 24px; width: 40px; height: 40px; border-radius: 50%; }
.pop-emoji:hover { background: #ffffff18; transform: scale(1.15); }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
  padding: 0; width: min(440px, 92vw); box-shadow: 0 20px 60px #000c;
}
dialog::backdrop { background: #000a; }
.dlg-body { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.dlg-body h3 { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.pair-code { font: 700 34px/1.2 ui-monospace, Consolas, monospace; letter-spacing: 4px; text-align: center; padding: 14px; background: var(--bg); border-radius: 12px; color: var(--accent); user-select: all; }
.devices { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.device { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--bg); border-radius: 10px; padding: 10px 12px; }

.cam { width: min(760px, 96vw); background: #000; }
.cam video { width: 100%; display: block; max-height: 75vh; background: #000; }
.cam-actions { display: flex; justify-content: space-around; align-items: center; padding: 12px; }
.shutter { width: 64px; height: 64px; border-radius: 50%; border: 4px solid #fff; background: #ffffff33; }
.shutter:hover { background: #ffffff66; }

.lightbox { position: fixed; inset: 0; z-index: 60; background: #000e; display: flex; flex-direction: column; }
.lb-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.lb-bar span { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-body { flex: 1; display: grid; place-items: center; overflow: hidden; padding: 0 10px 10px; }
.lb-body img, .lb-body video { max-width: 100%; max-height: calc(100dvh - 80px); object-fit: contain; }

.drop {
  position: fixed; inset: 0; z-index: 70; background: #19c37d26; border: 3px dashed var(--accent);
  display: grid; place-items: center; font-size: 24px; font-weight: 600; pointer-events: none;
}
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 80; background: #e9edef;
  color: #111; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw; box-shadow: 0 6px 20px #0008;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #ffffff22; border-radius: 4px; }

@media (max-width: 600px) {
  .view.chat { border: 0; }
  .messages { padding: 6px 8px 12px; }
  .bubble { max-width: 86%; }
  .icon { width: 40px; height: 40px; }
}
