/* ═══════════════════════════════════════════════════
   IPTV Chat Widget - Modern WhatsApp-style
   ═══════════════════════════════════════════════════ */

/* ─── CSS Variables (overridden by JS with admin settings) ─── */
.iptv-chat-widget {
    --chat-color: #6366f1;
    --chat-color-hover: #4f46e5;
    --chat-color-light: rgba(99, 102, 241, 0.08);
    --chat-radius: 16px;
    --chat-font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --chat-shadow: 0 8px 32px rgba(0,0,0,0.12);
    --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    position: fixed;
    z-index: 999999;
    font-family: var(--chat-font);
    line-height: 1.5;
    box-sizing: border-box;
}

.iptv-chat-widget *,
.iptv-chat-widget *::before,
.iptv-chat-widget *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Position */
.iptv-chat-widget[data-position="bottom-right"] {
    bottom: 24px;
    right: 24px;
}

.iptv-chat-widget[data-position="bottom-left"] {
    bottom: 24px;
    left: 24px;
}

/* ─── Toggle Button ─── */
.iptv-chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chat-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 2px 6px rgba(0,0,0,0.1);
    transition: var(--chat-transition);
    position: relative;
    color: #fff;
    outline: none;
}

.iptv-chat-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}

.iptv-chat-toggle-btn:active {
    transform: scale(0.95);
}

.iptv-chat-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
}

.iptv-chat-toggle-close {
    display: none;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
}

.iptv-chat-widget.open .iptv-chat-toggle-icon {
    display: none;
}

.iptv-chat-widget.open .iptv-chat-toggle-close {
    display: flex;
}

/* Unread Badge */
.iptv-chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
    line-height: 1.4;
    border: 2px solid #fff;
    animation: iptv-chat-badge-pulse 2s ease-in-out infinite;
}

@keyframes iptv-chat-badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ─── Chat Window ─── */
.iptv-chat-window {
    position: absolute;
    bottom: 72px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: iptv-chat-slide-up 0.3s ease;
    border: 1px solid rgba(0,0,0,0.06);
}

.iptv-chat-widget[data-position="bottom-right"] .iptv-chat-window {
    right: 0;
}

.iptv-chat-widget[data-position="bottom-left"] .iptv-chat-window {
    left: 0;
}

@keyframes iptv-chat-slide-up {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ─── Chat Header ─── */
.iptv-chat-header {
    background: var(--chat-color);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

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

.iptv-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;
    position: relative;
    flex-shrink: 0;
}

.iptv-chat-online-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid var(--chat-color);
}

.iptv-chat-header-text h4 {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    line-height: 1.3;
    color: #fff;
}

.iptv-chat-header-text span {
    font-size: 12px;
    opacity: 0.85;
    display: block;
    margin-top: 1px;
}

.iptv-chat-header-close {
    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;
    transition: background 0.2s;
    flex-shrink: 0;
}

.iptv-chat-header-close:hover {
    background: rgba(255,255,255,0.25);
}

/* ─── Chat Body ─── */
.iptv-chat-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #f0f2f5;
}

.iptv-chat-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── Login Card (Email & OTP) ─── */
.iptv-chat-login-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 24px;
    text-align: center;
    background: #fff;
    position: relative;
}

.iptv-chat-login-icon {
    color: var(--chat-color);
    margin-bottom: 16px;
    opacity: 0.8;
}

.iptv-chat-login-card h3 {
    font-size: 18px;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 6px;
}

.iptv-chat-login-card p {
    font-size: 13px;
    color: #64748b;
    margin: 0 0 20px;
    line-height: 1.5;
}

.iptv-chat-login-card p strong {
    color: var(--chat-color);
}

.iptv-chat-back-btn {
    position: absolute;
    top: 16px;
    left: 16px;
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 8px;
    transition: all 0.2s;
}

.iptv-chat-back-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

/* Input Group */
.iptv-chat-input-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.iptv-chat-input-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: var(--chat-font);
    color: #0f172a;
    background: #fff;
}

.iptv-chat-input-group input:focus {
    border-color: var(--chat-color);
    box-shadow: 0 0 0 3px var(--chat-color-light);
}

.iptv-chat-input-group input::placeholder {
    color: #94a3b8;
}

/* Primary Button */
.iptv-chat-btn-primary {
    width: 100%;
    padding: 12px 20px;
    background: var(--chat-color);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chat-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--chat-font);
}

