/* ==========================================================================
  ARCHIVO: style.css (VERSIÓN FINAL - KAIRÓS V5)
  Sistema de Diseño Editorial + Chatbot Morphing Entity Física y Orgánica
  ========================================================================== */


/* --- RESET GLOBAL --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}


/* --- TIPOGRAFÍAS AUTO-HOSPEDADAS (sin Google Fonts) ---------------------
 * Sin <link> a fonts.googleapis.com: no se filtra la IP del visitante a
 * Google ni se relaja la CSP con orígenes externos. Mismas familias que el
 * panel admin (admin-tokens.css): Bree Serif (titulares) + Montserrat (texto).
 * Archivos en /fonts/, MIME auto por serveDir, font-display:swap. */
@font-face {
    font-family: 'Bree Serif';
    src: url('/fonts/BreeSerif-Regular.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Montserrat';
    src: url('/fonts/Montserrat-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Montserrat';
    src: url('/fonts/Montserrat-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Montserrat';
    src: url('/fonts/Montserrat-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}


/* --- VARIABLES DE TEMA (Design Tokens) --- */
:root {
    --color-bg: #ffffff;           
    --color-bg-alt: #f4f4f0;       
    --color-text: #1a1a1a;         
    --color-muted: #666666;        
    --color-dot: rgba(0, 0, 0, 0.2); 
    --color-dot-active: #1a1a1a;   
    --color-btn-border: rgba(0, 0, 0, 0.3);

    /* Versiones RGB para Glassmorphism */
    --bg-rgb: 244, 244, 240;          
    --text-rgb: 26, 26, 26;

    --font-heading: 'Bree Serif', Georgia, serif;
    --font-body: 'Montserrat', system-ui, -apple-system, sans-serif;
    
    --transition-smooth: 0.8s cubic-bezier(0.16, 1, 0.3, 1);

    --fs-h1: clamp(2.5rem, 8vw, 5.5rem);   
    --fs-h2: clamp(2rem, 6vw, 3rem);        
    --fs-body: clamp(0.95rem, 1.5vw, 1.15rem); 
    --fs-small: clamp(0.65rem, 1.5vw, 0.85rem);

    /* Chatbot Morphing Tokens */
    --chat-width: 380px;
    --chat-height: 520px;
    --bubble-size: 70px;

    /* Paleta corporativa (3 colores) propagada desde el admin. Defaults aquí
       actúan de fallback si main.js no se ejecuta o el server no devuelve
       identity.{primary,secondary,accent}_color. Aplica al chat público y a
       TODA la landing. */
    --color-accent: #d4af37;
    --color-accent-rgb: 212, 175, 55;
    --color-primary: #d4af37;
    --color-primary-rgb: 212, 175, 55;
    --color-secondary: #6ab0de;
    --color-secondary-rgb: 106, 176, 222;
    --color-complement: #d99b6a;
    --color-complement-rgb: 217, 155, 106;
    /* Alias retrocompatibilidad: --accent ya existía en CSS legacy. */
    --accent: var(--color-primary);
}

[data-theme="light"] {
    --color-bg: #f4f4f0;
    --color-bg-alt: #e3e3df;
    --color-text: #1a1a1a;
    --color-muted: #666666;
    --color-dot: rgba(0, 0, 0, 0.2);
    --color-dot-active: #1a1a1a;
    --color-btn-border: rgba(0, 0, 0, 0.3);
    --bg-rgb: 244, 244, 240;
    --text-rgb: 26, 26, 26;
    --bg-gradient: linear-gradient(135deg, #ffffff 0%, #e8e8e8 100%);
}

[data-theme="dark"] {
    --color-bg: #0a0a0a;           /* Pure Black/Dark Gray */
    --color-bg-alt: #1a1a1a;       /* Darker Gray */
    --color-text: #ffffff;
    --color-muted: #a0a0a0;
    --color-dot: rgba(255, 255, 255, 0.4);
    --color-dot-active: #ffffff;
    --color-btn-border: rgba(255, 255, 255, 0.4);
    --bg-rgb: 10, 10, 10;          /* Pure Black/Dark Gray */
    --text-rgb: 255, 255, 255;
    --bg-gradient: linear-gradient(135deg, #0a0a0a 0%, #2c2c2c 100%); /* Black to Dark Gray */
}


/* --- ESTILOS BASE DEL DOCUMENTO --- */
body, html {
    height: 100%;
    min-height: 100dvh;
    background: var(--bg-gradient);
    color: var(--color-text);
    font-family: var(--font-body);
    overflow-x: hidden;
    transition: color 0.5s ease, background 1s ease, background-position 0.8s cubic-bezier(0.23, 1, 0.32, 1);
}

body { position: relative; z-index: 0; background-size: 400% 400%; }

a { text-decoration: none; color: inherit; transition: opacity 0.3s ease; }
a:hover { opacity: 0.7; }
.italic { font-style: italic; }


/* --- BARRA DE NAVEGACIÓN (Glassmorphism) --- */
.navbar {
    position: fixed; top: 0; width: 100%; z-index: 1000; padding: 10px clamp(18px, 2vw, 34px); display: flex; justify-content: space-between; align-items: center;
    background: rgba(var(--bg-rgb), 0.5); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(15px); border-bottom: 1px solid rgba(var(--text-rgb), 0.1); color: var(--color-text); transition: background 0.5s ease, border-color 0.5s ease;
}

.nav-left, .nav-right { flex: 1; display: flex; align-items: center; }
.nav-right { justify-content: flex-end; }
.logo { font-family: var(--font-heading); font-weight: 700; letter-spacing: 4px; font-size: clamp(1.1rem, 2.5vw, 1.5rem); }

.theme-btn { background: transparent; border: none; color: inherit; font-family: var(--font-body); font-size: var(--fs-small); letter-spacing: 2px; text-transform: uppercase; cursor: pointer; outline: none; display: flex; align-items: center; gap: 8px; transition: opacity 0.3s ease; }
.theme-btn svg { width: 16px; height: 16px; }

@keyframes spinScale {
    0% { transform: scale(1) rotate(0deg); opacity: 1; }
    50% { transform: scale(0.5) rotate(180deg); opacity: 0; }
    100% { transform: scale(1) rotate(360deg); opacity: 1; }
}

.theme-btn.animating svg { animation: spinScale 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94); }

.chapter-indicator { flex: 1; display: flex; justify-content: center; align-items: center; font-family: var(--font-body); font-size: var(--fs-small); letter-spacing: 3px; text-transform: uppercase; height: 20px; overflow: hidden; }
.chapter-text { display: inline-block; transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.5s ease; transform: translateY(0); opacity: 1; }

/* --- MENÚ DE NAVEGACIÓN (drawer con hamburguesa; conserva el indicador de
   capítulo y no altera el scroll/chat de la home) --- */
/* Laterales de ancho IGUAL (flex:1) y menú de ancho natural centrado entre
   ellos: así el menú NO se mueve aunque cambie el contenido de un lado (logo que
   se rellena, CTA que pasa a nombre, etc.) → cero saltos al navegar. */
.navbar .nav-left, .navbar .nav-right { flex: 1 1 0; min-width: 0; }
/* Escritorio: el conmutador de tema muestra SOLO el icono (+ su animación); el
   texto OSCURO/CLARO solo aparece en el menú móvil. */
@media (min-width: 861px) { .navbar #theme-text { display: none; } }
/* El conmutador de tema va PRIMERO; el CTA de cliente después. */
.navbar #theme-toggle { order: -1; }
/* Con sesión iniciada el CTA muestra el nombre → resalta con el color de marca. */
.navbar .site-cta.is-account {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  font-weight: 700;
}
.navbar .site-cta.is-account:hover { background: var(--color-primary); color: #fff; filter: brightness(1.08); }
.navbar .nav-right { gap: 14px; }
.navbar .site-menu {
  flex: 0 0 auto;
  display: flex; flex-direction: row; justify-content: center; align-items: center;
  gap: clamp(12px, 2.2vw, 30px);
  list-style: none; margin: 0; padding: 0;
}
.navbar .site-menu-link {
  position: relative;
  font-family: var(--font-body); text-transform: uppercase; letter-spacing: 2px;
  font-size: var(--fs-small); color: var(--color-text); white-space: nowrap;
}
.navbar .site-menu-link::after {
  content: ""; position: absolute; left: 0; bottom: -4px; width: 100%; height: 1px;
  background: var(--color-primary); transform: scaleX(0); transform-origin: left;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.navbar .site-menu-link:hover::after,
.navbar .site-menu-link[aria-current="page"]::after { transform: scaleX(1); }
.navbar .site-menu-link[aria-current="page"] { color: var(--color-primary); }
.navbar .site-menu-cta { display: none; }
.navbar .site-cta {
  font-family: var(--font-body); text-transform: uppercase; letter-spacing: 1.5px;
  font-size: calc(var(--fs-small) * 0.92); color: var(--color-text);
  border: 1px solid var(--color-btn-border); border-radius: 30px; padding: 6px 14px;
  white-space: nowrap; transition: background 0.3s ease, color 0.3s ease;
}
.navbar .site-cta:hover { background: var(--color-text); color: var(--color-bg); opacity: 1; }
.navbar .nav-hamburger { display: none; }

@media (max-width: 900px) {
  .navbar .site-menu {
    /* top/right negativos compensan el padding de la navbar (que actúa como
       bloque contenedor por su backdrop-filter): el drawer queda pegado al borde
       y, cerrado, fuera de pantalla del todo (sin la columna oscura). */
    position: fixed; top: -15px; right: -20px;
    width: min(76vw, 288px); height: calc(100dvh + 30px);
    flex-direction: column; justify-content: center; align-items: flex-start;
    gap: 14px; padding: 78px 26px 32px;
    background: rgba(var(--bg-rgb), 0.96);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid rgba(var(--text-rgb), 0.12);
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.45);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1200;
  }
  .navbar.menu-open .site-menu { transform: translateX(0); }
  .navbar .site-menu li { width: 100%; }
  .navbar .site-menu-link {
    display: block; padding: 8px 0;
    font-family: var(--font-heading); font-size: 1.4rem; letter-spacing: 1.5px;
    border-bottom: 1px solid rgba(var(--text-rgb), 0.08); white-space: normal;
  }
  .navbar .site-menu-link::after { display: none; }
  .navbar .nav-right .site-cta { display: none; }
  .navbar .site-menu-cta { display: block; margin-top: 12px; }
  .navbar .site-menu-cta a {
    display: inline-block; border: 1px solid var(--color-primary); color: var(--color-primary);
    border-radius: 30px; padding: 9px 22px; text-transform: uppercase; letter-spacing: 2px; font-size: 0.72rem;
  }
  .navbar .nav-hamburger {
    position: relative; z-index: 1300;
    display: flex; flex-direction: column; justify-content: center; gap: 5px;
    width: 34px; height: 34px; padding: 0; margin-left: 8px;
    background: transparent; border: none; cursor: pointer;
  }
  .navbar .nav-hamburger .hb-bar { width: 24px; height: 2px; background: var(--color-text); transition: transform 0.35s ease, opacity 0.25s ease; }
  .navbar.menu-open .nav-hamburger .hb-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .navbar.menu-open .nav-hamburger .hb-bar:nth-child(2) { opacity: 0; }
  .navbar.menu-open .nav-hamburger .hb-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
}

/* --- NAVEGACIÓN VERTICAL (Puntos laterales) --- */
.vertical-nav { position: fixed; right: 40px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 20px; z-index: 100; }
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background-color: var(--color-dot); transition: all 0.4s ease; position: relative; cursor: pointer; }
.nav-dot::before { content: ''; position: absolute; top: -15px; left: -15px; right: -15px; bottom: -15px; }
.nav-dot.active { background-color: var(--color-dot-active); transform: scale(1.8); }


/* --- CONTENEDOR SCROLL-SNAP --- */
.scroll-container { height: 100dvh; width: 100%; overflow-y: scroll; scroll-snap-type: y mandatory; scroll-behavior: smooth; scrollbar-width: none; -ms-overflow-style: none; background: transparent !important; }
.scroll-container::-webkit-scrollbar { display: none; }

.section { height: 100dvh; width: 100%; scroll-snap-align: start; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; background: transparent !important; }
.animate-up { opacity: 0; transform: translateY(40px); transition: opacity 1s ease-out, transform 1.2s cubic-bezier(0.16, 1, 0.3, 1); }
.section.is-visible .animate-up { opacity: 1; transform: translateY(0); }

.delay-1 { transition-delay: 0.2s; }
.delay-2 { transition-delay: 0.4s; }
.delay-3 { transition-delay: 0.6s; }


/* --- HERO SECTION --- */
/* Fondo oscuro fijo: la portada va al 60% de opacidad; sin este respaldo, en tema
   claro el fondo claro de la página se cuela por la imagen y la deslava. Doble
   clase (.section.hero-section) para ganar a `.section{background:transparent
   !important}` que aparece más abajo con igual especificidad. Así el hero se
   mantiene cinematográfico (oscuro) en ambos temas. */
.section.hero-section { background: #0a0a0a !important; }
.hero-bg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; opacity: 0.6; transform: scale(1.05); transition: transform 2.5s ease-out; }
.section.is-visible .hero-bg { transform: scale(1); }

.hero-section::after { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: radial-gradient(circle at center, transparent 0%, rgba(0,0,0,0.8) 100%), linear-gradient(to bottom, rgba(0,0,0,0.4) 0%, transparent 40%, rgba(0,0,0,0.6) 100%); z-index: 1; pointer-events: none; }

.hero-content { text-align: center; padding: 0 20px; z-index: 3; color: #ffffff; }
.hero-content h1 { font-family: var(--font-heading); font-size: var(--fs-h1); line-height: 1.1; margin-bottom: 20px; text-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.hero-content p { font-size: clamp(0.9rem, 2vw, 1.2rem); color: rgba(255,255,255,0.85); max-width: 600px; margin: 0 auto; text-shadow: 0 5px 15px rgba(0,0,0,0.5); }

.hero-details { margin-top: 40px; display: flex; justify-content: center; align-items: center; gap: 20px; font-size: var(--fs-small); text-transform: uppercase; letter-spacing: 3px; color: rgba(255,255,255,0.7); }
.hero-details .divider { width: 40px; height: 1px; background: rgba(255,255,255,0.4); }

.scroll-indicator { position: absolute; bottom: 50px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 12px; color: #ffffff; font-size: var(--fs-small); text-transform: uppercase; letter-spacing: 3px; opacity: 0.8; }
.mouse-icon { width: 22px; height: 34px; border: 1px solid rgba(255,255,255,0.5); border-radius: 12px; position: relative; }

@keyframes scrollBounce {
    100% { top: 6px; opacity: 1; }
    50% { top: 14px; opacity: 0; }
    0% { top: 6px; opacity: 0; }
}
.mouse-icon .wheel { width: 2px; height: 6px; background: #ffffff; position: absolute; top: 6px; left: 50%; transform: translateX(-50%); border-radius: 2px; animation: scrollBounce 2s infinite; }


/* --- EDITORIAL SECTIONS (Layout + Slider) --- */
.editorial-content { display: flex; width: 88%; max-width: 1400px; height: 75vh; align-items: center; gap: 8%; z-index: 2; margin-top: 20px; }
.section:nth-child(even) .editorial-content { flex-direction: row-reverse; }

.editorial-text { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.label { font-family: var(--font-body); text-transform: uppercase; letter-spacing: 4px; font-size: var(--fs-small); color: var(--color-muted); margin-bottom: 20px; display: block; }
.editorial-text h2 { font-family: var(--font-heading); font-size: var(--fs-h2); margin-bottom: 25px; line-height: 1.1; }
.editorial-text p { font-size: var(--fs-body); line-height: 1.8; color: var(--color-muted); max-width: 500px; }

.slider-container { flex: 1; aspect-ratio: 3 / 4 !important; height: auto; max-height: 80vh; position: relative; border-radius: 13px; overflow: hidden; box-shadow: 0 25px 50px rgba(0,0,0,0.2); }
.slider-track { display: flex; height: 100%; transition: transform 0.8s cubic-bezier(0.23, 1, 0.32, 1); }
.slide { flex: 0 0 100%; width: 100%; height: 100%; position: relative; }
.slide img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.05); transition: transform 1.5s ease; cursor: pointer; }
.section.is-visible .slide img { transform: scale(1); }

.slider-dots { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; z-index: 10; pointer-events: auto; }
.dot { width: 6px; height: 6px; background: rgba(255,255,255,0.4); border-radius: 50%; transition: all 0.3s ease; cursor: pointer; }
.dot.active { background: #ffffff; transform: scale(1.5); }

.exif-data { position: absolute; bottom: 20px; right: 20px; font-family: var(--font-body); font-size: 0.65rem; letter-spacing: 2px; color: #fff; background: rgba(0,0,0,0.5); padding: 5px 10px; border-radius: 4px; backdrop-filter: blur(5px); opacity: 0; transition: opacity 0.5s ease; pointer-events: none; z-index: 2; }
.slider-container:hover .exif-data { opacity: 1; }


/* --- MANIFESTO SECTION --- */
.manifesto-section { background-color: transparent !important; }
.manifesto-content { text-align: center; max-width: 800px; padding: 0 30px; z-index: 2;}
.quote { font-family: var(--font-heading); font-size: clamp(1.6rem, 4vw, 2.8rem); margin-bottom: 40px; line-height: 1.3; }
.manifesto-content p.desc { font-size: var(--fs-body); line-height: 1.8; color: var(--color-muted); margin-bottom: 50px; }

.cta-button { display: inline-block; cursor: pointer; border: 1px solid var(--color-btn-border); padding: 15px 40px; color: var(--color-text); font-family: var(--font-body); text-transform: uppercase; letter-spacing: 3px; font-size: 0.8rem; border-radius: 30px; transition: all 0.4s ease; }
.cta-button:hover { background: var(--color-text); color: var(--color-bg); }

.footer-bottom { margin-top: 60px; font-size: 0.7rem; letter-spacing: 2px; color: var(--color-muted); }


/* --- LIGHTBOX MODAL --- */
/* El telón del visor es SIEMPRE oscuro (independiente del tema): las fotos se
   miran sobre negro; un velo claro las deslavaría en modo claro. */
.lightbox { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(10, 10, 10, 0.93); z-index: 10000; display: flex; align-items: center; justify-content: center; opacity: 0.4; visibility: hidden; transition: opacity 0.3s ease; backdrop-filter: blur(10px); }
.lightbox.active { opacity: 1; visibility: visible; pointer-events: auto; }
.lightbox img { max-width: 90%; max-height: 90vh; object-fit: contain; border-radius: 13px; box-shadow: 0 10px 50px rgba(0,0,0,0.5); }

.lightbox-close { position: absolute; top: 30px; right: 40px; color: #fff; font-size: clamp(2rem, 5vw, 3rem); cursor: pointer; z-index: 10001; appearance: none; -webkit-appearance: none; background: none; border: 0; padding: 0; font-family: inherit; line-height: 1; }
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); color: #fff; font-size: clamp(2rem, 8vw, 4rem); cursor: pointer; padding: 20px; user-select: none; transition: opacity 0.3s ease; opacity: 0.7; z-index: 10001; appearance: none; -webkit-appearance: none; background: none; border: 0; font-family: inherit; line-height: 1; }
.lightbox-nav:hover { opacity: 1; }
.lightbox-prev { left: 20px; } .lightbox-next { right: 20px; }


/* --- MOBILE RESPONSIVE (GENERAL) --- */
@media (max-width: 900px) {

    .hero-top-left,
    .hero-top-right,
    .hero-frame {
        display: none;
    }

    .navbar {
        padding: 15px 20px;
    }

    .logo {
        font-size: 1rem;
        letter-spacing: 2px;
    }

    .chapter-indicator {
        font-size: 0.85rem;
        letter-spacing: 1px;
        display: flex !important;
    }

    .theme-btn {
        font-size: 0.6rem;
        letter-spacing: 1px;
    }

    .theme-btn span {
        display: none;
    }

    .editorial-content,
    .section:nth-child(even) .editorial-content {
        flex-direction: column !important;
        height: auto;
        padding: 20px 0;
        gap: 30px;
    }

    .label {
        display: none !important;
    }

    .slider-container {
        width: 100%;
        max-width: min(620px, 86vw);
        aspect-ratio: 3 / 4 !important;
        height: auto;
        flex: none;
        margin: 0 auto;
    }

    .editorial-text {
        text-align: center;
        flex: none;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .editorial-text h2 {
        font-size: clamp(1.8rem, 3vw, 2.5rem);
        margin-bottom: 10px;
    }

    .editorial-text p {
        font-size: 0.95rem;
        line-height: 1.4;
        max-width: 100%;
    }

    .vertical-nav {
        display: none;
    }
}

/* Tablet en vertical (iPad ~768–1024px): apila la editorial y ensancha el
   slider para que no quede el enorme hueco a los lados del layout de 2 columnas.
   Solo portrait: en horizontal el iPad usa el layout de escritorio. */
@media (min-width: 901px) and (max-width: 1024px) and (orientation: portrait) {
    .editorial-content,
    .section:nth-child(even) .editorial-content {
        flex-direction: column !important;
        height: auto;
        gap: 40px;
    }
    .slider-container {
        width: 100%;
        max-width: min(680px, 78vw);
        aspect-ratio: 3 / 4 !important;
        height: auto;
        flex: none;
        margin: 0 auto;
    }
    .editorial-text {
        flex: none;
        text-align: center;
        align-items: center;
    }
    .editorial-text p { max-width: 640px; }
}


/* ==========================================================================
   ELEGANT MINIMALIST BACKGROUND SYSTEM
   ========================================================================== */

body:has(#chat-widget.snaping) {
    background-position: bottom right !important; 
}

.section,
.scroll-container {
    background: transparent !important;
}


/* ==========================================================================
   CHATBOT WIDGET (KAIROS V5 - ENTIDAD FÍSICA Y ORGÁNICA)
   ========================================================================== */

#chat-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999;
}

/* La Cápsula (Contenedor de la entidad) */
#chat-entity {
    position: relative;
    width: var(--bubble-size);
    height: var(--bubble-size);
    border-radius: 50%; /* Estado inicial circular (Cápsula) */
    background: rgba(var(--bg-rgb), 0.12);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--color-btn-border);
    transition:
        width 0.7s cubic-bezier(0.68, -0.55, 0.265, 1.55), /* Efecto rebote/explosión */
        height 0.7s cubic-bezier(0.68, -0.55, 0.265, 1.55),
        border-radius 0.6s ease,
        border-color 0.4s ease;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* Estado Expandido (La entidad se convierte en el fondo) */
#chat-widget.is-expanded #chat-entity {
    width: var(--chat-width);
    height: var(--chat-height);
    border-radius: 24px; /* Se convierte en ventana rectangular redondeada */
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8), inset 0 0 50px rgba(var(--text-rgb), 0.1);
}

/* REDUCCIÓN DE INTERFERENCIA: Cuando está expandido, el ente se vuelve un fondo sutil */
#chat-widget.is-expanded #chat-core {
    opacity: 0.2; /* Muy tenue para no molestar la lectura */
    filter: blur(50px); /* Desenfoque extremo para que sea solo atmósfera */
}

/* EL NÚCLEO VIVO (Controlado por JS) - Ahora es un resplandor suave, no una forma sólida */
#chat-core {
    position: absolute;
    width: 40px; 
    height: 40px;
    background: radial-gradient(circle, rgba(255,255,255,1) 0%, rgba(0,255,255,0.6) 40%, rgba(138,43,226,0) 70%);
    border-radius: 50%;
    filter: blur(8px); /* Desenfoque para que parezca luz líquida */
    z-index: 5;
}

/* Animación de IMPACTO muy sutil (solo un pequeño pulso en la cápsula) */
@keyframes impactPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); border-color: rgba(255,255,255,0.5); }
    100% { transform: scale(1); }
}

#chat-entity.impact {
    animation: impactPulse 0.3s ease-out;
}

/* Botón de chat colapsado: cristal con brillo de marca subiendo de la base + rim
   fino, y un halo de marca que se expande y se disuelve (invita sin gritar). */
@keyframes chatHaloA {
    0%, 100% {
        transform: translateY(0) scale(1);
        box-shadow:
            0 12px 30px rgba(0, 0, 0, 0.32),
            0 6px 26px rgba(var(--color-primary-rgb), 0.28),
            0 0 0 0 rgba(var(--color-primary-rgb), 0.45);
    }
    50% {
        transform: translateY(-3px) scale(1.03);
        box-shadow:
            0 16px 36px rgba(0, 0, 0, 0.34),
            0 8px 30px rgba(var(--color-primary-rgb), 0.42),
            0 0 0 14px rgba(var(--color-primary-rgb), 0);
    }
}
#chat-widget:not(.is-expanded) #chat-entity {
    border-color: rgba(var(--color-primary-rgb), 0.5);
    background:
        radial-gradient(90% 70% at 50% 20%, rgba(var(--text-rgb), 0.14) 0%, rgba(var(--text-rgb), 0) 55%),
        radial-gradient(130% 100% at 50% 118%, rgba(var(--color-primary-rgb), 0.40) 0%, rgba(var(--color-primary-rgb), 0.12) 44%, rgba(var(--color-primary-rgb), 0) 72%),
        rgba(var(--bg-rgb), 0.14);
    animation: chatHaloA 3.8s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}
#chat-widget:not(.is-expanded):hover #chat-entity {
    border-color: rgba(var(--color-primary-rgb), 0.85);
}
@media (prefers-reduced-motion: reduce) {
    #chat-widget:not(.is-expanded) #chat-entity { animation: none; }
}

/* El botón de activación (Contenedor del icono) */
#chat-bubble {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    z-index: 20; /* Por encima de la nebulosa */
    background: transparent;
    transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Estilo del icono de mensaje */
.chat-icon {
    width: 30px;
    height: 30px;
    color: var(--color-text);
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1), color 0.4s ease, opacity 0.4s ease;
}
#chat-bubble:hover .chat-icon { transform: scale(1.1); color: var(--color-primary); }

