/* ═══════════════════════════════════════════════════════════════
   ChatWidge — Zendesk-Exact Customer Service Widget
   ═══════════════════════════════════════════════════════════════ */

:root {
    --cw-black: #000000;
    --cw-dark: #1a1a1a;
    --cw-white: #ffffff;
    --cw-body-bg: #f6f6f6;
    --cw-text: #2f3941;
    --cw-text-light: #68737d;
    --cw-border: #d8dcde;
    --cw-agent-bubble: #e9ebed;
    --cw-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
    --cw-font: 'system-ui', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ─── Widget Container ────────────────────────────────────────── */

.cw-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: var(--cw-font);
    font-size: 14px;
    line-height: 1.4;
    color: var(--cw-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── Chat Toggle Button (Zendesk: solid black circle) ────────── */

.cw-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--cw-black);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    position: relative;
    outline: none;
    padding: 0;
}

.cw-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

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

.cw-toggle-btn svg {
    width: 28px;
    height: 28px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.cw-toggle-btn .cw-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(0.8);
}

.cw-widget.cw-open .cw-toggle-btn .cw-icon-chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.8);
}

.cw-widget.cw-open .cw-toggle-btn .cw-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Unread Badge */
.cw-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e74536;
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid white;
    opacity: 0;
    transform: scale(0);
    transition: all 0.2s ease;
}

.cw-badge.cw-visible {
    opacity: 1;
    transform: scale(1);
}

/* Engagement Popup */
.cw-engage-popup {
    position: absolute;
    bottom: 76px;
    right: 0;
    background: #ffffff;
    color: #333;
    font-size: 14px;
    font-weight: 500;
    padding: 14px 38px 14px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    cursor: pointer;
}

.cw-engage-popup.cw-engage-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.cw-engage-close {
    position: absolute;
    top: 4px;
    right: 10px;
    font-size: 18px;
    cursor: pointer;
    color: #999;
    line-height: 1;
}

.cw-engage-close:hover {
    color: #333;
}

.cw-widget.cw-open .cw-engage-popup {
    display: none;
}

/* ─── Chat Window (Zendesk style) ────────────────────────────── */

.cw-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    height: 600px;
    background: var(--cw-white);
    border-radius: 24px;
    box-shadow: var(--cw-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.cw-widget.cw-open .cw-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ─── Header (Zendesk: solid black bar) ──────────────────────── */

.cw-header {
    background: var(--cw-black);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    flex-shrink: 0;
}

.cw-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.cw-header-avatar svg {
    width: 20px;
    height: 20px;
    fill: var(--cw-black);
}

.cw-header-avatar-badge {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 14px;
    height: 14px;
    background: #78a300;
    border-radius: 50%;
    border: 2px solid var(--cw-black);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cw-header-avatar-badge svg {
    width: 8px;
    height: 8px;
    fill: white;
}

.cw-header-info {
    flex: 1;
    min-width: 0;
}

.cw-header-info h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cw-header-info p {
    margin: 1px 0 0;
    font-size: 12px;
    opacity: 0.7;
    font-weight: 400;
}

.cw-close-header-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: none;
    /* Hidden by default on desktop */
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    margin-right: -8px;
    flex-shrink: 0;
}

.cw-close-header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.cw-close-header-btn svg {
    width: 20px;
    height: 20px;
    stroke: white;
}

/* ─── Pre-Chat Form ──────────────────────────────────────────── */

.cw-prechat {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 28px 24px;
    background: var(--cw-white);
}

.cw-prechat-greeting {
    text-align: center;
    margin-bottom: 28px;
}

.cw-prechat-greeting .cw-greeting-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--cw-agent-bubble);
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cw-prechat-greeting .cw-greeting-avatar svg {
    width: 28px;
    height: 28px;
    fill: var(--cw-text);
}

.cw-prechat h4 {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 700;
    color: var(--cw-text);
}

.cw-prechat p {
    margin: 0;
    color: var(--cw-text-light);
    font-size: 14px;
    line-height: 1.5;
}

.cw-form-group {
    margin-bottom: 14px;
}

.cw-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--cw-text);
    margin-bottom: 5px;
}

.cw-form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--cw-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--cw-font);
    color: var(--cw-text);
    background: white;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
    box-sizing: border-box;
}

.cw-form-group input:focus {
    border-color: var(--cw-black);
    box-shadow: 0 0 0 1px var(--cw-black);
}

.cw-form-group input::placeholder {
    color: #b6bbc0;
}

.cw-start-btn {
    width: 100%;
    padding: 12px;
    background: var(--cw-black);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--cw-font);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    margin-top: 8px;
}

.cw-start-btn:hover {
    background: var(--cw-dark);
}

.cw-start-btn:active {
    transform: scale(0.98);
}

.cw-start-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ─── Messages Area ──────────────────────────────────────────── */

.cw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--cw-body-bg);
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: smooth;
}

