:root {
  --brand: #0b5fff;
  --bg: #ffffff;
  --panel: #f3f5f9;
  --text: #14171f;
  --muted: #6b7280;
  --line: #e4e7ee;
  --in: #eef1f6;
  --out: var(--brand);
  --danger: #d92d20;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1218; --panel: #181c25; --text: #eef0f5; --muted: #98a0ae; --line: #262b36; --in: #1e232e; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-text-size-adjust: 100%;
}
#app { height: 100vh; height: 100dvh; height: var(--app-h, 100dvh); display: flex; flex-direction: column; max-width: 820px; margin: 0 auto; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
input, textarea { font-size: 16px; } /* evita el zoom automático de iOS al enfocar */

.top {
  display: flex; align-items: center; gap: 6px; padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left));
  background: var(--brand); color: #fff;
}
.top h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .ic { color: #fff; width: 44px; height: 44px; border-radius: 50%; font-size: 20px; }
.top .ic:active { background: rgba(255,255,255,.2); }

.search { padding: 10px 14px; background: var(--bg); border-bottom: 1px solid var(--line); }
.search input { width: 100%; padding: 10px 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--panel); outline: none; }

.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom); }
.row { display: flex; gap: 12px; min-height: 64px; padding: 10px 14px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; align-items: center; }
.row:active { background: var(--panel); }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 650; }
.rowmain { flex: 1; min-width: 0; }
.rowline { display: flex; justify-content: space-between; gap: 8px; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { color: var(--muted); font-size: 12px; flex: none; }
.preview { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.badge { flex: none; background: var(--brand); color: #fff; border-radius: 11px; min-width: 22px; height: 22px; padding: 0 6px; font-size: 12px; display: grid; place-items: center; }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }

.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 6px; background: var(--panel); }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--bg); padding: 2px 10px; border-radius: 10px; margin: 6px 0; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 16px; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble.in { align-self: flex-start; background: var(--in); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--out); color: #fff; border-bottom-right-radius: 4px; }
.bubble .meta { display: block; font-size: 11px; opacity: .7; text-align: right; margin-top: 2px; }
.bubble.failed .meta { color: #ffd0cb; opacity: 1; font-weight: 600; }
.bubble audio { display: block; width: 240px; max-width: 100%; margin: 2px 0; }
.bubble img { display: block; max-width: 100%; border-radius: 10px; margin: 2px 0; }
.bubble a { color: inherit; text-decoration: underline; }
.bubble em { opacity: .7; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { flex: 1; resize: none; max-height: 120px; padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel); outline: none; line-height: 1.3; }
.fab { flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 20px; display: grid; place-items: center; }
.fab:disabled { opacity: .5; }
.fab.rec { background: var(--danger); }

.recbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.recbar .time { font-variant-numeric: tabular-nums; flex: 1; }
.recbar audio { flex: 1; min-width: 0; height: 40px; }
.ghost { min-height: 44px; padding: 8px 14px; border-radius: 22px; background: var(--panel); }
.ghost.wide { width: 100%; }
.bubble audio { height: 44px; }
.notif { display: flex; flex-direction: column; gap: 8px; }
.sheet > div { max-height: 90dvh; overflow-y: auto; }
.sheet .go { min-height: 46px; }
@media (max-width: 480px) { .bubble { max-width: 88%; } .bubble audio { width: 100%; } }

.login { margin: auto; width: min(360px, 90%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login .logo { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto; }
.login input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); outline: none; }
.login .go { padding: 12px; border-radius: 12px; background: var(--brand); color: #fff; font-weight: 650; }
.login .err { color: var(--danger); min-height: 1.2em; font-size: 14px; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: end center; z-index: 5; }
.sheet > div { width: min(520px, 100%); background: var(--bg); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.sheet h2 { margin: 0; font-size: 17px; }
.sheet p { margin: 0; color: var(--muted); font-size: 14px; }
.sheet input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); outline: none; }
.sheet .go { padding: 11px; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 650; }

#toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #111; color: #fff; padding: 9px 16px; border-radius: 18px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90%; text-align: center; z-index: 10; }
#toast.show { opacity: .95; }