/* Desaparecer el icono con animación al expandirse */
#chat-widget.is-expanded #chat-bubble {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
}

/* Asegurar que el icono sea visible cuando no está expandido */
#chat-widget:not(.is-expanded) #chat-bubble {
    opacity: 1;
    transform: scale(1);
}

/* Ocultar completamente el núcleo físico para evitar distracciones */
#chat-core {
    display: none;
}


/* --- INTERFAZ DEL CHAT (Visible solo cuando está expandido) --- */

#chat-window {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0; /* Invisible mientras es pequeño para evitar que el texto se vea en la burbuja */
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 30; /* Siempre por encima de todo, incluyendo la nebulosa core */
}

#chat-widget.is-expanded #chat-window {
    opacity: 1;
    pointer-events: auto;
}


/* Cabecera del chat (Header) */
.chat-header {
    padding: 10px 16px;
    background: transparent; /* Sin fondo para look orgánico total */
    border-bottom: 1px solid var(--color-btn-border);
    display: flex; justify-content: space-between; align-items: center;
}

.chat-header .logo { font-family: var(--font-heading); letter-spacing: 1.5px; font-size: clamp(0.85rem, 1.3vw, 1rem); }

#close-chat { background: transparent; border: none; color: var(--color-muted); font-size: 1.8rem; cursor: pointer; transition: color 0.3s ease; line-height: 1; padding: 0;}
#close-chat:hover { color: #ff4d4d; }


