/* =========================================================
   Matrix Ultra PRO - Unified Production CSS
   ========================================================= */

:root {
    --matrix-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --matrix-transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    --matrix-radius: 16px;
    --matrix-zindex: 999999;
}

/* =======================================
   1. כפתור ההפעלה (Trigger) והבועה
   ======================================= */
#matrix-trigger-wrap {
    position: fixed;
    bottom: var(--mx-btn-bottom, 110px);
    right: var(--mx-btn-right, 30px);
    z-index: var(--matrix-zindex);
    display: flex;
    align-items: center;
    flex-direction: row-reverse;
    gap: 12px;
    transition: var(--matrix-transition);
}

.matrix-trigger-text {
    background: var(--mx-trigger-text-bg, #fff);
    color: var(--mx-trigger-text-color, #2d3748);
    padding: 10px 18px;
    border-radius: 20px;
    font-family: var(--matrix-font);
    font-size: var(--mx-trigger-text-size, 14px);
    font-weight: 800;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    border: 1px solid rgba(0,0,0,0.05);
    white-space: nowrap;
    display: flex; 
    align-items: center;
    justify-content: center;
    height: fit-content;
    line-height: 1.2;
    box-sizing: border-box;
    animation: mxBounceIn 0.6s ease;
}

#matrix-trigger {
    width: var(--mx-trigger-size, 64px);
    height: var(--mx-trigger-size, 64px);
    border-radius: 50%;
    /* שימוש בצבע העיצוב הדינמי */
    background: var(--matrix-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--matrix-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--matrix-transition);
    position: relative;
    padding: 0;
    overflow: hidden;
}

#matrix-trigger img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border-radius: 50% !important;
    display: block !important;
    aspect-ratio: 1/1 !important;
}

#matrix-trigger:hover {
    transform: scale(1.08);
}

.matrix-trigger-online-badge {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #10b981; /* נשאר ירוק לאותת "מחובר" */
    border: 2px solid #fff;
    border-radius: 50%;
    z-index: 2;
    animation: mxPulseBadge 2s infinite;
}

/* הילה (Pulse) מסונכרנת לעיצוב */
@keyframes mxPulseBadge {
    0% { box-shadow: 0 0 0 0 var(--matrix-pulse); }
    70% { box-shadow: 0 0 0 6px rgba(0,0,0,0); }
    100% { box-shadow: 0 0 0 0 rgba(0,0,0,0); }
}

/* =======================================
   2. חלון הצ'אט הראשי
   ======================================= */
#matrix-window {
    position: fixed;
    bottom: calc(var(--mx-btn-bottom, 110px) + var(--mx-trigger-size, 64px) + 20px);
    right: var(--mx-btn-right, 30px);
    width: 380px;
    height: 600px;
    max-height: 80vh;
    background: var(--matrix-chat-bg);
    border: 1px solid var(--matrix-border);
    border-radius: var(--matrix-radius);
    box-shadow: var(--matrix-shadow);
    z-index: var(--matrix-zindex);
    display: flex;
    flex-direction: column;
    font-family: var(--matrix-font);
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: var(--matrix-transition);
    direction: rtl;
}

#matrix-window.matrix-chat-active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* =======================================
   3. כותרת ותפריט עליון
   ======================================= */
#matrix-header {
    background: var(--matrix-primary);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    border-top-left-radius: var(--matrix-radius);
    border-top-right-radius: var(--matrix-radius);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 10;
}

.matrix-header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.matrix-avatar-img {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    flex-shrink: 0 !important; 
    border-radius: 50% !important;
    object-fit: cover !important;
    border: 2px solid rgba(255,255,255,0.3) !important;
    display: block !important;
    aspect-ratio: 1/1 !important;
}

.matrix-avatar-fallback {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    flex-shrink: 0 !important;
    border-radius: 50% !important;
    background: rgba(255,255,255,0.2) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: 900 !important;
    font-size: 18px !important;
    border: 2px solid rgba(255,255,255,0.3) !important;
    aspect-ratio: 1/1 !important;
}

.matrix-header-text-wrap {
    display: flex;
    flex-direction: column;
}

.matrix-bot-name {
    font-weight: 800;
    font-size: 16px;
    line-height: 1.1;
}

