/* Chat Widget */
.chat-panel {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 380px;
    max-height: 500px;
    background: #0a0f1a;
    border: 1px solid rgba(83,140,190,0.3);
    border-radius: 16px;
    overflow: hidden;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    font-family: 'Outfit', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.chat-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* Header */
.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(83,140,190,0.15), rgba(83,140,190,0.05));
    border-bottom: 1px solid rgba(83,140,190,0.2);
}

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

.chat-panel-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: #f9fafb;
    margin: 0;
}

.chat-panel-status {
    font-size: 12px;
    color: #9ca3af;
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-panel-status .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}
.chat-panel-status .dot.online { background: #10b981; }
.chat-panel-status .dot.offline { background: #9ca3af; }

.chat-panel-header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-panel-maximize {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color 0.2s;
    display: flex;
    align-items: center;
}
.chat-panel-maximize:hover { color: #f9fafb; }

.chat-panel-close {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s;
}
.chat-panel-close:hover { color: #f9fafb; }

/* Pre-chat form */
.chat-prechat {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.chat-prechat p {
    font-size: 14px;
    color: #9ca3af;
    margin: 0;
    line-height: 1.5;
}

.chat-prechat input {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(83,140,190,0.2);
    border-radius: 8px;
    color: #f9fafb;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}
.chat-prechat input:focus { border-color: #538cbe; }
.chat-prechat input::placeholder { color: #6b7280; }

.chat-prechat-btn {
    width: 100%;
    padding: 11px;
    background: #538cbe;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-family: inherit;
}
.chat-prechat-btn:hover { background: #7ab0d9; }
.chat-prechat-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Offline form */
.chat-offline {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.chat-offline p {
    font-size: 14px;
    color: #9ca3af;
    margin: 0;
    line-height: 1.5;
}

.chat-offline input,
.chat-offline textarea {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(83,140,190,0.2);
    border-radius: 8px;
    color: #f9fafb;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}
.chat-offline input:focus,
.chat-offline textarea:focus { border-color: #538cbe; }
.chat-offline textarea { resize: none; height: 80px; }
.chat-offline input::placeholder,
.chat-offline textarea::placeholder { color: #6b7280; }

.chat-offline-btn {
    width: 100%;
    padding: 11px;
    background: #538cbe;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-family: inherit;
}
.chat-offline-btn:hover { background: #7ab0d9; }
.chat-offline-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.chat-form-msg {
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 6px;
    display: none;
}
.chat-form-msg.success {
    display: block;
    background: rgba(16,185,129,0.1);
    border: 1px solid rgba(16,185,129,0.3);
    color: #10b981;
}
.chat-form-msg.error {
    display: block;
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.3);
    color: #ef4444;
}

/* Chat body */
#cwBody {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

.chat-msg {
    max-width: 80%;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.chat-msg.visitor {
    align-self: flex-end;
    background: #538cbe;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg.agent {
    align-self: flex-start;
    background: #111827;
    border: 1px solid rgba(255,255,255,0.08);
    color: #f9fafb;
    border-bottom-left-radius: 4px;
}

.chat-msg.system {
    align-self: center;
    background: none;
    color: #9ca3af;
    font-size: 12px;
    font-style: italic;
    padding: 2px 0;
}

.chat-msg-time {
    font-size: 10px;
    margin-top: 3px;
    opacity: 0.6;
}

.chat-msg.visitor .chat-msg-time { color: rgba(255,255,255,0.7); }
.chat-msg.agent .chat-msg-time { color: #9ca3af; }

/* Emoji picker */
.chat-emoji-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 8px 10px;
    border-top: 1px solid rgba(83,140,190,0.15);
    background: rgba(0,0,0,0.3);
    flex-shrink: 0;
}

.chat-emoji-item {
    background: none;
    border: none;
    font-size: 20px;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.chat-emoji-item:hover { background: rgba(255,255,255,0.1); }

.chat-emoji-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
    flex-shrink: 0;
}
.chat-emoji-btn:hover { opacity: 1; }

/* Input area */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid rgba(83,140,190,0.2);
    background: rgba(0,0,0,0.2);
    flex-shrink: 0;
}

.chat-input-area input {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(83,140,190,0.2);
    border-radius: 8px;
    color: #f9fafb;
    padding: 9px 12px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}
.chat-input-area input:focus { border-color: #538cbe; }
.chat-input-area input::placeholder { color: #6b7280; }

.chat-send-btn {
    background: #538cbe;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.chat-send-btn:hover { background: #7ab0d9; }

/* Chat closed state */
.chat-closed-msg {
    text-align: center;
    padding: 20px;
    color: #9ca3af;
    font-size: 13px;
}
.chat-closed-msg p { margin: 0 0 12px; }

.chat-restart-btn {
    background: rgba(83,140,190,0.15);
    color: #7ab0d9;
    border: 1px solid rgba(83,140,190,0.3);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.chat-restart-btn:hover { background: rgba(83,140,190,0.25); }

/* Maximized */
.chat-panel.maximized {
    bottom: 20px;
    right: 20px;
    width: 500px;
    max-height: 80vh;
    height: 80vh;
    border-radius: 16px;
}
/* Responsive */
@media (max-width: 480px) {
    .chat-panel,
    .chat-panel.maximized {
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        width: 100%;
        max-height: none;
        height: 100%;
        border-radius: 0;
    }

    .chat-panel-maximize { display: none; }

    /* Prevent iOS auto-zoom on input focus */
    .chat-prechat input,
    .chat-offline input,
    .chat-offline textarea,
    .chat-input-area input {
        font-size: 16px;
    }
}

/* Body scroll lock when chat fullscreen on mobile */
body.chat-open-mobile {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Hide button + preview when chat fullscreen */
body.chat-open-mobile .chat-widget,
body.chat-open-mobile .chat-preview-bubble,
body.chat-open-mobile .back-to-top {
    display: none !important;
}

/* Links in messages */
.chat-msg a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}
.chat-msg a:hover { opacity: 0.8; }

/* Typing indicator */
.chat-typing {
    font-style: italic;
}

.typing-dots span {
    animation: typingDot 1.4s infinite;
    opacity: 0;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { opacity: 0; }
    30% { opacity: 1; }
}

/* Preview bubble */
.chat-preview-bubble {
    position: fixed;
    bottom: 108px;
    right: 20px;
    max-width: 260px;
    background: #111827;
    border: 1px solid rgba(83,140,190,0.3);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    color: #f9fafb;
    line-height: 1.4;
    cursor: pointer;
    z-index: 9998;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    font-family: 'Outfit', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    animation: bubbleFadeIn 0.3s ease;
    word-break: break-word;
}
.chat-preview-bubble::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 24px;
    width: 12px;
    height: 12px;
    background: #111827;
    border-right: 1px solid rgba(83,140,190,0.3);
    border-bottom: 1px solid rgba(83,140,190,0.3);
    transform: rotate(45deg);
}

@keyframes bubbleFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Powered by */
.chat-powered {
    text-align: center;
    padding: 6px 10px;
    font-size: 11px;
    color: #6b7280;
    border-top: 1px solid rgba(83,140,190,0.1);
    flex-shrink: 0;
}
.chat-powered a {
    color: #7ab0d9;
    text-decoration: none;
    font-weight: 600;
}
.chat-powered a:hover { text-decoration: underline; }

/* Loading */
.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    flex: 1;
}

.chat-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(83,140,190,0.2);
    border-top-color: #538cbe;
    border-radius: 50%;
    animation: chatSpin 0.7s linear infinite;
}

@keyframes chatSpin {
    to { transform: rotate(360deg); }
}

/* Read receipt */
.chat-read-receipt {
    font-size: 10px;
    color: rgba(255,255,255,0.5);
    text-align: right;
    margin-top: 2px;
}

/* Online indicator on widget button */
.chat-widget.agents-online::after {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #10b981;
    border-radius: 50%;
    border: 2.5px solid #030712;
    animation: onlinePulse 2s ease-in-out infinite;
}
@keyframes onlinePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.4); }
    50% { box-shadow: 0 0 0 4px rgba(16,185,129,0); }
}

/* Queue indicator */
.chat-queue-indicator {
    background: rgba(83,140,190,0.1) !important;
    border: 1px solid rgba(83,140,190,0.2);
    border-radius: 8px;
    padding: 8px 12px !important;
    text-align: center;
    font-style: normal !important;
    font-size: 12px !important;
    color: #7ab0d9 !important;
}