/**
 * Área de mensajes (Messages Area).
 */
#chat-messages {
    flex: 1; /* Ocupa todo el espacio disponible entre header e input */
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Scrollbar personalizada para que sea minimalista y elegante en la ventana de chat */
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(var(--text-rgb), 0.2); border-radius: 10px; }


/**
 * Burbujas de mensajes (Message Bubbles).
 */
.chat-message {
    max-width: 85%;
    padding: 8px 12px;
    font-size: var(--fs-small);
    line-height: 1.5;
    border-radius: 14px;
    white-space: pre-wrap; /* Mantiene los saltos de línea del agente */
}

/* Mensajes del Usuario (Derecha, color destacado) */
.message-user {
    align-self: flex-end;
    background: var(--color-text); 
    color: var(--color-bg);       /* Texto oscuro para contraste */
    border-bottom-right-radius: 4px; /* Estilo de burbuja moderna */
}

/* Mensajes del Bot (Izquierda, color sutil) */
.message-bot {
    align-self: flex-start;
    background: rgba(var(--text-rgb), 0.15); /* Fondo semi-transparente para dejar ver el ente debajo */
    color: var(--color-text);
    border-bottom-left-radius: 4px;
}


/**
 * Área de entrada (Input Area).
 */
.chat-input-area {
    padding: 20px;
    background: transparent; /* Sin fondo para look orgánico total */
    display: flex; gap: 12px; align-items: center;
}

