/* MULTIFICHAS — chat + onda violeta/oro de la web */
:root {
  --purple: #7b2ff7;
  --purple-dark: #4a1f8f;
  --purple-light: #a568ff;
  --gold: #ffc42e;
  --gold-2: #ffe07a;
  --gold-light: #ffe07a;
  --gold-dark: #e0a800;
  --gold-dim: rgba(255, 196, 46, 0.16);
  --felt: #0d3b2e;
  --felt-2: #0a2f25;
  --wa-teal: #00a884;
  --wa-teal-dark: #0b5c4a;
  --wa-header: #22143a;
  --wa-panel: #140c24;
  --wa-panel-2: #0e0918;
  --wa-elevated: #2a1848;
  --wa-input: #2a1a48;
  --wa-hover: #2f1d52;
  --wa-active: #352257;
  --wa-border: rgba(255, 196, 46, 0.14);
  --wa-text: #f2eefc;
  --wa-text-sec: #a89bc0;
  --wa-text-strong: #fffaf0;
  --wa-bubble-out: #4a1f8f;
  --wa-bubble-in: #241536;
  --wa-tick: #b8a8d0;
  --wa-tick-read: #ffc42e;
  --wa-danger: #ea4335;
  --wa-shadow: 0 1px 1px rgba(0, 0, 0, 0.28);
  --font: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --app-height: 100dvh;
  --touch: 44px;
  --composer-btn: 44px;
  --sidebar-w: min(400px, 100%);
  --bg: var(--wa-panel-2);
  --bg-2: var(--wa-panel);
  --bg-3: var(--wa-elevated);
  --panel: var(--wa-header);
  --text: var(--wa-text);
  --muted: var(--wa-text-sec);
  --green: var(--wa-teal);
  --line: var(--wa-border);
  --bubble-out: var(--wa-bubble-out);
  --bubble-in: var(--wa-bubble-in);
}

* { box-sizing: border-box; }
html {
  width: 100%;
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  width: 100%;
  max-width: 100%;
}
body {
  margin: 0;
  font-family: var(--font);
  color: var(--wa-text);
  background: #070b0e;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button, input, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer;
  border: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}
a { color: var(--gold-2); }

input, textarea, select { font-size: 16px !important; }

.hidden { display: none !important; }
.muted { color: var(--wa-text-sec); }
.tiny { font-size: 12px; display: block; line-height: 1.25; }
.block { width: 100%; }

/* Scrollbars tipo chat */
.chat-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.member-picker::-webkit-scrollbar {
  width: 6px;
}
.chat-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.member-picker::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.12);
  border-radius: 99px;
}

