/* Chat Screen */
.chat-screen {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Chat Section */
.chat-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-container {
    flex: 1;
    /* Piso de altura: aunque el dashboard esté todo desplegado en un celular
       bajito, el chat SIEMPRE queda visible (el panel del home cede y scrollea
       adentro — ver #homePanel en index.html). */
    min-height: 170px;
    /* Fondo estilo WhatsApp: el patrón de garabatos, en mosaico.
       La imagen viene casi blanca; el `background-color` beige + `multiply` la
       tiñe al tono de WhatsApp sin necesitar una segunda imagen. Así el mismo
       archivo sirve aunque después se quiera cambiar el tono. */
    background-color: #efeae2;
    background-image: url('/img/chat-bg-light.webp');
    background-repeat: repeat;
    background-size: 380px auto;
    background-blend-mode: multiply;
    border: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0;
}

.chat-messages {
    flex: 1;
    padding: 12px 9px 14px 9px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

.message-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    position: relative;
    width: 100%;
}

.message-wrapper.sent {
    justify-content: flex-end;
}

.message-wrapper.received {
    justify-content: flex-start;
}

.message {
    max-width: 78%;
    min-width: 90px;
    padding: 7px 10px 20px 10px;  /* espacio abajo-derecha para la hora */
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
    box-sizing: border-box;
    width: fit-content;
    font-size: 14.5px;
    line-height: 1.4;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}

.message > div {
    min-width: 60px;
    /* Reserva a la derecha de la última línea para que el texto no se meta
       debajo de la hora. */
    padding-right: 42px;
}

/* Mensajes DEL AGENTE (los que recibe el cliente) → blancos, a la izquierda.
   ⚠️ El nombre de la clase engaña: `usuario` = lo que ve el usuario, no lo que
   escribe. Lo que escribe el cliente es `.agente` (ver chat.js:57). */
.message.usuario {
    background: #ffffff;
    color: #111b21;
    align-self: flex-start;
    margin-right: auto;
    border-top-left-radius: 0;   /* la "colita" del lado del que habla */
}

/* Mensajes PROPIOS del cliente → verde claro, a la derecha. */
.message.agente {
    background: #d9fdd3;
    color: #111b21;
    align-self: flex-end;
    margin-left: auto;
    border-top-right-radius: 0;
}

.message img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.message img:hover {
    transform: scale(1.05);
}

/* Links clickeables en el chat */
.chat-link {
    color: #027eb5;
    text-decoration: underline;
    word-break: break-all;
}

.chat-link:hover {
    color: #81d4fa;
    text-decoration: none;
}

.message.agente .chat-link {
    color: #b3e5fc;
}

.message.agente .chat-link:hover {
    color: #e1f5fe;
}

/* Lightbox para imágenes */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.lightbox.active {
    display: flex;
}

.lightbox img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 10px;
    cursor: default;
}

.lightbox-close {
    position: absolute;
    top: max(20px, env(safe-area-inset-top, 20px));
    right: 30px;
    font-size: 40px;
    color: #fff;
    cursor: pointer;
    background: none;
    border: none;
    z-index: 10001;
}

.lightbox-close:hover {
    color: #ff4444;
}

/* La hora va ANCLADA abajo a la derecha DENTRO de la burbuja, como WhatsApp
   (por eso .message tiene padding-bottom extra). */
