/* ================= Charla — estilos ================= */
:root {
  --brand: #008069;
  --accent: #00a884;
  --accent-dark: #008f72;
  --bar-bg: #008069;
  --bar-fg: #ffffff;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #111b21;
  --text-2: #667781;
  --line: #e9edef;
  --hover: #f5f6f6;
  --chat-bg: #efeae2;
  --me: #d9fdd3;
  --them: #ffffff;
  --bubble-shadow: 0 1px .5px rgba(11, 20, 26, .13);
  --tick: #8696a0;
  --tick-read: #53bdeb;
  --danger: #ea0038;
  --chip: #ffffff;
  --chip-text: #54656f;
  --wave: #c2cbcf;
  --wave-me: #a9c6a4;
  --wave-on: #00a884;
  --input-bg: #ffffff;
  --composer-bg: transparent;
  --wallpaper: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220'%3E%3Cg fill='none' stroke='%23000' stroke-opacity='.06' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M30 40c-6-8-18-3-14 6 3 6 14 13 14 13s11-7 14-13c4-9-8-14-14-6z'/%3E%3Cpath d='M150 20l5 11 12 1-9 8 3 12-11-6-11 6 3-12-9-8 12-1z'/%3E%3Cpath d='M90 90h40a8 8 0 0 1 8 8v18a8 8 0 0 1-8 8h-26l-10 9v-9h-4a8 8 0 0 1-8-8V98a8 8 0 0 1 8-8z'/%3E%3Cpath d='M40 150v-28l20-5v28'/%3E%3Ccircle cx='34' cy='150' r='6'/%3E%3Ccircle cx='54' cy='145' r='6'/%3E%3Ccircle cx='180' cy='160' r='16'/%3E%3Cpath d='M173 165c4 4 10 4 14 0M174 154h.01M186 154h.01'/%3E%3Crect x='112' y='170' width='30' height='22' rx='4'/%3E%3Ccircle cx='127' cy='181' r='6'/%3E%3Cpath d='M200 80v12M194 86h12M60 70v8M56 74h8'/%3E%3Cpath d='M70 200a10 10 0 0 1 20-2 8 8 0 0 1 2 16H72a7 7 0 0 1-2-14z'/%3E%3Ccircle cx='100' cy='30' r='2'/%3E%3Ccircle cx='20' cy='100' r='2'/%3E%3Ccircle cx='200' cy='130' r='2'/%3E%3C/g%3E%3C/svg%3E");
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bar-bg: #202c33;
    --bar-fg: #e9edef;
    --bg: #111b21;
    --panel: #111b21;
    --panel-2: #202c33;
    --text: #e9edef;
    --text-2: #8696a0;
    --line: #222d34;
    --hover: #202c33;
    --chat-bg: #0b141a;
    --me: #005c4b;
    --them: #202c33;
    --bubble-shadow: 0 1px .5px rgba(0, 0, 0, .3);
    --tick: #8696a0;
    --chip: #182229;
    --chip-text: #8696a0;
    --wave: #4c5a62;
    --wave-me: #3f8a7a;
    --wave-on: #21c063;
    --input-bg: #2a3942;
    --composer-bg: #202c33;
    --wallpaper: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220'%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='.035' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M30 40c-6-8-18-3-14 6 3 6 14 13 14 13s11-7 14-13c4-9-8-14-14-6z'/%3E%3Cpath d='M150 20l5 11 12 1-9 8 3 12-11-6-11 6 3-12-9-8 12-1z'/%3E%3Cpath d='M90 90h40a8 8 0 0 1 8 8v18a8 8 0 0 1-8 8h-26l-10 9v-9h-4a8 8 0 0 1-8-8V98a8 8 0 0 1 8-8z'/%3E%3Cpath d='M40 150v-28l20-5v28'/%3E%3Ccircle cx='34' cy='150' r='6'/%3E%3Ccircle cx='54' cy='145' r='6'/%3E%3Ccircle cx='180' cy='160' r='16'/%3E%3Cpath d='M173 165c4 4 10 4 14 0M174 154h.01M186 154h.01'/%3E%3Crect x='112' y='170' width='30' height='22' rx='4'/%3E%3Ccircle cx='127' cy='181' r='6'/%3E%3Cpath d='M200 80v12M194 86h12M60 70v8M56 74h8'/%3E%3Cpath d='M70 200a10 10 0 0 1 20-2 8 8 0 0 1 2 16H72a7 7 0 0 1-2-14z'/%3E%3Ccircle cx='100' cy='30' r='2'/%3E%3Ccircle cx='20' cy='100' r='2'/%3E%3Ccircle cx='200' cy='130' r='2'/%3E%3C/g%3E%3C/svg%3E");
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }

