/**
 * Clever Chat - Widget Styles (white-labeled)
 * All classes prefixed with clever-chat- to avoid theme conflicts
 */

/* CSS Custom Properties - populated via JS from settings */
:root {
    --cc-primary: #0073aa;
    --cc-text: #ffffff;
    --cc-header: #0073aa;
    --cc-bg: #ffffff;
    --cc-font: inherit;
    --cc-bubble-size: 60px;
    --cc-width: 380px;
    --cc-height: 520px;
}

/* Widget Container */
.clever-chat-widget {
    position: fixed;
    z-index: 99999;
    font-family: var(--cc-font);
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

.clever-chat-widget *,
.clever-chat-widget *::before,
.clever-chat-widget *::after {
    box-sizing: border-box;
}

.clever-chat-bottom-right {
    bottom: 20px;
    right: 20px;
}

.clever-chat-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Chat Bubble - base styles, colors applied via inline JS */
.clever-chat-bubble {
    width: var(--cc-bubble-size);
    height: var(--cc-bubble-size);
    border-radius: 50%;
    background: #0073aa;
    color: #ffffff;
    border: 2px solid #0073aa;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    padding: 0;
}

.clever-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.clever-chat-bubble:focus {
    outline: 2px solid currentColor;
    outline-offset: 3px;
}

.clever-chat-bubble-svg {
    width: 28px;
    height: 28px;
    color: inherit;
}

.clever-chat-bubble-img {
    width: 65%;
    height: 65%;
    border-radius: 50%;
    object-fit: cover;
}

/* Unread Badge */
.clever-chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3232;
    color: #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Chat Panel */
.clever-chat-panel {
    position: absolute;
    bottom: calc(var(--cc-bubble-size) + 15px);
    width: var(--cc-width);
    height: var(--cc-height);
    background: var(--cc-bg);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ccSlideUp 0.25s ease-out;
}

.clever-chat-bottom-right .clever-chat-panel {
    right: 0;
}

.clever-chat-bottom-left .clever-chat-panel {
    left: 0;
}

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

/* Header */
.clever-chat-header {
    background: var(--cc-header);
    color: var(--cc-text);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

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

.clever-chat-header-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
}

.clever-chat-header-name {
    font-weight: 600;
    font-size: 15px;
}

.clever-chat-header-status {
    font-size: 11px;
    opacity: 0.85;
}

/* Close button - base styles, colors applied via inline JS */
.clever-chat-close {
    background: transparent;
    border: 2px solid transparent;
    border-radius: 6px;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
}

.clever-chat-close:hover {
    opacity: 0.8;
}

/* GDPR Screen */
.clever-chat-gdpr {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
}

.clever-chat-gdpr-content {
    text-align: center;
}

.clever-chat-gdpr-content p {
    font-size: 13px;
    color: #555;
    line-height: 1.6;
    margin-bottom: 20px;
}

/* Messages Area */
.clever-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.clever-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.clever-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.clever-chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

/* Message Bubbles */
.cc-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.45;
    animation: ccFadeIn 0.2s ease;
}

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

.cc-msg-bot,
.cc-msg-ai {
    background: #f0f0f0;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.cc-msg-visitor {
    background: var(--cc-primary);
    color: var(--cc-text);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.cc-msg-operator {
    background: #e8f4f8;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.cc-msg-system {
    background: transparent;
    color: #999;
    font-size: 12px;
    text-align: center;
    align-self: center;
    padding: 5px 10px;
}

.cc-msg-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.7;
}

.cc-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 3px;
    text-align: right;
}

/* Typing Indicator */
.clever-chat-typing-indicator {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.clever-chat-dot {
    width: 7px;
    height: 7px;
    background: #999;
    border-radius: 50%;
    animation: ccBounce 1.4s infinite both;
}

.clever-chat-dot:nth-child(2) { animation-delay: 0.16s; }
.clever-chat-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes ccBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Hold Message */

/* Pre-Chat Contact Form */
.clever-chat-prechat {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    justify-content: center;
}

.clever-chat-prechat-intro {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin: 0 0 4px 0;
    text-align: center;
}

.clever-chat-prechat-field input {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--cc-font);
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}

.clever-chat-prechat-field input:focus {
    border-color: var(--cc-primary);
}

.clever-chat-prechat .clever-chat-btn {
    margin-top: 4px;
    width: 100%;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
}

/* Hold Message */
    padding: 12px 16px;
    background: #fff8e1;
    border-top: 1px solid #ffe082;
    text-align: center;
    font-size: 13px;
    color: #555;
}

.clever-chat-hold-message p {
    margin: 0 0 6px 0;
}

.clever-chat-hold-timer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff3cd;
    border: 1px solid #ffe082;
    border-radius: 12px;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #856404;
    font-variant-numeric: tabular-nums;
}

/* FAQ Suggestions */
.clever-chat-faq-suggestions {
    padding: 12px 16px;
    border-top: 1px solid #eee;
}

/* Force-hide input when FAQ suggestions or rating are active */
.clever-chat-panel.cc-hide-input .clever-chat-input-wrap {
    display: none !important;
}

.clever-chat-faq-heading {
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #555;
}