.message-time {
    position: absolute;
    right: 9px;
    bottom: 4px;
    font-size: 11px;
    color: #667781;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Tildes de los mensajes PROPIOS del cliente, como WhatsApp: ✓✓ gris = enviado,
   ✓✓ celestes = un admin abrió el chat y los leyó. El celeste es el MISMO tono
   que usa WhatsApp para el "leído" (#53bdeb). El flip en vivo lo hace socket.js
   (evento messages_read_by_admin). */
.msg-ticks {
    display: inline-flex;
    align-items: center;
    color: #8696a0;
}

.msg-ticks svg { display: block; }

.msg-ticks.msg-read { color: #53bdeb; }

.copy-btn {
    background: rgba(0, 0, 0, 0.08);
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    opacity: 0;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.message-wrapper:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: rgba(0, 0, 0, 0.18);
    transform: scale(1.1);
}

/* Chat Input — réplica de la barra de WhatsApp (foto de referencia del owner):
   fondo beige, input pill blanco, íconos de trazo fino SIN fondo. */
.chat-input-container {
    flex: 0 0 auto;
    padding: 7px 8px;
    padding-bottom: max(7px, env(safe-area-inset-bottom, 7px));
    border-top: none;
    background: #f0ebe3;   /* beige de la barra de WhatsApp mobile */
    z-index: 999;
}

.chat-input {
    display: flex;
    /* Con letra del sistema muy grande, los botones ocupan de más y el cuadro
       de escribir queda aplastado. flex-wrap permite que el textarea baje a su
       propia línea (ancho completo) en lugar de quedar diminuto. */
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.action-btn {
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.deposit-btn {
    background: linear-gradient(135deg, #00ff88 0%, #00cc6a 100%);
    color: #000;
}

.deposit-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

.withdraw-btn {
    background: linear-gradient(135deg, #ff4444 0%, #cc0000 100%);
    color: #fff;
}

.withdraw-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 68, 68, 0.5);
}

/* Íconos de la barra al estilo WhatsApp: trazo fino, SIN fondo ni círculo.
   (Los usan #cbuChatBtn y #attachBtn — el color va por `currentColor` del SVG.) */
.wa-icon-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 46px;
    padding: 0;
    background: none;
    border: none;
    color: #1b1b1b;          /* casi negro, como los íconos de la foto */
    cursor: pointer;
    display: flex;
    flex-direction: column;  /* deja poner una mini-etiqueta bajo el ícono (CBU) */
    align-items: center;
    justify-content: center;
    gap: 1px;
    transition: transform 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.wa-icon-btn:hover { color: #000; }
.wa-icon-btn:active { transform: scale(0.88); }

/* Mini-etiqueta bajo el ícono ("CBU"): para que se sepa qué es el botón. */
.wa-btn-label {
    font-size: 8px;
    font-weight: 800;
    letter-spacing: 0.4px;
    line-height: 1;
}

/* Botón de modo claro/oscuro: en la cabecera del chat, a la vista (es el que
   empuja el bloque de botones al borde derecho con margin-left:auto). */
.theme-topbar-btn {
    margin-left: auto;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.theme-topbar-btn:active { transform: scale(0.92); }

/* Campanita de notificaciones en la cabecera (movida del menú ☰, 2026-08-05).
   Estados: .active = notificaciones andando (verde), .blocked = bloqueadas (rojo). */
.notif-topbar-btn {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 7px;
}
.notif-topbar-btn:active { transform: scale(0.92); }
.notif-topbar-btn.active { background: rgba(0, 255, 136, 0.22); box-shadow: 0 0 8px rgba(0, 255, 136, 0.45); }
.notif-topbar-btn.blocked { background: rgba(255, 80, 80, 0.25); }

/* Botón Fueguito (racha diaria): en la CABECERA del chat, a la derecha —
   fuera de la barra de escribir para que esa quede 100% WhatsApp. */
.fire-topbar-btn {
    margin-left: 7px;        /* el empuje a la derecha lo hace .theme-topbar-btn */
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: visible;
    -webkit-tap-highlight-color: transparent;
}

.fire-topbar-btn:active { transform: scale(0.92); }

/* Badge con el número de racha, en la esquina del botón. */
.fire-streak-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: #fff;
    color: #ff4500;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.withdraw-row-btn {
    display: block;
    width: auto;
    margin: 7px 8px;
    background: linear-gradient(135deg, #ff4444 0%, #cc0000 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.5px;
    cursor: pointer;
    box-shadow: 0 2px 9px rgba(255, 68, 68, 0.4);
}

.withdraw-row-btn:active {
    transform: scale(0.99);
}

#messageInput {
    flex: 1;
    /* Piso de ancho usable: si no entra (letra grande), .chat-input lo baja a
       su propia línea en vez de dejarlo diminuto. Con letra normal no se nota. */
    min-width: 90px;
    padding: 11px 16px;
    border: none;
    border-radius: 22px;
    background: #ffffff;
    color: #111b21;
    font-size: 15px;
    resize: none;
    min-height: 44px;
    max-height: 100px;
    font-family: inherit;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}
#messageInput::placeholder { color: #8696a0; }

#messageInput:focus {
    outline: none;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}

/* Botón de enviar: círculo verde WhatsApp. */
.send-btn {
    background: #00a884;
    color: #fff;
    border: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    font-size: 17px;
    font-weight: bold;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.send-btn:hover { background: #017561; }
.send-btn:active { transform: scale(0.95); }

.chat-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
    margin: 8px 0;
}

.chat-date-separator span {
    background: #ffffff;
    color: #54656f;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 13px;
    border-radius: 7px;
    text-transform: capitalize;
    letter-spacing: 0.2px;
    border: none;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}

/* ============================================================
   CABECERA DEL CHAT (estilo WhatsApp)
   ============================================================ */
.chat-topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 13px;
    background: #075e54;          /* verde WhatsApp */
    color: #fff;
}

.chat-topbar-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: #0b7d6e;
    flex-shrink: 0;
}

.chat-topbar-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;               /* deja que el nombre se recorte en vez de empujar */
}

.chat-topbar-name {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-topbar-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    opacity: 0.9;
}

/* Puntito verde de "en línea". Es decorativo (no es un estado real de conexión
   del agente): el soporte atiende 24/7, así que se muestra fijo. */
.chat-topbar-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #25d366;
    display: inline-block;
    flex-shrink: 0;
}

/* ============================================================
   MODO OSCURO (se activa con .wa-dark en <body>; ver ui.js)
   ============================================================
   Sólo afecta al CHAT. El menú/dashboard queda igual en los dos modos. */
body.wa-dark .chat-container {
    /* La imagen oscura ya viene con el tono correcto: no se tiñe (blend normal),
       si no `multiply` la dejaría negra del todo y se perderían los garabatos. */
    background-color: #0b141a;
    background-image: url('/img/chat-bg-dark.webp');
    background-repeat: repeat;
    background-size: 380px auto;
    background-blend-mode: normal;
}

body.wa-dark .chat-topbar { background: #1f2c33; }

body.wa-dark .message.usuario {          /* mensajes del agente */
    background: #202c33;
    color: #e9edef;
}

body.wa-dark .message.agente {           /* mensajes propios */
    background: #005c4b;
    color: #e9edef;
}

body.wa-dark .message-time { color: #8696a0; }

body.wa-dark .chat-date-separator span {
    background: #182229;
    color: #8696a0;
}

body.wa-dark .chat-input-container { background: #1f2c33; }

body.wa-dark #messageInput {
    background: #2a3942;
    color: #e9edef;
}
body.wa-dark #messageInput::placeholder { color: #8696a0; }

/* Íconos de la barra en oscuro: gris claro sobre la barra, como WhatsApp dark. */
body.wa-dark .wa-icon-btn { color: #aebac1; }
body.wa-dark .wa-icon-btn:hover { color: #e9edef; }

body.wa-dark .fire-topbar-btn { background: rgba(255, 255, 255, 0.08); }

body.wa-dark .chat-link { color: #53bdeb; }

body.wa-dark .copy-btn { background: rgba(255,255,255,0.12); }
body.wa-dark .copy-btn:hover { background: rgba(255,255,255,0.22); }

body.wa-dark #typingIndicator { color: #8696a0 !important; }

/* ============================================================
   INTERRUPTOR del modo oscuro (Configuración)
   ============================================================ */
.wa-switch { position: relative; display: inline-block; flex-shrink: 0; cursor: pointer; }
.wa-switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.wa-switch-track {
    display: block;
    width: 46px;
    height: 26px;
    background: rgba(255,255,255,0.18);
    border-radius: 13px;
    transition: background 0.2s ease;
}

.wa-switch-thumb {
    display: block;
    width: 20px;
    height: 20px;
    margin: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}

.wa-switch input:checked + .wa-switch-track { background: #00a884; }
.wa-switch input:checked + .wa-switch-track .wa-switch-thumb { transform: translateX(20px); }
/* Foco visible por teclado (accesibilidad): sin esto el switch es inalcanzable
   para quien no usa mouse. */
.wa-switch input:focus-visible + .wa-switch-track { outline: 2px solid #d4af37; outline-offset: 2px; }

/* ══ #237 HISTORIAS (réplica de PICA ROJA): botón del header + visor a pantalla completa ══ */
.tb-stories { flex:0 0 auto; display:inline-flex; align-items:center; gap:5px; height:34px; padding:0 9px 0 6px; border-radius:9px; cursor:pointer;
  background:linear-gradient(135deg,#9b30ff,#ff1744); color:#fff; border:1px solid transparent; box-shadow:0 4px 14px rgba(155,48,255,.35); position:relative; }
.tb-stories .tb-stories-text { font-size:10.5px; font-weight:800; letter-spacing:.3px; white-space:nowrap; }
.tb-stories .st-ring { position:relative; width:22px; height:22px; border-radius:50%; display:inline-flex; align-items:center; justify-content:center; background:#1a0a2e; border:2px solid rgba(255,255,255,.55); box-sizing:border-box; }
.tb-stories .st-core { font-size:8px; color:#fff; margin-left:1px; }
.tb-stories.has-active .st-ring { border-color:transparent; background:linear-gradient(#1a0a2e,#1a0a2e) padding-box, linear-gradient(135deg,#ffd166,#fff) border-box; }
.tb-stories.has-new .st-ring { box-shadow:0 0 12px rgba(255,23,68,.55); animation:stPulse 1.6s ease-in-out infinite; }
@keyframes stPulse { 0%,100% { transform:scale(1); } 50% { transform:scale(1.08); } }
.tb-stories .st-badge { position:absolute; top:-6px; right:-8px; min-width:15px; height:15px; padding:0 4px; border-radius:999px; background:#ff1744; color:#fff; font:900 9px/15px inherit; text-align:center; border:2px solid #0b0b14; }
@media (max-width:380px) { .tb-stories .tb-stories-text { display:none; } .tb-stories { padding:0 6px; } }
.story-viewer { position:fixed; inset:0; z-index:30000; background:#000; display:none; flex-direction:column; color:#fff; --st-l:max(0px, calc(50% - 100dvh * 9 / 32)); -webkit-touch-callout:none; -webkit-user-select:none; user-select:none; }
.story-viewer.open { display:flex; }
body.story-open { overflow:hidden; }
.story-viewer::before { content:""; position:absolute; top:0; left:var(--st-l); right:var(--st-l); height:120px; background:linear-gradient(180deg, rgba(0,0,0,.62), transparent); z-index:3; pointer-events:none; }
.story-viewer .st-bars { position:absolute; top:calc(10px + env(safe-area-inset-top, 0px)); left:calc(var(--st-l) + 10px); right:calc(var(--st-l) + 10px); display:flex; gap:4px; z-index:5; }
.story-viewer .st-bars i { flex:1 1 0; height:3px; border-radius:999px; background:rgba(255,255,255,.35); overflow:hidden; display:block; }
.story-viewer .st-bars i b { display:block; height:100%; width:0; background:#fff; border-radius:999px; }
.story-viewer .st-bars i.done b { width:100%; }
.story-viewer .st-head { position:absolute; top:calc(22px + env(safe-area-inset-top, 0px)); left:calc(var(--st-l) + 12px); right:calc(var(--st-l) + 12px); display:flex; align-items:center; gap:8px; z-index:5; }
.story-viewer .st-logo img { width:32px; height:32px; border-radius:50%; border:2px solid #fff; background:#000; display:block; }
.story-viewer .st-who { display:flex; flex-direction:row; align-items:center; gap:8px; flex:1 1 auto; min-width:0; }
.story-viewer .st-brand { font-weight:900; font-size:13.5px; letter-spacing:1.2px; color:#fff; text-shadow:0 1px 6px rgba(0,0,0,.7); }
.story-viewer .st-brand-sub, .story-viewer .st-title-hidden { display:none; }
.story-viewer #storyWhen { font-weight:600; font-size:11.5px; color:rgba(255,255,255,.8); text-shadow:0 1px 6px rgba(0,0,0,.7); }
.story-viewer .st-close { width:34px; height:34px; border-radius:50%; background:rgba(0,0,0,.35); color:#fff; border:0; font-size:18px; line-height:34px; text-align:center; cursor:pointer; flex:0 0 auto; }
.story-viewer .st-media { position:absolute; top:0; bottom:0; left:var(--st-l); right:var(--st-l); display:flex; align-items:center; justify-content:center; overflow:hidden; }
.story-viewer .st-media img, .story-viewer .st-media video { width:100%; height:100%; object-fit:contain; background:#000; }
.story-viewer .st-media .st-blur { display:none; }
.story-viewer .st-media .st-textonly { height:100%; width:100%; display:flex; align-items:center; justify-content:center; text-align:center; padding:60px 26px; font-weight:900; font-size:26px; line-height:1.3; text-shadow:0 2px 12px rgba(0,0,0,.6); }
.story-viewer .st-tap { position:absolute; inset:0; z-index:4; touch-action:none; }
.story-viewer .st-foot { position:absolute; left:var(--st-l); right:var(--st-l); bottom:0; z-index:5; padding:14px 14px calc(18px + env(safe-area-inset-bottom, 0px)); background:linear-gradient(180deg, transparent, rgba(0,0,0,.75)); display:flex; flex-direction:column; align-items:center; gap:8px; pointer-events:none; }
.story-viewer .st-caption { font-weight:700; font-size:14px; line-height:1.35; text-align:center; text-shadow:0 1px 6px rgba(0,0,0,.8); }
.story-viewer .st-link { pointer-events:auto; display:inline-block; width:calc(100% - 24px); max-width:360px; text-align:center; background:linear-gradient(135deg,#d4af37,#b8860b); color:#111; font-weight:900; font-size:13px; text-transform:uppercase; letter-spacing:.6px; padding:12px 18px; border-radius:999px; text-decoration:none; }
.story-viewer #storyLink.st-bonus { background:linear-gradient(135deg,#0a7a3e,#16a34a); color:#fff; animation:stPulse 1.6s ease-in-out infinite; }
.story-viewer .st-react { pointer-events:auto; display:flex; gap:6px; justify-content:center; margin:6px 0 2px; }
.story-viewer .st-rbtn { pointer-events:auto; border:1px solid rgba(255,255,255,.35); background:rgba(0,0,0,.35); color:#fff; border-radius:999px; padding:4px 10px; font-size:16px; line-height:1; cursor:pointer; display:inline-flex; align-items:center; gap:4px; }
.story-viewer .st-rbtn b { font-size:11px; font-weight:800; }
.story-viewer .st-rbtn.on { background:#d4af37; border-color:#d4af37; color:#111; transform:scale(1.08); }
@media (prefers-reduced-motion: reduce) { .tb-stories.has-new .st-ring, .story-viewer #storyLink.st-bonus { animation:none; } }
