/* ==========================================================================
   1. VARIABLES / TOKENS
   ========================================================================== */
:root {
    /* Colors — marca */
    --primary-color: #008069;
    --primary-dark: #005c4b;
    --accent-color: #7dba00;
    --danger: #ef5350;
    --danger-dark: #b71c1c;

    /* Colors — base */
    --bg-color: #efeae2;
    --bg-app: #ffffff;
    --bg-input: #f0f0f0;
    --bg-subtle: #f9f9f9;
    --bg-pinned: rgba(241, 243, 224, 0.95);

    /* Colors — texto */
    --text-primary: #111b21;
    --text-secondary: #667781;
    --text-muted: #888;
    --text-soft: #8696a0;

    /* Colors — burbujas */
    --incoming-bubble: #ffffff;
    --outgoing-bubble: #d9fdd3;

    /* Colors — header */
    --header-bg: #008069;
    --header-text: #ffffff;

    /* Colors — bordes y grises de UI */
    --border-color: #e9edef;
    --border-strong: #d1d7db;
    --border-soft: #dcdcdc;
    --surface-hover: #f0f2f5;
    --surface-pressed: #d1d7db;
    --surface-soft: #f5f5f5;

    /* Colors — estado cancelar */
    --danger-bg: #ffebee;
    --danger-border: #ffcdd2;
    --danger-border-hover: #ef9a9a;

    /* Colors — link */
    --link-color: #027eb5;

    /* Colors — sistema action sheet */
    --ios-blue: #007aff;
    --ios-divider: #e5e5e5;
    --ios-label: #8e8e93;
    --ios-pressed: #f2f2f2;

    /* Colors — halo onboarding (historial) */
    --aqua: #c3dd90;
    --blue: #7dba00;
    --navy: #FFDC00;
    --teal: #a8c176;
    --green: #7baa00;
    --olive: #3D9970;
    --lime: #7dba00;
    --yellow: #FFDC00;
    --orange: #c3dd90;
    --red: #7dba00;
    --fuchsia: #a8c176;
    --purple: #3D9970;
    --maroon: #7dba00;

    /* Gradientes reutilizables */
    --gradient-accent: linear-gradient(135deg, #7dba00, #a8c176);
    --gradient-danger: linear-gradient(135deg, #ef5350, #ff8a65);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Typography — escala */
    --fs-xs: 0.7rem;     /* 11.2px */
    --fs-sm: 0.85rem;    /* 13.6px */
    --fs-base: 1.0625rem;     /* 17px */
    --fs-md: 1.125rem;   /* 18px — tamaño dominante de texto */
    --fs-lg: 1.25rem;    /* 20px */
    --fs-xl: 1.3125rem;  /* 21px — títulos */

    /* Typography — familia */
    --font-family: "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    /* Capas (z-index) */
    --z-header: 50;
    --z-dropdown: 100;
    --z-modal: 2000;
    --z-fullscreen: 3000;
    --z-action-sheet: 5000;
    --z-voice-modal: 6000;

    /* Sombras */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 2px 5px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.2);
    --shadow-bubble: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}


/* ==========================================================================
   2. RESET / BASE
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

/* Respetar el atributo hidden frente a reglas más específicas (ej. #inlinePregunta).
   Forma idiomática de marcar un elemento como oculto en el DOM. */
[hidden] {
    display: none !important;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    font-size: var(--fs-base);
    line-height: 1.25;
    color: var(--text-primary);
    background-color: var(--bg-color);
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}


/* ==========================================================================
   3. ACCESIBILIDAD
   ========================================================================== */

/* Tamaño de fuente según parámetro fsize (1=normal, 2=grande, 3=extra grande) */
html.fsize-1 { font-size: 16px; }
html.fsize-2 { font-size: 20px; }
html.fsize-3 { font-size: 24px; }

/* Focus visible accesible (WCAG 2.4.7) */
:focus-visible {
    outline: 1px solid var(--accent-color);
    outline-offset: 2px;
}

/* Respetar preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}


/* ==========================================================================
   4. UTILIDADES
   ========================================================================== */
.hide {
    display: none !important;
}

.paste-btn,
.copy-button {
    display: none !important;
}


/* ==========================================================================
   5. TIPOGRAFÍA — TÍTULOS
   ========================================================================== */
h1,
.header-title,
.titulo {
    font-size: var(--fs-xl);
    font-weight: 600;
}

h2,
h3,
h4,
.subtitulo,
.card-title {
    font-size: var(--fs-lg);
    font-weight: 500;
}


/* ==========================================================================
   6. LAYOUT — HEADER (CHAT)
   ========================================================================== */
.chat-header {
    background: var(--accent-color);
    color: #ffffff;
    padding: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    height: 60px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    z-index: var(--z-header);
}

.icon-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: var(--spacing-sm);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.icon-btn:active {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Iconos PNG/SVG insertados como <img> dentro de un .icon-btn sobre fondo de
   color (ej. info.svg en el header del historial): se invierten a blanco. */
.icon-btn img {
    filter: brightness(0) invert(1);
}

.chat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chat-info h2 {
    font-size: var(--fs-base);
    margin: 0;
    font-weight: 600;
}

.header-title {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

#titulo-conversacion {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    font-size: var(--fs-md)!important;
    font-weight: 600;
}

.subtitle-campanya {
    font-size: 0.75rem;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    flex-shrink: 0;
}

.chat-subtitle-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.chat-subtitle-icon {
    display: none;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: var(--fs-xs);
    color: rgba(255, 255, 255, 0.8);
}

#select-campanya {
    appearance: none;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.9);
    font-size: var(--fs-sm);
    font-family: inherit;
    padding-right: 20px;
    cursor: pointer;
    width: auto;
    min-width: 120px;
}

#select-campanya:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

#select-campanya option {
    color: #333;
}

/* Selector nativo de campaña: ocultado en favor del action sheet */
#campanya-select {
    display: none !important;
}

/* Con fsize=3 dar más espacio al header */
html.fsize-3 .chat-header {
    min-height: 76px;
    height: auto;
    padding-top: 12px;
    padding-bottom: 12px;
}
html.fsize-3 .header-title {
    gap: var(--spacing-xs);
}
html.fsize-3 .subtitle-campanya {
    margin-top: var(--spacing-xs);
}


/* ==========================================================================
   7. LAYOUT — CHAT AREA
   ========================================================================== */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: 20px;
    background-color: var(--bg-color);
    background-image: url('/unica_test/static/vegetables.png');
    background-repeat: repeat;
    background-size: 700px;
    position: relative;
    scroll-behavior: smooth;
    overflow-anchor: none;
}


/* ==========================================================================
   8. COMPONENTE — MENSAJES
   ========================================================================== */
.msg {
    max-width: 75vw;
    padding: var(--spacing-sm) 12px;
    border-radius: var(--spacing-sm);
    box-shadow: var(--shadow-bubble);
    position: relative;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
    scroll-margin-top: 70px;
}

.msg.user {
    align-self: flex-end;
    background-color: var(--outgoing-bubble);
    border-top-right-radius: 0;
    color: var(--text-primary);
}

.msg.bot {
    align-self: flex-start;
    background-color: transparent;
    box-shadow: none;
    border: none;
    padding: 6px 0;
    margin-left: 0;
    color: var(--text-primary);
    width: auto;
    max-width: 85vw;
}

/* Tablas y gráficos: usar todo el ancho, sin burbuja */
.msg.bot:has(table),
.msg.bot:has(.chart-container) {
    max-width: 100%;
    background-color: transparent;
    box-shadow: none;
    padding: 0;
    display: block;
}

/* Ocultar líneas horizontales que markdown a veces inyecta */
.msg.bot .msg-content hr {
    display: none;
}

.msg-content {
    margin-right: 12px;
    margin-bottom: 2px;
}

.msg-content p {
    margin: 10px 0;
}

.msg-content p:first-child {
    margin-top: 0;
}

.msg-content p:last-child {
    margin-bottom: 0;
}

.msg strong {
    color: var(--text-primary);
}

.msg a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
}

.msg ul,
.msg ol {
    padding-left: 1.2em;
    margin: 12px 0;
}

.msg li {
    margin: 6px 0;
}

.msg i {
    display: block;
    background: var(--bg-color);
    padding: 6px 12px;
    font-size: var(--fs-sm)!important;
    border-radius: 8px;
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    -ms-border-radius: 8px;
    -o-border-radius: 8px;
}

/* Hora del mensaje */
.msg-time {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-align: right;
    margin-top: var(--spacing-xs);
    margin-left: 10px;
    line-height: 1;
    opacity: 0.8;
    align-self: flex-end;
}