#user-msg-input {
    flex: 1;
    background: rgba(var(--text-rgb), 0.05);
    border: 1px solid var(--color-btn-border);
    padding: 12px 16px; border-radius: 30px; color: var(--color-text); font-family: var(--font-body); font-size: 16px; outline: none; transition: all 0.3s ease; /* Font size fixed to avoid mobile zoom */
}

#user-msg-input:focus { border-color: var(--color-text); background: rgba(var(--text-rgb), 0.15); }

#send-btn {
    width: 36px; height: 36px; border-radius: 50%; background: var(--color-text); color: var(--color-bg);
    border: none; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.3s ease; padding: 0; overflow: hidden;
}

#send-btn .send-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

#send-btn:hover { transform: scale(1.1); background: var(--color-text); opacity: 0.9; }
#send-btn:active { transform: scale(0.95); }
#send-btn:active { transform: scale(0.95); }


/* --- RESPONSIVE CHATBOT (Móviles) --- */
@media (max-width: 480px) {
    #chat-widget { bottom: 20px; right: 20px; }

    /* Corregido para evitar el óvalo gigante en móviles */
    #chat-entity {
        width: var(--bubble-size); /* Tamaño de burbuja por defecto (círculo) */
        height: var(--bubble-size);
        border-radius: 50%;
    }

    /* Al expandirse, usamos dimensiones relativas al viewport para que sea una ventana controlada */
    #chat-widget.is-expanded #chat-entity {
        width: calc(100vw - 40px); /* Ancho casi total de la pantalla menos márgenes laterales */
        height: 75vh;              /* Altura máxima del 75% para no tapar todo el contenido visual si se desea ver algo detrás */
        border-radius: 24px;       /* Bordes redondeados tipo ventana móvil moderna */
    }

    #user-msg-input { font-size: 16px; } /* Evita que iOS haga zoom automático al enfocar el input */
}

