/* Chatu — tema oscuro estilo gaming. Sin fuentes ni recursos externos. */
:root {
  --bg: #0b0f17;
  --bg2: #111827;
  --panel: #151d2e;
  --panel2: #1b2540;
  --line: #24314f;
  --text: #e6edf7;
  --muted: #8a97b2;
  --accent: #c04dff;
  --accent2: #22d3ff;
  --danger: #ff4d6d;
  --warn: #ffb547;
  --mine: #2a1645;
  --theirs: #19223a;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.4 var(--font); -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .45; cursor: default; }
a { color: var(--accent2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.danger { color: var(--danger); }
.noscript { padding: 24px; }

#app { height: 100%; display: flex; flex-direction: column; }
.boot { margin: auto; text-align: center; color: var(--muted); }
.logo-mark { width: 88px; height: 88px; margin: 0 auto 12px; border-radius: 22px; background: url(/icons/icon-192.png) center/cover; box-shadow: 0 0 32px #c04dff44; }

/* ---------- botones e inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px; border-radius: 12px;
  background: var(--panel2); border: 1px solid var(--line); font-weight: 600; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: 0; box-shadow: 0 0 18px #c04dff55; text-shadow: 0 1px 2px #0006; }
.btn.danger { background: #3a1220; border-color: #6b1d33; color: #ffd5de; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; color: var(--text); }
.icon-btn:hover, .btn:hover { filter: brightness(1.12); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
input[type=text], input:not([type]), textarea, select { width: 100%; padding: 11px 13px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); outline: none; }
input:focus, textarea:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px #18c8ff22; }
label.field { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
.switch { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); margin-top: 2px; flex: none; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); font-size: 12px; }

/* ---------- pantalla de acceso ---------- */
.lock { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b)); gap: 14px;
  background: radial-gradient(circle at 50% 0%, #2a1245 0%, var(--bg) 55%); }
.lock h1 { margin: 0; font-size: 28px; letter-spacing: .5px; }
.lock .sub { color: var(--muted); margin: 0 0 6px; text-align: center; }
.lock .user-row { width: 100%; max-width: 320px; }
.lmsg { min-height: 22px; text-align: center; max-width: 340px; margin: 6px auto; }
.lmsg.error { color: var(--danger); }
.lmsg.warn { color: var(--warn); }
.dots { display: flex; gap: 16px; margin: 6px 0; }
.dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent2); }
.dots span.on { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 10px var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; }
.keypad button { height: 64px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); font-size: 24px; font-weight: 600; }
.keypad button:active { background: var(--panel2); }
.blocked-code { font: 700 26px/1 ui-monospace, Consolas, monospace; letter-spacing: 3px; color: var(--warn); }

/* ---------- estructura principal ---------- */
.shell { flex: 1; display: grid; grid-template-columns: 360px 1fr; min-height: 0; }
.sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--bg2); min-height: 0; }
.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 10px; border-bottom: 1px solid var(--line); background: var(--bg2); }
.topbar h2 { margin: 0; font-size: 18px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .brand { font-weight: 800; letter-spacing: .5px; background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.list { flex: 1; overflow-y: auto; }
.tabs { display: flex; border-top: 1px solid var(--line); padding-bottom: var(--safe-b); background: var(--bg2); }
.tabs button { flex: 1; padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 12px; position: relative; }
.tabs button.on { color: var(--accent); }
.tabs button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; }
.tabs .badge { position: absolute; top: 4px; left: 55%; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.pane { flex: 1; overflow-y: auto; padding: 4px 16px 24px; }

.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid #1a2238; cursor: pointer; }
.row:hover, .row.on { background: var(--panel); }
.avatar { width: 44px; height: 44px; border-radius: 14px; flex: none; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #04140c; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- conversación ---------- */
.messages { flex: 1; overflow-y: auto; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 4px;
  background: linear-gradient(180deg, #0b0f17, #0d1320); }
.msg { max-width: min(78%, 560px); padding: 8px 11px 6px; border-radius: 14px; background: var(--theirs); align-self: flex-start; position: relative; word-wrap: break-word; overflow-wrap: anywhere; user-select: text; }
.msg.mine { background: var(--mine); align-self: flex-end; border: 1px solid #5b2a85; }
.msg .who { font-size: 12px; font-weight: 700; color: var(--accent2); margin-bottom: 2px; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.msg .meta .st-read { color: var(--accent2); }
.msg.selected { outline: 2px solid var(--accent); }
.msg .quote { border-left: 3px solid var(--accent2); background: #0003; padding: 4px 8px; border-radius: 6px; margin-bottom: 4px; font-size: 13px; color: var(--muted); max-height: 60px; overflow: hidden; cursor: pointer; }
.msg .sticker { font-size: 64px; line-height: 1.1; }
.msg img.media, .msg video.media { max-width: 100%; max-height: 360px; border-radius: 10px; display: block; }
.msg audio { width: 240px; max-width: 100%; }
.msg .file { display: flex; gap: 10px; align-items: center; padding: 6px; background: #0003; border-radius: 10px; min-width: min(240px, 60vw); }
.msg .file .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.msg .file > svg { width: 28px; height: 28px; flex: none; stroke: var(--accent2); fill: none; stroke-width: 2; }
.msg .reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.msg .reactions span { background: #0006; border-radius: 999px; padding: 1px 7px; font-size: 13px; cursor: pointer; }
.msg .reactions span.me { outline: 1px solid var(--accent); }
.msg.err { opacity: .7; font-style: italic; }
.day { align-self: center; font-size: 12px; color: var(--muted); padding: 4px 10px; background: var(--panel); border-radius: 999px; margin: 8px 0; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg2); }
.composer textarea { resize: none; max-height: 140px; min-height: 42px; }
.replybar, .selbar, .progress { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line); font-size: 13px; }
.replybar .grow, .selbar .grow, .progress .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress .bar { height: 6px; background: var(--bg2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.progress .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); width: 0; }
.picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 8px; background: var(--panel); border-top: 1px solid var(--line); max-height: 220px; overflow-y: auto; }
.picker button { font-size: 24px; padding: 6px 0; border-radius: 8px; }
.picker button:hover { background: var(--panel2); }
.picker.stickers button { font-size: 42px; }
.banner { padding: 8px 12px; background: #3a2a0f; color: #ffe1a8; font-size: 13px; border-bottom: 1px solid #5c4313; }
.recording { color: var(--danger); font-weight: 700; }

/* ---------- menús, modales, avisos ---------- */
#modal-layer:empty, #call-layer:empty { display: none; }
.backdrop { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; }
.modal h3 { margin: 0 0 10px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.menu { position: fixed; z-index: 60; min-width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px; box-shadow: 0 10px 40px #000a; }
.menu button { display: flex; width: 100%; padding: 10px 12px; border-radius: 10px; text-align: left; gap: 10px; }
.menu button:hover { background: var(--panel2); }
.menu .react-row { display: flex; justify-content: space-between; padding: 4px; }
.menu .react-row button { width: auto; font-size: 22px; padding: 6px; }
#toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 80; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.on { opacity: 1; }
.qr { background: #fff; padding: 14px; border-radius: 14px; display: inline-block; }
.qr canvas, .qr img { display: block; image-rendering: pixelated; width: 240px; height: 240px; }
.scanner video { width: 100%; border-radius: 12px; background: #000; }
.code { font: 600 15px/1.6 ui-monospace, Consolas, monospace; letter-spacing: 1px; word-spacing: 6px; }
.friendpin { font: 800 30px/1 ui-monospace, Consolas, monospace; letter-spacing: 4px; color: var(--accent); }

/* ---------- llamadas ---------- */
.call { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(circle at 50% 30%, #2a1245, #05070c 70%); padding: 24px; text-align: center; }
.call h2 { margin: 0; font-size: 26px; }
.call .peers { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.call .ctrls { display: flex; gap: 22px; }
.call .round { width: 68px; height: 68px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--panel2); }
.call .round svg { width: 30px; height: 30px; stroke: currentColor; fill: none; stroke-width: 2; }
.call .round.red { background: var(--danger); color: #fff; }
.call .round.green { background: #22d39a; color: #04140c; }
.call .round.on { background: var(--warn); color: #000; }
.call-mini { position: fixed; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 65; background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 999px; font-weight: 700; cursor: pointer; }

/* ---------- móvil ---------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .shell.in-chat .sidebar { display: none; }
  .shell:not(.in-chat) .main { display: none; }
  .msg { max-width: 86%; }
}
@media (min-width: 761px) {
  .back-btn { display: none !important; }
}

.lock select { width: auto; padding: 6px 10px; font-size: 13px; }
