/* ============ Chatea con nosotros - estilo WhatsApp ============ */

:root, [data-theme="light"] {
  --teal:            #008069;
  --teal-strong:     #017561;
  --green:           #00a884;
  --green-dark:      #06cf9c;
  --chat-bg:         #efeae2;
  --panel:           #f0f2f5;
  --panel-2:         #ffffff;
  --bubble-in:       #ffffff;
  --bubble-out:      #d9fdd3;
  --text:            #111b21;
  --text-2:          #667781;
  --text-3:          #8696a0;
  --divider:         #e9edef;
  --tick:            #53bdeb;
  --notice:          #ffeecd;
  --notice-text:     #7d6f4c;
  --danger:          #ea4335;
  --bubble-shadow:   0 1px .5px rgba(11,20,26,.13);
  --panel-shadow:    0 2px 5px rgba(11,20,26,.06);
  --icon:            #54656f;
  --hover:           rgba(11,20,26,.04);
  --wallpaper-tint:  #d9d2c8;
  --doodle:          #0b141a;
  --doodle-alpha:    1;
}

[data-theme="dark"] {
  --teal:            #202c33;
  --teal-strong:     #1d282f;
  --green:           #00a884;
  --chat-bg:         #0b141a;
  --panel:           #202c33;
  --panel-2:         #2a3942;
  --bubble-in:       #202c33;
  --bubble-out:      #005c4b;
  --text:            #e9edef;
  --text-2:          #8696a0;
  --text-3:          #8696a0;
  --divider:         #2a3942;
  --notice:          #182229;
  --notice-text:     #ffd279;
  --bubble-shadow:   0 1px .5px rgba(11,20,26,.35);
  --panel-shadow:    0 2px 5px rgba(11,20,26,.26);
  --icon:            #aebac1;
  --hover:           rgba(255,255,255,.05);
  --wallpaper-tint:  #0c1317;
  --doodle:          #ffffff;
  --doodle-alpha:    .85;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, "Lucida Grande", Arial, sans-serif;
  color: var(--text);
  background: var(--panel);
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

button { font: inherit; border: 0; background: none; cursor: pointer; color: inherit; }
input, textarea { font: inherit; }
img { max-width: 100%; display: block; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: var(--icon);
  flex: none; transition: background .15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ============ header del chat ============ */

.chat-header {
  flex: none; display: flex; align-items: center; gap: 10px;
  height: 60px; padding: 0 8px 0 12px;
  background: var(--teal); color: #fff;
}
[data-theme="dark"] .chat-header { background: var(--panel); }
.chat-header .icon-btn { color: #fff; }
.chat-header .icon-btn:hover { background: rgba(255,255,255,.12); }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; overflow: hidden;
  background: #d1d7db; color: #fff; font-weight: 500; font-size: 16px;
  user-select: none;
}
.avatar svg { width: 100%; height: 100%; }
.avatar.lg { width: 49px; height: 49px; font-size: 19px; }

.header-meta { flex: 1; min-width: 0; line-height: 1.25; }
.header-meta h1 {
  margin: 0; font-size: 16px; font-weight: 500; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-meta .status {
  font-size: 12.5px; color: rgba(255,255,255,.78);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}
.header-actions { display: flex; align-items: center; }

/* ============ cuerpo del chat ============ */

.chat-body {
  flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; z-index: 1;
  padding: 12px 0 8px; scrollbar-width: thin; background: transparent;
}

.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background: rgba(11,20,26,.2); border-radius: 3px; }
[data-theme="dark"] .chat-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); }

.chat-scroll { display: flex; flex-direction: column; justify-content: flex-end; min-height: 100%; }

.notice {
  align-self: center; max-width: 85%; margin: 4px auto 10px;
  background: var(--notice); color: var(--notice-text);
  font-size: 12.5px; line-height: 18px; text-align: center;
  padding: 5px 12px; border-radius: 7.5px; box-shadow: var(--bubble-shadow);
}
.notice svg { width: 11px; height: 11px; fill: currentColor; vertical-align: -1px; margin-right: 2px; }