.iptv-chat-btn-primary:hover {
    background: var(--chat-color-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.iptv-chat-btn-primary:active {
    transform: translateY(0);
}

.iptv-chat-btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.iptv-chat-btn-primary.loading span::after {
    content: '...';
    animation: iptv-chat-dots 1.5s steps(4, end) infinite;
}

@keyframes iptv-chat-dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

/* Hint / Error */
.iptv-chat-hint {
    font-size: 12px;
    color: #ef4444;
    margin-top: 8px;
}

.iptv-chat-hint.success {
    color: #10b981;
}

.iptv-chat-resend {
    font-size: 12px;
    color: #64748b;
    margin-top: 12px;
}

.iptv-chat-resend a {
    color: var(--chat-color);
    text-decoration: none;
    font-weight: 600;
}

.iptv-chat-resend a:hover {
    text-decoration: underline;
}

/* ─── OTP Inputs ─── */
.iptv-chat-otp-inputs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}

.iptv-chat-otp-digit {
    width: 44px;
    height: 52px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: var(--chat-font);
    background: #fff;
}

.iptv-chat-otp-digit:focus {
    border-color: var(--chat-color);
    box-shadow: 0 0 0 3px var(--chat-color-light);
}

/* ─── Messages Screen ─── */
.iptv-chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #f0f2f5;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23e2e8f0' fill-opacity='0.25'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* Message Bubbles */
.iptv-chat-msg-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    animation: iptv-chat-msg-appear 0.2s ease;
}

@keyframes iptv-chat-msg-appear {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.iptv-chat-msg-user-bubble {
    align-self: flex-end;
    background: var(--chat-color);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.iptv-chat-msg-admin-bubble {
    align-self: flex-start;
    background: #fff;
    color: #0f172a;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.iptv-chat-msg-bubble .iptv-chat-msg-time {
    font-size: 10px;
    opacity: 0.65;
    margin-top: 4px;
    display: block;
}

.iptv-chat-msg-user-bubble .iptv-chat-msg-time {
    text-align: right;
    color: rgba(255,255,255,0.8);
}

.iptv-chat-msg-admin-bubble .iptv-chat-msg-time {
    color: #94a3b8;
}

/* Date Separator */
.iptv-chat-date-divider {
    text-align: center;
    margin: 12px 0;
}

.iptv-chat-date-divider span {
    background: rgba(0,0,0,0.06);
    color: #64748b;
    font-size: 11px;
    padding: 3px 12px;
    border-radius: 8px;
    font-weight: 500;
}

/* Typing indicator */
.iptv-chat-typing {
    align-self: flex-start;
    background: #fff;
    padding: 12px 16px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    display: flex;
    gap: 4px;
}

.iptv-chat-typing-dot {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: iptv-chat-typing-bounce 1.4s ease-in-out infinite;
}

.iptv-chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.iptv-chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes iptv-chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ─── Message Input Area ─── */
.iptv-chat-input-area {
    padding: 10px 14px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.iptv-chat-message-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 6px 8px 6px 16px;
}

.iptv-chat-message-input-wrap textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 14px;
    line-height: 1.5;
    max-height: 100px;
    background: transparent;
    font-family: var(--chat-font);
    padding: 6px 0;
    color: #0f172a;
}

.iptv-chat-message-input-wrap textarea::placeholder {
    color: #94a3b8;
}

.iptv-chat-send-msg-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--chat-color);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--chat-transition);
}

.iptv-chat-send-msg-btn:hover {
    background: var(--chat-color-hover);
    transform: scale(1.05);
}

.iptv-chat-send-msg-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ─── Responsive ─── */
@media (max-width: 480px) {
    .iptv-chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 100px);
        bottom: 68px;
        border-radius: 12px;
    }

    .iptv-chat-widget[data-position="bottom-right"] {
        right: 8px;
        bottom: 16px;
    }

    .iptv-chat-widget[data-position="bottom-left"] {
        left: 8px;
        bottom: 16px;
    }

    .iptv-chat-widget[data-position="bottom-right"] .iptv-chat-window,
    .iptv-chat-widget[data-position="bottom-left"] .iptv-chat-window {
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }

    .iptv-chat-toggle-btn {
        width: 54px;
        height: 54px;
    }

    .iptv-chat-otp-digit {
        width: 38px;
        height: 46px;
        font-size: 18px;
    }
}
