/* Noesis Chat Plugin - Stili con Orb Three.js */

/* ====== LAYOUT CONTAINER ====== */
.noesis-chat-container {
    width: 100%;
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.noesis-chat-container * {
    box-sizing: border-box;
}

/* ====== STATO INIZIALE MINIMALISTA ====== */
.noesis-initial-state {
    width: 100%;
    background: transparent;
    border-radius: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    order: 1;
}

.noesis-input-container {
    position: relative;
    display: flex;
    align-items: center;
    background: #000000;
    padding: 0;
    transition: all 0.3s ease;
    min-height: 56px;
}

.noesis-input-container:focus-within {
    border-bottom-color: #ffffff;
}

.noesis-message-input {
    flex: 1;
    background: none!important;
    border: none!important;
    outline: none;
    border-bottom:1px solid #333!important;
    color: #ffffff!important;
    font-size: 24px;
    padding: 16px 20px;
    font-weight: 200;
    letter-spacing: 0.3px;
    line-height: 1.4;
}

.noesis-message-input::placeholder {
    color: #888888;
    font-weight: 300;
}

.noesis-message-input:focus::placeholder {
    color: #666666 !important;
    border-color:#333!important;
}

.noesis-send-button,
.noesis-voice-button {
    background: transparent;
    border: none;
    padding: 14px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
}

.noesis-send-button:hover,
.noesis-voice-button:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

.noesis-send-button:active,
.noesis-voice-button:active {
    transform: scale(0.95);
}

.noesis-send-icon,
.noesis-mic-icon {
    width: 20px;
    height: 20px;
    fill: #ffffff;
    transition: fill 0.3s ease;
}

.noesis-voice-button.recording .noesis-mic-icon {
    fill: #ff4444;
    animation: pulse 1.5s ease-in-out infinite;
}

/* Status bar minimalista */
.noesis-status-bar {
    margin-top: 12px;
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.noesis-status-text {
    color: #fff !important;
}

.noesis-connection-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #b0b0b0;
}

.noesis-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    transition: background 0.3s ease;
}

.noesis-status-dot.connected {
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.3);
}

/* ====== STATO ESPANSO (CHAT COMPLETA) ====== */
.noesis-expanded-state {
    width: 100%;
    background: #000000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: none; /* Nascosto per default */
    flex-direction: column;
    max-height: 0;
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 20px;
    order: -1;
}

/* FIX: Stato attivo più esplicito */
.noesis-expanded-state.active {
    display: flex !important;
    opacity: 1 !important;
    max-height: 70vh !important;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ====== ORB THREE.JS HEADER CONTAINER ====== */
.noesis-chat-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 20px;
    border-bottom: 1px solid #1a1a1a;
    background: #000000;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    min-height: 200px;
}

/* Background particles effect */
.noesis-chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 30%, rgba(102, 126, 234, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(118, 75, 162, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 40% 80%, rgba(59, 130, 246, 0.03) 0%, transparent 50%);
    animation: particleFloat 20s ease-in-out infinite;
    pointer-events: none;
}

@keyframes particleFloat {
    0%, 100% { 
        transform: translateY(0px) scale(1);
        opacity: 0.8;
    }
    50% { 
        transform: translateY(-10px) scale(1.05);
        opacity: 1;
    }
}

/* ====== THREE.JS ORB CONTAINER ====== */
.noesis-orb-container {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 0 auto 15px auto;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.noesis-orb-canvas {
    width: 160px !important;
    height: 160px !important;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.3s ease;
}

/* Animazione fallback se Three.js non carica */
@keyframes orbFallbackGlow {
    0%, 100% { 
        background-position: 0% 50%;
        box-shadow: 0 0 20px rgba(102, 126, 234, 0.3);
    }
    50% { 
        background-position: 100% 50%;
        box-shadow: 0 0 30px rgba(118, 75, 162, 0.4);
    }
}

.noesis-orb-canvas:hover {
    transform: scale(1.02);
}

/* ====== STATUS TEXT ====== */
.noesis-orb-status {
    color: #e0e0e0;
    font-size: 14px;
    font-weight: 400;
    text-align: center;
    opacity: 0.9;
    transition: all 0.3s ease;
    letter-spacing: 0.5px;
    z-index: 2;
}

/* ====== CONTROLS POSIZIONATI NELL'ANGOLO ====== */
.noesis-chat-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    gap: 8px;
    z-index: 3;
}

