/**
 * AI Chat Widget - עיצוב הצ'אט
 */

/* ==========================================
   CSS Variables & Base Styles
   ========================================== */
:root {
    --ai-chat-primary: #0073aa;
    --ai-chat-primary-hover: #005a87;
    --ai-chat-primary-light: #e6f3fa;
    --ai-chat-bg: #ffffff;
    --ai-chat-bg-secondary: #f8f9fa;
    --ai-chat-text: #1e1e1e;
    --ai-chat-text-secondary: #666666;
    --ai-chat-border: #e0e0e0;
    --ai-chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --ai-chat-radius: 16px;
    --ai-chat-radius-sm: 8px;
    --ai-chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================
   Widget Container
   ========================================== */
.ai-chat-widget {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    direction: rtl;
}

/* LTR Support for English */
.ai-chat-widget.ai-chat-lang-en {
    direction: ltr;
}

.ai-chat-widget.ai-chat-lang-en .ai-chat-send-btn svg {
    transform: rotate(0deg);
}

.ai-chat-widget.ai-chat-lang-en .ai-chat-message-user {
    align-self: flex-end;
}

.ai-chat-widget.ai-chat-lang-en .ai-chat-message-bot {
    align-self: flex-start;
}

.ai-chat-widget.ai-chat-lang-en .ai-chat-message-user .ai-chat-message-bubble {
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 18px;
}

.ai-chat-widget.ai-chat-lang-en .ai-chat-message-bot .ai-chat-message-bubble {
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 18px;
}

.ai-chat-widget.ai-chat-lang-en .ai-chat-message-user .ai-chat-message-time {
    text-align: left;
}

.ai-chat-widget.ai-chat-lang-en .ai-chat-message-bot .ai-chat-message-time {
    text-align: right;
}

.ai-chat-position-right {
    right: 20px;
}

.ai-chat-position-left {
    left: 20px;
}

/* ==========================================
   Toggle Button
   ========================================== */
.ai-chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-primary-hover) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 115, 170, 0.4);
    transition: var(--ai-chat-transition);
    position: relative;
    overflow: hidden;
}

.ai-chat-toggle-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 100%);
    border-radius: 50%;
}

.ai-chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(0, 115, 170, 0.5);
}

.ai-chat-toggle-btn:active {
    transform: scale(0.95);
}

.ai-chat-toggle-icon {
    width: 28px;
    height: 28px;
    color: #fff;
    transition: var(--ai-chat-transition);
    position: absolute;
}

.ai-chat-toggle-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.ai-chat-toggle-icon svg {
    width: 100%;
    height: 100%;
}

.ai-chat-icon-chat {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.ai-chat-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

/* Hide toggle button when chat is open */
.ai-chat-widget.is-open .ai-chat-toggle-btn {
    display: none;
}

.ai-chat-widget.is-open .ai-chat-icon-chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.ai-chat-widget.is-open .ai-chat-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Notification Badge */
.ai-chat-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 22px;
    height: 22px;
    background: #ff4757;
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ai-chat-pulse 2s infinite;
}

@keyframes ai-chat-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.6);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 71, 87, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 71, 87, 0);
    }
}

/* ==========================================
   Chat Window - CRITICAL: Hidden by default
   ========================================== */
.ai-chat-window {
    position: absolute;
    bottom: 80px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: var(--ai-chat-bg);
    border-radius: var(--ai-chat-radius);
    box-shadow: var(--ai-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* CRITICAL: Start hidden */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: var(--ai-chat-transition);
}

.ai-chat-position-right .ai-chat-window {
    right: 0;
}

.ai-chat-position-left .ai-chat-window {
    left: 0;
}

/* Show window when widget is open */
.ai-chat-widget.is-open .ai-chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ==========================================
   Chat Header
   ========================================== */
.ai-chat-header {
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-primary-hover) 100%);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat-header-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.ai-chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-header-avatar svg {
    width: 24px;
    height: 24px;
    fill: #fff;
}

.ai-chat-header-text {
    display: flex;
    flex-direction: column;
}

.ai-chat-header-title {
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-header-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-chat-status-dot {
    width: 8px;
    height: 8px;
    background: #2ed573;
    border-radius: 50%;
    animation: ai-chat-status-pulse 2s infinite;
}

@keyframes ai-chat-status-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.ai-chat-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--ai-chat-transition);
}

.ai-chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-close-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ==========================================
   Messages Area
   ========================================== */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--ai-chat-bg-secondary);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: var(--ai-chat-border);
    border-radius: 3px;
}

/* Message Bubbles */
.ai-chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: ai-chat-message-in 0.3s ease-out;
}

@keyframes ai-chat-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#ai-chat-widget .ai-chat-message-user {
    align-self: flex-end !important;
}

#ai-chat-widget .ai-chat-message-bot {
    align-self: flex-start !important;
}

#ai-chat-widget .ai-chat-message-bubble {
    padding: 12px 16px !important;
    border-radius: 18px !important;
    word-wrap: break-word !important;
    position: relative !important;
    display: block !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    border: none !important;
}