.msg.user .msg-time {
    color: rgba(0, 0, 0, 0.45);
}

/* Mensaje de sistema: minimalista, centrado */
.msg.system {
    font-size: var(--fs-xs);
    padding: 2px 10px;
    margin: 6px auto;
    background-color: rgba(0, 0, 0, 0.04);
    color: var(--text-soft);
    width: fit-content;
    max-width: 95%;
    border-radius: 10px;
    align-self: center;
    display: inline-block;
    white-space: nowrap;
    text-align: center;
    box-shadow: none;
    border: none;
}

@media (max-width: 360px) {
    .msg.system {
        white-space: normal;
    }
}

/* Mensaje de carga (spinner inline) */
.msg.loading {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    background-color: transparent;
    box-shadow: none;
    border: none;
    padding: 0 10px;
    margin: 10px 0;
    font-style: normal;
    color: var(--text-secondary);
    width: auto;
}

.loading-spinner-icon {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--accent-color);
    border-radius: 50%;
    animation: spinSmall 1s linear infinite !important;
    flex-shrink: 0;
}


/* Tarjeta de error de conexión / interrupción de respuesta */
.error-card {
    background: #fff5f5;
    border: 1px solid #feb2b2;
    padding: 12px;
    border-radius: var(--spacing-sm);
    margin: var(--spacing-sm) 0;
    align-self: flex-start;
    max-width: 85%;
}

.error-card-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    color: #c53030;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
}

.error-card-text {
    font-size: var(--fs-sm);
    color: #742a2a;
    margin-bottom: 10px;
}

.error-card-retry-btn {
    background: #ffffff;
    border: 1px solid #fc8181;
    color: #c53030;
    cursor: pointer;
    width: 100%;
    justify-content: center;
}

.error-card-retry-btn svg {
    margin-right: 6px;
}

/* Mensaje breve "Cargando..." / "Error..." inyectado en línea por JS */
.inline-loading-msg {
    padding: 10px;
    color: #666;
}


/* ==========================================================================
   9. COMPONENTE — MENSAJES COLAPSABLES
   ========================================================================== */
.msg-content.collapsed {
    overflow: hidden;
}

.msg-content.collapsed .collapsible-hidden {
    display: none;
}

.msg-content.collapsed .collapsible-compact-body {
    display: none;
}

.msg-content.collapsed .collapsible-compact {
    margin-bottom: var(--spacing-sm);
}

.see-more-container {
    display: inline-flex;
    align-items: baseline;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-xs);
    font-size: var(--fs-sm);
    line-height: 1;
}

.ellipsis-indicator {
    font-weight: bold;
    color: #666;
}

.msg.user .ellipsis-indicator {
    color: rgba(255, 255, 255, 0.8);
}

.see-more-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: inherit;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    margin: 0;
    line-height: inherit;
    vertical-align: baseline;
}

.see-more-btn:hover {
    text-decoration: underline;
}


/* ==========================================================================
   10. COMPONENTE — BOTÓN COPIAR
   ========================================================================== */
.copy-button {
    position: absolute;
    top: var(--spacing-xs);
    right: 0;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    cursor: pointer;
    padding: var(--spacing-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s ease;
    color: var(--text-secondary);
    z-index: 5;
}

@media (hover: hover) {
    .msg:hover .copy-button {
        opacity: 1;
    }
}

@media (hover: none) {
    .copy-button {
        opacity: 0.5;
        background: rgba(255, 255, 255, 0.4);
    }
}

.copy-button:hover,
.copy-button:active {
    opacity: 1;
    background: #ffffff;
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.copy-button svg {
    width: 14px;
    height: 14px;
}

.msg.system .copy-button {
    display: none;
}


/* ==========================================================================
   11. LAYOUT — INPUT AREA (FOOTER)
   ========================================================================== */
.chat-input-area {
    background: var(--bg-input);
    padding: 6px 0 var(--spacing-sm) 0;
    border-top: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-sm);
    padding: 0 var(--spacing-sm);
}

.input-container {
    flex: 1;
    background: white;
    border-radius: var(--spacing-sm);
    padding: var(--spacing-sm) 12px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-strong);
    position: relative;
}

.input-container:focus-within {
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
}

.input-container textarea {
    width: 100%;
    border: none;
    outline: none;
    font-size: var(--fs-base);
    font-family: inherit;
    resize: none;
    max-height: 100px;
    background: transparent;
    padding: 0;
    margin: 0;
    line-height: 1.4;
}

.input-container textarea:focus-visible {
    outline: none;
}

.paste-btn {
    position: absolute;
    right: 12px;
    top: var(--spacing-sm);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--spacing-xs);
    opacity: 0.6;
    transition: opacity 0.2s;
    display: none;
}

.paste-btn:hover {
    opacity: 1;
    color: var(--primary-color);
}

textarea:placeholder-shown + .paste-btn {
    display: block;
}

.disclaimer {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 2px;
    padding-bottom: 2px;
}

#inlinePregunta {
    display: flex;
    background: #e6ffda;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--spacing-xs);
    margin-bottom: var(--spacing-xs);
    font-size: var(--fs-sm);
    align-items: center;
    justify-content: space-between;
    color: #2e5d0a;
}

.cancelar-selector-btn {
    background: none;
    border: none;
    color: #d32f2f;
    font-weight: bold;
    cursor: pointer;
}

#productoChips {
    flex-wrap: nowrap;
}


/* ==========================================================================
   12. COMPONENTE — CHIPS / QUICK ACTIONS
   ========================================================================== */
.quick-actions-carousel {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: var(--spacing-xs) 8px;
    scrollbar-width: none;
    max-height: 80px;
    opacity: 1;
    transform: translateY(0);
    transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.22s ease, padding 0.22s ease;
}

.quick-actions-carousel::-webkit-scrollbar {
    display: none;
}

/* Estado oculto con animación (alternativa a .hide para los carouseles de
   chips: colapsan vertical + fade en lugar de desaparecer instantáneamente). */
.quick-actions-carousel.is-hidden {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    overflow: hidden;
}

.chip {
    background: white;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    padding: 10px 14px;
    border-radius: var(--spacing-sm);
    font-size: var(--fs-sm);
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.subproductos-chips .chip {
    background: var(--accent-color);
    color: #ffffff;
}

/* Chip volver */
.chip.chip-cancel {
    background: white;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: var(--fs-sm);
    padding: 2px 4px;
}

.chip-icon {
    display: none;
}

/* Botones de acción dentro de mensajes (chip alterno blanco) */
.action-buttons-container {
    margin-top: var(--spacing-sm);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
}

.action-buttons-container .chip {
    background: #ffffff;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    box-shadow: none;
    white-space: normal;
    text-align: center;
    line-height: 1.3;
    max-width: 100%;
    flex: 0 1 auto;
    min-width: fit-content;
}

.action-buttons-container .chip:active {
    background: var(--surface-pressed);
    transform: none;
}

.action-buttons-container .chip.full-width {
    flex: 1 1 100%;
    max-width: 100%;
}

/* ==========================================================================
   13. COMPONENTE — BOTÓN ENVIAR Y BOTÓN VOZ
   ========================================================================== */
.btn-send {
    background: var(--accent-color);
    color: #ffffff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: transform 0.1s;
    flex-shrink: 0;
}

.btn-send:active {
    transform: scale(0.95);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-voice {
    width: 40px;
    height: 40px;
    border-radius: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    box-shadow: none;
}

.btn-voice:active {
    transform: scale(0.95);
    background: var(--surface-pressed);
}

.btn-voice:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}


/* ==========================================================================
   14. COMPONENTE — TABLAS Y CABECERAS ORDENABLES
   ========================================================================== */
.table-container {
    margin-top: var(--spacing-sm);
    margin-bottom: var(--spacing-lg);
    border-radius: var(--spacing-sm);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: #ffffff;
    position: relative;
}

.table-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: 36px;
}

.table-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
    flex: 1;
    line-height: 1.2;
}

.table-header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    flex-shrink: 0;
}

.expand-button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: var(--spacing-xs);
    border-radius: var(--spacing-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    transition: background 0.2s;
}

.expand-button:hover {
    background: rgba(0, 128, 105, 0.08);
}

.expand-button svg {
    width: 16px;
    height: 16px;
}

.table-scroll {
    overflow-x: auto;
    max-height: 300px;
}

.table-container table,
.fs-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-base);
    white-space: nowrap;
}

.table-container th {
    background: var(--surface-hover);
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
    font-size: var(--fs-xs);
    text-transform: uppercase;
    padding: var(--spacing-sm) 12px;
    position: sticky;
    top: 0;
    z-index: 2;
    cursor: pointer;
    transition: all 0.2s ease;
    padding-right: 20px;
    user-select: none;
}