.noesis-voice-toggle,
.noesis-minimize-button {
    background: rgba(30, 30, 30, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.noesis-voice-toggle:hover,
.noesis-minimize-button:hover {
    background: rgba(50, 50, 50, 0.9);
    border-color: rgba(102, 126, 234, 0.6);
    transform: translateY(-2px);
}

.noesis-voice-toggle.active {
    background: rgba(102, 126, 234, 0.3);
    border-color: #667eea;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.4);
}

.noesis-speaker-icon,
.noesis-minimize-icon {
    width: 16px;
    height: 16px;
    fill: #ffffff;
    transition: fill 0.3s ease;
}

.noesis-voice-toggle:not(.active) .noesis-speaker-icon {
    fill: #666666;
}

.noesis-voice-toggle.active .noesis-speaker-icon {
    fill: #ffffff;
}

/* Container messaggi - con scroll interno */
.noesis-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    scroll-behavior: smooth;
    min-height: 200px;
    max-height: calc(70vh - 160px);
}

.noesis-messages {
    display: flex;
    flex-direction: column;
    padding: 16px 0;
}

/* Messaggi utente - in bubble con testo più chiaro */
.noesis-message {
    margin-bottom: 24px;
    animation: messageAppear 0.4s ease-out;
}

.noesis-message.user {
    display: flex;
    justify-content: flex-end;
    padding: 0 24px;
}

.noesis-message.user .noesis-message-content {
    background: #2d2d2d;
    color: #f0f0f0;
    padding: 16px 20px;
    border-radius: 20px 20px 4px 20px;
    max-width: 80%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Messaggi Noesis - fullscreen stile ChatGPT con testo più chiaro */
.noesis-message.assistant {
    padding: 32px 24px;
    width: 100%;
}

.noesis-message.assistant .noesis-message-content {
    color: #e0e0e0;
    font-size: 15px;
    line-height: 1.6;
    max-width: none;
    background: transparent;
    word-wrap: break-word;
    letter-spacing: 0.2px;
}

.noesis-message.assistant .noesis-message-content p {
    margin: 0 0 16px 0;
    color: #e0e0e0;
}

.noesis-message.assistant .noesis-message-content p:last-child {
    margin-bottom: 0;
}

/* Streaming text effect */
.noesis-streaming-text {
    position: relative;
}

.noesis-streaming-text::after {
    content: '▊';
    color: #667eea;
    animation: blink 1s infinite;
    margin-left: 2px;
}

/* Voice indicator (per registrazione microfono) */
.noesis-voice-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    color: #f0f0f0;
    font-size: 14px;
    background: #1a1a1a;
    margin-bottom: 16px;
    border-radius: 8px;
}

.noesis-voice-wave {
    display: flex;
    gap: 3px;
    align-items: center;
}

.noesis-wave-bar {
    width: 3px;
    height: 12px;
    background: #667eea;
    border-radius: 2px;
    animation: wave 1.4s ease-in-out infinite;
}

.noesis-wave-bar:nth-child(2) { animation-delay: 0.1s; }
.noesis-wave-bar:nth-child(3) { animation-delay: 0.2s; }
.noesis-wave-bar:nth-child(4) { animation-delay: 0.3s; }
.noesis-wave-bar:nth-child(5) { animation-delay: 0.4s; }

/* ====== ANIMAZIONI ====== */

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

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@keyframes wave {
    0%, 100% { height: 8px; }
    50% { height: 24px; }
}

/* ====== RESPONSIVE DESIGN ====== */
@media (max-width: 768px) {
    .noesis-input-container {
        min-height: 52px;
    }
    
    .noesis-message-input {
        font-size: 16px;
        padding: 14px 16px;
    }
    
    .noesis-chat-header {
        padding: 20px 15px;
        min-height: 180px;
    }
    
    .noesis-orb-container {
        width: 140px;
        height: 140px;
        margin-bottom: 12px;
    }
    
    .noesis-orb-status {
        font-size: 12px;
    }
    
    .noesis-chat-controls {
        top: 10px;
        right: 10px;
    }
    
    .noesis-voice-toggle,
    .noesis-minimize-button {
        padding: 6px;
    }
    
    .noesis-speaker-icon,
    .noesis-minimize-icon {
        width: 14px;
        height: 14px;
    }
    
    .noesis-message.user {
        padding: 0 16px;
    }
    
    .noesis-message.user .noesis-message-content {
        max-width: 85%;
        font-size: 14px;
        padding: 12px 16px;
    }
    
    .noesis-message.assistant {
        padding: 20px 16px;
    }
    
    .noesis-message.assistant .noesis-message-content {
        font-size: 14px;
        line-height: 1.5;
    }
    
    .noesis-expanded-state.active {
        max-height: 85vh;
    }
    
    .noesis-messages-container {
        max-height: calc(85vh - 140px);
    }
}

@media (max-width: 480px) {
    .noesis-orb-container {
        width: 120px;
        height: 120px;
    }
    
    .noesis-message.user .noesis-message-content {
        max-width: 90%;
    }
    
    .noesis-send-icon,
    .noesis-mic-icon {
        width: 18px;
        height: 18px;
    }
}

/* Nascondi elementi vocali quando voice è disabilitato */
.noesis-chat-container[data-voice="false"] .noesis-voice-button,
.noesis-chat-container[data-voice="false"] .noesis-expanded-voice-button,
.noesis-chat-container[data-voice="false"] .noesis-voice-toggle,
.noesis-chat-container[data-voice="false"] .noesis-voice-indicator {
    display: none !important;
}

/* ====== COMPATIBILITÀ DIVI ====== */
.et_pb_module .noesis-chat-container {
    font-family: inherit;
}

.et_pb_code .noesis-chat-container {
    margin: 0;
}

.et_pb_code .noesis-chat-container * {
    color: inherit;
    font-family: inherit;
}

.et_pb_code .noesis-message-input,
.et_pb_code .noesis-message-textarea {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif !important;
}

/* ====== DEBUG PANEL (solo in sviluppo) ====== */
.noesis-debug-panel {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid #333;
    border-radius: 8px;
    padding: 16px;
    color: white;
    font-size: 12px;
    z-index: 10000;
    max-width: 300px;
}

.noesis-debug-info {
    margin: 8px 0;
    font-family: monospace;
    font-size: 11px;
    line-height: 1.4;
}

.noesis-test-tts {
    background: #667eea;
    border: none;
    border-radius: 4px;
    color: white;
    padding: 6px 12px;
    font-size: 11px;
    cursor: pointer;
    margin-top: 8px;
}

/* ====== ACCESSIBILITÀ ====== */
@media (prefers-reduced-motion: reduce) {
    .noesis-chat-container,
    .noesis-expanded-state,
    .noesis-message,
    .noesis-send-button,
    .noesis-voice-button {
        transition: none;
        animation: none;
    }
    
    .noesis-streaming-text::after {
        animation: none;
    }
    
    .noesis-wave-bar {
        animation: none;
    }
    
    .noesis-chat-header::before {
        animation: none !important;
    }
}

/* Focus per accessibilità */
.noesis-send-button:focus,
.noesis-voice-button:focus,
.noesis-voice-toggle:focus,
.noesis-minimize-button:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .noesis-input-container {
        border-bottom-color: #ffffff;
        border-width: 3px;
    }
    
    .noesis-message.user .noesis-message-content {
        background: #ffffff;
        color: #000000;
        border: 2px solid #000000;
    }
    
    .noesis-message.assistant {
        background: #000000;
        border-bottom: 3px solid #ffffff;
    }
}