.matrix-status {
    font-size: 11px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}

.matrix-online-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    display: inline-block;
}

.matrix-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mx-header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: var(--matrix-transition);
}

.mx-header-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.1);
}

/* =======================================
   4. סרגל כלים חכם (מצלמה, שיחה חיה)
   ======================================= */
.mx-smart-toolbar {
    background: #fff;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding: 8px 15px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

.mx-tool-btn {
    flex: 1;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    padding: 8px;
    border-radius: 8px;
    color: #4a5568;
    font-size: 12px;
    font-weight: 800;
    font-family: var(--matrix-font);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--matrix-transition);
}

.mx-tool-btn:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
    color: var(--matrix-primary);
}

/* =======================================
   5. אזור ההודעות (Logs) והבועות
   ======================================= */
#matrix-logs {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
}

#matrix-logs::-webkit-scrollbar {
    width: 6px;
}
#matrix-logs::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 10px;
}

.log-user {
    align-self: flex-start;
    background: var(--matrix-user-bg);
    color: var(--matrix-user-text);
    padding: 12px 16px;
    border-radius: 16px 16px 0 16px;
    max-width: 85%;
    font-size: 14px;
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    animation: mxFadeInUp 0.3s ease;
}

.log-ai {
    align-self: flex-end;
    background: var(--matrix-bot-bg);
    color: var(--matrix-bot-text);
    padding: 14px 18px;
    border-radius: 16px 16px 16px 0;
    max-width: 88%;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.02);
    animation: mxFadeInUp 0.3s ease;
}

.matrix-welcome-card {
    align-self: center;
    max-width: 100%;
    width: 100%;
    text-align: center;
    background: #fff;
    padding: 20px;
}

.matrix-welcome-card h3 {
    margin: 0 0 10px 0;
    color: var(--matrix-primary);
    font-size: 18px;
}

.matrix-welcome-card p {
    margin: 0 0 20px 0;
    font-size: 14px;
    color: #4a5568;
}

.matrix-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.matrix-qr-btn {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    color: var(--matrix-primary);
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    font-family: inherit;
    transition: var(--matrix-transition);
}

.matrix-qr-btn:hover {
    background: var(--matrix-primary);
    color: #fff;
    border-color: var(--matrix-primary);
}

/* =======================================
   6. אזור ההקלדה והמיקרופון (Input Wrap)
   ======================================= */
#matrix-input-wrap {
    padding: 15px;
    background: #fff;
    border-top: 1px solid rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 5;
}

#matrix-input {
    flex: 1;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    padding: 12px 15px;
    border-radius: 25px;
    font-family: var(--matrix-font);
    font-size: 14px;
    outline: none;
    transition: var(--matrix-transition);
}

#matrix-input:focus {
    background: #fff;
    border-color: var(--matrix-primary);
    box-shadow: 0 0 0 3px rgba(255, 106, 0, 0.1);
}

.matrix-send-btn {
    background: var(--matrix-primary);
    color: #fff;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: var(--matrix-transition);
}

.matrix-send-btn:hover {
    transform: translateX(-3px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.matrix-mic-btn {
    background: #edf2f7;
    color: #2d3748;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: var(--matrix-transition);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}

.matrix-mic-btn.recording {
    background: #e53e3e;
    color: #fff;
    animation: mxPulseRecord 1.5s infinite;
}

/* =======================================
   7. אנימציות רכיבים וקול
   ======================================= */
@keyframes mxBounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes mxFadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes mxPulseRecord {
    0% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.7); transform: scale(1); }
    50% { box-shadow: 0 0 0 10px rgba(229, 62, 62, 0); transform: scale(1.1); }
    100% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0); transform: scale(1); }
}

.mx-avatar-speaking {
    animation: mxSpeaking 1s infinite alternate;
    border-color: var(--matrix-primary) !important;
}
@keyframes mxSpeaking {
    from { box-shadow: 0 0 0 0 var(--matrix-primary); }
    to { box-shadow: 0 0 0 6px var(--matrix-pulse); }
}

/* =======================================
   8. ויזואליזציה של סאונד (Siri Waves)
   ======================================= */
#mx-ai-visualizer {
    background: #111;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border-bottom: 1px solid #333;
}

.mx-vis-text {
    color: #a0aec0;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1px;
}