.table-container td {
    padding: var(--spacing-sm) 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.table-container tr:last-child td {
    border-bottom: none;
}

.table-container th:hover {
    background: var(--surface-hover);
}

/* Indicador de orden (siempre presente, tenue) */
.table-container th::after {
    content: '';
    position: absolute;
    right: var(--spacing-sm);
    top: 50%;
    transform: translateY(-50%);
    border-left: var(--spacing-xs) solid transparent;
    border-right: var(--spacing-xs) solid transparent;
    border-bottom: var(--spacing-xs) solid #000;
    opacity: 0.15;
    transition: all 0.2s ease;
}

.table-container th:hover::after {
    opacity: 0.4;
}

.table-container th.asc::after {
    opacity: 1;
    border-bottom-color: var(--primary-color);
    transform: translateY(-50%) rotate(0deg);
    -webkit-transform: translateY(-50%) rotate(0deg);
    -moz-transform: translateY(-50%) rotate(0deg);
    -ms-transform: translateY(-50%) rotate(0deg);
    -o-transform: translateY(-50%) rotate(0deg);
}

.table-container th.desc::after {
    opacity: 1;
    border-bottom-color: var(--primary-color);
    transform: translateY(-50%) rotate(180deg);
    -webkit-transform: translateY(-50%) rotate(180deg);
    -moz-transform: translateY(-50%) rotate(180deg);
    -ms-transform: translateY(-50%) rotate(180deg);
    -o-transform: translateY(-50%) rotate(180deg);
}

.zoom-button {
    display: none;
}


/* ==========================================================================
   15. COMPONENTE — GRÁFICOS
   ========================================================================== */
.chart-container {
    margin-top: var(--spacing-lg);
    margin-bottom: 20px;
    border-radius: var(--spacing-sm);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: #ffffff;
    position: relative;
}

.chart-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    min-height: 36px;
}

.chart-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
}

/* Envoltorio del canvas dentro de .chart-container: fija altura para que
   Chart.js (con maintainAspectRatio:false) tenga un alto definido. */
.chart-canvas-wrap {
    height: 280px;
    padding: 10px;
}

/* Aviso de fallo al parsear el JSON de un gráfico devuelto por el bot */
.chart-error-msg {
    padding: 10px;
    background: #fff5f5;
    color: #c53030;
    font-size: 0.8rem;
    border-radius: 6px;
    border: 1px dashed #fc8181;
    margin: 5px 0;
}


/* ==========================================================================
   16. COMPONENTE — MODAL FULLSCREEN (TABLAS / GRÁFICOS)
   ========================================================================== */
#fullscreenModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-app);
    z-index: var(--z-fullscreen);
    display: none;
    flex-direction: column;
}

.fs-header {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--accent-color);
    color: #ffffff;
    flex-shrink: 0;
}
.fs-title {
    font-size: var(--fs-base);
    font-weight: 600;
    color: #ffffff;
    padding-left: 12px;
}

.fs-content {
    flex: 1;
    overflow: auto;
    padding: var(--spacing-md);
    background: var(--bg-subtle);
    display: block;
}

.fs-content table {
    font-size: var(--fs-base);
    background: #ffffff;
    width: max-content;
    min-width: 100%;
    margin: 0 auto;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.fs-content img {
    max-width: 100%;
    display: block;
    margin: 0 auto;
}

#closeFullscreenBtn {
    font-size: 1.25rem;
    width: 36px;
    height: 36px;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
}

.fs-header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

#rotateFullscreenBtn {
    width: 34px;
    height: 34px;
    background-color: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease;
    color: #ffffff;
}

#rotateFullscreenBtn[hidden] {
    display: none;
}

#rotateFullscreenBtn:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

#rotateFullscreenBtn.active {
    background-color: rgba(0, 0, 0, 0.1);
    color: #ffffff;
}

/* Defensa en profundidad: si por algún motivo llega un .expand-button al clon, ocúltalo.
   La cabecera de la tabla clonada no debe quedarse sticky dentro del modal. */
.fs-content .expand-button {
    display: none;
}

.fs-content .table-header-bar {
    position: static;
}

/* Dentro del modal: el .table-container conserva su overflow:hidden (mantiene
   el border-radius limpio). El scroll horizontal lo gestiona el .table-scroll
   interno, que mantiene su overflow-x: auto original. */
.fs-content .table-container {
    margin: 0 auto;
    max-width: 100%;
}

/* Rotación CSS solo en móvil portrait: simula móvil girado para tablas anchas.
   Las dimensiones se intercambian y centramos el modal con translate(-50%,-50%)
   antes de rotar para que el rectángulo girado quede alineado con el viewport.
   --vw-real / --vh-real son fallbacks JS para WebViews donde 100dvh/100dvw
   se comportan mal. */
@media (orientation: portrait) and (max-width: 900px) {
    #fullscreenModal.fs-rotated {
        width: var(--vh-real, 100dvh);
        height: var(--vw-real, 100dvw);
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) rotate(90deg);
        transform-origin: center center;
    }

    #fullscreenModal.fs-rotated .fs-content {
        padding-top: max(env(safe-area-inset-left), var(--spacing-md));
        padding-bottom: max(env(safe-area-inset-right), var(--spacing-md));
    }

    #fullscreenModal.fs-rotated .table-container {
        border: none;
        border-radius: 0;
        margin: 0;
        max-width: 100%;
    }

    /* Cuando el modal rotado contiene una imagen (gráfico ampliado), centrarla y
       hacer que se ajuste sin desbordar usando object-fit: contain. */
    #fullscreenModal.fs-rotated .fs-content:has(img) {
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
    }

    #fullscreenModal.fs-rotated .fs-content img {
        max-width: 100%;
        max-height: 100%;
        width: auto;
        height: auto;
        object-fit: contain;
    }
}


/* ==========================================================================
   17. COMPONENTE — VISOR FACTURA
   ========================================================================== */
#facturaModal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    z-index: var(--z-modal);
    flex-direction: column;
}

#facturaModal .fs-title {
    color: var(--text-primary);
    padding-left: 0;
}

#btnVolverChat,
#btnDescargarFactura {
    color: #333;
}

#downloadLoader {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    background: rgba(255, 255, 255, 0.9);
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.download-loader-text {
    color: var(--accent-color);
    font-weight: 600;
}

#facturaViewer {
    flex: 1;
    width: 100%;
    border: none;
    position: relative;
    background: var(--bg-input);
}

#facturaViewer iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Iframe del visor: arranca invisible y JS hace style.opacity='1' al onload
   para encadenar con el spinner sin parpadeo. */
#docIframe {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.document-loader-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.document-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 1;
}

.spinner {
    width: 40px;
    height: 40px;
    border: var(--spacing-xs) solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}


/* ==========================================================================
   18. COMPONENTE — DROPDOWN MENU (3 PUNTOS)
   ========================================================================== */
.menu-container {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--spacing-sm);
    background: #ffffff;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    min-width: 160px;
    z-index: var(--z-dropdown);
    overflow: hidden;
}

.dropdown-menu.show {
    display: flex;
    animation: fadeIn 0.1s ease-out;
}

