/* Manegix Premium Chat Widget */
:root {
    --chat-primary: #667eea;
    --chat-primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --chat-bg: #fdfdfd;
    --chat-header-text: #ffffff;
    --chat-agent-bg: #ffffff;
    --chat-agent-text: #2d3748;
    --chat-visitor-bg: #667eea;
    --chat-visitor-text: #ffffff;
    --chat-input-bg: #f7fafc;
    --chat-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
}

/* Widget Container */
#chat-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    gap: 15px;
}

/* Chat Toggle Button */
#chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chat-primary-gradient);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(118, 75, 162, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-size: 24px;
}

#chat-toggle:hover {
    transform: scale(1.1);
}

/* ─── Buton ikonları (tema-bağımsız) ──────────────────────────
   Sorun: ikonlar Font Awesome'a bağımlıydı (<i class="fa-solid fa-comment-dots">
   layout'larda, <i class="fa-brands fa-whatsapp"> chat-widget.js içinde).
   Font Awesome yüklemeyen temalarda (Eremia, Hairy ve Tailwind tabanlı NextSaaS)
   butonlar BOŞ görünüyordu.
   Çözüm: ikon artık CSS'e gömülü SVG mask — currentColor'ı miras alır, hiçbir
   tema varlığına bağımlı değildir ve tüm temalarda aynı görünür. */
#chat-toggle > i,
.whatsapp-toggle > i {
    display: none;
}

#chat-toggle::before,
.whatsapp-toggle::before {
    content: "";
    width: 28px;
    height: 28px;
    background-color: currentColor;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}

/* Sohbet balonu (üç noktalı) */
#chat-toggle::before {
    -webkit-mask-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M4 2a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h2v4l5-4h9a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H4zm4 6.7a1.3 1.3 0 1 0 0 2.6 1.3 1.3 0 0 0 0-2.6zm4 0a1.3 1.3 0 1 0 0 2.6 1.3 1.3 0 0 0 0-2.6zm4 0a1.3 1.3 0 1 0 0 2.6 1.3 1.3 0 0 0 0-2.6z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M4 2a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h2v4l5-4h9a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H4zm4 6.7a1.3 1.3 0 1 0 0 2.6 1.3 1.3 0 0 0 0-2.6zm4 0a1.3 1.3 0 1 0 0 2.6 1.3 1.3 0 0 0 0-2.6zm4 0a1.3 1.3 0 1 0 0 2.6 1.3 1.3 0 0 0 0-2.6z'/%3E%3C/svg%3E");
}

/* WhatsApp */
.whatsapp-toggle::before {
    -webkit-mask-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z'/%3E%3C/svg%3E");
}

/* Chat Panel */
#chat-panel {
    width: 380px;
    height: 600px;
    max-height: 80vh;
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: var(--chat-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: chat-slide-up 0.4s ease-out;
}

#chat-widget.open.show-chat-panel #chat-panel {
    display: flex;
}

#chat-widget.open #chat-toggle {
    display: none !important;
}

@keyframes chat-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.chat-header {
    background: var(--chat-primary-gradient);
    padding: 20px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.chat-title h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-title span {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-title span::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    background: #48bb78;
    border-radius: 50%;
}

.chat-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.chat-close-btn:hover {
    color: white;
}

/* Messages Area */
#chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #fdfdfd;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Scrollbar */
#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

/* Message Bubbles */
.chat-message {
    max-width: 80%;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Animation */
.chat-message {
    animation: message-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes message-pop {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Visitor (Me) */
.chat-message.visitor {
    align-self: flex-end;
    background: var(--chat-primary-gradient);
    color: white;
    border-radius: 18px 18px 2px 18px;
}

/* Agent (Them) */
.chat-message.agent {
    align-self: flex-start;
    background: var(--chat-agent-bg);
    color: var(--chat-agent-text);
    border-radius: 18px 18px 18px 2px;
    border: 1px solid #edf2f7;
}

/* Footer / Input */
.chat-footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #edf2f7;
    display: flex;
    gap: 10px;
    align-items: center;
}

#chat-input {
    flex: 1;
    border: 1px solid #edf2f7;
    background: var(--chat-input-bg);
    padding: 12px 16px;
    border-radius: 24px;
    font-size: 14px;
    transition: all 0.2s;
    outline: none;
}

#chat-input:focus {
    border-color: #a3bffa;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--chat-primary-gradient);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    box-shadow: 0 2px 5px rgba(118, 75, 162, 0.3);
}

#chat-send:hover {
    transform: scale(1.05);
}

#chat-send i {
    font-size: 16px;
    margin-left: -2px;
    /* optical adjustment for plane icon */
}

/* ─── Pre-Chat Form ────────────────────────────────────── */
.chat-prechat-panel {
    width: 380px;
    max-height: 80vh;
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: var(--chat-shadow);
    display: none;
    flex-direction: column;
    align-items: stretch;
    overflow: hidden;
    animation: chat-slide-up 0.4s ease-out;
}

#chat-widget.open.show-pre-chat .chat-prechat-panel {
    display: flex;
}

.chat-prechat-inner {
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-prechat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--chat-primary-gradient);
    margin: -32px -28px 0;
    padding: 20px 24px;
    color: white;
    font-size: 16px;
    font-weight: 600;
}

.chat-prechat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-prechat-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
    padding: 0;
}

.chat-prechat-close-btn:hover {
    color: white;
}

.chat-prechat-header i {
    font-size: 22px;
}

.chat-prechat-desc {
    font-size: 14px;
    color: #4a5568;
    margin: 8px 0 0;
    line-height: 1.5;
}

.chat-prechat-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-prechat-field input {
    border: 1.5px solid #e2e8f0;
    background: #f7fafc;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    font-family: inherit;
}

.chat-prechat-field input:focus {
    border-color: #a3bffa;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-prechat-error {
    font-size: 12px;
    color: #e53e3e;
    margin-top: 2px;
}

.chat-prechat-btn {
    background: var(--chat-primary-gradient);
    color: white;
    border: none;
    padding: 13px 20px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 4px;
}

.chat-prechat-btn:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.chat-prechat-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.chat-prechat-spinner {
    font-size: 14px;
}

/* ─── Responsive Adjustments ────────────────────────────── */
@media (max-width: 480px) {
    #chat-widget {
        bottom: 20px;
        right: 20px;
        left: 20px;
        align-items: flex-end;
    }

    #chat-panel, .chat-prechat-panel {
        width: calc(100vw - 40px) !important;
        height: 600px !important;
        max-height: 80vh !important;
    }

    #chat-toggle, .whatsapp-toggle {
        width: 50px !important;
        height: 50px !important;
        font-size: 20px !important;
    }
}

/* ─── WhatsApp Button ────────────────────────────────────── */
.whatsapp-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(37, 211, 102, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-size: 28px;
    text-decoration: none !important;
}

.whatsapp-toggle:hover {
    transform: scale(1.1);
    color: white;
}

#chat-widget.open .whatsapp-toggle {
    display: none !important;
}