/* ============================================
   Chat Wizard — floating widget
   Drop-in replacement for third-party chat
   ============================================ */

/* Floating launcher button */
.cw-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--forest);
    color: var(--cream);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(16, 37, 33, 0.3);
    z-index: 1010;
    transition: all 0.3s var(--ease);
    border: none;
}
.cw-launcher:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 14px 36px rgba(16, 37, 33, 0.4);
}
.cw-launcher svg { width: 28px; height: 28px; }
.cw-launcher.open svg.cw-icon-chat { display: none; }
.cw-launcher.open svg.cw-icon-close { display: block; }
.cw-launcher svg.cw-icon-close { display: none; }

/* Pulse animation when closed */
.cw-launcher::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--terracotta);
    opacity: 0;
    transform: scale(1);
}
.cw-launcher:not(.open)::before {
    animation: cw-pulse 2.5s infinite;
}
@keyframes cw-pulse {
    0%   { opacity: 0.5; transform: scale(1); }
    100% { opacity: 0;   transform: scale(1.5); }
}

/* Notification badge */
.cw-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: var(--terracotta);
    color: var(--cream);
    border-radius: 50%;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--cream);
}

/* Chat panel */
.cw-panel {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 140px);
    background: var(--cream);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
    z-index: 1009;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: cw-slide-in 0.3s var(--ease);
}
.cw-panel.visible { display: flex; }
@keyframes cw-slide-in {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* Header */
.cw-header {
    background: var(--forest);
    color: var(--cream);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.cw-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--terracotta);
    color: var(--cream);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 18px;
    flex-shrink: 0;
    position: relative;
}
.cw-avatar::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #4ade80;
    border: 2px solid var(--forest);
}
.cw-header-info { flex: 1; }
.cw-header-info .name {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    color: var(--cream);
}
.cw-header-info .status {
    font-size: 11px;
    opacity: 0.75;
    color: var(--cream);
}
.cw-close {
    background: transparent;
    border: none;
    color: var(--cream);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.cw-close:hover { opacity: 1; background: rgba(250,246,239,0.1); }

/* Body (messages area) */
.cw-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 18px 8px;
    background: linear-gradient(180deg, #faf6ef 0%, #f5efe2 100%);
    scroll-behavior: smooth;
}
.cw-body::-webkit-scrollbar { width: 6px; }
.cw-body::-webkit-scrollbar-track { background: transparent; }
.cw-body::-webkit-scrollbar-thumb {
    background: rgba(16, 37, 33, 0.15);
    border-radius: 3px;
}

/* Messages */
.cw-msg {
    display: flex;
    margin-bottom: 10px;
    animation: cw-msg-in 0.25s var(--ease);
}
@keyframes cw-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.cw-msg.bot { justify-content: flex-start; }
.cw-msg.user { justify-content: flex-end; }
.cw-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    max-width: 80%;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
}
.cw-msg.bot .cw-msg-bubble {
    background: var(--cream-dark);
    color: var(--ink);
    border-bottom-left-radius: 4px;
}
.cw-msg.user .cw-msg-bubble {
    background: var(--forest);
    color: var(--cream);
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.cw-typing {
    display: flex;
    gap: 4px;
    padding: 14px 16px;
    background: var(--cream-dark);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}
.cw-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: cw-bounce 1.4s infinite;
}
.cw-typing span:nth-child(2) { animation-delay: 0.2s; }
.cw-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cw-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-6px); opacity: 1; }
}

/* Choice buttons */
.cw-choices {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 6px 0 14px;
    padding-left: 0;
}
.cw-choice {
    background: var(--cream);
    border: 1.5px solid var(--line);
    color: var(--forest);
    padding: 10px 14px;
    border-radius: 100px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s var(--ease);
    display: flex;
    align-items: center;
    gap: 8px;
}
.cw-choice:hover {
    border-color: var(--forest);
    background: rgba(26, 60, 52, 0.04);
    transform: translateX(2px);
}
.cw-choice.primary {
    border-color: var(--forest);
    background: var(--forest);
    color: var(--cream);
}
.cw-choice.primary:hover {
    background: var(--forest-dark);
}
.cw-choice .ico {
    font-size: 14px;
    flex-shrink: 0;
}