.dropdown-item {
    background: none;
    border: none;
    padding: 12px var(--spacing-md);
    text-align: left;
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.1s;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.dropdown-item:hover {
    background-color: var(--surface-soft);
}

.dropdown-item.danger {
    color: var(--danger);
}

.dropdown-item.danger:hover {
    background-color: rgba(239, 83, 80, 0.1);
}


/* ==========================================================================
   19. COMPONENTE — MODAL RENOMBRAR
   ========================================================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: start;
    justify-content: center;
    z-index: var(--z-fullscreen);
    padding-top: 20vh;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #ffffff;
    border-radius: var(--spacing-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 360px;
    padding: var(--spacing-lg);
    text-align: center;
    animation: scaleIn 0.2s ease-out;
}

.modal-content h3 {
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
    font-size: 1.1rem;
}

.input-group {
    margin-bottom: var(--spacing-lg);
    text-align: left;
}

.input-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--spacing-sm);
    font-size: var(--fs-base);
    outline: none;
    font-family: inherit;
}

.input-group input:focus {
    border-color: var(--primary-color);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn-modal {
    flex: 1;
    padding: 12px;
    border-radius: var(--spacing-lg);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    border: none;
}

.btn-cancel {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-save {
    background: var(--primary-color);
    color: #ffffff;
}


/* ==========================================================================
   20. COMPONENTE — ACTION SHEET (SELECTOR CAMPAÑA)
   ========================================================================== */
.action-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: var(--z-action-sheet);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.action-sheet-overlay.show {
    opacity: 1;
    visibility: visible;
}

.action-sheet-container {
    background-color: transparent;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 10px;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.action-sheet-overlay.show .action-sheet-container {
    transform: translateY(0);
}

.sheet-group {
    background: #ffffff;
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 10px;
    text-align: center;
}

.sheet-header {
    padding: 14px;
    font-size: 0.8rem;
    color: var(--ios-label);
    font-weight: 600;
    border-bottom: 1px solid var(--ios-divider);
    text-transform: uppercase;
}

.sheet-btn {
    display: block;
    width: 100%;
    padding: var(--spacing-md);
    font-size: 1.1rem;
    color: var(--ios-blue);
    background: #ffffff;
    border: none;
    border-bottom: 1px solid var(--ios-divider);
    cursor: pointer;
    font-weight: 400;
}

.sheet-btn:last-child {
    border-bottom: none;
}

.sheet-btn:active {
    background-color: var(--ios-pressed);
}

.sheet-btn.selected {
    font-weight: 600;
    color: var(--primary-color);
}

.sheet-cancel-btn {
    display: block;
    width: 100%;
    padding: var(--spacing-md);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ios-blue);
    background: #ffffff;
    border: none;
    border-radius: 14px;
    cursor: pointer;
}

.sheet-cancel-btn:active {
    background-color: var(--ios-pressed);
}


/* ==========================================================================
   21. COMPONENTE — VOICE AGENT MODAL
   ========================================================================== */
#voice-agent-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backdrop-filter: blur(4px);
    background:
        radial-gradient(120% 80% at 50% 0%, rgba(70, 95, 140, 0.14) 0%, rgba(70, 95, 140, 0) 72%),
        radial-gradient(100% 70% at 50% 100%, rgba(55, 75, 115, 0.11) 0%, rgba(55, 75, 115, 0) 78%),
        linear-gradient(180deg, rgba(6, 9, 14, 0.92) 0%, rgba(4, 7, 12, 0.88) 48%, rgba(5, 8, 13, 0.94) 100%);
    z-index: var(--z-voice-modal);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: fadeInVoice 0.3s ease;
}

#voice-agent-modal.show {
    display: flex;
}

.voice-modal-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px var(--spacing-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.voice-campaign-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

#voice-active-campaign-label {
    font-size: 1rem;
    color: #ccc;
    font-weight: 500;
    padding-left: 10px;
}

.voice-header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.voice-walkie-btn {
    width: auto;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.05);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

.voice-walkie-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

.voice-walkie-btn.active {
    background: rgba(125, 186, 0, 0.25);
}

.voice-walkie-btn svg {
    object-fit: contain;
    max-width: 90px;
}

.voice-walkie-btn .voice-mode-walkie {
    display: none;
}

.voice-walkie-btn.active .voice-mode-conversation {
    display: none;
}

.voice-walkie-btn.active .voice-mode-walkie {
    display: block;
}

.voice-walkie-btn {
    position: relative;
}

.voice-walkie-btn::before,
.voice-walkie-btn::after {
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease-out;
}

/* Anillo pulsante: borde verde Unica que crece y se desvanece en bucle. */
.voice-walkie-btn::before {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 999px;
    border: 2px solid #7dba00;
    box-shadow: 0 0 12px rgba(125, 186, 0, 0.5);
    transform-origin: center;
}

/* Tarjeta tooltip explicativa, ancla bajo el botón alineada a la derecha. */
.voice-walkie-btn::after {
    content: "Toca aquí para alternar entre Walkie talkie (mantén pulsado para hablar) y Conversación continua.";
    position: absolute;
    top: calc(100% + 14px);
    right: 0;
    width: 240px;
    padding: 12px 14px;
    background: #ffffff;
    color: #1a2a1a;
    font-size: 13px;
    line-height: 1.4;
    text-align: left;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    transform: translateY(-6px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
    z-index: 10;
    white-space: normal;
}

/* Estado activo del hint: se pinta cuando el modal lleva `.show-walkie-hint`. */
#voice-agent-modal.show-walkie-hint .voice-walkie-btn::before {
    opacity: 1;
    animation: walkie-hint-ring 1.6s ease-out infinite;
}

#voice-agent-modal.show-walkie-hint .voice-walkie-btn::after {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.25s;
}

@keyframes walkie-hint-ring {
    0% {
        transform: scale(0.95);
        opacity: 0.85;
    }
    70% {
        transform: scale(1.7);
        opacity: 0;
    }
    100% {
        transform: scale(1.7);
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    #voice-agent-modal.show-walkie-hint .voice-walkie-btn::before {
        animation: none;
    }
}

/* ───── Hint #2: botón Push-to-Talk ─────
   Se activa con la clase `.show-ptt-hint` en el modal, encadenado tras
   cerrarse el primer hint. Tooltip va ARRIBA porque el botón está abajo. */

.voice-ptt-wrapper {
    position: relative;
}

.voice-ptt-wrapper::before,
.voice-ptt-wrapper::after {
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease-out;
}

.voice-ptt-wrapper::before {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid #7dba00;
    box-shadow: 0 0 16px rgba(125, 186, 0, 0.55);
    transform-origin: center;
}

.voice-ptt-wrapper::after {
    content: "Pulsa este botón para empezar a hablar.";
    position: absolute;
    bottom: calc(100% + 16px);
    left: 50%;
    width: 220px;
    margin-left: -110px;
    padding: 12px 14px;
    background: #ffffff;
    color: #1a2a1a;
    font-size: 13px;
    line-height: 1.4;
    text-align: center;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    transform: translateY(6px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
    z-index: 10;
}

#voice-agent-modal.show-ptt-hint .voice-ptt-wrapper::before {
    opacity: 1;
    animation: walkie-hint-ring 1.6s ease-out infinite;
}

#voice-agent-modal.show-ptt-hint .voice-ptt-wrapper::after {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.25s;
}

@media (prefers-reduced-motion: reduce) {
    #voice-agent-modal.show-ptt-hint .voice-ptt-wrapper::before {
        animation: none;
    }
}

.voice-modal-title {
    color: #ffffff;
    font-size: var(--fs-base);
    font-weight: 600;
}

.voice-close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.voice-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Contador de tiempo */
.voice-conversation-timer-wrap {
    display: flex;
    justify-content: center;
}

.voice-conversation-timer {
    font-variant-numeric: tabular-nums;
    font-size: var(--fs-base);
    color: rgba(255, 255, 255, 0.9);
    padding: var(--spacing-xs) 10px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: var(--spacing-sm);
    min-width: 4ch;
    text-align: center;
}

/* Halo animado */
.voice-halo-container {
    width: 300px;
    height: 300px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 6dvh;
}

.voice-content-loader {
    width: 100%;
    height: 100%;
    position: relative;
    display: grid;
    place-items: center;
    grid-template-rows: 1fr;
    grid-template-columns: 1fr;
}

.voice-logo-placeholder {
    grid-area: 1 / 1;
    z-index: 20;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
}

.voice-logo-placeholder img {
    width: 120px;
    height: auto;
    object-fit: contain;
}

.voice-stack {
    grid-area: 1 / 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    animation: voice-breathe infinite 3s ease-in-out;
    -webkit-animation: voice-breathe infinite 3s ease-in-out;
    transition: all 0.5s ease;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
}

.voice-blobs {
    position: relative;
    width: 250px;
    height: 250px;
    display: block;
    filter: blur(8px);
    -webkit-filter: blur(8px);
    transition: all 0.5s ease;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transform-origin: 50% 50%;
    -webkit-transform-origin: 50% 50%;
    -moz-transform-origin: 50% 50%;
    -ms-transform-origin: 50% 50%;
    -o-transform-origin: 50% 50%;
    animation: voice-spin infinite 10s linear;
    -webkit-animation: voice-spin infinite 10s linear;
}

.voice-blob {
    --border-radius: 115% 140% 145% 110% / 125% 140% 110% 125%;
    --border-width: 12px;
    position: absolute;
    inset: 0;
    display: block;
    background-size: calc(100% + var(--border-width) * 2);
    background-repeat: no-repeat;
    background-position: center;
    border: var(--border-width) solid transparent;
    border-radius: var(--border-radius, 50%);
    -webkit-mask-image: linear-gradient(transparent, transparent), linear-gradient(black, white);
    mask-image: linear-gradient(transparent, transparent), linear-gradient(black, white);
    -webkit-mask-clip: padding-box, border-box;
    mask-clip: padding-box, border-box;
    -webkit-mask-composite: source-in, xor;
    mask-composite: intersect;
    mix-blend-mode: screen;
    height: 100%;
    width: 100%;
}

