/* Chat Widget Container - uses site :root vars (--ucl-*) */
#modern-chat-widget.chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ucl-ink, #1b1b1f);
}

/* Chat Toggle Button - brand purple */
.chat-widget-container .chat-toggle-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ucl-purple, #5b2b82);
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(91, 43, 130, 0.3);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-widget-container .chat-toggle-button:hover {
    transform: translateY(-2px);
    background: var(--ucl-purple-700, #442065);
    box-shadow: 0 4px 16px rgba(91, 43, 130, 0.4);
}

.chat-widget-container .chat-toggle-button:focus-visible {
    outline: 2px solid var(--ucl-purple, #5b2b82);
    outline-offset: 2px;
}

.chat-widget-container .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    min-width: 22px;
    height: 22px;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    animation: chatBadgePulse 2s ease-in-out infinite;
}

@keyframes chatBadgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* Chat Window - site surface & shadow */
.chat-widget-container .chat-window {
    position: absolute;
    bottom: 68px;
    right: 0;
    width: 360px;
    height: 440px;
    max-height: calc(100vh - 96px);
    background: var(--ucl-surface, #ffffff);
    border-radius: var(--radius, 18px);
    box-shadow: var(--shadow-lg, 0 20px 45px rgba(0, 0, 0, 0.12)), 0 0 0 1px rgba(91, 43, 130, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatWindowSlideUp 0.25s ease;
}

@keyframes chatWindowSlideUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chat Header - brand purple gradient (matches site) */
.chat-widget-container .chat-header {
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--ucl-purple, #5b2b82) 0%, #7c3aed 100%);
    color: white;
    padding: 10px 14px 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.chat-widget-container .chat-title {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.chat-widget-container .chat-title h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.chat-widget-container .agent-status {
    font-size: 11px;
    opacity: 0.92;
    margin: 1px 0 0 0;
}

.chat-widget-container .agent-status.online {
    opacity: 1;
}

.chat-widget-container .agent-status.offline {
    opacity: 0.88;
}

.chat-widget-container .chat-header-actions {
    display: flex;
    gap: 2px;
    align-items: center;
}

.chat-widget-container .chat-minimize-btn,
.chat-widget-container .chat-close-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background-color 0.15s ease;
}

.chat-widget-container .chat-minimize-btn:hover,
.chat-widget-container .chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-widget-container .chat-minimize-btn:focus-visible,
.chat-widget-container .chat-close-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 1px;
}

/* Chat Messages Area - site background tint */
.chat-widget-container .chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 14px 12px;
    background: #faf8ff;
    display: flex;
    flex-direction: column;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
}

.chat-widget-container .chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-widget-container .chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-widget-container .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(91, 43, 130, 0.25);
    border-radius: 3px;
}

.chat-widget-container .chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(91, 43, 130, 0.4);
}

.chat-widget-container .chat-welcome {
    text-align: center;
    padding: 16px 12px;
    margin: auto 0;
}