/* --- CHATBOT INTERACTIVE COMPONENTS (NEW) --- */

.chat-button-group {
    display: flex;
    flex-direction: column; /* Vertical stack para mejor lectura en chat móvil/estrecho */
    gap: 10px;
    margin: 15px 0;
}

.chat-option-btn {
    background: rgba(var(--text-rgb), 0.08);
    border: 1px solid var(--color-btn-border);
    padding: 12px 16px;
    border-radius: 14px;
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: clamp(0.85rem, 3vw, 0.95rem);
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    text-align: left; /* Alineación profesional */
}

.chat-option-btn:hover {
    background: rgba(var(--text-rgb), 0.2);
    transform: translateX(8px); /* Efecto de desplazamiento sutil al pasar el mouse */
    border-color: var(--color-text);
}

/* Estilo para cuando se pulsa en móvil (feedback táctil) */
@media (max-width: 480px) {
    .chat-option-btn {
        padding: 15px; /* Más área de toque en móviles */
    }
}

/* Notificaciones internas del sistema dentro del chat */
.chat-notification {
    text-align: center;
    margin: 8px auto;
    animation: fadeInDown 0.4s ease forwards;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Estilo para mensajes de error o advertencia */
.notif-warning { 
    color: #ff9800 !important; 
    font-weight: 500; 
    background-color: rgba(255, 165, 0, 0.2) !important;
}
.notif-info { 
    color: var(--color-muted) !important; 
    background-color: rgba(255, 255, 255, 0.1) !important;
}

/* Logo container styles */
.logo-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Chat idle timer style (Deprecated - moved to chat-system-message) */
#chat-idle-timer {
    display: none;
}