.voice-blob:nth-child(1) {
    background-color: #7dba00;
    background-image: linear-gradient(#7dba00, #a8c176, #7dba00);
    rotate: 30deg;
    -webkit-rotate: 30deg;
    -moz-rotate: 30deg;
    -ms-rotate: 30deg;
    -o-rotate: 30deg;
    scale: 1.03;
}

.voice-blob:nth-child(2) {
    background-color: #7dba00;
    background-image: linear-gradient(#7dba00, #c3dd90, #7dba00);
    rotate: 60deg;
    -webkit-rotate: 60deg;
    -moz-rotate: 60deg;
    -ms-rotate: 60deg;
    -o-rotate: 60deg;
    scale: 0.95;
}

.voice-blob:nth-child(3) {
    background-color: #3D9970;
    background-image: linear-gradient(#3D9970, #7dba00, #3D9970);
    rotate: 90deg;
    -webkit-rotate: 90deg;
    -moz-rotate: 90deg;
    -ms-rotate: 90deg;
    -o-rotate: 90deg;
    scale: 0.97;
}

.voice-blob:nth-child(4) {
    background-color: #3D9970;
    background-image: linear-gradient(#3D9970, #7dba00, #3D9970);
    rotate: 120deg;
    -webkit-rotate: 120deg;
    -moz-rotate: 120deg;
    -ms-rotate: 120deg;
    -o-rotate: 120deg;
    scale: 1.02;
}

@property --voice-pulse {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
}
@property --halo-active {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
}
@property --halo-blur {
    syntax: '<length>';
    inherits: true;
    initial-value: 8px;
}
@property --halo-brightness {
    syntax: '<number>';
    inherits: true;
    initial-value: 1;
}
@property --halo-extra {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
}
@property --halo-spin-boost {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
}
@property --halo-boost-osc {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
}
@property --voice-wave {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
}

.voice-halo-container {
    --voice-amp: 0;
    -webkit---voice-amp: 0;
    animation:
        voice-pulse-driver 1s ease-in-out infinite,
        voice-boost 1.6s ease-in-out infinite,
        voice-wave-driver 0.35s linear infinite;
    -webkit-animation:
        voice-pulse-driver 1s ease-in-out infinite,
        voice-boost 1.6s ease-in-out infinite,
        voice-wave-driver 0.35s linear infinite;
    transition:
        --halo-active     1200ms cubic-bezier(0.16, 1, 0.3, 1),
        --halo-blur       1200ms cubic-bezier(0.16, 1, 0.3, 1),
        --halo-brightness 1200ms cubic-bezier(0.16, 1, 0.3, 1),
        --halo-extra      1200ms cubic-bezier(0.16, 1, 0.3, 1),
        --halo-spin-boost 1200ms cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-transition:
        --halo-active     1200ms cubic-bezier(0.16, 1, 0.3, 1),
        --halo-blur       1200ms cubic-bezier(0.16, 1, 0.3, 1),
        --halo-brightness 1200ms cubic-bezier(0.16, 1, 0.3, 1),
        --halo-extra      1200ms cubic-bezier(0.16, 1, 0.3, 1),
        --halo-spin-boost 1200ms cubic-bezier(0.16, 1, 0.3, 1);
}

.voice-halo-container.connecting,
.voice-halo-container.thinking {
    transition-duration: 320ms infinite;
}
.voice-halo-container.talking {
    transition-duration: 280ms infinite;
}

/* Cada estado fija valores objetivo de las variables; el motor las interpola */
.voice-halo-container.idle {
    --halo-active: 1;
    --halo-blur: 2px;
    --halo-brightness: 1;
    --halo-extra: 0;
    --halo-spin-boost: 0;
}
.voice-halo-container.connecting {
    --halo-active: 0;
    --halo-blur: 5px;
    --halo-brightness: 1.05;
    --halo-extra: 0.25;
    --halo-spin-boost: 0.2;
}
.voice-halo-container.thinking {
    --halo-active: 1;
    --halo-blur: 6px;
    --halo-brightness: 1.10;
    --halo-extra: 0.3;
    --halo-spin-boost: 0.3;
}
.voice-halo-container.talking {
    --halo-active: 1.5;
    --halo-blur: 6px;
    --halo-brightness: 1.05; 
    --halo-extra: 0.35;     
    --halo-spin-boost: 0.5; 
}

.voice-halo-container .voice-blobs {
    filter:
        blur(calc(var(--halo-blur)
                - var(--halo-active) * var(--voice-amp)  * 4px
                - var(--halo-active) * var(--voice-wave) * 1.5px))
        brightness(calc(var(--halo-brightness) + var(--halo-active) * var(--voice-amp) * 0.28));
    -webkit-filter:
        blur(calc(var(--halo-blur)
                - var(--halo-active) * var(--voice-amp)  * 4px
                - var(--halo-active) * var(--voice-wave) * 1.5px))
        brightness(calc(var(--halo-brightness) + var(--halo-active) * var(--voice-amp) * 0.28));
    scale: calc(
        1
        + var(--halo-extra)
        + var(--halo-spin-boost) * var(--halo-boost-osc) * 0.06
        + var(--halo-active) * (0.02
                              + var(--voice-amp)   * 0.18
                              + var(--voice-pulse) * 0.08
                              + var(--voice-wave)  * 0.06)
    );
}

@media (prefers-reduced-motion: reduce) {
    .voice-halo-container {
        animation: none;
        -webkit-animation: none;
    }
    .voice-halo-container .voice-blobs {
        animation: none;
        -webkit-animation: none;
        scale: calc(1 + var(--halo-extra));
    }
}

.voice-subtitle-display-fixed {
    width: 80vw;
    max-width: 320px;
    min-height: 100px;
    margin-bottom: 4dvh;
    text-align: center;
}

#voice-subtitle-inner {
    padding: 0 var(--spacing-xs);
    max-width: 80vw;
    max-height: 100px;
    overflow-y: auto;
    overflow-x: hidden;
    text-align: center;
    line-height: 1.35;
    word-spacing: normal;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    align-items: flex-end;
    /* scrollbar oculta — el scroll lo controla JS para anclar al fondo */
    scrollbar-width: none;
}

#voice-subtitle-inner::-webkit-scrollbar {
    display: none;
}

#voice-subtitle-inner.speaker-user {
    color: #cccccc;
    font-style: italic;
}

#voice-subtitle-inner.speaker-bot {
    color: #ffffff;
    font-style: normal;
}

/* Karaoke: cada palabra es un span que aparece al pronunciarse */
#voice-subtitle-inner .word {
    display: inline;
    opacity: 0;
    transition: opacity 220ms ease-out;
}

#voice-subtitle-inner .word.spoken {
    opacity: 1;
}

/* Texto de estado */
.voice-status-text {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    font-size: 0.75rem;
    color: var(--ios-label);
    text-wrap: balance;
    text-align: center;
}

/* Estados iniciales ocultos: JS los muestra/oculta vía .style.display.
   Mantenemos display:none por defecto para no romper esa lógica. */
.voice-ptt-icon-stop,
#voice-end-conversation-btn,
#voice-connect-btn {
    display: none;
}

/* Botón conectar/desconectar */
.voice-connect-btn {
    background: var(--gradient-accent);
    color: #ffffff;
    border: none;
    border-radius: 30px;
    padding: 14px 36px;
    font-size: var(--fs-base);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(125, 186, 0, 0.3);
}

.voice-connect-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(125, 186, 0, 0.4);
}

.voice-connect-btn:disabled {
    background: gray;
    cursor: not-allowed;
    opacity: 0.6;
}

.voice-connect-btn.active {
    background: var(--gradient-danger);
}

/* Controles de la conversación */
.voice-controls-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.voice-ptt-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4dvh
}