.clever-chat-faq-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.clever-chat-faq-item {
    padding: 8px 12px;
    background: #f5f5f5;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
    border: none;
    text-align: left;
    width: 100%;
    color: #333;
}

.clever-chat-faq-item:hover {
    background: #e8e8e8;
}

/* Email Form */
.clever-chat-email-form {
    padding: 16px;
    border-top: 1px solid #eee;
}

.clever-chat-form-intro {
    font-size: 13px;
    color: #555;
    margin: 0 0 12px 0;
}

.clever-chat-form-field {
    margin-bottom: 10px;
}

.clever-chat-form-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 3px;
    color: #333;
}

.clever-chat-form-field input,
.clever-chat-form-field textarea,
.clever-chat-form-field select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    font-family: var(--cc-font);
}

.clever-chat-form-field textarea {
    resize: vertical;
    min-height: 60px;
}

/* Rating */
.clever-chat-rating {
    padding: 20px 16px;
    text-align: center;
    border-top: 1px solid #eee;
}

.clever-chat-rating p {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #555;
}

.clever-chat-rating-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.clever-chat-rating-btn {
    background: none;
    border: 2px solid #ddd;
    border-radius: 50%;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    color: #999;
}

.clever-chat-rating-btn:hover {
    border-color: var(--cc-primary);
    color: var(--cc-primary);
}

.clever-chat-rating-btn.cc-selected {
    background: var(--cc-primary);
    border-color: var(--cc-primary);
    color: var(--cc-text);
}

/* Buttons */
.clever-chat-btn {
    display: inline-block;
    padding: 8px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
    font-family: var(--cc-font);
}

.clever-chat-btn:hover {
    opacity: 0.9;
}

.clever-chat-btn-primary {
    background: var(--cc-primary);
    color: var(--cc-text);
}

.clever-chat-btn-secondary {
    background: #f0f0f0;
    color: #333;
}

/* Input Area */
.clever-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.clever-chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    font-family: var(--cc-font);
    outline: none;
    transition: border-color 0.15s;
}

.clever-chat-input:focus {
    border-color: var(--cc-primary);
}

.clever-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--cc-primary);
    color: var(--cc-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.clever-chat-send:hover {
    opacity: 0.85;
}

/* Mobile Responsiveness - Full screen takeover */
@media (max-width: 480px) {
    .clever-chat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        height: 100% !important;
        border-radius: 0;
        animation: ccSlideUpMobile 0.25s ease-out;
    }

    @keyframes ccSlideUpMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .clever-chat-header {
        padding: 16px;
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .clever-chat-header-name {
        font-size: 16px;
    }

    .clever-chat-input-wrap {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .clever-chat-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .clever-chat-messages {
        padding: 12px;
    }

    .cc-msg {
        max-width: 90%;
        font-size: 15px;
    }

    .clever-chat-faq-item {
        font-size: 14px;
        padding: 10px 14px;
    }

    .clever-chat-btn {
        font-size: 15px;
        padding: 10px 20px;
    }

    .clever-chat-close {
        width: 36px;
        height: 36px;
    }

    .clever-chat-form-field input,
    .clever-chat-form-field textarea,
    .clever-chat-form-field select {
        font-size: 16px; /* Prevents iOS zoom */
    }

    .clever-chat-rating-btn {
        width: 60px;
        height: 60px;
    }

    /* Hide bubble when panel is open on mobile */
    .clever-chat-widget .clever-chat-bubble[aria-expanded="true"] {
        display: none;
    }

    .clever-chat-hold-message {
        font-size: 14px;
    }

    .clever-chat-gdpr-content {
        padding: 20px 10px;
    }

    .clever-chat-gdpr-content p {
        font-size: 14px;
    }

    .clever-chat-email-form {
        padding: 12px;
    }
}

/* Tablet adjustments */
@media (min-width: 481px) and (max-width: 768px) {
    .clever-chat-panel {
        width: 340px !important;
    }
}

/* Accessibility */
.clever-chat-widget:focus-within .clever-chat-panel {
    outline: none;
}

/* Focus visible for keyboard users */
.clever-chat-bubble:focus-visible,
.clever-chat-close:focus-visible,
.clever-chat-send:focus-visible,
.clever-chat-faq-item:focus-visible,
.clever-chat-btn:focus-visible,
.clever-chat-rating-btn:focus-visible {
    outline: 2px solid #005fcc;
    outline-offset: 2px;
}

/* Ensure links in messages are accessible */
.cc-msg a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cc-msg a:focus-visible {
    outline: 2px solid #005fcc;
    outline-offset: 1px;
}

/* Screen reader only text */
.cc-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* High contrast mode support */
@media (forced-colors: active) {
    .clever-chat-bubble {
        border: 2px solid ButtonText;
    }
    .clever-chat-close {
        border: 1px solid ButtonText;
    }
    .cc-msg {
        border: 1px solid CanvasText;
    }
}

@media (prefers-reduced-motion: reduce) {
    .clever-chat-panel,
    .cc-msg,
    .clever-chat-bubble {
        animation: none;
        transition: none;
    }

    .clever-chat-dot {
        animation: none;
        opacity: 0.6;
    }
}

/* Print - hide widget */
@media print {
    .clever-chat-widget {
        display: none !important;
    }
}