/* Utility classes for CSP compliance */
.hidden {
    display: none !important;
}

/* Integrated System Messages in Chat Flow */
.chat-system-message {
    align-self: center;
    font-size: var(--fs-small);
    padding: 8px 16px;
    border-radius: 20px;
    margin: 10px 0;
    text-align: center;
    width: fit-content;
    max-width: 85%;
    animation: fadeInDown 0.4s ease forwards;
    font-weight: 500;
}

.chat-system-message.warning {
    background-color: rgba(241, 196, 15, 0.15); /* Soft Yellow/Orange */
    color: #f1c40f;
    border: 1px solid rgba(241, 196, 15, 0.3);
}

.chat-system-message.finalized {
    background-color: rgba(231, 76, 60, 0.15); /* Soft Red */
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.3);
}

/* --- STATUS DOT (Header Connection Indicator) --- */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: transparent; /* Hidden by default */
    transition: background-color 0.3s ease, transform 0.3s ease;
}

.status-dot.green {
    background-color: #2ecc71;
    box-shadow: 0 0 8px #2ecc71;
}

.status-dot.orange {
    background-color: #f39c12;
    box-shadow: 0 0 8px #f39c12;
    animation: pulseOrange 1s infinite ease-in-out;
}

.status-dot.red {
    background-color: #e74c3c;
    box-shadow: 0 0 8px #e74c3c;
}

