/* css/chat.css - Hub & Chat Styles */

.sa-chat--large {
    min-height: 220px;
    display: flex;
    flex-direction: column;
}

.sa-chat-window {
    background: transparent;
    padding: 5px 0;
    min-height: 150px;
    max-height: 500px;
    /* Limitar para asegurar visibilidad total */
    overflow-y: auto;
    font-size: 0.9rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    scrollbar-gutter: stable;
}

.sa-chat-message {
    margin-bottom: 16px;
    line-height: 1.6;
    position: relative;
    max-width: 92%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.sa-chat-message p {
    margin: 0 0 8px 0;
    /* Espaciado controlado entre párrafos */
}

.sa-chat-message p:first-child {
    margin-top: 0;
}

.sa-chat-message p:last-child {
    margin-bottom: 0;
}

.sa-chat-message--user {
    align-self: flex-end;
    margin-left: auto;
    margin-right: 20px;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 8px 0 8px 8px;
    padding: 12px 16px;
    color: #e0f2fe;
}

.sa-chat-message--bot {
    align-self: flex-start;
    margin-right: auto;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid #334155;
    border-radius: 12px 12px 12px 0;
    /* 3 ángulos redondeados, 1 recto (inferior izquierdo) */
    padding: 12px 16px;
    color: #f1f5f9;
    max-width: 90%;
    position: relative;
    box-sizing: border-box;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Neon Glow for Latest Bot Message (Active) */
.sa-chat-message--latest {
    border: 1px solid transparent;
    background-image: linear-gradient(#0f172a, #0f172a),
        linear-gradient(135deg, #a855f7, #7c3aed, #4ade80);
    background-origin: border-box;
    background-clip: padding-box, border-box;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.3);
    animation: sa-neon-pulse 3s infinite alternate;
}

@keyframes sa-neon-pulse {
    0% {
        box-shadow: 0 0 10px rgba(168, 85, 247, 0.2);
        filter: brightness(1);
    }

    100% {
        box-shadow: 0 0 20px rgba(168, 85, 247, 0.5);
        filter: brightness(1.1);
    }
}

/* --- NUEVO LAYOUT PRECISO 12:50 --- */
.input-section-wrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-start;
    width: 100%;
    margin-top: 15px;
}

/* 1. El Textarea con medida exacta */
.custom-textarea {
    width: calc(100% - 180px);
    /* Alineado con la píldora superior */
    background: rgba(15, 17, 26, 0.7);
    border: 1px solid #2d2f3f;
    border-radius: 12px;
    padding: 16px;
    padding-right: 15px !important;
    /* Contenido respete el borde */
    font-family: inherit;
    /* Hereda del saludo */
    font-size: 16px;
    color: #ffffff;
    resize: none;
    outline: none;
    min-height: 80px;
    max-height: 300px;
    line-height: 1.5;
    box-sizing: border-box;
    transition: border-color 0.2s;

    /* Reserva espacio para scroll y evita saltos visuales */
    scrollbar-gutter: stable;
    overflow-x: hidden;
    overflow-y: overlay;
    /* Forzado según indicación */
}

/* Estilización Minimalista y Flotante del Scrollbar (Silicon Valley Style) */
.custom-textarea::-webkit-scrollbar {
    width: 12px;
    /* Espacio para márgenes internos */
}

.custom-textarea::-webkit-scrollbar-track {
    background: transparent;
    margin: 5px;
    /* Separa la barra de los bordes redondeados */
}

.custom-textarea::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    border: 3px solid transparent;
    /* Efecto flotante */
    background-clip: content-box;
    /* Color dentro del borde transparente */
}

.custom-textarea::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

.custom-textarea:focus {
    border-color: var(--accent-purple);
}

/* 2. El Área del Triángulo (Botones) */
.buttons-aside {
    width: 150px;
    margin-left: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.sa-actions-base {
    display: flex;
    gap: 10px;
}

/* 3. Botón Expandir (Lógica de Escritorio vs Móvil) */
.btn-expand-textarea {
    display: none !important;
    /* Desaparece en PC */
}

@media (max-width: 900px) {

    /* --- CONTENEDOR ROBUSTO (768px Coords) --- */
    .input-section-wrapper {
        position: relative !important;
        display: block !important;
        width: 100% !important;
    }

    .custom-textarea {
        width: 100% !important;
        padding-bottom: 60px !important;
        /* Espacio para que el texto no tape los botones flotantes */
        min-height: 100px !important;
        box-sizing: border-box !important;
    }

    .buttons-aside {
        position: relative !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: flex-end !important;
        width: 100% !important;
        margin: 12px 0 0 !important;
        gap: 8px !important;
        pointer-events: auto !important;
        z-index: 30 !important;
        padding: 0 10px !important;
        box-sizing: border-box !important;
    }

    .sa-actions-base {
        display: contents !important;
        /* Mic y Copy participan directamente en flex/grid */
    }

    /* Botones 42x42 Precisión */
    .sa-btn-icon,
    #sa-chat-send-btn,
    #sa-chat-mic-btn,
    #sa-chat-copy-btn {
        width: 42px !important;
        height: 42px !important;
        min-width: 42px !important;
        min-height: 42px !important;
        margin: 0 !important;
        position: static !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 0 !important;
    }

    /* Orden en Fila Horizontal: Mic (1), Copy (2), Send (3) */
    #sa-chat-mic-btn {
        order: 1 !important;
    }

    #sa-chat-copy-btn {
        order: 2 !important;
    }

    #sa-chat-send-btn {
        order: 3 !important;
    }

    /* --- ARQUITECTURA EN VISTA EXPANDIDA (MODO TRIÁNGULO) --- */
    /* El botón expandir ahora está después de buttons-aside, pero usamos ~ para los botones */
    .custom-textarea.expanded~.buttons-aside {
        position: relative !important;
        display: grid !important;
        grid-template-columns: 42px 42px !important;
        grid-template-rows: auto auto !important;
        gap: 12px 15px !important;
        justify-content: flex-end !important;
        /* EMPUJAR A LA DERECHA DEL CONTENEDOR */
        margin: 5px 0 0 auto !important;
        /* MINIMIZAR ESPACIO CON TEXTAREA */
        width: 100% !important;
        max-width: 600px !important;
        right: auto !important;
        bottom: auto !important;
        padding-right: 0 !important;
        padding-bottom: 20px !important;
        box-sizing: border-box !important;
    }

    /* El botón Send se vuelve la punta del triángulo */
    .custom-textarea.expanded~.buttons-aside #sa-chat-send-btn {
        grid-column: span 2 !important;
        justify-self: center !important;
        order: -1 !important;
        margin-bottom: 5px !important;
    }

    .custom-textarea.expanded~.buttons-aside #sa-chat-mic-btn {
        grid-column: 1 !important;
        order: 1 !important;
        justify-self: center !important;
    }

    .custom-textarea.expanded~.buttons-aside #sa-chat-copy-btn {
        grid-column: 2 !important;
        order: 2 !important;
        justify-self: center !important;
    }

    /* Configuración del Overlay Expandido */
    body.sa-chat-expanded-mode .input-section-wrapper {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 60000 !important;
        background: rgba(0, 0, 0, 0.45) !important;
        /* FONDO TRASLÚCIDO SOLICITADO */
        backdrop-filter: blur(10px) !important;
        /* Efecto premium */
        padding: 40px 20px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    body.sa-chat-expanded-mode .custom-textarea {
        flex: 0 0 75vh !important;
        /* 75% de la altura para maximizar espacio */
        width: 100% !important;
        max-width: 600px !important;
        margin: 0 auto !important;
        padding: 20px !important;
        padding-right: 45px !important;
        /* Espacio para el botón de minimize */
        box-sizing: border-box !important;
        background: #000 !important;
        /* El textarea se mantiene oscuro sólido */
    }

    body.sa-chat-expanded-mode .buttons-aside {
        width: 100% !important;
        max-width: 600px !important;
        align-self: center !important;
    }

    body.sa-chat-expanded-mode .btn-expand-textarea {
        display: flex !important;
        position: absolute !important;
        top: 55px !important;
        /* Ajustado para flotar dentro del textarea expandido */
        right: 35px !important;
        opacity: 0.8 !important;
        z-index: 60005 !important;
        background: transparent !important;
        /* TRANSPARENTE TOTAL */
        border: none !important;
        box-shadow: none !important;
        padding: 5px !important;
    }

    .btn-expand-textarea {
        display: flex !important;
        position: absolute !important;
        top: 15px !important;
        /* Visualmente dentro del textarea superior derecho */
        right: 15px !important;
        z-index: 500 !important;
        background: transparent !important;
        /* TRANSPARENTE TOTAL */
        border: none !important;
        border-radius: 0 !important;
        opacity: 0 !important;
        /* Invisible hasta que se escriba */
        pointer-events: none !important;
        padding: 5px !important;
        transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
        box-shadow: none !important;
    }

    .btn-expand-textarea.sa-visible {
        opacity: 0.8 !important;
        pointer-events: auto !important;
    }

    /* Forzar visibilidad de las flechitas */
    .btn-expand-textarea svg,
    .btn-expand-textarea svg line,
    .btn-expand-textarea svg polyline {
        stroke: #94a3b8 !important;
    }
}