.cw-messages::-webkit-scrollbar {
    width: 6px;
}

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

.cw-messages::-webkit-scrollbar-thumb {
    background: #c8c8c8;
    border-radius: 3px;
}

/* Timestamp Divider (Zendesk shows timestamps as dividers) */
.cw-time-divider {
    text-align: center;
    font-size: 12px;
    color: var(--cw-text-light);
    padding: 12px 0 6px;
}

/* Message Bubble */
.cw-message {
    max-width: 80%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.45;
    animation: cw-fadeIn 0.15s ease-out;
    word-wrap: break-word;
    white-space: pre-wrap;
}

@keyframes cw-fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

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

/* Customer bubbles (Zendesk: dark/black, right-aligned) */
.cw-message.cw-customer {
    align-self: flex-end;
    background: var(--cw-black);
    color: white;
    border-radius: 18px 18px 4px 18px;
}

/* Agent bubbles (Zendesk: light gray, left-aligned) */
.cw-message.cw-agent {
    align-self: flex-start;
    background: var(--cw-agent-bubble);
    color: var(--cw-text);
    border-radius: 18px 18px 18px 4px;
}

.cw-message-time {
    font-size: 11px;
    color: var(--cw-text-light);
    margin-top: 4px;
    display: block;
}

.cw-message.cw-customer .cw-message-time {
    text-align: right;
    color: rgba(255, 255, 255, 0.6);
}

/* Agent Label */
.cw-agent-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--cw-text-light);
    margin-bottom: 3px;
    margin-left: 2px;
    margin-top: 10px;
}

/* Welcome Message */
.cw-welcome {
    text-align: center;
    padding: 24px 16px;
    color: var(--cw-text-light);
    font-size: 13px;
    line-height: 1.5;
}

.cw-welcome-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--cw-agent-bubble);
    margin: 0 auto 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cw-welcome-icon svg {
    width: 24px;
    height: 24px;
    fill: var(--cw-text);
}

/* ─── Typing Indicator ───────────────────────────────────────── */

.cw-typing {
    align-self: flex-start;
    background: var(--cw-agent-bubble);
    padding: 12px 16px;
    border-radius: 18px 18px 18px 4px;
    display: none;
    gap: 5px;
    align-items: center;
}

.cw-typing.cw-visible {
    display: flex;
}

.cw-typing-dot {
    width: 6px;
    height: 6px;
    background: #87929d;
    border-radius: 50%;
    animation: cw-bounce 1.4s infinite ease-in-out;
}

.cw-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.cw-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes cw-bounce {

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

    30% {
        transform: translateY(-4px);
    }
}

/* ─── Input Area (Zendesk: paperclip + pill input) ───────────── */

.cw-input-area {
    padding: 12px 16px 14px;
    background: var(--cw-white);
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 10px;
}

.cw-attach-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.cw-attach-btn:hover {
    opacity: 0.8;
}

.cw-attach-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--cw-text);
}

.cw-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--cw-border);
    border-radius: 24px;
    font-size: 14px;
    font-family: var(--cw-font);
    color: var(--cw-text);
    outline: none;
    transition: border-color 0.15s ease;
    background: var(--cw-white);
}

.cw-input:focus {
    border-color: #999;
}

.cw-input::placeholder {
    color: #b6bbc0;
}

.cw-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cw-black);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s ease, opacity 0.15s ease;
    flex-shrink: 0;
    opacity: 0.9;
}

.cw-send-btn:hover {
    opacity: 1;
    transform: scale(1.05);
}

.cw-send-btn:active {
    transform: scale(0.92);
}

.cw-send-btn svg {
    width: 16px;
    height: 16px;
    fill: white;
}

/* ─── Powered By (Zendesk style) ─────────────────────────────── */

.cw-powered {
    text-align: center;
    padding: 8px 16px 10px;
    background: var(--cw-white);
    font-size: 11px;
    color: #b6bbc0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.cw-powered svg {
    width: 12px;
    height: 12px;
    fill: #b6bbc0;
}

.cw-powered a {
    color: #87929d;
    text-decoration: none;
    font-weight: 600;
}

/* ─── Session Closed Banner ──────────────────────────────────── */

.cw-closed-banner {
    padding: 12px 20px;
    background: #fff9e6;
    border-top: 1px solid #f0e4b8;
    text-align: center;
    font-size: 13px;
    color: #735f19;
    font-weight: 500;
    display: none;
}

.cw-closed-banner.cw-visible {
    display: block;
}

/* ─── Mobile Responsive ──────────────────────────────────────── */

@media (max-width: 480px) {
    .cw-widget {
        bottom: 0;
        right: 0;
    }

    .cw-window {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    .cw-toggle-btn {
        bottom: 16px;
        right: 16px;
        position: fixed;
    }

    .cw-widget.cw-open .cw-toggle-btn {
        display: none;
    }

    .cw-close-header-btn {
        display: flex;
        /* Show only on mobile */
    }
}