@keyframes pulseOrange {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* Inactivity Status Bar (Integrated at bottom of chat) */
.inactivity-status-bar {
    width: 100%;
    padding: 8px 15px;
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
    transition: all 0.4s ease;
    animation: slideUp 0.3s ease-out;
}

/* Warning State (Yellow) */
.inactivity-status-bar.warning {
    background-color: #f1c40f; /* Yellow */
    color: #2c3e50;
}

/* Finalized State (Red) */
.inactivity-status-bar.finalized {
    background-color: #e74c3c; /* Red */
    color: #ffffff;
}

@keyframes slideUp {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}


/* ==========================================================================
   CHAT ENHANCEMENTS V8.2
   - Indicador de escritura estilo WhatsApp
   - Hora en burbujas de mensajes
   - Estado de espera (bloqueo de input)
   - Notificación de error
   ========================================================================== */

/* ─── INDICADOR DE ESCRITURA (TYPING INDICATOR) ─────────────────────────── */
.typing-indicator {
    padding: 12px 16px !important;
    display: flex !important;
    align-items: center;
    gap: 5px;
    width: fit-content !important;
    min-height: 0 !important;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text);
    opacity: 0.4;
    animation: typingBounce 1.2s infinite ease-in-out;
    display: inline-block;
    flex-shrink: 0;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0);   opacity: 0.4; }
    30%           { transform: translateY(-6px); opacity: 1;   }
}