/* Form inputs inside chat */
.cw-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 6px 0 14px;
}
.cw-form input,
.cw-form select,
.cw-form textarea {
    background: var(--cream);
    border: 1.5px solid var(--line);
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    width: 100%;
    transition: border 0.2s;
}
.cw-form input:focus,
.cw-form select:focus,
.cw-form textarea:focus {
    border-color: var(--forest);
    outline: none;
}
.cw-form button {
    background: var(--forest);
    color: var(--cream);
    border: none;
    padding: 10px 16px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}
.cw-form button:hover { background: var(--forest-dark); }

/* Footer (quick actions) */
.cw-footer {
    background: var(--cream);
    border-top: 1px solid var(--line);
    padding: 10px 14px;
    display: flex;
    gap: 8px;
    justify-content: space-around;
    align-items: center;
}
.cw-quick {
    flex: 1;
    background: transparent;
    border: none;
    padding: 8px 4px;
    color: var(--ink-soft);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
    text-decoration: none;
}
.cw-quick:hover {
    background: var(--cream-dark);
    color: var(--forest);
}
.cw-quick svg { width: 18px; height: 18px; }
.cw-quick.sms { color: var(--terracotta); }
.cw-quick.wa { color: #25d366; }

/* Mobile: full-screen panel */
/* Tablets */
@media (max-width: 768px) {
    .cw-panel {
        width: 360px;
        height: 540px;
        bottom: 90px;
        right: 16px;
    }
    .cw-launcher {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    .cw-launcher svg {
        width: 24px;
        height: 24px;
    }
}

/* Phones - panel takes full screen */
@media (max-width: 480px) {
    .cw-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        max-width: 100%;
    }
    .cw-launcher {
        bottom: 14px;
        right: 14px;
        width: 54px;
        height: 54px;
    }
    /* Make inputs at 16px to prevent iOS zoom on focus */
    .cw-form input,
    .cw-form select,
    .cw-form textarea {
        font-size: 16px !important;
    }
    /* Bigger tap targets for choices */
    .cw-choice {
        padding: 14px 16px;
        font-size: 14px;
    }
    /* Quick footer buttons larger */
    .cw-quick {
        padding: 12px 4px;
        min-height: 44px;
    }
}

/* Hide chat panel on print */
@media print {
    .cw-launcher, .cw-panel { display: none !important; }
}

/* === LIVE CHAT extensions === */

/* Agent message bubble (when team replies to visitor) */
.cw-msg.agent {
    justify-content: flex-start;
    align-items: flex-start;
}
.cw-msg.agent .cw-msg-bubble {
    background: #c8634a;
    color: #faf6ef;
    border-bottom-left-radius: 4px;
}
.cw-msg-sender {
    font-size: 0.7rem;
    color: rgba(26, 60, 52, 0.6);
    margin-bottom: 3px;
    padding-left: 4px;
    font-weight: 500;
}

/* Visitor live input bar at the bottom of the chat panel */
.cw-live-input {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    background: #faf6ef;
    border-top: 1px solid #e4ddd0;
    align-items: flex-end;
}
.cw-live-input textarea {
    flex: 1;
    border: 1.5px solid #e4ddd0;
    border-radius: 18px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    background: #fff;
    color: #1a1a1a;
    outline: none;
    line-height: 1.4;
    max-height: 100px;
    min-height: 38px;
    transition: border-color 0.2s;
}
.cw-live-input textarea:focus {
    border-color: #c8634a;
}
.cw-send-btn {
    background: #c8634a;
    color: #faf6ef;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.cw-send-btn:hover { background: #b45740; }
.cw-send-btn:active { transform: scale(0.95); }

/* On mobile, make input bigger to prevent iOS zoom */
@media (max-width: 480px) {
    .cw-live-input textarea {
        font-size: 16px;
    }
}
