/* ============================================================
   SupportCandy Chat Widget
   ============================================================ */

#sc-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* ── Toggle Button ────────────────────────────────────────── */

.sc-cw-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: #0073aa;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: background 0.2s, transform 0.2s;
}

.sc-cw-toggle:hover {
    background: #005a87;
    transform: scale(1.05);
}

/* ── Chat Window ──────────────────────────────────────────── */

.sc-cw-window {
    display: none;
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
    flex-direction: column;
    overflow: hidden;
}

#sc-chat-widget.sc-cw-open .sc-cw-window {
    display: flex;
}

#sc-chat-widget.sc-cw-open #sc-cw-icon-chat {
    display: none;
}

#sc-chat-widget.sc-cw-open #sc-cw-icon-close {
    display: block;
}

#sc-chat-widget.sc-cw-closed #sc-cw-icon-chat {
    display: block;
}

#sc-chat-widget.sc-cw-closed #sc-cw-icon-close {
    display: none;
}

/* ── Header ───────────────────────────────────────────────── */

.sc-cw-header {
    background: #0073aa;
    color: #fff;
    padding: 16px 20px;
    flex-shrink: 0;
}

.sc-cw-header-title {
    font-size: 16px;
    font-weight: 600;
}

.sc-cw-agent {
    font-size: 12px;
    opacity: 0.85;
    margin-top: 2px;
    min-height: 18px;
}

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

.sc-cw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f5f7fa;
}

.sc-cw-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    animation: sc-cw-fade-in 0.2s ease;
}

@keyframes sc-cw-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Customer messages — right */
.sc-cw-msg.sc-cw-in {
    background: #0073aa;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Agent / system messages — left */
.sc-cw-msg.sc-cw-out {
    background: #fff;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.sc-cw-msg.sc-cw-system {
    background: #e8f0fe;
    color: #555;
    align-self: center;
    font-size: 12px;
    border-radius: 8px;
    text-align: center;
    max-width: 90%;
}

.sc-cw-msg-agent {
    font-size: 11px;
    font-weight: 600;
    color: #0073aa;
    margin-bottom: 2px;
}

.sc-cw-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 4px;
}

/* ── Typing indicator ─────────────────────────────────────── */

.sc-cw-typing {
    align-self: flex-start;
    padding: 10px 14px;
    background: #fff;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: none;
}

.sc-cw-typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    margin: 0 1px;
    animation: sc-cw-bounce 1.2s infinite;
}

.sc-cw-typing span:nth-child(2) { animation-delay: 0.2s; }
.sc-cw-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sc-cw-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* ── Input Area ───────────────────────────────────────────── */

.sc-cw-input-area {
    display: flex;
    align-items: flex-end;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
    gap: 8px;
}

.sc-cw-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    max-height: 80px;
    outline: none;
    transition: border-color 0.2s;
}

.sc-cw-input:focus {
    border-color: #0073aa;
}

.sc-cw-send {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: #0073aa;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.sc-cw-send:hover {
    background: #005a87;
}

.sc-cw-send:disabled {
    background: #a0c4d8;
    cursor: not-allowed;
}

/* ── Footer ───────────────────────────────────────────────── */

.sc-cw-footer {
    padding: 6px 12px;
    border-top: 1px solid #f0f0f0;
    text-align: center;
    flex-shrink: 0;
    background: #fff;
}

.sc-cw-end-btn {
    background: none;
    border: none;
    color: #999;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s;
}

.sc-cw-end-btn:hover {
    color: #e53e3e;
}

/* ── Closed state ─────────────────────────────────────────── */

.sc-cw-closed-notice {
    text-align: center;
    padding: 20px;
    color: #666;
}

.sc-cw-closed-notice button {
    margin-top: 12px;
    background: #0073aa;
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.sc-cw-closed-notice button:hover {
    background: #005a87;
}

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

@media (max-width: 480px) {
    .sc-cw-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 90px);
        bottom: 68px;
        right: -16px;
        border-radius: 12px 12px 0 0;
    }
}