.chat-widget-container .welcome-message i {
    font-size: 28px;
    color: var(--ucl-purple, #5b2b82);
    margin-bottom: 8px;
    display: block;
    opacity: 0.9;
}

.chat-widget-container .welcome-message h4 {
    margin: 0 0 4px 0;
    color: var(--ucl-ink, #1b1b1f);
    font-size: 14px;
    font-weight: 600;
}

.chat-widget-container .welcome-message p {
    margin: 0;
    color: var(--ucl-slate, #5b616e);
    font-size: 12px;
    line-height: 1.4;
}

/* Message Bubbles - compact */
.chat-widget-container .message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 88%;
    animation: chatMessageIn 0.18s ease;
}

.chat-widget-container .message.customer {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-widget-container .message.agent {
    align-self: flex-start;
}

.chat-widget-container .message.system {
    align-self: center;
    align-items: center;
    max-width: 92%;
}

@keyframes chatMessageIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-widget-container .message-bubble {
    padding: 7px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 13px;
    line-height: 1.38;
}

.chat-widget-container .message.customer .message-bubble {
    background: var(--ucl-purple, #5b2b82);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(91, 43, 130, 0.3);
}

.chat-widget-container .message.agent .message-bubble {
    background: var(--ucl-surface, #fff);
    color: var(--ucl-ink, #1b1b1f);
    border: 1px solid rgba(91, 43, 130, 0.12);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow, 0 10px 25px rgba(0, 0, 0, 0.08));
}

.chat-widget-container .message.system .message-bubble {
    background: rgba(91, 43, 130, 0.08);
    color: var(--ucl-slate, #5b616e);
    font-size: 12px;
    text-align: center;
    border-radius: 10px;
    border: 1px solid rgba(91, 43, 130, 0.1);
    padding: 6px 10px;
}

.chat-widget-container .message-meta {
    font-size: 10px;
    color: var(--ucl-slate, #5b616e);
    margin-top: 2px;
    padding: 0 1px;
}

.chat-widget-container .message.customer .message-meta {
    text-align: right;
}

.chat-widget-container .message.agent .message-meta {
    text-align: left;
}

/* Typing Indicator - compact */
.chat-widget-container .typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--ucl-surface, #fff);
    border: 1px solid rgba(91, 43, 130, 0.12);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    max-width: 56px;
    box-shadow: var(--shadow, 0 10px 25px rgba(0, 0, 0, 0.08));
}

.chat-widget-container .typing-dots {
    display: flex;
    gap: 4px;
}

.chat-widget-container .typing-dot {
    width: 6px;
    height: 6px;
    background: var(--ucl-purple, #5b2b82);
    opacity: 0.6;
    border-radius: 50%;
    animation: chatTypingDot 1.2s ease-in-out infinite;
}

.chat-widget-container .typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-widget-container .typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatTypingDot {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.6; }
    40% { transform: translateY(-6px); opacity: 1; }
}

/* Chat Input Area - compact, brand */
.chat-widget-container .chat-input-area {
    flex-shrink: 0;
    background: var(--ucl-surface, #fff);
    border-top: 1px solid rgba(91, 43, 130, 0.12);
    padding: 8px 12px 12px;
}

.chat-widget-container .chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #faf8ff;
    border: 1px solid rgba(91, 43, 130, 0.15);
    border-radius: 18px;
    padding: 6px 10px 6px 14px;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.chat-widget-container .chat-input-container:focus-within {
    border-color: var(--ucl-purple, #5b2b82);
    box-shadow: 0 0 0 3px rgba(91, 43, 130, 0.15);
}

.chat-widget-container #chat-message-input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.35;
    max-height: 80px;
    min-height: 20px;
    color: var(--ucl-ink, #1b1b1f);
}

.chat-widget-container #chat-message-input::placeholder {
    color: var(--ucl-slate, #5b616e);
}

.chat-widget-container #chat-message-input:focus {
    outline: none;
}

.chat-widget-container .chat-send-button {
    background: var(--ucl-purple, #5b2b82);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background 0.25s ease, transform 0.25s ease;
    box-shadow: 0 2px 8px rgba(91, 43, 130, 0.3);
}

.chat-widget-container .chat-send-button:hover:not(:disabled) {
    background: var(--ucl-purple-700, #442065);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(91, 43, 130, 0.35);
}

.chat-widget-container .chat-send-button:disabled {
    background: #ced4da;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.chat-widget-container .chat-send-button:focus-visible {
    outline: 2px solid var(--ucl-purple, #5b2b82);
    outline-offset: 2px;
}

.chat-widget-container .chat-input-footer {
    margin-top: 4px;
    text-align: center;
}

.chat-widget-container .chat-input-footer small {
    color: var(--ucl-slate, #5b616e);
    font-size: 10px;
}

/* Loading / Error / Success - compact */
.chat-widget-container .chat-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    color: #495057;
    font-size: 13px;
}

.chat-widget-container .chat-loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid rgba(91, 43, 130, 0.2);
    border-top-color: var(--ucl-purple, #5b2b82);
    border-radius: 50%;
    animation: chatSpin 0.8s linear infinite;
    margin-left: 8px;
}

@keyframes chatSpin {
    to { transform: rotate(360deg); }
}

.chat-widget-container .chat-error {
    background: #fce8ec;
    color: #721c24;
    padding: 8px 12px;
    border-radius: 10px;
    margin: 4px 0;
    font-size: 12px;
    border: 1px solid #f5c2c7;
}

.chat-widget-container .chat-success {
    background: rgba(91, 43, 130, 0.08);
    color: var(--ucl-purple-700, #442065);
    padding: 8px 12px;
    border-radius: 10px;
    margin: 4px 0;
    font-size: 12px;
    border: 1px solid rgba(91, 43, 130, 0.2);
}

/* Responsive - compact */
@media (max-width: 480px) {
    .chat-widget-container {
        bottom: 10px;
        right: 10px;
    }

    .chat-widget-container .chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 80px);
        max-height: none;
        bottom: 64px;
        right: 0;
        left: 0;
        margin: 0 auto;
        border-radius: var(--radius, 18px) var(--radius, 18px) 0 0;
    }

    .chat-widget-container .chat-toggle-button {
        width: 50px;
        height: 50px;
        font-size: 18px;
    }

    .chat-widget-container .chat-messages {
        padding: 8px 12px 10px;
        gap: 5px;
    }

    .chat-widget-container .chat-header {
        padding: 8px 12px 8px 14px;
        min-height: 40px;
    }

    .chat-widget-container .chat-title h3 {
        font-size: 14px;
    }

    .chat-widget-container .agent-status {
        font-size: 10px;
    }
}