/* ========== LOGIN (colores web: violeta + oro) ========== */
.auth-body {
  min-height: var(--app-height);
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(12px, var(--safe-t))
    max(14px, var(--safe-r))
    max(16px, var(--safe-b))
    max(14px, var(--safe-l));
  background:
    radial-gradient(circle at 15% 15%, rgba(123, 47, 247, 0.35), transparent 45%),
    radial-gradient(circle at 85% 25%, rgba(34, 211, 238, 0.1), transparent 40%),
    radial-gradient(900px 420px at 50% -10%, rgba(255, 196, 46, 0.14), transparent 55%),
    linear-gradient(180deg, #120a24 0%, #0a0614 45%, #07060f 100%);
}
.auth-card {
  width: min(420px, 100%);
  margin: auto;
  background: linear-gradient(180deg, rgba(32, 22, 58, 0.98) 0%, rgba(18, 12, 36, 0.98) 100%);
  border: 1px solid rgba(123, 47, 247, 0.4);
  border-radius: 18px;
  padding: clamp(16px, 3.5vw, 28px) clamp(14px, 3.5vw, 24px) clamp(14px, 3vw, 22px);
  box-shadow:
    0 0 0 1px rgba(255, 196, 46, 0.12),
    0 18px 50px rgba(0, 0, 0, 0.55),
    0 0 40px rgba(123, 47, 247, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--purple), var(--gold), var(--purple-light), transparent);
}
.brand-mark {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: var(--wa-teal);
  color: #fff;
  margin: 0 auto 16px;
}
.brand-logo {
  display: block;
  width: clamp(88px, 28vw, 140px);
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: #000;
  border: 2px solid rgba(255, 196, 46, 0.65);
  box-shadow:
    0 0 0 4px rgba(123, 47, 247, 0.2),
    0 10px 28px rgba(0,0,0,.55),
    0 0 40px rgba(255, 196, 46, 0.2);
}
.empty-logo {
  display: block;
  width: 104px;
  height: 104px;
  object-fit: cover;
  border-radius: 50%;
  margin: 0 auto 14px;
  border: 2px solid rgba(212, 175, 55, 0.4);
  box-shadow: 0 6px 22px rgba(0,0,0,.4);
  background: #000;
}
.auth-card h1 {
  margin: 0 0 4px;
  font-size: clamp(1.2rem, 4.5vw, 1.55rem);
  font-weight: 600;
  letter-spacing: 1.5px;
  text-align: center;
  color: var(--gold-2);
  text-shadow: 0 1px 0 rgba(0,0,0,.4);
}
.auth-card > .muted {
  text-align: center;
  margin: 0 0 4px;
  font-size: clamp(12px, 3.4vw, 14px);
  line-height: 1.35;
  padding: 0 4px;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 14px 0 2px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(123, 47, 247, 0.35);
}
.auth-tab {
  text-align: center;
  padding: 11px 8px;
  min-height: var(--touch);
  display: grid;
  place-items: center;
  border-radius: 9px;
  font-size: clamp(13px, 3.5vw, 14px);
  font-weight: 600;
  color: #b8b0d8;
  text-decoration: none;
}
.auth-tab.active {
  background: linear-gradient(135deg, #ffe07a, #ffc42e 45%, #e0a800);
  color: #1a1030;
}
.fineprint a { color: var(--gold-2); font-weight: 600; }
.stack { display: grid; gap: 12px; margin-top: 16px; }
label {
  display: grid;
  gap: 5px;
  font-size: 11px;
  color: var(--gold);
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.auth-card input,
.auth-card textarea {
  width: 100%;
  max-width: 100%;
  border: 1px solid rgba(255,255,255,.08) !important;
  border-bottom: 1px solid rgba(255,255,255,.08) !important;
  background: rgba(0,0,0,.28) !important;
  border-radius: 12px !important;
  padding: 12px 14px !important;
  min-height: var(--touch);
  outline: none;
  color: var(--wa-text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.auth-card input:focus,
.auth-card textarea:focus {
  border-color: rgba(165, 104, 255, 0.65) !important;
  box-shadow: 0 0 0 3px rgba(123, 47, 247, 0.22);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 40px;
  padding: 13px 18px;
  min-height: var(--touch);
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  font-size: 13px;
  text-decoration: none;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}
.btn:active { transform: scale(0.985); }
.btn.primary {
  background: linear-gradient(135deg, #ffe07a, #ffc42e 40%, #e0a800);
  color: #1a1030;
  box-shadow: 0 10px 28px rgba(255, 196, 46, 0.35);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost {
  background: rgba(123, 47, 247, 0.14);
  border: 1px solid rgba(165, 104, 255, 0.45);
  color: #f4f1ff;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}
.btn.ghost:hover {
  border-color: var(--gold);
  background: rgba(123, 47, 247, 0.24);
}
.auth-actions {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}
.alert {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;
}
.alert.error { background: rgba(234, 67, 53, 0.12); color: #f15c6d; border: 1px solid rgba(234,67,53,.2); }
.alert.ok { background: rgba(0, 168, 132, 0.12); color: #25d366; border: 1px solid rgba(0,168,132,.2); }
.fineprint {
  margin: 12px 0 10px;
  font-size: 12px;
  color: var(--wa-text-sec);
  text-align: center;
  line-height: 1.4;
}

/* ========== APP SHELL ========== */
.app-body {
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: var(--app-height);
  background:
    radial-gradient(1200px 500px at 50% -20%, rgba(123,47,247,.18), transparent 50%),
    radial-gradient(800px 400px at 80% 100%, rgba(255,196,46,.08), transparent 45%),
    #07060f;
}
.shell {
  height: 100%;
  height: var(--app-height);
  width: min(1600px, 100%);
  max-width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  background: #100b1c;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(123,47,247,.25), 0 20px 60px rgba(0,0,0,.45);
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(123,47,247,.28);
  background: linear-gradient(180deg, #1a1230 0%, #100b1c 100%);
  min-height: 0;
  min-width: 0;
  padding-left: var(--safe-l);
}
.side-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 10px;
  padding: calc(12px + var(--safe-t)) 12px 12px 14px;
  background: linear-gradient(145deg, #4c1d95 0%, #2e1065 42%, #1a1230 100%);
  flex-shrink: 0;
  min-height: 64px;
  border-bottom: 1px solid rgba(255,196,46,.28);
  box-shadow: 0 8px 22px rgba(0,0,0,.28);
}
.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.35px;
  text-transform: uppercase;
  color: #86efac;
}
.conn-pill.offline { color: #f0b429; }
.me {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  flex: 1 1 180px;
}
.me .avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  min-width: 42px;
  max-width: 42px;
  aspect-ratio: 1;
}
.me-meta {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.me strong {
  display: block;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  letter-spacing: .15px;
}
.me .muted.tiny {
  color: var(--gold-2);
  font-size: 11.5px;
  font-weight: 600;
  opacity: .95;
}
.side-actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
  align-items: center;
  margin-left: auto;
}
.icon-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  border-radius: 11px;
  color: var(--gold-2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,196,46,.14);
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover,
.icon-btn:active {
  background: var(--gold-dim);
  color: #fff;
  border-color: rgba(255,196,46,.4);
}
.icon-btn svg { width: 20px; height: 20px; }

.avatar {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  font-size: 18px;
  box-shadow: 0 0 0 2px rgba(255,196,46,.35);
  overflow: hidden;
  background: #000;
}
.avatar-logo,
img.avatar {
  display: block;
  object-fit: cover;
  object-position: center;
  padding: 0;
  background: #000;
  border: 1.5px solid rgba(255,196,46,.55);
  box-shadow:
    0 0 0 2px rgba(123,47,247,.25),
    0 4px 12px rgba(0,0,0,.35);
}
.side-header .avatar,
.chat-header .avatar {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  font-size: 16px;
}
.avatar.avatar-client {
  background: linear-gradient(145deg, #6b2fd4, #2a1548 55%, #1a0b2e);
  border: 1.5px solid rgba(255,196,46,.45);
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: .5px;
  flex-shrink: 0;
  aspect-ratio: 1;
}
.avatar.avatar-group {
  background: linear-gradient(145deg, #3b1d6e, #160e28);
  border: 1.5px solid rgba(255,196,46,.35);
}

.search-wrap {
  padding: 10px 12px 8px;
  background: transparent;
  flex-shrink: 0;
}
.search-wrap input {
  width: 100%;
  border: 1px solid rgba(255,196,46,.14) !important;
  border-radius: 14px;
  background: rgba(255,255,255,.04);
  padding: 11px 14px 11px 40px;
  min-height: 42px;
  font-size: 14px !important;
  color: var(--wa-text);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='%23ffc42e' viewBox='0 0 24 24'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 18px;
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.search-wrap input::placeholder { color: var(--wa-text-sec); }
.search-wrap input:focus {
  outline: none;
  border-color: rgba(255,196,46,.45) !important;
  background-color: rgba(123,47,247,.14);
  box-shadow: 0 0 0 3px rgba(255,196,46,.08);
}

.chat-list {
  overflow: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 4px 8px calc(10px + var(--safe-b));
}
.chat-item {
  width: 100%;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 11px 12px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 14px;
  min-height: 72px;
  position: relative;
  margin-bottom: 4px;
  transition: background .14s ease, border-color .14s ease, transform .12s ease;
}
.chat-item::after { display: none; }
.chat-item:hover {
  background: rgba(168,85,247,.1);
  border-color: rgba(255,196,46,.12);
}
.chat-item:active { transform: scale(.985); }
.chat-item.active {
  background: linear-gradient(105deg, rgba(255,196,46,.16), rgba(123,47,247,.22));
  border-color: rgba(255,196,46,.32);
  box-shadow: inset 3px 0 0 var(--gold);
}
.chat-item.active::before { display: none; }
.chat-item > div:nth-child(2) { min-width: 0; }
.chat-item .title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  font-size: 15.5px;
  color: #fff;
  line-height: 1.25;
}
.chat-item .title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item .preview {
  color: var(--wa-text-sec);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
  line-height: 1.3;
}
.chat-item .meta { text-align: right; flex-shrink: 0; align-self: start; padding-top: 2px; }
.chat-item .time {
  font-size: 11.5px;
  color: var(--gold);
  font-weight: 600;
  opacity: .85;
}
.chat-item .time.has-unread { color: var(--gold-2); font-weight: 700; opacity: 1; }
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f0d78c, #d4af37);
  color: #1a1405;
  font-size: 12px;
  font-weight: 700;
  margin-top: 6px;
}
.dot-online {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--wa-teal);
  box-shadow: 0 0 0 2px var(--wa-panel), 0 0 8px rgba(0,168,132,.5);
  position: absolute;
  right: 0;
  bottom: 0;
}
.avatar-wrap { position: relative; width: 49px; height: 49px; }
.chip-tag {
  display: inline-block;
  margin-top: 4px;
  font-size: 10px;
  font-weight: 800;
  color: var(--gold-2);
  letter-spacing: 0.35px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255,196,46,.12);
  border: 1px solid rgba(255,196,46,.28);
}

/* ========== CHAT ========== */
.chat-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-right: var(--safe-r);
  background-color: #0e0918;
  background-image:
    linear-gradient(180deg, rgba(18, 10, 36, 0.94), rgba(10, 6, 20, 0.96)),
    radial-gradient(circle at 18% 12%, rgba(123,47,247,.16), transparent 42%),
    radial-gradient(circle at 82% 88%, rgba(255,196,46,.08), transparent 40%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260'%3E%3Cg fill='none' stroke='%23ffc42e' stroke-opacity='0.05' stroke-width='1'%3E%3Cpath d='M20 40c10-8 22-6 28 4M60 30c6 10 2 22-8 26M110 50c12-4 20 8 12 18M160 35c8 8 4 20-6 22M210 48c10-6 18 4 12 14M40 100c8-10 24-6 26 8M90 110c10 6 8 20-4 24M140 95c14-2 18 14 8 22M190 115c8-12 26-8 28 6M30 170c12-6 22 6 14 16M80 180c10 8 4 22-8 22M130 165c14 0 18 16 6 22M180 185c10-10 26-4 26 10M50 230c10-8 24 0 22 14M110 235c8 8 0 18-12 16M170 225c12-4 20 10 10 18'/%3E%3Ccircle cx='70' cy='70' r='3'/%3E%3Ccircle cx='150' cy='140' r='2.5'/%3E%3Cpath d='M100 200l6 10 12-4-6-10z'/%3E%3C/g%3E%3C/svg%3E");
  background-size: auto, auto, auto, 340px;
}

.empty-chat {
  margin: auto;
  text-align: center;
  color: var(--wa-text-sec);
  padding: 28px 24px;
  max-width: 460px;
  background: linear-gradient(180deg, #2a1848, #160e28);
  border-radius: 18px;
  border: 1px solid rgba(255,196,46,.28);
  box-shadow: 0 12px 40px rgba(0,0,0,.4), 0 0 40px rgba(123,47,247,.15);
}
.empty-chat h2 {
  color: var(--gold-2);
  margin: 0 0 8px;
  font-weight: 600;
  font-size: 24px;
  letter-spacing: 1px;
}
.empty-illu {
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #2a3942;
  font-size: 32px;
}

.active-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  min-width: 0;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) 14px 10px 10px;
  background: linear-gradient(145deg, #3b1d6e 0%, #22143a 55%, #160e28 100%);
  border-bottom: 1px solid rgba(255,196,46,.22);
  flex-shrink: 0;
  min-height: 64px;
  box-shadow: 0 8px 22px rgba(0,0,0,.28);
}
.chat-header .avatar {
  width: 40px;
  height: 40px;
  font-size: 16px;
}
.peer-meta { min-width: 0; overflow: hidden; flex: 1; }
.peer-meta strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 16px;
  font-weight: 500;
  color: var(--wa-text-strong);
}
.peer-meta .tiny {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--wa-text-sec);
  font-size: 13px;
  margin-top: 1px;
}

.messages {
  flex: 1;
  overflow: auto;
  overflow-x: hidden;
  padding: 18px max(6%, var(--safe-l)) 10px max(6%, var(--safe-r));
  display: flex;
  flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.day-sep {
  align-self: center;
  background: rgba(36, 21, 54, 0.95);
  color: var(--gold-2);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  margin: 10px 0;
  box-shadow: var(--wa-shadow);
  border: 1px solid rgba(255,196,46,.22);
  text-transform: capitalize;
  letter-spacing: 0.25px;
}

.bubble-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  padding: 0 2px;
}
.bubble-row.mine { justify-content: flex-end; }
.bubble {
  max-width: min(68%, 560px);
  padding: 8px 11px 6px;
  border-radius: 14px;
  background: var(--wa-bubble-in);
  box-shadow: 0 2px 10px rgba(0,0,0,.28);
  position: relative;
  animation: pop .14s ease;
  word-break: break-word;
  overflow-wrap: anywhere;
  border: 1px solid rgba(255,255,255,.05);
}
.bubble-row.mine .bubble {
  background: linear-gradient(165deg, #6b2fd4 0%, #4a1f8f 55%, #3b186e 100%);
  border-top-right-radius: 4px;
  border-color: rgba(255,196,46,.22);
  box-shadow: 0 2px 12px rgba(74,31,143,.35);
}
.bubble-row:not(.mine) .bubble {
  border-top-left-radius: 4px;
  background: linear-gradient(180deg, #2a1848 0%, #1e1234 100%);
  border-color: rgba(168,85,247,.18);
}

.bubble-row.mine .bubble::before {
  content: "";
  position: absolute;
  top: 0;
  right: -6px;
  width: 8px;
  height: 12px;
  background: #6b2fd4;
  clip-path: polygon(0 0, 100% 0, 0 100%);
}
.bubble-row:not(.mine) .bubble::before {
  content: "";
  position: absolute;
  top: 0;
  left: -6px;
  width: 8px;
  height: 12px;
  background: #2a1848;
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.bubble .text {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--wa-text);
}
.bubble .text .msg-link {
  color: var(--gold-2);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.bubble-row.mine .bubble .text .msg-link {
  color: #ffe07a;
}
.bubble .meta {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  margin-left: 10px;
  font-size: 11px;
  color: rgba(255,255,255,.55);
  float: right;
  clear: both;
  position: relative;
  top: 2px;
}
.ticks {
  letter-spacing: -1.5px;
  font-size: 13px;
  color: var(--wa-tick);
  line-height: 1;
}
.ticks.read { color: var(--wa-tick-read); }

.reply-quote {
  border-left: 3px solid var(--gold);
  background: rgba(0, 0, 0, 0.22);
  border-radius: 8px;
  padding: 5px 8px;
  margin-bottom: 5px;
  font-size: 12.5px;
  color: var(--wa-text-sec);
  cursor: pointer;
}
.sender-name {
  font-size: 12.8px;
  font-weight: 700;
  margin-bottom: 2px;
  line-height: 1.3;
}

.bubble-actions {
  order: 2;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .15s ease, transform .15s ease;
  align-self: center;
  position: static;
  transform: none;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bubble-row:not(.mine) .bubble-actions { order: 0; }
.bubble-row:hover .bubble-actions,
.bubble-row:focus-within .bubble-actions,
.bubble-row.show-actions .bubble-actions,
.bubble.show-actions ~ .bubble-actions,
.bubble-row:has(.bubble.show-actions) .bubble-actions { opacity: 1; }
.bubble-actions button {
  background: rgba(26, 18, 48, 0.95);
  border: 1px solid rgba(255,196,46,.35);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 13px;
  color: var(--gold-2);
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.bubble-actions button:hover {
  background: rgba(123,47,247,.35);
  color: #fff;
}
.bubble-actions button[data-del-msg]:hover {
  background: rgba(234,67,53,.25);
  border-color: rgba(234,67,53,.45);
}

.composer {
  display: grid;
  grid-template-columns: var(--composer-btn) var(--composer-btn) var(--composer-btn) minmax(0, 1fr) 48px;
  gap: 6px;
  align-items: end;
  padding: 10px max(12px, var(--safe-r)) calc(12px + var(--safe-b)) max(10px, var(--safe-l));
  background: linear-gradient(180deg, #22143a 0%, #160e28 100%);
  border-top: 1px solid rgba(255,196,46,.18);
  flex-shrink: 0;
}
.composer .icon-btn {
  width: var(--composer-btn);
  height: var(--composer-btn);
  min-width: var(--composer-btn);
  min-height: var(--composer-btn);
  background: rgba(255,255,255,.04);
}
.composer.recording {
  opacity: .55;
  pointer-events: none;
}

.audio-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #22143a;
  border-top: 1px solid rgba(255,196,46,.16);
}
.audio-bar-meta { flex: 1; min-width: 0; }
.audio-bar-meta strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--gold-2);
}
.audio-rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 0 rgba(239,68,68,.5);
  animation: livePulse 1.2s ease-out infinite;
  flex-shrink: 0;
}
.audio-send { width: 44px; height: 44px; min-width: 44px; }
.bubble.has-audio { min-width: min(280px, 80vw); }

/* ===== Voice player custom (WhatsApp / Telegram style) ===== */
.voice-player {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(280px, 76vw);
  padding: 8px 10px 8px 8px;
  margin: 2px 0 4px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,196,46,.14);
  border-radius: 14px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.bubble.mine .voice-player {
  background: rgba(0,0,0,.18);
  border-color: rgba(255,255,255,.10);
}

/* Botón play/pause */
.voice-play {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: #1a1030;
  background: linear-gradient(135deg, #ffe07a, #ffc42e 45%, #e0a800);
  box-shadow: 0 4px 14px rgba(255,196,46,.32), inset 0 -1px 0 rgba(0,0,0,.15);
  transition: transform .12s ease, filter .12s ease;
}
.voice-play:hover { filter: brightness(1.06); }
.voice-play:active { transform: scale(.94); }
.voice-play .ico {
  position: absolute;
  transition: opacity .15s ease, transform .2s ease;
  display: block;
}
.voice-play .ico-pause,
.voice-play .ico-loading { opacity: 0; transform: scale(.6); }
.voice-player[data-state="playing"] .voice-play .ico-play { opacity: 0; transform: scale(.6); }
.voice-player[data-state="playing"] .voice-play .ico-pause { opacity: 1; transform: scale(1); }
.voice-player[data-state="loading"] .voice-play .ico-play { opacity: 0; }
.voice-player[data-state="loading"] .voice-play .ico-loading {
  opacity: 1;
  transform: scale(1);
  animation: voiceSpin .9s linear infinite;
}
@keyframes voiceSpin {
  from { transform: rotate(0deg) scale(1); }
  to   { transform: rotate(360deg) scale(1); }
}

/* Waveform (barras verticales, dos capas: gris + progreso pintado encima) */
.voice-wave {
  flex: 1;
  position: relative;
  height: 34px;
  min-width: 0;
  cursor: pointer;
  touch-action: none;
}
.voice-wave:focus-visible { outline: 2px solid rgba(255,196,46,.55); outline-offset: 2px; border-radius: 4px; }
.voice-bars {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow: hidden;
  pointer-events: none;
}
.voice-bars > span {
  flex: 1 1 0;
  min-width: 2px;
  border-radius: 2px;
  background: rgba(255,255,255,.22);
}
.bubble.mine .voice-bars > span {
  background: rgba(255,255,255,.28);
}
.voice-bars-progress {
  width: 0;
  transition: width .08s linear;
}
.voice-bars-progress > span {
  background: linear-gradient(180deg, #ffe07a, #ffc42e 55%, #e0a800);
  box-shadow: 0 0 6px rgba(255,196,46,.4);
}
.bubble.mine .voice-bars-progress > span {
  background: linear-gradient(180deg, #ffffff, #ffe9b0 65%, #ffc42e);
}

/* Tiempo */
.voice-time {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
  color: var(--gold-2, #ffe07a);
  min-width: 34px;
  text-align: right;
  flex-shrink: 0;
  opacity: .95;
}
.bubble.mine .voice-time { color: rgba(255,255,255,.85); }
.voice-player[data-state="playing"] .voice-time { animation: voiceTimePulse 1.4s ease-in-out infinite; }
@keyframes voiceTimePulse {
  50% { opacity: .55; }
}

/* Estado de error */
.voice-player[data-state="error"] .voice-play {
  background: linear-gradient(135deg, #f87171, #dc2626);
  color: #fff;
}

.photo-bar,
.reply-bar { flex-shrink: 0; }

.photo-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #22143a;
  border-top: 1px solid rgba(255,196,46,.16);
}
.photo-bar img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
  border: 1px solid rgba(212,175,55,.25);
}
.photo-bar-meta { flex: 1; min-width: 0; }
.photo-bar-meta strong {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--gold-2);
}

.bubble-photo {
  display: block;
  max-width: min(280px, 72vw);
  max-height: min(320px, 45vh);
  width: auto;
  height: auto;
  border-radius: 8px;
  margin-bottom: 3px;
  cursor: zoom-in;
  background: rgba(0,0,0,0.25);
}
.bubble.has-photo { padding: 3px 3px 4px; }
.bubble.has-photo .text { padding: 2px 6px 0; }
.bubble.has-photo .meta { margin-right: 4px; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0,0,0,.94);
  display: grid;
  place-items: center;
  padding: max(16px, var(--safe-t)) max(16px, var(--safe-r)) max(16px, var(--safe-b)) max(16px, var(--safe-l));
}
.lightbox img {
  max-width: 100%;
  max-height: 85dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(212,175,55,.2);
}
.lightbox-close {
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: max(12px, var(--safe-r));
  width: var(--touch);
  height: var(--touch);
  border-radius: 50%;
  background: rgba(212,175,55,.15);
  color: var(--gold-2);
  font-size: 18px;
}

.composer textarea {
  resize: none !important;
  max-height: 120px;
  min-height: 42px;
  border-radius: 22px;
  padding: 11px 14px;
  background: rgba(255,255,255,.06);
  line-height: 1.35;
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(255,196,46,.16) !important;
  color: var(--wa-text);
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
  overflow-x: hidden;
  overflow-y: auto;
  field-sizing: content;
}
.composer textarea::-webkit-resizer { display: none; }
.composer textarea::-webkit-scrollbar { width: 4px; }
.composer textarea::-webkit-scrollbar-thumb {
  background: rgba(255,196,46,.35);
  border-radius: 99px;
}
.composer textarea::placeholder { color: var(--wa-text-sec); }
.composer textarea:focus {
  outline: none;
  border-color: rgba(255,196,46,.4) !important;
  background: rgba(123,47,247,.14);
  box-shadow: 0 0 0 3px rgba(255,196,46,.08);
}

.send-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f0d78c, #d4af37 55%, #b8922a);
  color: #1a1405;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(212,175,55,.3);
}
.send-btn:active { filter: brightness(0.95); }
.send-btn svg { fill: currentColor; }

.reply-bar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  background: #22143a;
  border-left: 4px solid var(--gold);
}
.reply-label {
  color: var(--gold);
  font-size: 12.5px;
  font-weight: 700;
}
.reply-bar p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--wa-text-sec);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(70vw, 420px);
}

.emoji-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: #22143a;
  border-top: 1px solid rgba(255,196,46,.16);
  max-height: min(180px, 28vh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}
.emoji-panel button {
  width: var(--touch);
  height: var(--touch);
  font-size: 22px;
  border-radius: 10px;
}
.emoji-panel button:hover { background: var(--gold-dim); }

.typing-line {
  align-self: flex-start;
  color: var(--gold-2);
  font-size: 12.5px;
  padding: 4px 8px 10px;
  font-style: italic;
}

/* ========== MODALES ========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 10, 0.78);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: max(12px, var(--safe-t)) max(12px, var(--safe-r)) max(12px, var(--safe-b)) max(12px, var(--safe-l));
  z-index: 50;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-card {
  width: min(440px, 100%);
  background: linear-gradient(180deg, #1f2a31, #151e24);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid rgba(212,175,55,.22);
  box-shadow: 0 16px 48px rgba(0,0,0,.5);
  max-height: min(90dvh, 720px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-card.modal-wide { width: min(520px, 100%); }
.modal-card h3 {
  margin: 0 0 4px;
  font-weight: 600;
  font-size: 20px;
  color: var(--gold-2);
}
.row-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.row-actions .btn { min-height: var(--touch); }

.avatar-group { border-radius: 50% !important; }

.member-picker {
  margin-top: 8px;
  display: grid;
  gap: 2px;
  max-height: 220px;
  overflow: auto;
  padding: 4px 0;
}
.member-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s ease;
}
.member-option:hover { background: var(--gold-dim); }
.member-option input { width: auto; accent-color: var(--gold); }
.avatar.mini {
  width: 40px;
  height: 40px;
  font-size: 15px;
}
.member-list {
  display: grid;
  gap: 0;
  margin: 12px 0;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.member-row .grow { flex: 1; min-width: 0; }
.member-row .grow strong {
  display: block;
  font-size: 16px;
  font-weight: 500;
}
.tiny-btn {
  padding: 8px 12px;
  font-size: 13px;
  text-transform: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  background: #1a242b;
  border: 1px solid rgba(212,175,55,.25);
  padding: 12px 18px;
  border-radius: 12px;
  z-index: 60;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  max-width: calc(100vw - 32px);
  text-align: center;
  color: var(--wa-text);
}

@keyframes pop {
  from { transform: translateY(5px) scale(0.98); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.chat-menu-wrap {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}
.chat-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: linear-gradient(180deg, #2a1848, #160e28);
  border: 1px solid rgba(255,196,46,.28);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
  padding: 6px;
  z-index: 20;
}
.chat-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 9px;
  color: var(--wa-text);
  font-size: 14.5px;
  font-weight: 600;
}
.chat-menu button:hover { background: rgba(255,196,46,.12); }
.chat-menu button.danger { color: #ff8a80; }
.chat-menu button.danger:hover { background: rgba(234,67,53,.12); }

.back-btn { display: none; }

/* ========== RESPONSIVE ========== */
@media (max-width: 980px) {
  :root { --sidebar-w: 340px; }
}

/* Auth: mobile / pantallas angostas */
@media (max-width: 480px) {
  .auth-body {
    align-items: stretch;
    padding:
      max(8px, var(--safe-t))
      max(10px, var(--safe-r))
      max(12px, var(--safe-b))
      max(10px, var(--safe-l));
  }
  .auth-card {
    width: 100%;
    border-radius: 16px;
    margin: 0;
  }
  .brand-logo { width: clamp(72px, 22vw, 104px); margin-bottom: 8px; }
  .auth-card h1 { letter-spacing: 1px; }
  .stack { gap: 10px; margin-top: 12px; }
  .auth-card input,
  .auth-card textarea { padding: 11px 12px !important; }
  .btn { padding: 12px 14px; font-size: 12.5px; }
  .fineprint { margin: 10px 0 8px; }
}

/* Auth: altura baja (teclado / landscape) */
@media (max-height: 720px) {
  .brand-logo { width: clamp(64px, 16vh, 100px); }
  .auth-card > .muted { display: none; }
  .stack { gap: 8px; margin-top: 10px; }
  .auth-tabs { margin-top: 10px; }
}

@media (max-height: 560px) {
  .auth-body { align-items: flex-start; }
  .brand-logo { width: 56px; margin-bottom: 6px; }
  .auth-card h1 { font-size: 1.1rem; }
  .auth-actions .btn.ghost:not(#installBtn) { display: none; }
}

@media (max-width: 860px) {
  .shell {
    width: 100%;
    grid-template-columns: 1fr;
    position: relative;
    box-shadow: none;
  }
  .back-btn { display: grid; }
  .sidebar,
  .chat-pane {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-right: 0;
    padding-left: 0;
    padding-right: 0;
  }
  .sidebar { z-index: 2; }
  .chat-pane { z-index: 1; visibility: hidden; pointer-events: none; }
  body.show-chat .sidebar {
    visibility: hidden;
    pointer-events: none;
    z-index: 1;
  }
  body.show-chat .chat-pane {
    visibility: visible;
    pointer-events: auto;
    z-index: 3;
  }
  .empty-chat { display: none; }

  .messages { padding-left: 10px; padding-right: 10px; }
  .bubble { max-width: min(82%, 520px); }
  .bubble-actions { opacity: 0; }
  .bubble-row.show-actions .bubble-actions,
  .bubble-row:has(.bubble.show-actions) .bubble-actions { opacity: 1; }
  .bubble-photo { max-width: min(250px, 78vw); }
  .side-actions .icon-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 10px;
  }
  .side-actions .icon-btn svg { width: 20px; height: 20px; }

  .modal {
    place-items: end center;
    padding: 0;
  }
  .modal-card,
  .modal-card.modal-wide {
    width: 100%;
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    max-height: min(92dvh, 100%);
    padding-bottom: calc(16px + var(--safe-b));
  }
  .member-picker { max-height: min(220px, 32vh); }
  .toast { bottom: calc(16px + var(--safe-b)); }
}

@media (max-width: 380px) {
  :root { --touch: 44px; --composer-btn: 40px; }
  .side-header { gap: 4px; padding-left: 10px; padding-right: 6px; }
  .me .muted.tiny { display: none; }
  .chat-item {
    grid-template-columns: 52px minmax(0, 1fr) auto;
    gap: 10px;
    padding: 10px;
  }
  .avatar, .avatar-wrap { width: 46px; height: 46px; }
  .composer {
    grid-template-columns: var(--composer-btn) var(--composer-btn) var(--composer-btn) minmax(0, 1fr) 48px;
    gap: 4px;
  }
  .send-btn { width: 48px; height: 48px; min-width: 48px; }
  .chat-item .title { font-size: 16px; }
  .auth-tab { font-size: 12.5px; padding: 10px 6px; }
  .label, label { font-size: 10.5px; }
  .side-actions .icon-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
  }
}

@media (max-width: 320px) {
  .side-actions #btnInstall { display: none; }
  .photo-bar img { width: 48px; height: 48px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .side-header,
  .chat-header { padding-top: 6px; padding-bottom: 6px; min-height: 48px; }
  .emoji-panel { max-height: 100px; }
  .composer textarea { max-height: 72px; min-height: 38px; }
  .modal-card { max-height: 95dvh; }
  .member-picker { max-height: 120px; }
  .bubble-photo { max-height: 140px; }
}

@media (min-width: 700px) and (max-width: 860px) {
  .shell { grid-template-columns: 340px 1fr; }
  .side-header .me { flex-basis: 100%; }
  .side-actions { margin-left: 0; }
  .sidebar,
  .chat-pane {
    position: relative;
    visibility: visible !important;
    pointer-events: auto !important;
  }
  .back-btn { display: none; }
  body.show-chat .sidebar {
    visibility: visible;
    pointer-events: auto;
  }
  .empty-chat { display: block; }
}

@supports not (height: 100dvh) {
  :root { --app-height: 100vh; }
}