/* Botón Push-to-Talk */
.voice-ptt-btn {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    border: 3px solid var(--accent-color);
    background: rgba(125, 186, 0, 0.35);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px rgba(125, 186, 0, 0.35);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.voice-ptt-btn:hover:not(:disabled) {
    transform: scale(1.05);
    background: rgba(125, 186, 0, 0.5);
    box-shadow: 0 6px 24px rgba(125, 186, 0, 0.45);
}

.voice-ptt-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.voice-ptt-btn.voice-ptt-recording {
    border-color: var(--danger);
    background: rgba(239, 83, 80, 0.45);
    box-shadow: 0 4px 20px rgba(239, 83, 80, 0.4);
    animation: pulse-recording 1.5s infinite;
    -webkit-animation: pulse-recording 1.5s infinite;
}

.voice-ptt-btn.voice-ptt-recording:hover:not(:disabled) {
    background: rgba(239, 83, 80, 0.55);
    box-shadow: 0 6px 24px rgba(239, 83, 80, 0.5);
}

.voice-ptt-btn .voice-ptt-icon-mic,
.voice-ptt-btn .voice-ptt-icon-stop {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    pointer-events: none;
}

.voice-ptt-btn .voice-ptt-label,
.voice-ptt-btn.voice-ptt-label {
    font-size: var(--fs-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.15;
    text-align: center;
    max-width: 100px;
    word-break: normal;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    user-select: none;
}

.voice-controls-buttons-container {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* Botón terminar conversación */
.voice-end-conversation-btn {
    padding: 12px var(--spacing-lg);
    border: none;
    background: var(--primary-dark);
    color: #ffffff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-wrap: nowrap;
    border-radius: 8px;
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    -ms-border-radius: 8px;
    -o-border-radius: 8px;
    transition: all 0.2s ease;
    -webkit-transition: all 0.2s ease;
    -moz-transition: all 0.2s ease;
    -ms-transition: all 0.2s ease;
    -o-transition: all 0.2s ease;
}

/* Foco visible accesible (refuerza el outline global dentro del modal) */
#voice-agent-modal :focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 3px;
    border-radius: 8px;
}


/* ==========================================================================
   21.1. COMPONENTE — VOICE AGENT MODAL · RESPONSIVE
   ========================================================================== */

/* Móviles medianos (≤480px): reducir halo, botones y espaciados */
@media (max-width: 480px) {
    .voice-modal-header {
        padding: 8px var(--spacing-sm);
    }

    .voice-close-btn {
        width: 36px;
        height: 36px;
    }

    .voice-halo-container {
        width: 220px;
        height: 220px;
    }

    .voice-blobs {
        width: 180px;
        height: 180px;
    }

    .voice-logo-placeholder img {
        width: 90px;
    }

    .voice-status-text {
        font-size: 0.85rem;
        margin-bottom: 14px;
    }

    .voice-controls-container {
        gap: var(--spacing-md);
    }

}

/* Móviles muy compactos (iPhone SE, Android 5"): compresión adicional */
@media (max-width: 360px) {
    .voice-halo-container {
        width: 180px;
        height: 180px;
    }

    .voice-blobs {
        width: 150px;
        height: 150px;
    }

    .voice-logo-placeholder img {
        width: 72px;
    }

    .voice-ptt-btn .voice-ptt-icon-mic,
    .voice-ptt-btn .voice-ptt-icon-stop {
        width: 22px;
        height: 22px;
    }

    .voice-ptt-btn .voice-ptt-label {
        font-size: 0.62rem;
    }

    .voice-connect-btn {
        padding: 10px 22px;
        font-size: 0.9rem;
    }
}

/* Landscape de móvil: poca altura → reducir halo y compactar verticalmente */
@media (orientation: landscape) and (max-height: 500px) {
    .voice-modal-header {
        padding: 6px var(--spacing-sm);
    }

    .voice-halo-container {
        width: 140px;
        height: 140px;
        margin-bottom: 8px;
    }

    .voice-blobs {
        width: 120px;
        height: 120px;
    }

    .voice-logo-placeholder img {
        width: 60px;
    }

    .voice-status-text {
        margin-bottom: 6px;
        font-size: 0.85rem;
    }

    .voice-conversation-timer {
        font-size: 0.85rem;
        padding: 2px 8px;
    }

    .voice-ptt-btn {
        width: 80px;
        height: 80px;
    }

    .voice-ptt-btn .voice-ptt-icon-mic,
    .voice-ptt-btn .voice-ptt-icon-stop {
        width: 20px;
        height: 20px;
    }

    .voice-ptt-btn .voice-ptt-label {
        font-size: 0.6rem;
        max-width: 80px;
    }

    .voice-controls-container {
        gap: 10px;
    }

    .voice-connect-btn {
        padding: 10px 22px;
        font-size: 0.85rem;
    }

}


/* ==========================================================================
   22. ANIMACIONES (KEYFRAMES)
   ========================================================================== */


@-webkit-keyframes pulse-recording {
    0%, 100% { -webkit-box-shadow: 0 0 0 0 rgba(239, 83, 80, 0.4); }
    50% { -webkit-box-shadow: 0 0 0 20px rgba(239, 83, 80, 0); }
}

@keyframes pulse-recording {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 83, 80, 0.4); }
    50% { box-shadow: 0 0 0 20px rgba(239, 83, 80, 0); }
}

@keyframes spin {
    from {
        rotate: 0deg;
    }
    to {
        rotate: 360deg;
    }
}

@keyframes spinSmall {
    from {
        rotate: 0deg;
    }
    to {
        rotate: 360deg;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
        -webkit-transform: translateY(-5px);
        -moz-transform: translateY(-5px);
        -ms-transform: translateY(-5px);
        -o-transform: translateY(-5px);
}
    to {
        opacity: 1;
        transform: translateY(0);
        -webkit-transform: translateY(0);
        -moz-transform: translateY(0);
        -ms-transform: translateY(0);
        -o-transform: translateY(0);
}
}

@keyframes fadeInVoice {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes voice-spin {
    from {
        transform: rotate(0deg);
        -webkit-transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
        -webkit-transform: rotate(360deg);
    }
}

@keyframes voice-breathe {
    0% {
        transform: scale(1);
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        -ms-transform: scale(1);
        -o-transform: scale(1);
}
    50% {
        transform: scale(1.1);
        -webkit-transform: scale(1.1);
        -moz-transform: scale(1.1);
        -ms-transform: scale(1.1);
        -o-transform: scale(1.1);
}
    100% {
        transform: scale(1);
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        -ms-transform: scale(1);
        -o-transform: scale(1);
}
}

@keyframes voice-pulse-driver {
    0%, 100% { --voice-pulse: 0; }
    50%      { --voice-pulse: 1; }
}

@keyframes voice-boost {
    0%, 100% { --halo-boost-osc: 0; }
    50%      { --halo-boost-osc: 1; }
}

@keyframes voice-wave-driver {
    0%, 100% { --voice-wave: 0; }
    50%      { --voice-wave: 1; }
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
        -webkit-transform: scale(0.9);
        -moz-transform: scale(0.9);
        -ms-transform: scale(0.9);
        -o-transform: scale(0.9);
}
    to {
        transform: scale(1);
        opacity: 1;
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        -ms-transform: scale(1);
        -o-transform: scale(1);
}
}

@keyframes breathe {
    0%, 100% {
        transform: scale(1);
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        -ms-transform: scale(1);
        -o-transform: scale(1);
}
    50% {
        transform: scale(1.25);
        -webkit-transform: scale(1.25);
        -moz-transform: scale(1.25);
        -ms-transform: scale(1.25);
        -o-transform: scale(1.25);
}
}

@keyframes fabGlowPulse {
    0%, 100% {
        opacity: 0.55;
        stroke-dashoffset: 0;
        -webkit-stroke-dashoffset: 0;
        -moz-stroke-dashoffset: 0;
        -ms-stroke-dashoffset: 0;
        -o-stroke-dashoffset: 0;
    }
    50% {
        opacity: 1;
        stroke-dashoffset: -12;
        -webkit-stroke-dashoffset: -12;
        -moz-stroke-dashoffset: -12;
        -ms-stroke-dashoffset: -12;
        -o-stroke-dashoffset: -12;
    }
}


/* ==========================================================================
   23. PÁGINA HISTORIAL — HEADER Y BUSCADOR
   ========================================================================== */
.main-header {
    background-color: var(--accent-color);
    color: #ffffff;
    padding: 12px;
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.header-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-weight: 600;
    font-size: 1.1rem;
}

.header-left img {
    display: block;
    height: 20px;
    width: auto;
}

.search-bar-container {
    width: 100%;
    display: flex;
    align-items: center;
}

.search-input-wrapper {
    background: rgba(255, 255, 255, 0.25);
    border-radius: var(--spacing-sm);
    display: flex;
    align-items: center;
    padding: 0 12px;
    flex: 1;
    height: 40px;
}

.search-input-wrapper input {
    background: transparent;
    border: none;
    color: #ffffff;
    padding: 0 10px;
    width: 100%;
    outline: none;
    font-size: 1.0625rem;
    font-weight: 500;
}

.search-input-wrapper input::placeholder {
    color: rgba(255, 255, 255, 0.8);
    font-weight: 400;
}

.search-icon {
    opacity: 0.8;
}

