/* ============================================
   Crystal Live Chat - Frontend Widget Styles
   ============================================ */

:root {
    --cl-primary: #6C5CE7;
    --cl-primary-dark: #5A4BD1;
    --cl-primary-light: #A29BFE;
    --cl-gradient: linear-gradient(135deg, #6C5CE7 0%, #A29BFE 100%);
    --cl-dark: #1a1a2e;
    --cl-dark-2: #16213e;
    --cl-text: #2d3436;
    --cl-text-light: #636e72;
    --cl-bg: #ffffff;
    --cl-bg-light: #f8f9fa;
    --cl-border: #e9ecef;
    --cl-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --cl-shadow-sm: 0 4px 15px rgba(0, 0, 0, 0.1);
    --cl-radius: 16px;
    --cl-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Chat Toggle Button ── */
.cl-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--cl-gradient);
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 25px rgba(108, 92, 231, 0.45);
    z-index: 999998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--cl-transition);
    outline: none;
}

.cl-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 30px rgba(108, 92, 231, 0.55);
}

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

.cl-chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: #fff;
    transition: var(--cl-transition);
}

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

.cl-chat-toggle.cl-open .cl-icon-close {
    display: block;
}

.cl-chat-toggle:not(.cl-open) .cl-icon-close {
    display: none;
}

/* Pulse animation */
.cl-chat-toggle::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--cl-gradient);
    animation: cl-pulse 2s ease-in-out infinite;
    z-index: -1;
}

.cl-chat-toggle.cl-open::before {
    animation: none;
}

@keyframes cl-pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.3);
        opacity: 0;
    }
}

/* Unread Badge */
.cl-unread-count {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ff3b5c;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    animation: cl-badge-pop 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@keyframes cl-badge-pop {
    0% {
        transform: scale(0);
    }

    60% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* ── Chat Window ── */
.cl-chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--cl-bg);
    border-radius: var(--cl-radius);
    box-shadow: var(--cl-shadow);
    z-index: 999999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.cl-chat-window.cl-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Chat Header ── */
.cl-chat-header {
    background: var(--cl-gradient);
    padding: 20px 20px 16px;
    color: #fff;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.cl-chat-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    position: relative;
    z-index: 2;
}

.cl-chat-header-text {
    flex: 1;
    min-width: 0;
}

/* Close button — hidden on desktop, shown on mobile */
.cl-chat-close-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    flex-shrink: 0;
    margin-left: 8px;
    transition: var(--cl-transition);
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.cl-chat-close-btn:hover,
.cl-chat-close-btn:active {
    background: rgba(255, 255, 255, 0.35);
}

.cl-chat-close-btn svg {
    width: 20px;
    height: 20px;
    fill: #fff;
    display: block;
}

.cl-chat-header::after {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
}

.cl-chat-header::before {
    content: '';
    position: absolute;
    bottom: -30px;
    left: -10px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
}

.cl-chat-title {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.cl-chat-subtitle {
    margin: 0;
    font-size: 13px;
    opacity: 0.85;
    font-weight: 400;
}

.cl-online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #00e676;
    margin-right: 6px;
    box-shadow: 0 0 6px rgba(0, 230, 118, 0.5);
    animation: cl-online-pulse 2s ease infinite;
}

@keyframes cl-online-pulse {

    0%,
    100% {
        box-shadow: 0 0 6px rgba(0, 230, 118, 0.5);
    }

    50% {
        box-shadow: 0 0 12px rgba(0, 230, 118, 0.8);
    }
}

/* ── Pre-chat Form ── */
.cl-prechat-form {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
    justify-content: center;
}

.cl-prechat-form h3 {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 600;
    color: var(--cl-text);
}

.cl-prechat-form p {
    margin: 0 0 8px;
    font-size: 13px;
    color: var(--cl-text-light);
    line-height: 1.5;
}

.cl-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cl-form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--cl-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cl-form-group input {
    padding: 10px 14px;
    border: 1.5px solid var(--cl-border);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: var(--cl-transition);
    background: var(--cl-bg-light);
    font-family: inherit;
}

.cl-form-group input:focus {
    border-color: var(--cl-primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
    background: #fff;
}

.cl-start-chat-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    background: var(--cl-gradient);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--cl-transition);
    margin-top: 4px;
    font-family: inherit;
}

.cl-start-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.35);
}

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

/* ── Messages Area ── */
.cl-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--cl-bg-light);
    scroll-behavior: smooth;
}

.cl-messages::-webkit-scrollbar {
    width: 5px;
}

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

.cl-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}

/* Welcome Message */
.cl-welcome-msg {
    text-align: center;
    padding: 12px 16px;
    margin-bottom: 4px;
}

.cl-welcome-msg p {
    margin: 0;
    font-size: 13px;
    color: var(--cl-text-light);
    line-height: 1.5;
    background: #fff;
    display: inline-block;
    padding: 10px 16px;
    border-radius: 12px;
    box-shadow: var(--cl-shadow-sm);
}

/* Message Bubbles */
.cl-message {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    animation: cl-msg-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes cl-msg-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cl-message.cl-visitor {
    align-self: flex-end;
}

.cl-message.cl-admin {
    align-self: flex-start;
}

.cl-message-bubble {
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.cl-visitor .cl-message-bubble {
    background: var(--cl-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.cl-admin .cl-message-bubble {
    background: #fff;
    color: var(--cl-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.cl-message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    padding: 0 4px;
}

.cl-visitor .cl-message-meta {
    justify-content: flex-end;
}

.cl-message-sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--cl-text-light);
}

.cl-message-time {
    font-size: 11px;
    color: #b2bec3;
}

/* Typing Indicator */
.cl-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    background: #fff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    align-self: flex-start;
    max-width: 80px;
}

.cl-typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b2bec3;
    animation: cl-typing 1.4s infinite;
}

.cl-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.cl-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes cl-typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ── Input Area ── */
.cl-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--cl-border);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
}

.cl-input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--cl-border);
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    resize: none;
    max-height: 100px;
    transition: var(--cl-transition);
    background: var(--cl-bg-light);
    font-family: inherit;
}

.cl-input-area textarea:focus {
    border-color: var(--cl-primary);
    background: #fff;
}

.cl-input-area textarea::placeholder {
    color: #b2bec3;
}

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

.cl-send-msg-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.35);
}

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

.cl-send-msg-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ── Powered By ── */
.cl-powered-by {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: #b2bec3;
    background: #fff;
    border-top: 1px solid var(--cl-border);
    flex-shrink: 0;
}

/* ── Date Divider ── */
.cl-date-divider {
    text-align: center;
    margin: 8px 0;
    font-size: 11px;
    color: #b2bec3;
    position: relative;
}

.cl-date-divider span {
    background: var(--cl-bg-light);
    padding: 0 12px;
    position: relative;
    z-index: 1;
}

.cl-date-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--cl-border);
}

/* ── Mobile Responsive ── */
@media (max-width: 480px) {
    .cl-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .cl-chat-close-btn {
        display: flex;
    }

    .cl-chat-toggle.cl-open {
        display: none;
    }

    .cl-chat-toggle {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .cl-chat-toggle svg {
        width: 24px;
        height: 24px;
    }
}

/* ── Animations ── */
.cl-fade-in {
    animation: cl-fade 0.3s ease forwards;
}

@keyframes cl-fade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}