/* ---------- Botones genéricos ---------- */
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center; flex: none;
  color: inherit; text-decoration: none;
  transition: background .15s;
}
.icon-btn:active { background: rgba(127, 127, 127, .2); }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn.small svg { width: 20px; height: 20px; }
.icon-btn.muted { color: var(--text-2); }
.icon-btn.light { color: #fff; }
.icon-btn.danger { color: var(--text-2); }
.btn-primary {
  background: var(--accent); color: #fff; font-weight: 600;
  border-radius: 24px; padding: 13px 22px; width: 100%;
  font-size: 16px; transition: background .15s, transform .1s;
}
.btn-primary:active { background: var(--accent-dark); transform: scale(.99); }
.btn-primary:disabled { opacity: .6; }
.btn-outline {
  border: 1px solid var(--accent); color: var(--accent); border-radius: 22px;
  padding: 10px 20px; font-weight: 600; margin-top: 12px;
}
.btn-text { padding: 10px 16px; font-weight: 600; color: var(--accent); }
.btn-text.light { color: #fff; opacity: .85; }

/* ---------- Avatares ---------- */
.avatar {
  border-radius: 50%; object-fit: cover; background: #dfe5e7; display: block; flex: none;
}
.avatar.sm { width: 40px; height: 40px; }
.avatar.md { width: 49px; height: 49px; }
.avatar.xl { width: 200px; height: 200px; }
.avatar-btn { border-radius: 50%; }

/* ================= Acceso ================= */
.auth {
  min-height: 100%; overflow-y: auto; height: 100%;
  background: linear-gradient(var(--brand) 0 230px, var(--panel-2) 230px);
  display: flex; flex-direction: column; align-items: center;
  padding: calc(40px + var(--safe-top)) 16px 32px;
}
@media (prefers-color-scheme: dark) {
  .auth { background: linear-gradient(#103529 0 230px, var(--bg) 230px); }
}
.auth-top { text-align: center; color: #fff; margin-bottom: 24px; }
.auth-logo { width: 76px; height: 76px; border-radius: 22px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.auth-top h1 { margin: 12px 0 4px; font-size: 28px; letter-spacing: -.3px; }
.auth-top p { margin: 0; opacity: .85; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel);
  border-radius: 16px; padding: 20px; box-shadow: 0 8px 30px rgba(0, 0, 0, .12);
  display: flex; flex-direction: column; gap: 14px;
}
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel-2); border-radius: 12px; padding: 4px; }
.tab { padding: 10px; border-radius: 9px; font-weight: 600; color: var(--text-2); transition: all .15s; }
.tab.active { background: var(--panel); color: var(--brand); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
@media (prefers-color-scheme: dark) { .tab.active { background: var(--input-bg); color: #21c063; } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field input {
  width: 100%; padding: 13px 14px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--input-bg); outline: none; font-size: 16px;
}
.field input:focus { border-color: var(--accent); }
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 46px; }
.pass-wrap .icon-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); color: var(--text-2); }
.auth-error { color: var(--danger); margin: 0; min-height: 0; font-size: 14px; }
.auth-error:empty { display: none; }

/* ================= Estructura ================= */
.app { position: fixed; inset: var(--app-top, 0px) 0 auto 0; height: var(--app-h, 100%); display: grid; grid-template-columns: 1fr; background: var(--panel); overflow: hidden; overflow: clip; }
.pane { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.list-pane { grid-area: 1 / 1; }
.chat-pane {
  grid-area: 1 / 1; z-index: 2;
  transform: translateX(100%); transition: transform .25s ease;
  visibility: hidden;
}
.app.chat-open .chat-pane { transform: none; visibility: visible; }
.chat-placeholder { display: none; }

@media (min-width: 900px) {
  .app { grid-template-columns: minmax(340px, 32%) 1fr; }
  .list-pane { grid-area: 1 / 1; border-right: 1px solid var(--line); }
  .chat-pane { grid-area: 1 / 2; transform: none; visibility: visible; transition: none; }
  .chat-placeholder {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; background: var(--panel-2); color: var(--text-2); text-align: center; gap: 4px;
    border-bottom: 6px solid var(--accent);
  }
  .chat-placeholder img { width: 96px; height: 96px; border-radius: 28px; opacity: .9; margin-bottom: 12px; }
  .chat-placeholder h2 { color: var(--text); font-weight: 400; margin: 0; font-size: 28px; }
  .chat-placeholder p { margin: 0; }
  .app.chat-open .chat-placeholder { display: none; }
  .chat-bar .back { display: none; }
}

/* ---------- Barras superiores ---------- */
.bar {
  display: flex; align-items: center; gap: 6px; flex: none;
  min-height: calc(56px + var(--safe-top)); padding: var(--safe-top) 8px 0 12px;
  background: var(--bar-bg); color: var(--bar-fg);
}
.brand { font-size: 21px; font-weight: 600; margin: 0 auto 0 4px; letter-spacing: -.2px; }
.bar-actions { display: flex; align-items: center; gap: 8px; }
.bar-title { display: flex; flex-direction: column; margin-left: 8px; min-width: 0; }
.bar-title span { font-size: 19px; font-weight: 500; }
.bar-title small { opacity: .8; font-size: 13px; }

/* ---------- Buscador ---------- */
.search-row {
  display: flex; align-items: center; gap: 12px; margin: 8px 12px; padding: 0 14px;
  background: var(--panel-2); border-radius: 24px; color: var(--text-2); height: 40px; flex: none;
}
.search-row svg { width: 20px; height: 20px; }
.search-row input { flex: 1; border: 0; outline: 0; background: none; height: 100%; font-size: 15px; color: var(--text); min-width: 0; }

/* ---------- Lista de chats ---------- */
.chat-list { list-style: none; margin: 0; padding: 0 0 96px; overflow-y: auto; flex: 1; }
.chat-item {
  display: flex; align-items: center; gap: 13px; padding: 0 14px; cursor: pointer;
  transition: background .12s; position: relative;
}
.chat-item:active, .chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--panel-2); }
.chat-item .avatar-wrap { position: relative; padding: 10px 0; }
.chat-item .online-dot {
  position: absolute; right: 1px; bottom: 11px; width: 13px; height: 13px; border-radius: 50%;
  background: #25d366; border: 2px solid var(--panel);
}
.chat-item .body { flex: 1; min-width: 0; padding: 12px 0; border-bottom: 1px solid var(--line); align-self: stretch; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.chat-item:last-child .body { border-bottom: 0; }
.chat-item .top, .chat-item .bottom { display: flex; align-items: center; gap: 8px; }
.chat-item .name { flex: 1; font-size: 16.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .time { font-size: 12px; color: var(--text-2); flex: none; }
.chat-item.unread .time { color: #1fa855; font-weight: 600; }
.chat-item .preview { flex: 1; color: var(--text-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 3px; min-width: 0; }
.chat-item .preview svg { width: 17px; height: 17px; flex: none; }
.chat-item .preview .txt { overflow: hidden; text-overflow: ellipsis; }
.chat-item .preview.typing { color: #1fa855; font-weight: 500; }
.chat-item .count {
  background: #25d366; color: #fff; font-size: 12px; font-weight: 700;
  min-width: 21px; height: 21px; padding: 0 6px; border-radius: 11px; display: grid; place-items: center;
}
@media (prefers-color-scheme: dark) { .chat-item .count { color: #111b21; } }
.section-label { color: var(--accent); font-size: 14px; font-weight: 600; margin: 10px 18px 4px; }

.list-empty { text-align: center; color: var(--text-2); padding: 40px 28px; }
.list-empty p { margin: 4px 0; }
.list-empty strong { color: var(--text); font-weight: 600; }
.empty-illustration { font-size: 52px; margin-bottom: 8px; }

.fab {
  position: absolute; right: 18px; bottom: calc(20px + var(--safe-bottom));
  width: 58px; height: 58px; border-radius: 17px; background: var(--accent); color: #fff;
  display: grid; place-items: center; box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
  transition: transform .12s;
}
.fab:active { transform: scale(.94); }

/* ================= Conversación ================= */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; }
.chat-bar { padding-left: 2px; gap: 2px; }
.chat-peer { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; text-align: left; padding: 6px 4px; border-radius: 24px; }
.peer-text { display: flex; flex-direction: column; min-width: 0; }
.peer-name { font-size: 17px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status:empty { display: none; }

.wallpaper { background-color: var(--chat-bg); background-image: var(--wallpaper); }
.messages {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px 0 8px;
  display: flex; flex-direction: column; overscroll-behavior: contain;
}
#msg-list { margin-top: auto; padding: 0 4% 4px; }
@media (min-width: 900px) { #msg-list { padding: 0 7% 4px; } }
.load-more { text-align: center; color: var(--text-2); font-size: 13px; padding: 6px; }

.day-chip {
  display: table; margin: 10px auto 8px; padding: 5px 12px; border-radius: 8px;
  background: var(--chip); color: var(--chip-text); font-size: 12.5px; box-shadow: var(--bubble-shadow);
  text-transform: uppercase; position: sticky; top: 4px; z-index: 1;
}
.notice-chip {
  display: table; margin: 8px auto; padding: 6px 12px; border-radius: 8px; max-width: 85%;
  background: #ffeecd; color: #54656f; font-size: 12.5px; text-align: center;
}
@media (prefers-color-scheme: dark) { .notice-chip { background: #182229; color: #ffd279; } }

.row { display: flex; margin-top: 2px; }
.row.first { margin-top: 10px; }
.row.me { justify-content: flex-end; }
.bubble {
  position: relative; max-width: min(78%, 520px); padding: 6px 7px 8px 9px;
  border-radius: 8px; box-shadow: var(--bubble-shadow); font-size: 15.2px; line-height: 1.38;
  overflow-wrap: anywhere; background: var(--them);
}
.row.me .bubble { background: var(--me); }
.row.first.me .bubble { border-top-right-radius: 0; }
.row.first.them .bubble { border-top-left-radius: 0; }
.row.first .bubble::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px; background: inherit;
}
.row.first.me .bubble::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.row.first.them .bubble::before { left: -8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.bubble .text { white-space: pre-wrap; }
.bubble .text a { color: #027eb5; }
@media (prefers-color-scheme: dark) { .bubble .text a { color: #53bdeb; } }
.bubble .text.big { font-size: 40px; line-height: 1.15; }
.spacer { display: inline-block; width: 46px; height: 1px; }
.row.me .spacer { width: 66px; }
.meta {
  position: absolute; right: 7px; bottom: 3px; display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--text-2); white-space: nowrap; line-height: 15px;
}
.meta svg { width: 16px; height: 15px; color: var(--tick); }
.meta svg.read { color: var(--tick-read); }
.meta svg.clock { width: 13px; height: 13px; }

/* Media */
.bubble.media { padding: 3px; }
.bubble.media .thumb {
  position: relative; display: block; border-radius: 6px; overflow: hidden; cursor: pointer;
  width: min(300px, 66vw); max-height: 360px; min-height: 120px; background: rgba(0, 0, 0, .08);
}
.bubble.media .thumb img, .bubble.media .thumb video { display: block; width: 100%; height: 100%; max-height: 360px; object-fit: cover; }
.bubble.media .caption { padding: 5px 5px 4px 6px; }
.bubble.media .caption .text { white-space: pre-wrap; }
.bubble.media.nocap .meta {
  color: #fff; right: 8px; bottom: 7px; padding: 2px 4px 0; border-radius: 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.35)); text-shadow: 0 1px 1px rgba(0,0,0,.4);
}
.bubble.media.nocap .meta svg:not(.read) { color: #fff; }
.thumb .play {
  position: absolute; inset: 0; margin: auto; width: 52px; height: 52px; border-radius: 50%;
  background: rgba(0, 0, 0, .45); display: grid; place-items: center; color: #fff;
}
.thumb .play svg { width: 30px; height: 30px; }
.thumb .vlen {
  position: absolute; left: 8px; bottom: 6px; color: #fff; font-size: 11px; display: flex; gap: 3px; align-items: center;
  text-shadow: 0 1px 1px rgba(0,0,0,.5);
}
.thumb .vlen svg { width: 16px; height: 16px; }
.uploading {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .3);
}
.ring { width: 52px; height: 52px; }
.ring circle { fill: none; stroke-width: 3; }
.ring .bgc { stroke: rgba(255, 255, 255, .35); }
.ring .fgc { stroke: #fff; stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset .2s; }
.failed { color: var(--danger); font-size: 12px; padding: 4px 6px 0; display: flex; align-items: center; gap: 4px; }
.failed button { color: var(--accent); font-weight: 600; text-decoration: underline; font-size: 12px; }

/* Nota de voz */
.bubble.audio { padding: 7px 8px 6px 7px; }
.voice { display: flex; align-items: center; gap: 8px; width: min(290px, 68vw); }
.row.me .voice .v-avatar, .row.me .voice .speed { order: 3; }
.voice .v-avatar { position: relative; flex: none; }
.voice .v-avatar .avatar { width: 50px; height: 50px; }
.voice .v-avatar .mic {
  position: absolute; bottom: -2px; width: 20px; height: 20px; color: #1fa855;
}
.row.them .voice .v-avatar .mic { right: -4px; }
.row.me .voice .v-avatar .mic { left: -4px; }
.voice.played .v-avatar .mic { color: var(--tick-read); }
.voice .speed {
  display: none; width: 50px; height: 50px; place-items: center; flex: none;
}
.voice .speed span { background: rgba(0,0,0,.35); color: #fff; font-size: 13px; font-weight: 700; padding: 3px 9px; border-radius: 12px; }
.voice.playing .speed, .voice.speed-on .speed { display: grid; }
.voice.playing .v-avatar, .voice.speed-on .v-avatar { display: none; }
.voice .v-play { width: 34px; height: 34px; display: grid; place-items: center; color: var(--text-2); flex: none; }
.voice .v-play svg { width: 32px; height: 32px; }
.voice .v-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding-top: 10px; }
.voice .wave { position: relative; height: 28px; display: flex; align-items: center; gap: 2px; cursor: pointer; touch-action: none; }
.voice .wave i { flex: 1; border-radius: 2px; background: var(--wave); min-height: 3px; max-width: 3px; }
.row.me .voice .wave i { background: var(--wave-me); }
.voice .wave i.on { background: var(--wave-on); }
.row.me .voice .wave i.on { background: #4fb6ec; }
.voice .knob {
  position: absolute; top: 50%; width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; border-radius: 50%;
  background: var(--wave-on); left: 0; pointer-events: none;
}
.row.me .voice .knob { background: #4fb6ec; }
.voice .v-info { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-2); height: 15px; }
.bubble.audio .meta { position: static; }
.bubble.audio.sending .v-play svg { animation: spin 1s linear infinite; }

/* Indicador "escribiendo" dentro del chat */
.typing-row .bubble { padding: 10px 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-2); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes spin { to { transform: rotate(360deg); } }

.scroll-down {
  position: absolute; right: 14px; bottom: calc(76px + var(--safe-bottom)); z-index: 3;
  width: 44px; height: 44px; border-radius: 50%; background: var(--panel); color: var(--text-2);
  display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}
.scroll-down .badge {
  position: absolute; top: -6px; right: -2px; background: #25d366; color: #fff; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 5px;
}

/* ---------- Barra de escritura ---------- */
.composer {
  flex: none; display: flex; align-items: flex-end; gap: 6px;
  padding: 6px 6px calc(7px + var(--safe-bottom)); background: var(--chat-bg);
  position: relative;
}
@media (prefers-color-scheme: dark) { .composer { background: var(--composer-bg); } }
.input-box, .rec-box {
  flex: 1; min-width: 0; display: flex; align-items: flex-end; background: var(--input-bg);
  border-radius: 25px; min-height: 48px; padding: 4px 4px 4px 16px; box-shadow: var(--bubble-shadow);
}
.input-box textarea {
  flex: 1; min-width: 0; border: 0; outline: 0; resize: none; background: none;
  font-size: 16.5px; line-height: 22px; padding: 9px 0; min-height: 40px; max-height: 132px; color: var(--text);
}
.input-box .icon-btn { margin-bottom: 0; }
.composer.has-text #btn-camera { display: none; }
.send-btn {
  width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff; flex: none;
  display: grid; place-items: center; box-shadow: var(--bubble-shadow); touch-action: none; user-select: none; -webkit-user-select: none;
  transition: transform .15s, background .15s;
}
.send-btn svg { grid-area: 1 / 1; transition: transform .15s, opacity .15s; }
.send-btn .i-send { opacity: 0; transform: scale(.5) rotate(-30deg); width: 22px; height: 22px; margin-left: 3px; }
.composer.has-text .send-btn .i-mic, .composer.recording.locked .send-btn .i-mic { opacity: 0; transform: scale(.5); }
.composer.has-text .send-btn .i-send, .composer.recording.locked .send-btn .i-send { opacity: 1; transform: none; }
.composer.recording:not(.locked) .send-btn { transform: scale(1.45); background: var(--accent-dark); }

.rec-box { align-items: center; gap: 8px; padding-left: 4px; overflow: hidden; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; flex: none; }
@keyframes pulse { 50% { opacity: .2; } }
.rec-time { font-variant-numeric: tabular-nums; min-width: 38px; color: var(--text); }
.rec-wave { flex: 1; min-width: 0; height: 32px; }
.rec-hint { color: var(--text-2); font-size: 14px; white-space: nowrap; padding-right: 10px; }
.composer.recording.locked .rec-hint { display: none; }
.composer:not(.locked) #rec-cancel { display: none; }
.composer:not(.locked) .rec-box { padding-left: 16px; }

/* ---------- Menú adjuntar ---------- */
.attach-menu {
  position: fixed; z-index: 30; left: 8px; right: 8px; bottom: calc(66px + var(--safe-bottom));
  max-width: 420px; margin: 0 auto; background: var(--panel); border-radius: 18px;
  padding: 18px 10px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25); animation: pop .18s ease;
}
.attach-menu button { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); }
.attach-menu .dot { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.dot.purple { background: #7f66ff; } .dot.pink { background: #ff2e74; } .dot.red { background: #ff5b46; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.97); } }

/* ================= Paneles deslizantes ================= */
.sheet {
  position: absolute; inset: 0; z-index: 10; background: var(--panel); display: flex; flex-direction: column;
  animation: slide-in .22s ease;
}
@keyframes slide-in { from { transform: translateX(30%); opacity: 0; } }
@media (min-width: 900px) {
  #new-chat, #profile { right: auto; width: max(340px, 32%); border-right: 1px solid var(--line); }
  #contact { left: auto; width: 400px; border-left: 1px solid var(--line); box-shadow: -4px 0 20px rgba(0,0,0,.08); }
}
.sheet-body { flex: 1; overflow-y: auto; background: var(--panel-2); padding-bottom: calc(24px + var(--safe-bottom)); }
@media (prefers-color-scheme: dark) { .sheet-body { background: var(--bg); } }
.profile-photo { display: flex; justify-content: center; padding: 28px 0 22px; background: var(--panel-2); }
@media (prefers-color-scheme: dark) { .profile-photo { background: var(--bg); } }
.big-avatar { position: relative; border-radius: 50%; }
.cam-badge {
  position: absolute; right: 6px; bottom: 6px; width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.info-row {
  display: flex; gap: 22px; padding: 14px 20px; align-items: flex-start; background: var(--panel); color: var(--text-2);
  border-bottom: 1px solid var(--line);
}
.info-row > svg { margin-top: 12px; }
.info-row .pencil { width: 20px; height: 20px; color: var(--accent); }
.info-text { flex: 1; min-width: 0; }
.info-text small { font-size: 13.5px; }
.info-text input, .info-text p {
  display: block; width: 100%; border: 0; border-bottom: 2px solid transparent; outline: 0; background: none;
  color: var(--text); font-size: 16.5px; padding: 4px 0; margin: 0;
}
.info-text input:focus { border-bottom-color: var(--accent); }
.info-text .hint { font-size: 13px; color: var(--text-2); border: 0; padding: 2px 0 0; }
.menu-row {
  display: flex; align-items: center; gap: 22px; width: 100%; padding: 16px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); color: var(--text); font-size: 16px; text-align: left; margin-top: 0;
}
.menu-row:first-of-type { margin-top: 10px; }
.menu-row svg { color: var(--text-2); }
.menu-row.danger, .menu-row.danger svg { color: var(--danger); }
.contact-head { background: var(--panel); text-align: center; padding: 28px 16px 20px; margin-bottom: 10px; }
.contact-head .big-avatar { margin: 0 auto 14px; display: block; }
.contact-head h2 { margin: 0; font-size: 24px; font-weight: 500; }
.muted-text { color: var(--text-2); margin: 4px 0 0; }
.card { background: var(--panel); padding: 14px 20px; margin-bottom: 10px; }
.card p { margin: 6px 0 0; font-size: 16px; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 10px; }
.media-grid:empty::after { content: "Nada todavía"; color: var(--text-2); grid-column: 1 / -1; font-size: 14px; }
.media-grid button { aspect-ratio: 1; border-radius: 6px; overflow: hidden; position: relative; background: #0002; }
.media-grid img, .media-grid video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid .play { position: absolute; left: 4px; bottom: 2px; color: #fff; }
.media-grid .play svg { width: 18px; height: 18px; }

/* ================= Capas a pantalla completa ================= */
.overlay {
  position: fixed; inset: var(--app-top, 0px) 0 auto 0; height: var(--app-h, 100%); z-index: 40; background: #0b141a; color: #fff;
  display: flex; flex-direction: column; animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.overlay-bar { display: flex; align-items: center; gap: 12px; padding: calc(8px + var(--safe-top)) 8px 8px; flex: none; }
.viewer-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.viewer-title small { opacity: .7; }
.viewer-stage, .preview-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px; }
.viewer-stage img, .viewer-stage video, .preview-stage img, .preview-stage video {
  max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px;
}
.viewer-caption { text-align: center; padding: 10px 16px calc(18px + var(--safe-bottom)); margin: 0; white-space: pre-wrap; }
.viewer-caption:empty { display: none; }
.preview-thumbs { display: flex; gap: 8px; padding: 6px 12px; overflow-x: auto; justify-content: center; flex: none; }
.preview-thumbs:empty { display: none; }
.preview-thumbs button { width: 52px; height: 52px; border-radius: 8px; overflow: hidden; border: 2px solid transparent; flex: none; opacity: .7; }
.preview-thumbs button.active { border-color: var(--accent); opacity: 1; }
.preview-thumbs img, .preview-thumbs video { width: 100%; height: 100%; object-fit: cover; }
.preview-foot { display: flex; gap: 8px; padding: 8px 10px calc(10px + var(--safe-bottom)); align-items: center; flex: none; }
.preview-foot input {
  flex: 1; min-width: 0; height: 48px; border-radius: 24px; border: 0; outline: 0; padding: 0 18px;
  background: #2a3942; color: #fff; font-size: 16px;
}

.crop-stage { flex: 1; position: relative; overflow: hidden; touch-action: none; cursor: grab; }
.crop-stage img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; -webkit-user-select: none; max-width: none; }
.crop-mask {
  position: absolute; left: 50%; top: 50%; width: var(--crop, 280px); height: var(--crop, 280px);
  transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .6); border: 2px solid rgba(255, 255, 255, .85);
}
.crop-tools { padding: 14px 20px calc(16px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; flex: none; }
.crop-tools input[type=range] { width: 100%; accent-color: var(--accent); }
.crop-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.crop-actions .btn-primary { width: auto; padding: 11px 30px; }

/* ---------- Aviso flotante ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60;
  background: #323739; color: #fff; padding: 11px 18px; border-radius: 22px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3); max-width: calc(100% - 32px); text-align: center; animation: pop .2s ease;
}
.chat-list:empty { flex: 0; padding: 0; }

/* Con el teclado abierto no hace falta el margen de la barra de inicio del iPhone */
.kb-open .composer { padding-bottom: 7px; }
.kb-open .preview-foot { padding-bottom: 10px; }

/* ================= Responder y reaccionar ================= */
.row { position: relative; touch-action: pan-y; border-radius: 8px; }
.row.has-rx { margin-bottom: 18px; }
.row.selected { background: rgba(0, 168, 132, .16); }
.row.flash { animation: rowflash 1.5s ease; }
@keyframes rowflash { 0%, 35% { background: rgba(0, 168, 132, .28); } 100% { background: transparent; } }
@media (pointer: coarse) {
  .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}

/* Cita del mensaje respondido */
.quote {
  display: flex; align-items: stretch; gap: 6px; min-width: 0; max-width: 100%;
  border-radius: 6px; overflow: hidden; background: rgba(11, 20, 26, .05); border-left: 4px solid #7f66ff;
  margin: 0 0 5px; cursor: pointer; text-align: left;
}
.row.me .quote { background: rgba(11, 20, 26, .06); }
@media (prefers-color-scheme: dark) { .quote, .row.me .quote { background: rgba(0, 0, 0, .22); } }
.quote.q-me { border-left-color: #06cf9c; }
.quote.q-me .q-name { color: #008069; }
@media (prefers-color-scheme: dark) { .quote.q-me .q-name { color: #06cf9c; } }
.quote.q-them .q-name { color: #7f66ff; }
@media (prefers-color-scheme: dark) { .quote.q-them { border-left-color: #a594ff; } .quote.q-them .q-name { color: #a594ff; } }
.q-body { flex: 1; min-width: 0; padding: 5px 8px 6px 6px; display: flex; flex-direction: column; gap: 1px; }
.q-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.q-text { font-size: 13.5px; line-height: 1.3; color: var(--text-2); display: flex; align-items: flex-start; gap: 4px; min-width: 0; }
.q-text > span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; white-space: pre-wrap; overflow-wrap: anywhere; }
.q-text svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.q-thumb { width: 56px; min-height: 56px; object-fit: cover; flex: none; display: block; }
.bubble.has-quote { min-width: min(220px, 64vw); }
.bubble.media .quote { margin: 0 0 3px; }
.bubble.media .quote + .thumb { margin-top: 0; }

/* Barra "respondiendo a…" encima de la caja de texto */
.input-box { flex-wrap: wrap; }
.reply-preview { flex: 0 0 calc(100% + 8px); display: flex; align-items: flex-start; gap: 2px; margin: 2px 2px 2px -10px; }
.reply-slot { flex: 1; min-width: 0; }
.reply-slot .quote { margin: 0; cursor: default; }
.composer.replying .input-box { border-radius: 20px; }

/* Ícono que aparece al deslizar para responder */
.swipe-ico {
  position: absolute; left: -36px; top: 50%; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; background: var(--chip); color: var(--text-2); box-shadow: var(--bubble-shadow);
  opacity: var(--swipe, 0); transform: translateY(-50%) scale(calc(.6 + var(--swipe, 0) * .4)); pointer-events: none;
}
.swipe-ico svg { width: 18px; height: 18px; }

/* Botón 🙂 al pasar el mouse (computadora) */
.react-btn {
  align-self: center; flex: none; width: 30px; height: 30px; margin: 0 6px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text-2); background: var(--chip); box-shadow: var(--bubble-shadow);
  opacity: 0; transition: opacity .12s;
}
.react-btn svg { width: 19px; height: 19px; }
.row.me .react-btn { order: -1; }
.row:hover .react-btn, .react-btn:focus-visible { opacity: 1; }
@media (pointer: coarse) { .react-btn { display: none; } }

/* Reacciones debajo de la burbuja */
.rx {
  position: absolute; bottom: -17px; z-index: 1; display: flex; align-items: center; gap: 1px;
  padding: 1px 6px; border-radius: 14px; font-size: 14.5px; line-height: 21px;
  background: var(--them); border: 2px solid var(--chat-bg); box-shadow: 0 1px 2px rgba(11, 20, 26, .15);
}
.row.me .rx { left: 8px; }
.row.them .rx { left: 8px; }
.rx span { font-size: 12px; color: var(--text-2); margin-left: 3px; }

/* Menú del mensaje */
.msg-menu { position: fixed; inset: 0; z-index: 35; }
.mm-backdrop { position: absolute; inset: 0; background: rgba(11, 20, 26, .22); animation: fade .15s ease; }
.react-bar {
  position: fixed; display: flex; gap: 2px; padding: 5px 7px; border-radius: 30px;
  background: var(--panel); box-shadow: 0 6px 24px rgba(0, 0, 0, .25); animation: pop .16s ease;
}
.react-bar button { width: 42px; height: 42px; border-radius: 50%; font-size: 27px; display: grid; place-items: center; transition: transform .12s; }
.react-bar button:active { transform: scale(1.25); }
.react-bar button.on { background: var(--panel-2); }
.react-bar .more { color: var(--text-2); background: var(--panel-2); }
.react-bar .more svg { width: 22px; height: 22px; }
.mm-actions {
  position: fixed; min-width: 190px; padding: 6px 0; border-radius: 14px;
  background: var(--panel); box-shadow: 0 6px 24px rgba(0, 0, 0, .25); animation: pop .16s ease;
}
.mm-actions button { display: flex; align-items: center; gap: 16px; width: 100%; padding: 12px 18px; font-size: 15.5px; text-align: left; }
.mm-actions button:active, .mm-actions button:hover { background: var(--hover); }
.mm-actions svg { color: var(--text-2); width: 21px; height: 21px; }
.mm-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; max-height: 62%; overflow-y: auto;
  padding: 8px 12px calc(16px + var(--safe-bottom)); border-radius: 18px 18px 0 0;
  background: var(--panel); box-shadow: 0 -6px 24px rgba(0, 0, 0, .2); animation: sheet-up .2s ease;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
.mm-title { text-align: center; color: var(--text-2); font-size: 14px; margin: 8px 0 10px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 2px; }
.emoji-grid button { height: 50px; font-size: 30px; border-radius: 10px; }
.emoji-grid button:active, .emoji-grid button:hover { background: var(--panel-2); }
.rx-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 6px; border-radius: 10px; text-align: left; }
.rx-row:active, .rx-row:hover { background: var(--hover); }
.rx-who { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.rx-who small { color: var(--text-2); font-size: 13px; }
.rx-emoji { font-size: 26px; }
.input-box textarea { flex: 1 1 50%; }