#btn-clear-search {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: var(--spacing-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    -webkit-opacity: 0.7;
    -moz-opacity: 0.7;
    -ms-opacity: 0.7;
    -o-opacity: 0.7;
    transition: opacity 0.2s;
    -webkit-transition: opacity 0.2s;
    -moz-transition: opacity 0.2s;
    -ms-transition: opacity 0.2s;
    -o-transition: opacity 0.2s;
}

#btn-clear-search:hover {
    opacity: 1;
    -webkit-opacity: 1;
    -moz-opacity: 1;
    -ms-opacity: 1;
    -o-opacity: 1;
}

#btn-clear-search.hidden {
    display: none;
}


/* ==========================================================================
   24. PÁGINA HISTORIAL — LISTA DE CONVERSACIONES
   ========================================================================== */
.conversation-list-container {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    background-color: var(--bg-color);
    background-image: url('/unica_test/static/vegetables.png');
    background-repeat: repeat;
    background-size: 700px;
    padding-bottom: 96px;
}

/* Pull-to-refresh */
.ptr-host {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    margin-top: 0;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), margin-top 0.2s ease;
    will-change: transform;
}

.ptr-host.ptr-dragging,
.ptr-host.ptr-loading {
    margin-top: 4px;
}

.ptr-host.ptr-dragging {
    transition: margin-top 0.15s ease;
}

.ptr-host > .conversation-list-container {
    flex: 1;
    min-height: 0;
}

.ptr-indicator {
    position: absolute;
    top: -44px;
    left: 50%;
    width: 36px;
    height: 36px;
    margin-left: -18px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease, box-shadow 0.25s ease, transform 0.25s ease;
}

.ptr-host.ptr-loading .ptr-indicator {
    box-shadow: 0 4px 14px rgba(125, 186, 0, 0.45);
    animation: ptr-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ptr-spinner {
    width: 22px;
    height: 22px;
    transform-origin: 50% 50%;
    animation: ptr-spin 0.8s linear infinite;
    -webkit-animation: ptr-spin 0.8s linear infinite;
}

.ptr-host.ptr-loading .ptr-spinner {
    animation-duration: 0.6s;
    -webkit-animation-duration: 0.6s;
}

@keyframes ptr-spin {
    to { transform: rotate(360deg); -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -ms-transform: rotate(360deg); -o-transform: rotate(360deg); }
}

@keyframes ptr-pop {
    0%   { transform: scale(0.85); -webkit-transform: scale(0.85); -moz-transform: scale(0.85); -ms-transform: scale(0.85); -o-transform: scale(0.85); }
    60%  { transform: scale(1.15); -webkit-transform: scale(1.15); -moz-transform: scale(1.15); -ms-transform: scale(1.15); -o-transform: scale(1.15); }
    100% { transform: scale(1); -webkit-transform: scale(1); -moz-transform: scale(1); -ms-transform: scale(1); -o-transform: scale(1); }
}

.conversation-item {
    display: flex;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    background: #ffffff;
    align-items: start;
}

.conversation-item:active {
    background-color: var(--surface-soft);
}

.conversation-item.hidden {
    display: none !important;
}

.conversation-item.pinned {
    border-left: 4px solid rgba(125, 186, 0, 0.75);
    -webkit-border-left: 4px solid rgba(125, 186, 0, 0.75);
    -moz-border-left: 4px solid rgba(125, 186, 0, 0.75);
    -ms-border-left: 4px solid rgba(125, 186, 0, 0.75);
    -o-border-left: 4px solid rgba(125, 186, 0, 0.75);
}


.pin-indicator {
    display: inline-flex;
    align-items: center;
    margin: -4px 6px 0 0;
    color: var(--primary-color);
    background-color: var(--bg-pinned);
    vertical-align: middle;
    padding: 4px;
    border-radius: 4px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    -ms-border-radius: 4px;
    -o-border-radius: 4px;
}

.pin-indicator svg {
    display: block;
    rotate: 45deg;
    transform-origin: center;
}

.conv-content {
    flex: 1;
    min-width: 0;
}

.conv-title {
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text-primary);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 3px 0;
}

.conv-subtitle {
    font-size: var(--fs-base);
    color: var(--text-secondary);
    line-height: 1.3;
    margin-bottom: 4px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 95%;
}

.conv-date {
    font-size: 0.85rem !important;
    color: #8fa0a8;
    margin-top: var(--spacing-xs);
}

.conv-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.action-btn-list {
    padding: var(--spacing-sm);
    border-radius: 50%;
    color: var(--text-secondary);
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.action-btn-list:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--primary-color);
}

.btn-delete-conv:hover {
    color: var(--danger);
    background: rgba(239, 83, 80, 0.1);
}

.historial-list {
    list-style: none;
    padding: 2px 0 0;
    margin: 0;
}


/* ==========================================================================
   25. PÁGINA HISTORIAL — ACORDEÓN POR MES
   (no se renderiza con el flujo actual; se mantiene por compatibilidad)
   ========================================================================== */
.month-container.hidden {
    display: none !important;
}

.month-header {
    background-color: var(--bg-pinned);
    padding: 12px var(--spacing-md);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(5px);
}

.month-chevron {
    transition: transform 0.3s ease;
}

.month-chevron.closed {
    transform: rotate(-90deg);
}


/* ==========================================================================
   26. PÁGINA HISTORIAL — FAB, EMPTY STATE Y BOTÓN VER MÁS
   ========================================================================== */
.fab {
    position: absolute;
    bottom: var(--spacing-lg);
    right: var(--spacing-lg);
    height: 56px;
    padding: 0 20px;
    border-radius: 28px;
    background: var(--accent-color);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    font-size: 0.95rem;
    font-weight: 600;
    z-index: 40;
    transition: transform 0.2s ease, box-shadow 0.2s ease, width 0.2s ease, padding 0.2s ease;
}

.fab-icon-wrap {
    position: relative;
    width: var(--spacing-lg);
    height: var(--spacing-lg);
    flex: 0 0 var(--spacing-lg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.fab .outline-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.fab .outline-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.35);
    stroke-width: 5;
}

.fab .outline-glow {
    fill: none;
    stroke: rgba(255, 255, 255, 0.8);
    stroke-width: 2.4;
    stroke-dasharray: 8 6;
    transform-origin: 50% 50%;
    animation: fabGlowPulse 2.8s ease-in-out infinite;
}

.fab .icon-box {
    position: relative;
    z-index: 1;
    width: var(--spacing-xl);
    height: var(--spacing-xl);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
}

.fab .icon-box svg {
    width: var(--spacing-xl);
    height: var(--spacing-xl);
    display: block;
}

.fab-label {
    white-space: nowrap;
    transition: opacity 0.16s ease, width 0.16s ease, margin 0.16s ease;
}

.fab:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
}

.fab:active {
    transform: translateY(0);
}

.fab.fab--compact {
    width: 56px;
    min-width: 56px;
    padding: 0;
    border-radius: 50%;
    gap: 0;
}

.fab.fab--compact .fab-label {
    opacity: 0;
    width: 0;
    margin: 0;
    overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .fab,
    .fab .outline-glow,
    .fab-label {
        animation: none !important;
        transition: none !important;
    }
}

.btn-ver-mas {
    display: block;
    width: calc(100% - 32px);
    margin: 12px var(--spacing-md) var(--spacing-md);
    padding: 12px var(--spacing-md);
    background: #ffffff;
    color: var(--accent-color);
    border: 1.5px solid var(--accent-color);
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s, color 0.15s;
}

.btn-ver-mas:hover {
    background: var(--accent-color);
    color: #ffffff;
}

.btn-ver-mas:disabled {
    opacity: 0.5;
    cursor: default;
}

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.8);
    margin: 20px;
    border-radius: 12px;
}


/* ==========================================================================
   27. PÁGINA HISTORIAL — ONBOARDING (SLIDES + HALO + PROGRESO)
   ========================================================================== */
.onboarding-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    background-image: url('/unica_test/static/vegetables.png');
    background-repeat: repeat;
    background-size: 700px;
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.onboarding-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.onboarding-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
    text-align: center;
    margin-top: 40px;
    width: 100%;
}

.onboarding-slides {
    width: 100%;
    height: 100%;
    position: relative;
}

.slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.slide.active {
    opacity: 1;
    pointer-events: auto;
}

.slide h1 {
    font-size: 1.8rem;
    margin-bottom: var(--spacing-md);
    color: var(--primary-color);
}

.slide p {
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.5;
    max-width: 320px;
}