/* 4. Texto de Verificación */
.verify-text {
    width: calc(100% - 180px);
    /* Centrado respecto al textarea */
    text-align: center;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
    margin: 0px 0 0;
    /* Subido al máximo (0px) */
    opacity: 0;
    transition: opacity 1s ease;
}

.verify-text.show {
    opacity: 1;
}

/* Estilos de botones específicos para Silicon Valley Triangle */
.sa-btn-apex {
    background: var(--gradient-sa) !important;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
    width: 42px !important;
    height: 42px !important;
}

.sa-actions-base .sa-btn {
    width: 40px !important;
    height: 40px !important;
}

/* Disclaimer y selectores antiguos sincronizados */
#sa-dynamic-disclaimer {
    display: block;
    /* Debe ser visible como verify-text */
}

/* ── Model Selector ─────────────────────────────────────────────────────── */
.sa-model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    width: calc(100% - 180px); /* Alineado con el textarea */
    flex-wrap: wrap;
}

.sa-model-selector-label {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.35);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
    margin-right: 2px;
}

.sa-model-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 14px;
    border-radius: 20px;
    border: 1px solid #2d2f3f;
    background: rgba(15, 17, 26, 0.5);
    color: rgba(255, 255, 255, 0.45);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.18s ease;
    white-space: nowrap;
    line-height: 1.6;
}

