/* ══════════════════════════════════════════════════════
   PRO IPTV - Site Chat Widget
   Full-screen WhatsApp-like chat UI, dark theme
   ══════════════════════════════════════════════════════ */

/* Chat Toggle Button */
#efendi-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #f97316, #ea580c);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 24px rgba(249, 115, 22, 0.4);
    transition: all 0.3s ease;
}
#efendi-chat-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 32px rgba(249, 115, 22, 0.6);
}
#efendi-chat-btn i {
    color: #fff;
    font-size: 28px;
    transition: transform 0.3s;
}
#efendi-chat-btn:not(.open) i.fa-times { display: none; }

/* CRITICAL: Hide toggle button completely when chat is open */
#efendi-chat-btn.open,
#efendi-chat-btn.open i.fa-comments {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* Unread badge */
#efendi-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
}
#efendi-chat-badge.show { display: flex; }

/* Pulse animation for unread */
@keyframes efChatPulse {
    0% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(249, 115, 22, 0); }
    100% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0); }
}
#efendi-chat-btn.has-unread { animation: efChatPulse 2s infinite; }

/* ── Chat Container - Full Screen Overlay ── */
#efendi-chat-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', 'Poppins', system-ui, sans-serif;
}
#efendi-chat-container.open {
    display: flex;
    animation: efChatFadeIn 0.3s ease;
}
@keyframes efChatFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── Chat Window (centered card) ── */
.efendi-chat-window {
    width: 90vw;
    max-width: 900px;
    height: 85vh;
    max-height: 700px;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    animation: efChatSlideUp 0.3s ease;
}
@keyframes efChatSlideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Chat Header ── */
.efendi-chat-header {
    background: linear-gradient(135deg, #f97316, #ea580c);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.efendi-chat-header-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.efendi-chat-header-avatar i { color: #fff; font-size: 18px; }
.efendi-chat-header-info { flex: 1; min-width: 0; }
.efendi-chat-header-name {
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.efendi-chat-header-status {
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.efendi-chat-header-status .dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
}
.efendi-chat-close {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.efendi-chat-close:hover { background: rgba(255, 255, 255, 0.25); }

/* ── Pre-chat Form ── */
.efendi-prechat {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 40px;
    gap: 18px;
    max-width: 440px;
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
}
.efendi-prechat h3 {
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    margin: 0;
}
.efendi-prechat p {
    color: #94a3b8;
    font-size: 14px;
    text-align: center;
    margin: 0;
    line-height: 1.6;
}
.efendi-prechat-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.efendi-prechat-field label {
    color: #94a3b8;
    font-size: 13px;
    font-weight: 500;
}
.efendi-prechat-field input {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    color: #e2e8f0;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}
.efendi-prechat-field input:focus {
    border-color: #f97316;
}
.efendi-prechat-field input::placeholder { color: #475569; }
.efendi-prechat-btn {
    background: linear-gradient(135deg, #f97316, #ea580c);
    border: none;
    border-radius: 12px;
    padding: 14px;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 6px;
}
.efendi-prechat-btn:hover { opacity: 0.9; transform: scale(1.01); }
.efendi-prechat-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.efendi-prechat-error {
    color: #f87171;
    font-size: 13px;
    text-align: center;
}

/* ── Messages Area ── */
.efendi-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #0f172a;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}
.efendi-chat-messages::-webkit-scrollbar { width: 5px; }
.efendi-chat-messages::-webkit-scrollbar-track { background: transparent; }
.efendi-chat-messages::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

/* ── Message Bubbles ── */
.efendi-msg {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
}
.efendi-msg-user {
    align-self: flex-end;
    background: #f97316;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.efendi-msg-bot {
    align-self: flex-start;
    background: #1e293b;
    color: #e2e8f0;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}
.efendi-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 3px;
    text-align: right;
    user-select: none;
    -webkit-user-select: none;
}
.efendi-msg-image img {
    max-width: 100%;
    max-height: 250px;
    border-radius: 10px;
    cursor: pointer;
    display: block;
}
.efendi-msg-file a {
    color: #f97316;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Clickable links in messages */
.efendi-msg a {
    color: #60a5fa;
    text-decoration: underline;
    word-break: break-all;
}
.efendi-msg-user a {
    color: #fff;
    text-decoration: underline;
    opacity: 0.9;
}

/* Copyable badge (`text` in messages) */
.efendi-copy-badge {
    display: inline-block;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    margin: 1px 0;
    position: relative;
    transition: background 0.2s;
}
.efendi-copy-badge:hover {
    background: rgba(255, 255, 255, 0.18);
}
.efendi-copy-badge:active {
    transform: scale(0.96);
}
.efendi-msg-user .efendi-copy-badge {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}
.efendi-copy-badge.copied::after {
    content: 'Kopyalandi!';
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: #22c55e;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    animation: efCopyFade 1.2s ease forwards;
}
@keyframes efCopyFade {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; }
}

/* Welcome message */
.efendi-msg-welcome {
    align-self: center;
    background: rgba(249, 115, 22, 0.1);
    border: 1px solid rgba(249, 115, 22, 0.2);
    color: #f97316;
    font-size: 13px;
    text-align: center;
    border-radius: 14px;
    padding: 8px 16px;
    max-width: 90%;
}

/* ── Typing Indicator ── */
.efendi-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: #1e293b;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    margin: 0 0 4px;
}
.efendi-typing.show { display: flex; gap: 5px; align-items: center; }
.efendi-typing span {
    width: 7px;
    height: 7px;
    background: #64748b;
    border-radius: 50%;
    animation: efTypingBounce 1.4s infinite;
}
.efendi-typing span:nth-child(2) { animation-delay: 0.2s; }
.efendi-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes efTypingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-7px); }
}

/* ── Input Area ── */
.efendi-chat-input {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: #1e293b;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}
.efendi-chat-input textarea {
    flex: 1;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 22px;
    padding: 10px 16px;
    color: #e2e8f0;
    font-size: 16px;
    resize: none;
    max-height: 100px;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    -webkit-appearance: none;
}
.efendi-chat-input textarea:focus { border-color: #f97316; }
.efendi-chat-input textarea::placeholder { color: #475569; }

/* Attach button */
.efendi-chat-attach {
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 16px;
}
.efendi-chat-attach:hover { color: #f97316; background: rgba(249, 115, 22, 0.1); }

/* Send button */
.efendi-chat-send {
    width: 40px;
    height: 40px;
    background: #f97316;
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 15px;
}
.efendi-chat-send:hover { background: #ea580c; }
.efendi-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Connection Status ── */
.efendi-chat-offline {
    padding: 6px 12px;
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    font-size: 12px;
    text-align: center;
    display: none;
    flex-shrink: 0;
}
.efendi-chat-offline.show { display: block; }

/* ── Paste preview ── */
.efendi-paste-preview {
    padding: 8px 12px;
    background: #1a2332;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.efendi-paste-preview img {
    max-width: 60px;
    max-height: 50px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.efendi-paste-preview .paste-info {
    flex: 1;
    color: #94a3b8;
    font-size: 12px;
}
.efendi-paste-preview button {
    background: none;
    border: none;
    color: #f87171;
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
}

/* ══════════════════════════════════════════════════════
   Mobile Responsive
   ══════════════════════════════════════════════════════ */
@media (max-width: 640px) {
    /* Container: solid bg, no blur, full screen */
    #efendi-chat-container {
        background: #0f172a;
        backdrop-filter: none;
    }
    #efendi-chat-container.open {
        animation: none;
    }

    /* Window: fill the entire visible viewport */
    .efendi-chat-window {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
        border: none;
        box-shadow: none;
        animation: none;
    }

    /* Header with top safe area for notch phones */
    .efendi-chat-header {
        padding: 12px 14px;
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
        gap: 10px;
    }
    .efendi-chat-header-avatar {
        width: 34px;
        height: 34px;
    }
    .efendi-chat-header-avatar i { font-size: 15px; }
    .efendi-chat-header-name { font-size: 14px; }
    .efendi-chat-header-status { font-size: 11px; }
    .efendi-chat-close {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    /* Messages */
    .efendi-chat-messages {
        padding: 12px;
        gap: 6px;
    }
    .efendi-msg {
        max-width: 85%;
        font-size: 14px;
        padding: 9px 12px;
    }
    .efendi-msg-welcome {
        font-size: 12px;
        padding: 6px 12px;
    }

    /* Input area with bottom safe area */
    .efendi-chat-input {
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        gap: 6px;
    }
    .efendi-chat-input textarea {
        padding: 9px 14px;
        font-size: 16px;
        border-radius: 20px;
    }
    .efendi-chat-attach {
        width: 36px;
        height: 36px;
        font-size: 15px;
    }
    .efendi-chat-send {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    /* Toggle button */
    #efendi-chat-btn {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    #efendi-chat-btn i { font-size: 24px; }

    /* Pre-chat form */
    .efendi-prechat {
        padding: 20px 16px;
        padding-top: 32px;
        gap: 14px;
        justify-content: flex-start;
    }
    .efendi-prechat h3 { font-size: 18px; }
    .efendi-prechat p { font-size: 13px; }
    .efendi-prechat-field input {
        padding: 11px 14px;
        font-size: 16px;
    }
    .efendi-prechat-btn {
        padding: 13px;
        font-size: 14px;
    }

    /* Paste preview */
    .efendi-paste-preview { padding: 6px 10px; }
    .efendi-paste-preview img { max-width: 50px; max-height: 40px; }

    /* Typing */
    .efendi-typing { padding: 8px 12px; }
    .efendi-typing span { width: 6px; height: 6px; }
}

/* Extra small screens */
@media (max-width: 380px) {
    .efendi-chat-header { padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); gap: 8px; }
    .efendi-chat-header-avatar { width: 30px; height: 30px; }
    .efendi-chat-header-avatar i { font-size: 13px; }
    .efendi-chat-header-name { font-size: 13px; }
    .efendi-chat-close { width: 28px; height: 28px; font-size: 12px; }
    .efendi-msg { max-width: 88%; font-size: 13px; }
    .efendi-prechat { padding: 16px 12px; padding-top: 24px; }
}

/* ── Print ── */
@media print {
    #efendi-chat-btn,
    #efendi-chat-container { display: none !important; }
}