/* Ilustraciones de los slides 1 y 2 (farmer.svg, farmer-2.svg) */
.slide-illustration {
    width: 80%;
    max-width: 250px;
    height: auto;
    margin-bottom: var(--spacing-lg);
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.voice-modes-illustration {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    width: 60%;
    max-width: 240px;
    margin-bottom: var(--spacing-lg);
    background: linear-gradient(
        135deg,
        rgba(125, 186, 0, 0.16) 0%,
        rgba(152, 196, 74, 0.22) 28%,
        rgba(191, 166, 122, 0.2) 62%,
        rgba(214, 188, 149, 0.24) 100%
    );
    padding: 50px;
    min-width: 300px;
    height: 300px;
    border-radius: 300px;
    -webkit-border-radius: 300px;
    -moz-border-radius: 300px;
    -ms-border-radius: 300px;
    -o-border-radius: 300px;
}

.inline-voice-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8em;
    height: 1.8em;
    vertical-align: -0.35em;
    border-radius: var(--spacing-sm);
    flex-shrink: 0;
    cursor: pointer;
    background: #ffffff;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    box-shadow: none;
    transition: all 0.2s ease;
    -webkit-transition: all 0.2s ease;
    -moz-transition: all 0.2s ease;
    -ms-transition: all 0.2s ease;
    -o-transition: all 0.2s ease;
}

.inline-voice-icon svg {
    width: 100%;
    height: 100%;
    display: block;
    padding: 3px;
}

.voice-mode-card {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    opacity: 0;
    transform: translateY(8px);
}

.slide.active .voice-mode-card {
    animation: voiceModeIn 0.5s ease forwards;
}

.slide.active .voice-mode-card--conversation { animation-delay: 0.05s; }
.slide.active .voice-mode-card--walkie { animation-delay: 0.20s; }

.voice-mode-pill {
    width: 100%;
    height: auto;
    aspect-ratio: 532 / 201;
    display: block;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.12));
    transform-origin: center;
}

.slide.active .voice-mode-card--conversation .voice-mode-pill {
    animation: voiceModeFloat 3.4s ease-in-out 0.6s infinite alternate;
}

.slide.active .voice-mode-card--walkie .voice-mode-pill {
    animation: voiceModeFloat 3.4s ease-in-out 1.3s infinite alternate;
}

.voice-mode-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

@keyframes voiceModeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes voiceModeFloat {
    from { transform: translateY(0); }
    to   { transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    .slide.active .voice-mode-card,
    .slide.active .voice-mode-card--conversation .voice-mode-pill,
    .slide.active .voice-mode-card--walkie .voice-mode-pill {
        animation: none;
    }
    .voice-mode-card {
        opacity: 1;
        transform: none;
    }
}

.story-progress-container {
    display: flex;
    gap: var(--spacing-xs);
    padding: 12px var(--spacing-md);
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 2001;
}

.progress-bar-bg {
    flex: 1;
    height: 2px;
    background-color: #aaa;
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--primary-color);
    width: 0%;
    transition: width 0.1s linear;
}

.progress-bar-bg.completed .progress-bar-fill {
    width: 100%;
}

.progress-bar-bg.active .progress-bar-fill {
    width: 100%;
}

.content-loader-animation {
    position: relative;
    width: 260px;
    height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 60px;
}

.logo-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    overflow: hidden;
    z-index: 10;
}

.logo-placeholder img {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: contain;
    display: block;
    background: transparent;
}

.stack {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    animation: breathe infinite 3s ease-in-out;
    -webkit-animation: breathe infinite 3s ease-in-out;
    -moz-animation: breathe infinite 3s ease-in-out;
    -ms-animation: breathe infinite 3s ease-in-out;
    -o-animation: breathe infinite 3s ease-in-out;
}

.blobs {
    display: grid;
    grid-template-areas: 'stack';
    position: relative;
    animation: spin infinite 5s linear;
    width: 240px;
    height: 240px;
    filter: blur(8px);
    -webkit-filter: blur(8px);
}

.blob {
    --border-radius: 115% 140% 145% 110% / 125% 140% 110% 125%;
    --border-width: 12px;
    aspect-ratio: 1;
    display: block;
    grid-area: stack;
    background-size: calc(100% + var(--border-width) * 2);
    background-repeat: no-repeat;
    background-position: center;
    border: var(--border-width) solid transparent;
    border-radius: var(--border-radius, 50%);
    -webkit-mask-image: linear-gradient(transparent, transparent), linear-gradient(black, white);
    mask-image: linear-gradient(transparent, transparent), linear-gradient(black, white);
    -webkit-mask-clip: padding-box, border-box;
    mask-clip: padding-box, border-box;
    -webkit-mask-composite: source-in, xor;
    mask-composite: intersect;
    mix-blend-mode: screen;
    height: 100%;
    width: 100%;
    filter: none;
}

.blob:nth-child(1) {
    background-color: var(--blue);
    background-image: linear-gradient(var(--blue), var(--teal), var(--blue));
    rotate: 30deg;
    scale: 1.03;
}

.blob:nth-child(2) {
    background-color: var(--red);
    background-image: linear-gradient(var(--red), var(--orange), var(--red));
    rotate: 60deg;
    scale: 0.95;
}

.blob:nth-child(3) {
    background-color: var(--olive);
    background-image: linear-gradient(var(--olive), var(--lime), var(--olive));
    rotate: 90deg;
    scale: 0.97;
}

.blob:nth-child(4) {
    background-color: var(--purple);
    background-image: linear-gradient(var(--purple), var(--maroon), var(--purple));
    rotate: 120deg;
    scale: 1.02;
}

.onboarding-actions {
    padding: var(--spacing-lg);
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    padding-bottom: 40px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
    border: none;
    padding: 14px var(--spacing-lg);
    border-radius: var(--spacing-lg);
    font-size: 1rem;
    font-weight: 600;
    width: 100%;
    max-width: 300px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn-text {
    background: rgba(255, 255, 255, 0.6);
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    margin-top: var(--spacing-sm);
    padding: var(--spacing-xs) 12px;
    border-radius: 12px;
}


/* ==========================================================================
   28. PÁGINA HISTORIAL — SELECTOR DE CAMPAÑA (TRIGGER EN HEADER)
   ========================================================================== */
   .header-actions {
    position: relative;
    background-color: var(--accent-color);
    color: #ffffff;
    border-radius: var(--spacing-sm);
    height: 40px;
    padding: 0;
    margin-left: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
   }

   .header-actions .icon-btn {
    opacity: 0.7;
    -webkit-opacity: 0.7;
    -moz-opacity: 0.7;
    -ms-opacity: 0.7;
    -o-opacity: 0.7;
    transition: opacity 0.2s;
    -webkit-transition: opacity 0.2s;
    -moz-transition: opacity 0.2s;
    -ms-transition: opacity 0.2s;
   }

   .campaign-selector-wrapper {
    position: relative;
    background-color: var(--accent-color);
    color: #ffffff;
    border-radius: var(--spacing-sm);
    height: 40px;
    padding: 0 var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    margin-left: var(--spacing-sm);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#historial-campanya-select {
    display: none !important;
}

#historial-campanya-label {
    z-index: 1;
    pointer-events: none;
}


/* ==========================================================================
   29. PÁGINA HISTORIAL — DROPDOWN POR CONVERSACIÓN
   (overrides scoped al listado para no afectar al menú del chat)
   ========================================================================== */
.dropdown-container {
    position: relative;
}

.dropdown-trigger {
    border: 1px solid var(--border-color);
    background-color: transparent;
    padding: 6px;
    border-radius: 6px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.dropdown-trigger:hover {
    background-color: var(--surface-hover);
    color: var(--text-primary);
    border-color: #c0c7ce;
}

.dropdown-trigger.active {
    background-color: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.conv-actions .dropdown-menu {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--spacing-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 6px 0;
    min-width: 180px;
    z-index: 1000;
    margin-top: 0;
}

.conv-actions .dropdown-menu.show {
    display: block;
    animation: fadeIn 0.15s ease-out;
}

.conv-actions .dropdown-item {
    width: 100%;
    padding: 10px var(--spacing-md);
    gap: 12px;
    font-family: inherit;
    transition: background-color 0.2s;
}

.conv-actions .dropdown-item:hover {
    background-color: var(--surface-hover);
}

.conv-actions .dropdown-item svg {
    color: var(--text-secondary);
    stroke-width: 2;
}

.conv-actions .dropdown-item-pin svg {
    transform: rotate(45deg);
    -webkit-transform: rotate(45deg);
    -moz-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    -o-transform: rotate(45deg);
}

.dropdown-item.delete {
    color: #e53935;
}

.dropdown-item.delete svg {
    color: #e53935;
}

.dropdown-item.delete:hover {
    background-color: #feebe9;
}