.date-divider { display: flex; justify-content: center; margin: 10px 0; }
.date-divider span {
  background: var(--panel-2); color: var(--text-2);
  font-size: 12.5px; text-transform: uppercase; font-weight: 500;
  padding: 5px 12px; border-radius: 7.5px; box-shadow: var(--bubble-shadow);
}
[data-theme="dark"] .date-divider span { background: #182229; }

/* ============ burbujas ============ */

.msg { display: flex; padding: 0 5%; margin-bottom: 2px; }
.msg.out { justify-content: flex-end; }
.msg.group-start { margin-top: 10px; }

.bubble {
  position: relative; max-width: 78%; min-width: 88px;
  padding: 6px 9px 8px; border-radius: 7.5px;
  box-shadow: var(--bubble-shadow); font-size: 14.2px; line-height: 19px;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.in  .bubble { background: var(--bubble-in);  border-top-left-radius: 7.5px; }
.msg.out .bubble {
  background: var(--bubble-out); border-top-right-radius: 7.5px;
  color: var(--bubble-out-text, inherit);
}
.msg.out .bubble .meta { color: var(--bubble-out-meta, var(--text-2)); }
.msg.out .bubble .doc-sub { color: var(--bubble-out-meta, var(--text-2)); }

.msg.in.group-start  .bubble { border-top-left-radius: 0; }
.msg.out.group-start .bubble { border-top-right-radius: 0; }

.msg.group-start .bubble::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px;
}
.msg.in.group-start .bubble::before {
  left: -8px; background: var(--bubble-in);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}
.msg.out.group-start .bubble::before {
  right: -8px; background: var(--bubble-out);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.bubble .text { white-space: pre-wrap; }
.bubble .text a { color: #027eb5; text-decoration: underline; }
[data-theme="dark"] .bubble .text a { color: #53bdeb; }
.bubble .spacer { display: inline-block; width: 58px; height: 1px; }
.msg.out .bubble .spacer { width: 75px; }

.bubble .meta {
  position: absolute; right: 8px; bottom: 4px;
  display: flex; align-items: center; gap: 3px;
  font-size: 11px; line-height: 15px; color: var(--text-2);
  white-space: nowrap; user-select: none;
}
.bubble .meta .ticks { display: inline-flex; }
.bubble .meta .ticks svg { width: 16px; height: 15px; fill: currentColor; }
.bubble .meta .ticks.read { color: var(--tick); }

/* --- media --- */

.bubble.media { padding: 3px 3px 3px; min-width: 0; max-width: 330px; }
.bubble.media .thumb {
  position: relative; border-radius: 6px; overflow: hidden;
  background: rgba(11,20,26,.06); cursor: pointer; display: block;
}
.bubble.media .thumb img { width: 100%; height: auto; max-height: 400px; object-fit: cover; }
.bubble.media .meta { right: 10px; bottom: 8px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.bubble.media .meta .ticks.read { color: #fff; }
.bubble.media .thumb::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 46px;
  background: linear-gradient(to top, rgba(11,20,26,.5), transparent); pointer-events: none;
}
.bubble.media.has-caption .thumb::after { display: none; }
.bubble.media .caption { padding: 5px 6px 4px; font-size: 14.2px; line-height: 19px; }
.bubble.media.has-caption .meta { color: var(--text-2); text-shadow: none; right: 8px; bottom: 4px; }
.bubble.media.has-caption .meta .ticks.read { color: var(--tick); }

/* --- documento --- */

.doc {
  display: flex; align-items: center; gap: 10px; min-width: 230px;
  background: rgba(11,20,26,.04); border-radius: 6px; padding: 10px 12px;
  margin: 0 0 4px; text-decoration: none; color: inherit;
}
[data-theme="dark"] .doc { background: rgba(255,255,255,.05); }
.doc .doc-icon { width: 30px; height: 38px; flex: none; }
.doc .doc-info { min-width: 0; flex: 1; }
.doc .doc-name {
  font-size: 13.5px; line-height: 18px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.doc .doc-sub { font-size: 11.5px; color: var(--text-2); margin-top: 2px; text-transform: uppercase; }
.doc .doc-dl { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid rgba(11,20,26,.15); color: var(--text-2); flex: none; }
.doc .doc-dl svg { width: 18px; height: 18px; fill: currentColor; }

/* ============ reproductor de audio ============ */

.audio { display: flex; align-items: center; gap: 8px; min-width: 240px; padding: 3px 0 2px; }
.audio .play {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: var(--text-2);
}
.audio .play svg { width: 26px; height: 26px; fill: currentColor; }
.audio .track { flex: 1; min-width: 0; }
.audio .wave {
  display: flex; align-items: center; gap: 2px; height: 24px; cursor: pointer;
}
.audio .wave i {
  display: block; flex: 1; min-width: 2px; border-radius: 2px;
  background: var(--text-3); opacity: .45; transition: opacity .1s, background .1s;
}
.audio .wave i.on { opacity: 1; background: var(--green); }
.audio .below { display: flex; align-items: center; gap: 6px; margin-top: 1px; height: 14px; }
.audio .dur { font-size: 11px; color: var(--text-2); }
.audio .mic { width: 13px; height: 13px; fill: var(--text-3); margin-left: auto; }
.audio .mic.unplayed { fill: #09d261; }

/* ============ indicador escribiendo ============ */

.typing-bubble { display: flex; align-items: center; gap: 4px; padding: 4px 2px; }
.typing-bubble i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-3);
  animation: tdot 1.2s infinite ease-in-out;
}
.typing-bubble i:nth-child(2) { animation-delay: .18s; }
.typing-bubble i:nth-child(3) { animation-delay: .36s; }
@keyframes tdot {
  0%, 60%, 100% { opacity: .35; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ============ composer ============ */

.composer {
  flex: none; display: flex; align-items: flex-end; gap: 6px;
  padding: 5px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--panel); position: relative;
}

.pill {
  flex: 1; display: flex; align-items: flex-end; gap: 4px; min-width: 0;
  background: var(--panel-2); border-radius: 24px; padding: 4px 8px 4px 6px;
  min-height: 44px;
}
[data-theme="dark"] .pill { background: var(--panel-2); }
.pill .icon-btn { width: 36px; height: 36px; }
.pill .icon-btn svg { width: 22px; height: 22px; }

.pill textarea {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none; resize: none;
  color: var(--text); font-size: 15px; line-height: 21px;
  padding: 9px 4px; max-height: 110px; overflow-y: auto;
}
.pill textarea::placeholder { color: var(--text-3); }

.send-btn {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  background: var(--green); color: #fff; display: grid; place-items: center;
  transition: transform .12s;
}
.send-btn:active { transform: scale(.92); }
.send-btn svg { width: 24px; height: 24px; fill: currentColor; }

/* menu de adjuntos */
.attach-menu {
  position: absolute; bottom: calc(100% + 6px); right: 12px; z-index: 30;
  background: var(--panel-2); border-radius: 12px; padding: 8px;
  box-shadow: 0 4px 20px rgba(11,20,26,.25);
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px;
  transform-origin: bottom right; animation: pop .14s ease-out;
}
[data-theme="dark"] .attach-menu { background: #233138; }
@keyframes pop { from { opacity: 0; transform: scale(.9) translateY(6px); } }
.attach-menu button {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 10px;
  border-radius: 8px; color: var(--text); font-size: 14.5px; white-space: nowrap;
}
.attach-menu button:hover { background: var(--hover); }
.attach-menu .chip { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; }
.attach-menu .chip svg { width: 21px; height: 21px; fill: currentColor; }

/* ============ grabacion de audio ============ */

.recorder {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border-radius: 24px; min-height: 44px; padding: 0 12px;
}
.recorder .rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none;
  animation: blink 1.1s infinite;
}
@keyframes blink { 50% { opacity: .15; } }
.recorder .rec-time { font-size: 15px; color: var(--text); font-variant-numeric: tabular-nums; }
.recorder .rec-hint { flex: 1; text-align: center; font-size: 13px; color: var(--text-2); }
.recorder .icon-btn { width: 36px; height: 36px; }

/* ============ emoji picker ============ */

.emoji-panel {
  position: absolute; bottom: calc(100% + 6px); left: 8px; right: 8px; z-index: 30;
  background: var(--panel-2); border-radius: 12px; padding: 8px;
  box-shadow: 0 4px 20px rgba(11,20,26,.25); max-height: 230px; overflow-y: auto;
  animation: pop .14s ease-out;
}
[data-theme="dark"] .emoji-panel { background: #233138; }
.emoji-panel .cat { font-size: 11px; color: var(--text-2); text-transform: uppercase; margin: 6px 4px 2px; }
.emoji-panel .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); }
.emoji-panel .grid button { font-size: 23px; line-height: 1; padding: 6px 0; border-radius: 6px; }
.emoji-panel .grid button:hover { background: var(--hover); }

/* ============ lightbox ============ */

.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(11,20,26,.94);
  display: grid; grid-template-rows: 56px 1fr; animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }
.lightbox .lb-bar { display: flex; align-items: center; gap: 4px; padding: 0 10px; color: #d1d7db; }
.lightbox .lb-bar .name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox .lb-bar .icon-btn { color: #d1d7db; }
.lightbox .lb-body { display: grid; place-items: center; padding: 10px; overflow: auto; }
.lightbox .lb-body img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }

/* ============ toast ============ */

.toast-wrap {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: #202c33; color: #e9edef; font-size: 13.5px;
  padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.3);
  animation: rise .2s ease-out; max-width: 88vw; text-align: center;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ============ boton bajar ============ */

.scroll-down {
  position: absolute; right: 14px; bottom: 14px; z-index: 20;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--panel-2); color: var(--text-2);
  display: grid; place-items: center; box-shadow: 0 2px 6px rgba(11,20,26,.2);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  transform: translateY(8px);
}
.scroll-down.show { opacity: 1; pointer-events: auto; transform: translateY(0); }
.scroll-down svg { width: 22px; height: 22px; fill: currentColor; }
.scroll-down .badge {
  position: absolute; top: -4px; right: -2px; min-width: 19px; height: 19px;
  border-radius: 10px; background: var(--green); color: #fff;
  font-size: 11px; font-weight: 600; display: grid; place-items: center; padding: 0 5px;
}

/* ============ menu desplegable ============ */

.dropdown {
  position: absolute; top: 52px; right: 8px; z-index: 40;
  background: var(--panel-2); border-radius: 4px; padding: 6px 0; min-width: 190px;
  box-shadow: 0 4px 20px rgba(11,20,26,.25); animation: pop .13s ease-out;
  transform-origin: top right;
}
[data-theme="dark"] .dropdown { background: #233138; }
.dropdown button {
  display: block; width: 100%; text-align: left; padding: 11px 24px;
  font-size: 14.5px; color: var(--text);
}
.dropdown button:hover { background: var(--hover); }

/* ============ wrapper del cuerpo ============ */

.chat-wrap {
  position: relative; flex: 1; min-height: 0; display: flex; overflow: hidden;
  background-color: var(--chat-bg);
}
.chat-wrap > .chat-body { flex: 1; }

/* --- capa de fondo: doodle, imagen o nada --- */
.chat-wrap::before {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-color: var(--doodle); opacity: var(--doodle-alpha);
  -webkit-mask-image: url("../img/wa-bg.svg"); mask-image: url("../img/wa-bg.svg");
  -webkit-mask-repeat: repeat; mask-repeat: repeat;
  -webkit-mask-size: var(--doodle-size, 380px); mask-size: var(--doodle-size, 380px);
}

[data-wallpaper="color"] .chat-wrap::before,
[data-wallpaper="none"] .chat-wrap::before { display: none; }

[data-wallpaper="image"] .chat-wrap::before {
  background-color: transparent;
  background-image: var(--wall-image, none);
  background-size: cover; background-position: center; background-repeat: no-repeat;
  -webkit-mask-image: none; mask-image: none;
  opacity: 1;
}
[data-wallpaper="image"] .chat-wrap::after {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: rgba(11, 20, 26, var(--wall-dim, 0.2));
}

/* ============ pantalla de bienvenida vacia ============ */

.empty-hint { text-align: center; color: var(--text-2); font-size: 13.5px; padding: 24px 20px; }

.bubble.media .thumb.broken { min-height: 120px; display: grid; place-items: center; }
.bubble.media .thumb.broken img { display: none; }
.bubble.media .thumb.broken::before {
  content: "No se pudo cargar la imagen"; font-size: 12.5px; color: var(--text-2); padding: 20px;
}
