/* ═══════════════════════════════════════
 *  SmartChat Frontend Widget
 *  Colors: #0066CC blue, #1A1A2E dark, #FFFFFF white, #F0F2F5 light gray
 * ═══════════════════════════════════════ */

/* ── Reset for widget scope ── */
#smartchat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* ── Chat Bubble (toggle button) ── */
.smartchat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #0066CC;
    color: #FFFFFF;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 102, 204, 0.35);
    z-index: 999998;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.smartchat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 102, 204, 0.45);
}

.smartchat-bubble svg {
    width: 28px;
    height: 28px;
    fill: #FFFFFF;
}

.smartchat-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-radius: 10px;
    padding: 0 5px;
    display: none;
}

.smartchat-bubble-badge.has-unread {
    display: block;
}

/* ── Chat Window ── */
.smartchat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: #FFFFFF;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    z-index: 999999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: smartchat-slide-up 0.25s ease-out;
}

.smartchat-window.open {
    display: flex;
}

@keyframes smartchat-slide-up {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Header ── */
.smartchat-header {
    background: #1A1A2E;
    color: #FFFFFF;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.smartchat-header-info h4 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
    color: #FFFFFF;
}

.smartchat-header-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    gap: 6px;
}

.smartchat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.smartchat-status-dot.online {
    background: #22c55e;
}

.smartchat-status-dot.offline {
    background: #9ca3af;
}

.smartchat-header-close {
    background: none;
    border: none;
    color: #FFFFFF;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    font-size: 18px;
}

.smartchat-header-close:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ── Pre-chat form ── */
.smartchat-prechat {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.smartchat-prechat h5 {
    font-size: 15px;
    font-weight: 600;
    color: #1A1A2E;
    margin-bottom: 4px;
}

.smartchat-prechat p {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 4px;
}

.smartchat-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
    color: #1A1A2E;
    background: #FFFFFF;
}

.smartchat-input:focus {
    border-color: #0066CC;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.smartchat-input::placeholder {
    color: #9ca3af;
}

.smartchat-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

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

.smartchat-btn-primary {
    background: #0066CC;
    color: #FFFFFF;
}

.smartchat-btn-primary:hover {
    background: #0052a3;
}

.smartchat-btn-primary:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

/* ── Offline form ── */
.smartchat-offline {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.smartchat-offline h5 {
    font-size: 15px;
    font-weight: 600;
    color: #1A1A2E;
}

.smartchat-offline p {
    font-size: 13px;
    color: #6b7280;
}

.smartchat-offline textarea {
    resize: vertical;
    min-height: 80px;
}

.smartchat-offline-success {
    text-align: center;
    padding: 32px 20px;
    color: #1A1A2E;
}

.smartchat-offline-success .sc-check {
    width: 48px;
    height: 48px;
    background: #22c55e;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    color: #FFFFFF;
    font-size: 24px;
}

/* ── Messages area ── */
.smartchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    background: #F0F2F5;
    min-height: 200px;
    max-height: 320px;
}

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

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

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

.smartchat-msg {
    display: flex;
    margin-bottom: 8px;
}

.smartchat-msg.visitor {
    justify-content: flex-end;
}

.smartchat-msg.admin {
    justify-content: flex-start;
}

.smartchat-msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
}

.smartchat-msg.visitor .smartchat-msg-bubble {
    background: #0066CC;
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}

.smartchat-msg.admin .smartchat-msg-bubble {
    background: #FFFFFF;
    color: #1A1A2E;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.smartchat-msg-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
    padding: 0 4px;
}

.smartchat-msg.visitor .smartchat-msg-time {
    text-align: right;
}

/* ── Typing indicator ── */
.smartchat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #F0F2F5;
    font-size: 12px;
    color: #6b7280;
}

.smartchat-typing-dots {
    display: flex;
    gap: 3px;
}

.smartchat-typing-dots span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: smartchat-bounce 1.2s infinite ease-in-out;
}

.smartchat-typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.smartchat-typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes smartchat-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-4px);
    }
}

/* ── Input area ── */
.smartchat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    background: #FFFFFF;
    flex-shrink: 0;
}

.smartchat-input-area textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    font-size: 14px;
    resize: none;
    max-height: 80px;
    outline: none;
    font-family: inherit;
    color: #1A1A2E;
    background: #F0F2F5;
    line-height: 1.4;
}

.smartchat-input-area textarea:focus {
    border-color: #0066CC;
    background: #FFFFFF;
}

.smartchat-input-area textarea::placeholder {
    color: #9ca3af;
}

.smartchat-send-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: #0066CC;
    color: #FFFFFF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.smartchat-send-btn:hover {
    background: #0052a3;
}

.smartchat-send-btn:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

.smartchat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #FFFFFF;
}

/* ── Powered by ── */
.smartchat-powered {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: #9ca3af;
    background: #FFFFFF;
    border-top: 1px solid #f3f4f6;
}

.smartchat-powered a {
    color: #0066CC;
    text-decoration: none;
}

.smartchat-powered a:hover {
    text-decoration: underline;
}

/* ── Mobile responsive ── */
@media screen and (max-width: 480px) {
    .smartchat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .smartchat-bubble {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }

    .smartchat-messages {
        max-height: calc(100vh - 240px);
        max-height: calc(100dvh - 240px);
    }
}