#ai-chat-widget .ai-chat-message-user .ai-chat-message-bubble {
    background: var(--ai-chat-primary) !important;
    color: #fff !important;
    border-bottom-right-radius: 4px !important;
}

#ai-chat-widget .ai-chat-message-bot .ai-chat-message-bubble {
    background: #ffffff !important;
    color: var(--ai-chat-text) !important;
    border-bottom-left-radius: 4px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}

#ai-chat-widget .ai-chat-message-time {
    font-size: 11px;
    color: var(--ai-chat-text-secondary);
    margin-top: 4px;
    padding: 0 4px;
}

.ai-chat-message-user .ai-chat-message-time {
    text-align: right;
}

.ai-chat-message-bot .ai-chat-message-time {
    text-align: left;
}

/* ==========================================
   Typing Indicator
   ========================================== */
.ai-chat-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    background: var(--ai-chat-bg);
    border-radius: 18px;
    width: fit-content;
    margin-bottom: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ai-chat-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--ai-chat-primary);
    border-radius: 50%;
    animation: ai-chat-typing 1.4s infinite ease-in-out;
}

.ai-chat-typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.ai-chat-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chat-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ai-chat-typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ==========================================
   CTA Section
   ========================================== */
.ai-chat-cta {
    padding: 12px 16px;
    background: var(--ai-chat-primary-light);
    border-top: 1px solid var(--ai-chat-border);
    animation: ai-chat-cta-in 0.4s ease-out;
}

@keyframes ai-chat-cta-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat-cta-text {
    font-size: 13px;
    color: var(--ai-chat-text);
    margin-bottom: 10px;
    text-align: center;
}

.ai-chat-cta-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.ai-chat-cta-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 25px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: var(--ai-chat-transition);
    border: none;
    cursor: pointer;
}

.ai-chat-cta-btn svg {
    width: 16px;
    height: 16px;
}

.ai-chat-cta-phone {
    background: var(--ai-chat-primary);
    color: #fff;
}

.ai-chat-cta-phone:hover {
    background: var(--ai-chat-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 115, 170, 0.3);
}

.ai-chat-cta-whatsapp {
    background: #25D366;
    color: #fff;
}

.ai-chat-cta-whatsapp:hover {
    background: #1da851;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.ai-chat-cta-email {
    background: #ff6b6b;
    color: #fff;
}

.ai-chat-cta-email:hover {
    background: #ee5a5a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

/* ==========================================
   Input Area
   ========================================== */
.ai-chat-input-area {
    padding: 16px;
    background: var(--ai-chat-bg);
    border-top: 1px solid var(--ai-chat-border);
    flex-shrink: 0;
}

.ai-chat-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ai-chat-input {
    flex: 1;
    padding: 12px 18px;
    border: 2px solid var(--ai-chat-border);
    border-radius: 25px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--ai-chat-transition);
    background: var(--ai-chat-bg-secondary);
}

.ai-chat-input:focus {
    border-color: var(--ai-chat-primary);
    background: var(--ai-chat-bg);
}

.ai-chat-input::placeholder {
    color: var(--ai-chat-text-secondary);
}

.ai-chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--ai-chat-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--ai-chat-transition);
    flex-shrink: 0;
}

.ai-chat-send-btn:hover {
    background: var(--ai-chat-primary-hover);
    transform: scale(1.05);
}

.ai-chat-send-btn:active {
    transform: scale(0.95);
}

.ai-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-chat-send-btn svg {
    width: 20px;
    height: 20px;
    fill: #fff;
    transform: rotate(180deg);
}

/* ==========================================
   Animations
   ========================================== */
.ai-chat-bounce {
    animation: ai-chat-bounce 0.6s ease;
}

@keyframes ai-chat-bounce {

    0%,
    20%,
    60%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-10px);
    }

    80% {
        transform: translateY(-5px);
    }
}

.ai-chat-shake {
    animation: ai-chat-shake 0.5s ease;
}

@keyframes ai-chat-shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

/* Welcome animation */
.ai-chat-widget.ai-chat-welcome .ai-chat-toggle-btn {
    animation: ai-chat-welcome 2s ease-in-out;
}

@keyframes ai-chat-welcome {

    0%,
    100% {
        transform: scale(1);
    }

    10% {
        transform: scale(1.1);
    }

    20% {
        transform: scale(1);
    }

    30% {
        transform: scale(1.1);
    }

    40% {
        transform: scale(1);
    }
}

/* ==========================================
   Mobile Responsiveness
   ========================================== */
@media (max-width: 480px) {
    .ai-chat-widget {
        bottom: 10px;
        right: 10px !important;
        left: auto !important;
    }

    .ai-chat-toggle-btn {
        width: 56px;
        height: 56px;
    }

    /* When open on mobile: fullscreen chat */
    .ai-chat-widget.is-open {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100%;
        height: auto;
        z-index: 2147483647;
    }

    .ai-chat-widget.is-open .ai-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        transform: none;
    }

    .ai-chat-header {
        padding: 12px 16px;
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    .ai-chat-input-area {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}