.sa-model-btn:hover {
    border-color: #475569;
    color: rgba(255, 255, 255, 0.75);
}

/* M1 active — emerald */
.sa-model-btn--active[data-model="apisy_m1"] {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
}

/* M2 active — purple */
.sa-model-btn--active[data-model="apisy_m2"] {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.12);
    color: #a78bfa;
}

/* Inline variant — for use inside sidebars, cards and modals */
.sa-model-selector--inline {
    width: 100%;
    margin-top: 0;
    margin-bottom: 12px;
}

/* Text-only variant — no capsule, color = active / gray = inactive */
.sa-model-selector--text {
    flex-direction: column;
    gap: 0;
    width: 100%;
    margin-top: 0;
    margin-bottom: 14px;
    padding: 10px 0 2px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.sa-model-selector--text .sa-model-btn {
    border: none;
    background: none;
    border-radius: 0;
    padding: 5px 0;
    justify-content: flex-start;
    font-size: 13px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.28);
    gap: 6px;
    letter-spacing: 0.01em;
}

.sa-model-selector--text .sa-model-btn:hover {
    border: none;
    background: none;
    color: rgba(255, 255, 255, 0.55);
}

.sa-model-selector--text .sa-model-btn--active[data-model="apisy_m1"] {
    border: none;
    background: none;
    color: #34d399;
}

.sa-model-selector--text .sa-model-btn--active[data-model="apisy_m2"] {
    border: none;
    background: none;
    color: #a78bfa;
}

/* Hint text inside text-variant buttons */
.sa-model-hint {
    font-size: 11px;
    font-weight: 400;
    opacity: 0.65;
    margin-left: 2px;
}

@media (max-width: 900px) {
    .sa-model-selector {
        width: 100%;
        margin-top: 10px;
    }
}

/* AI Loading Wave */
.sa-loading-dots {
    display: inline-block;
    margin-left: 2px;
}

.sa-dot {
    display: inline-block;
    animation: sa-wave 1.4s infinite ease-in-out both;
    font-weight: bold;
}

.sa-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.sa-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes sa-wave {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ── Model Selector v2 — Hub & Chat Dropdown ───────────────────────────── */

/* Ocupa la fila completa del textarea dentro del input-section-wrapper */
.sa-ms-wrap {
    flex-basis: calc(100% - 180px); /* misma anchura que el textarea */
    width: calc(100% - 180px);
    display: flex;
    align-items: baseline;          /* MODEL y el nombre en la misma línea base */
    gap: 10px;
    margin-top: 6px;
    margin-bottom: 0;
    order: 10;                      /* aparece después del textarea y los botones */
}

.sa-ms-label {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.28);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    font-weight: 600;
    white-space: nowrap;
    user-select: none;
    line-height: 1;
}

.sa-ms-dropdown {
    position: relative;
}

/* Trigger — solo texto en color, sin cápsula ni flecha */
.sa-ms-trigger {
    display: inline-flex;
    align-items: baseline;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    transition: opacity 0.15s;
}
.sa-ms-trigger:hover { opacity: 0.75; }

/* Color del texto según modelo activo */
.sa-ms-current[data-model="apisy_m1"] { color: #00d4b4; } /* teal */
.sa-ms-current[data-model="apisy_m2"] { color: #a78bfa; } /* lila */
.sa-ms-current[data-model="bee_1"]    { color: #f59e0b; } /* amber */

/* Panel glassmorphism — abre hacia ABAJO */
.sa-ms-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 230px;
    background: rgba(15, 23, 42, 0.10);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 12px;
    padding: 5px;
    z-index: 500;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.sa-ms-panel.is-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Opciones: nombre + descripción en la MISMA fila */
.sa-ms-option {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    transition: background 0.14s;
    font-family: inherit;
}
.sa-ms-option:hover { background: rgba(255, 255, 255, 0.06); }

.sa-ms-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1;
}
.sa-ms-name--m1   { color: #00d4b4; }
.sa-ms-name--m2   { color: #a78bfa; }
.sa-ms-name--bee1 { color: #f59e0b; }

.sa-ms-desc {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.38);
    white-space: nowrap;
    line-height: 1;
}

.sa-ms-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 3px 8px;
}

@media (max-width: 900px) {
    .sa-ms-wrap {
        flex-basis: 100%;
        width: 100%;
        margin-top: 10px;
    }
}