.mx-vis-waves {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 20px;
}

.mx-siri-wave {
    width: 4px;
    background: var(--matrix-primary);
    border-radius: 4px;
    animation: mxWaveAnim 1.2s infinite ease-in-out;
}
.mx-siri-wave:nth-child(1) { height: 8px; animation-delay: -1.2s; }
.mx-siri-wave:nth-child(2) { height: 16px; animation-delay: -1.0s; }
.mx-siri-wave:nth-child(3) { height: 20px; animation-delay: -0.8s; background: var(--matrix-secondary); }
.mx-siri-wave:nth-child(4) { height: 16px; animation-delay: -0.6s; }
.mx-siri-wave:nth-child(5) { height: 8px; animation-delay: -0.4s; }

@keyframes mxWaveAnim {
    0%, 40%, 100% { transform: scaleY(0.4); }
    20% { transform: scaleY(1); }
}

/* =======================================
   9. מסך השיחה החיה (Live Call VAD)
   ======================================= */
#mx-live-call-screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(10, 15, 25, 0.98);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    padding: 20px;
}

.mx-live-header {
    position: absolute;
    top: 20px;
    right: 20px;
}

.mx-live-icon-btn {
    background: rgba(255,255,255,0.1);
    border: none; color: #fff;
    width: 40px; height: 40px;
    border-radius: 50%; font-size: 16px;
    cursor: pointer;
}

.mx-live-call-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* בועת השיחה החיה מסונכרנת לעיצוב הראשי! */
.mx-live-orb {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--matrix-primary), var(--matrix-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    box-shadow: 0 0 30px var(--matrix-pulse);
    transition: var(--matrix-transition);
    position: relative;
}

.mx-live-orb img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border-radius: 50% !important;
    display: block !important;
    aspect-ratio: 1/1 !important;
}

.mx-live-orb.listening {
    transform: scale(1.1);
    box-shadow: 0 0 50px rgba(16, 185, 129, 0.6);
    background: linear-gradient(135deg, #10b981, #059669);
}

.mx-live-orb.thinking {
    animation: mxThinkSpin 2s linear infinite;
    box-shadow: 0 0 40px var(--matrix-pulse);
    background: linear-gradient(135deg, var(--matrix-secondary), var(--matrix-primary));
}

.mx-live-orb.speaking {
    animation: mxPulseSpeak 1s infinite alternate;
}

@keyframes mxThinkSpin { 100% { transform: rotate(360deg) scale(1.05); } }
@keyframes mxPulseSpeak { 
    from { box-shadow: 0 0 20px var(--matrix-primary); transform: scale(1); } 
    to { box-shadow: 0 0 60px var(--matrix-primary); transform: scale(1.15); } 
}

.mx-call-status {
    margin-top: 30px;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 1px;
    color: #cbd5e0;
}

.mx-live-transcript {
    margin-top: 20px;
    text-align: center;
    font-size: 16px;
    color: #e2e8f0;
    max-width: 90%;
    line-height: 1.4;
    min-height: 45px;
}

.mx-live-end-action {
    background: #e53e3e;
    color: #fff;
    border: none;
    padding: 15px 40px;
    border-radius: 30px;
    font-size: 18px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(229, 62, 62, 0.3);
    margin-bottom: 20px;
    transition: var(--matrix-transition);
}

.mx-live-end-action:hover {
    background: #c53030;
    transform: translateY(-2px);
}

/* =======================================
   10. רספונסיביות למובייל (Mobile Overrides)
   ======================================= */
@media (max-width: 768px) {
    #matrix-window {
        width: 100%;
        height: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        border: none;
    }

    #matrix-header {
        border-radius: 0;
        padding: 12px 15px;
    }

    #matrix-trigger-wrap {
        bottom: var(--mx-btn-bottom-mob, 20px) !important;
        right: var(--mx-btn-right-mob, 20px) !important;
        transform: none !important; 
        transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s;
    }

    #matrix-window.matrix-chat-active ~ #matrix-trigger-wrap {
        transform: scale(0) !important;
        opacity: 0;
    }

    .log-user, .log-ai {
        max-width: 92%;
        font-size: 15px;
    }

    #matrix-input {
        font-size: 16px; 
    }
}