/* ─── HORA EN BURBUJA DE MENSAJE ─────────────────────────────────────────── */
/* La hora va inline al final del texto (estilo WhatsApp) para reducir altura. */
.msg-text {
    display: inline;
    white-space: pre-wrap;
    line-height: 1.5;
}

/* v2.0.4.5 — enlaces clicables embebidos en los mensajes del chat público.
   El frontend solo crea <a class="chat-link"> cuando el host pasa la whitelist
   (showcase_links + identity.website). Cualquier otro [texto](url) se renderiza
   como texto plano. */
.chat-link {
    color: var(--accent, #d4af37);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: opacity 0.15s ease;
}
.chat-link:hover {
    opacity: 0.75;
}
.chat-link:visited {
    color: var(--accent, #d4af37);
}

.msg-time {
    display: inline-block;
    margin-left: 6px;
    font-size: 0.55rem;
    opacity: 0.4;
    letter-spacing: 0.3px;
    font-family: var(--font-body);
    white-space: nowrap;
    vertical-align: baseline;
}

/* ─── BOTÓN "NUEVA CONVERSACIÓN" (tras endConversation) ─────────────────── */
.chat-new-session-btn {
    align-self: center;
    margin-top: 12px;
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid var(--color-btn-border);
    background: rgba(var(--text-rgb), 0.08);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: 0.85rem;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: background 0.25s ease, transform 0.15s ease;
}
.chat-new-session-btn:hover  { background: rgba(var(--text-rgb), 0.18); }
.chat-new-session-btn:active { transform: scale(0.97); }

/* ─── SEND BUTTON / INPUT: ESTADO DE ESPERA ─────────────────────────────── */
#send-btn.btn-waiting {
    opacity: 0.35 !important;
    cursor: not-allowed !important;
    pointer-events: none;
}

#user-msg-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* El input NO se deshabilita físicamente (mantiene foco); solo se atenúa visualmente
   mientras el asistente procesa la respuesta. */
#user-msg-input.input-waiting {
    opacity: 0.6;
}

/* ─── NOTIFICACIÓN DE ERROR ──────────────────────────────────────────────── */
.notif-error {
    color: #e74c3c !important;
    font-weight: 500;
    background-color: rgba(231, 76, 60, 0.15) !important;
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: 8px;
    padding: 6px 12px;
}
