/* ================================================
   SSW AI Chatbot - Frontend Widget Styles
   v2.2.5 — Light theme, mobile-friendly popup
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --ssw-primary:        #6C63FF;
    --ssw-primary-dark:   #5A52D5;
    --ssw-primary-light:  #8B85FF;

    /* Light theme */
    --ssw-bg-window:      #ffffff;
    --ssw-bg-chat:        #f5f5f7;
    --ssw-bg-msg-bot:     #ffffff;
    --ssw-bg-msg-user:    var(--ssw-primary);
    --ssw-text:           #1a1a2e;
    --ssw-text-muted:     #6b6b80;
    --ssw-border:         #e2e2ec;
    --ssw-shadow:         0 12px 40px rgba(0,0,0,0.15);
    --ssw-radius:         20px;
    --ssw-radius-sm:      12px;
    --ssw-transition:     0.25s cubic-bezier(0.4,0,0.2,1);
    --ssw-font:           'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Toggle Button ── */
#ssw-chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ssw-primary), var(--ssw-primary-dark));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 20px rgba(108,99,255,0.4), 0 0 0 0 rgba(108,99,255,0.3);
    transition: var(--ssw-transition);
    z-index: 99998;
    animation: ssw-pulse 2.5s infinite;
}
#ssw-chatbot-toggle:hover  { transform: scale(1.1); box-shadow: 0 6px 30px rgba(108,99,255,0.5); }
#ssw-chatbot-toggle:active { transform: scale(0.95); }

@keyframes ssw-pulse {
    0%,100% { box-shadow: 0 4px 20px rgba(108,99,255,0.4), 0 0 0 0  rgba(108,99,255,0.3); }
    50%      { box-shadow: 0 4px 20px rgba(108,99,255,0.4), 0 0 0 12px rgba(108,99,255,0); }
}

.ssw-chatbot-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--ssw-transition);
}

/* Badge */
.ssw-chatbot-badge {
    position: absolute;
    top: -4px; right: -4px;
    width: 22px; height: 22px;
    background: #FF4757;
    color: #fff;
    font-size: 11px; font-weight: 700;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
    animation: ssw-badge-bounce 0.5s ease;
}
@keyframes ssw-badge-bounce {
    0%,100% { transform: scale(1); }
    50%      { transform: scale(1.3); }
}

/* ── Position variants ── */
#ssw-chatbot-container.ssw-position-bottom-left #ssw-chatbot-toggle { left: 24px; right: auto; }
#ssw-chatbot-container.ssw-position-bottom-left .ssw-chatbot-window  { left: 24px; right: auto; }

/* ── Chat Window (desktop) ── */
.ssw-chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--ssw-bg-window);
    border-radius: var(--ssw-radius);
    box-shadow: var(--ssw-shadow);
    border: 1px solid var(--ssw-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999;
    font-family: var(--ssw-font);
    animation: ssw-window-open 0.3s ease;
}

@keyframes ssw-window-open {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}
.ssw-chatbot-window-closing {
    animation: ssw-window-close 0.22s ease forwards;
}
@keyframes ssw-window-close {
    to { opacity: 0; transform: translateY(16px) scale(0.97); }
}

/* Swipe-to-close drag feedback */
.ssw-chatbot-window.ssw-dragging {
    transition: none !important;
    animation: none !important;
}

/* ── Header ── */
.ssw-chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--ssw-primary), var(--ssw-primary-dark));
    color: #fff;
    flex-shrink: 0;
    user-select: none;
}
.ssw-chatbot-header-info { display: flex; align-items: center; gap: 10px; }

.ssw-chatbot-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex; align-items: center; justify-content: center;
    position: relative; flex-shrink: 0;
}
.ssw-chatbot-avatar img         { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.ssw-chatbot-avatar-default     { font-size: 20px; }

.ssw-chatbot-status-dot {
    position: absolute; bottom: 1px; right: 1px;
    width: 10px; height: 10px;
    background: #2ED573; border-radius: 50%;
    border: 2px solid var(--ssw-primary);
    animation: ssw-dot-pulse 2s infinite;
}
@keyframes ssw-dot-pulse {
    0%,100% { opacity: 1; }
    50%      { opacity: 0.5; }
}

.ssw-chatbot-header-text h4 {
    margin: 0;
    font-size: 14px; font-weight: 600; letter-spacing: 0.01em;
}
.ssw-chatbot-status { font-size: 11px; opacity: 0.85; }

/* Header action buttons */
.ssw-chatbot-header-actions { display: flex; gap: 4px; }

.ssw-chatbot-header-actions button {
    background: rgba(255,255,255,0.92);
    border: none;
    color: #1a1a2e !important;
    width: 30px; height: 30px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    transition: var(--ssw-transition);
}
.ssw-chatbot-header-actions button:hover  { background: #fff; transform: scale(1.08); }
.ssw-chatbot-header-actions button:active { transform: scale(0.93); }

/* Close (X) — red hover */
#ssw-chatbot-close {
    background: rgba(255,255,255,0.92);
    font-weight: 800;
}
#ssw-chatbot-close:hover { background: #ff4757; color: #fff !important; }

/* ── Messages Area ── */
.ssw-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--ssw-bg-chat);
    scroll-behavior: smooth;
}
.ssw-chatbot-messages::-webkit-scrollbar       { width: 4px; }
.ssw-chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.ssw-chatbot-messages::-webkit-scrollbar-thumb { background: #d0d0e0; border-radius: 10px; }

/* Message Bubbles */
.ssw-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: var(--ssw-radius-sm);
    font-size: 14px;
    line-height: 1.55;
    color: var(--ssw-text);
    word-wrap: break-word;
    animation: ssw-msg-in 0.25s ease;
    position: relative;
}
@keyframes ssw-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.ssw-msg-bot {
    align-self: flex-start;
    background: var(--ssw-bg-msg-bot);
    border: 1px solid var(--ssw-border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    color: #1a1a2e;
}
.ssw-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--ssw-primary), var(--ssw-primary-dark));
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Bot markdown */
.ssw-msg-bot p             { margin: 0 0 6px; color: #1a1a2e; }
.ssw-msg-bot p:last-child  { margin-bottom: 0; }
.ssw-msg-bot ul,.ssw-msg-bot ol { margin: 4px 0; padding-left: 16px; }
.ssw-msg-bot li            { margin-bottom: 3px; color: #1a1a2e; }
.ssw-msg-bot a             { color: var(--ssw-primary); text-decoration: underline; }
.ssw-msg-bot a:hover       { color: var(--ssw-primary-dark); }
.ssw-msg-bot strong        { color: #1a1a2e; font-weight: 600; }
.ssw-msg-bot code {
    background: #f0f0f8;
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--ssw-primary-dark);
}

/* Timestamp */
.ssw-msg-time {
    font-size: 10px;
    color: var(--ssw-text-muted);
    margin-top: 4px;
    display: block;
    opacity: 0.65;
}
.ssw-msg-user .ssw-msg-time { color: rgba(255,255,255,0.65); text-align: right; }

/* Typing Indicator */
.ssw-typing {
    display: flex; align-items: center; gap: 5px;
    padding: 12px 16px;
    background: var(--ssw-bg-msg-bot);
    border: 1px solid var(--ssw-border);
    border-radius: var(--ssw-radius-sm);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 70px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.ssw-typing-dot {
    width: 7px; height: 7px;
    background: #aaaacc;
    border-radius: 50%;
    animation: ssw-typing-bounce 1.4s infinite ease-in-out;
}
.ssw-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ssw-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ssw-typing-bounce {
    0%,60%,100% { transform: translateY(0);  opacity: 0.4; }
    30%          { transform: translateY(-7px); opacity: 1;   }
}

/* ── Input Area ── */
.ssw-chatbot-input-area {
    padding: 10px 14px 12px;
    background: var(--ssw-bg-window);
    border-top: 1px solid var(--ssw-border);
    flex-shrink: 0;
}
.ssw-chatbot-input-wrapper {
    display: flex; align-items: flex-end; gap: 8px;
    background: #f5f5f7;
    border: 1.5px solid var(--ssw-border);
    border-radius: 14px;
    padding: 6px 8px 6px 14px;
    transition: var(--ssw-transition);
}
.ssw-chatbot-input-wrapper:focus-within {
    border-color: var(--ssw-primary);
    box-shadow: 0 0 0 3px rgba(108,99,255,0.12);
    background: #fff;
}
#ssw-chatbot-input {
    flex: 1;
    border: none; outline: none;
    background: transparent;
    color: #1a1a2e;
    font-size: 14px;
    font-family: var(--ssw-font);
    resize: none;
    max-height: 100px;
    padding: 5px 0;
    line-height: 1.4;
}
#ssw-chatbot-input::placeholder { color: #aaaacc; }

#ssw-chatbot-send {
    width: 36px; height: 36px;
    border-radius: 10px; border: none;
    background: var(--ssw-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: var(--ssw-transition);
    flex-shrink: 0;
}
#ssw-chatbot-send:hover:not(:disabled) { background: var(--ssw-primary-dark); transform: scale(1.05); }
#ssw-chatbot-send:disabled             { opacity: 0.35; cursor: not-allowed; }

.ssw-chatbot-powered {
    text-align: center;
    font-size: 10px;
    color: var(--ssw-text-muted);
    margin-top: 6px;
    opacity: 0.55;
}
.ssw-chatbot-powered a { color: var(--ssw-text-muted); text-decoration: none; }

/* ── Error Message ── */
.ssw-msg-error {
    background: #fff0f0;
    border: 1px solid #ffc0c0;
    color: #cc3333;
    font-size: 13px;
    align-self: center;
    text-align: center;
    max-width: 90%;
    border-radius: var(--ssw-radius-sm);
    padding: 10px 14px;
}

/* ── Swipe hint (mobile only) ── */
.ssw-swipe-hint {
    display: none;
    text-align: center;
    font-size: 11px;
    color: rgba(255,255,255,0.6);
    padding-bottom: 2px;
    letter-spacing: 0.03em;
}

/* ═══════════════════════════════
   MOBILE  ≤ 600px
   Popup style: tidak fullscreen,
   muncul dari bawah dengan margin
   ═══════════════════════════════ */
@media (max-width: 600px) {
    .ssw-chatbot-window {
        /* Popup dari bawah, bukan fullscreen */
        width: calc(100vw - 20px);
        max-width: 100%;
        height: 72vh;
        max-height: 72vh;
        bottom: 90px;
        right: 10px;
        left: 10px;
        border-radius: 20px;
        border: 1px solid var(--ssw-border);
        box-shadow: 0 -4px 30px rgba(0,0,0,0.15);
        /* Untuk swipe gesture */
        touch-action: pan-y;
    }

    #ssw-chatbot-toggle {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .ssw-chatbot-header {
        padding: 12px 14px;
        border-radius: 20px 20px 0 0;
        /* Drag handle area */
        cursor: grab;
    }

    /* Drag handle indicator di atas header */
    .ssw-chatbot-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px; height: 4px;
        background: rgba(255,255,255,0.4);
        border-radius: 2px;
    }
    .ssw-chatbot-header { position: relative; }

    .ssw-swipe-hint { display: block; }

    /* Tombol X lebih besar dan kontras di mobile */
    #ssw-chatbot-close {
        width: 34px; height: 34px;
        background: rgba(255,255,255,0.3);
        border-radius: 50%;
        font-size: 16px;
    }
    #ssw-chatbot-close:hover,
    #ssw-chatbot-close:active { background: rgba(220,50,50,0.8); }

    .ssw-msg { font-size: 15px; }

    #ssw-chatbot-input { font-size: 16px; /* Cegah zoom di iOS */ }

    .ssw-chatbot-input-area { padding: 10px 12px 16px; /* Extra bottom untuk safe area */ }

    /* Safe area for iPhone notch/home bar */
    .ssw-chatbot-input-area {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* ── Transition for open/close ── */
.ssw-chatbot-hidden .ssw-chatbot-window { display: none !important; }

/* ════════════════════════════════════════════════
   Onboarding Gate & Language Picker  (light theme)
   ════════════════════════════════════════════════ */
/* Onboarding container — no overflow here, children control scroll */
.ssw-chatbot-onboarding {
    display: flex;
    flex-direction: column;
    flex: 1;
    background: #fff;
    overflow: hidden;   /* children manage their own scroll */
    min-height: 0;
}

/* Scrollable content — name, email, language flags */
.ssw-onboarding-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px 10px;
    min-height: 0;
}
.ssw-onboarding-scroll::-webkit-scrollbar       { width: 4px; }
.ssw-onboarding-scroll::-webkit-scrollbar-track { background: transparent; }
.ssw-onboarding-scroll::-webkit-scrollbar-thumb { background: #d0d0e0; border-radius: 10px; }

/* Sticky footer — always pinned at the bottom */
.ssw-onboarding-footer {
    padding: 10px 18px 18px;
    background: #fff;
    border-top: 1px solid #f0f0f8;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.05);
    flex-shrink: 0;
}

.ssw-chatbot-onboarding h3 {
    margin: 0 0 4px;
    font-size: 17px; font-weight: 700;
    color: #1a1a2e;
}
.ssw-onboarding-sub {
    margin: 0 0 14px;
    font-size: 13px;
    color: #6b6b80;
    line-height: 1.5;
}
.ssw-onboarding-label {
    display: block;
    margin: 10px 0 5px;
    font-size: 12px; font-weight: 600;
    color: #3a3a4e;
}
.ssw-onboarding-input {
    width: 100%;
    padding: 10px 13px;
    border: 1.5px solid #e2e2ec;
    border-radius: 10px;
    font-size: 14px;
    color: #1a1a2e;
    background: #fff;
    box-sizing: border-box;
    transition: border-color 0.18s ease;
}
.ssw-onboarding-input:focus {
    outline: none;
    border-color: var(--ssw-primary);
    box-shadow: 0 0 0 3px rgba(108,99,255,0.1);
}

/* Language flags grid */
.ssw-onboarding-langs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
    margin-top: 6px;
}
.ssw-lang-flag {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    background: #f4f4f8;
    border: 1.5px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.ssw-lang-flag:hover        { background: #ececf4; }
.ssw-lang-flag:active       { transform: scale(0.95); }
.ssw-lang-flag-active {
    border-color: var(--ssw-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(108,99,255,0.12);
}
.ssw-lang-flag-emoji { font-size: 20px; line-height: 1; }
.ssw-lang-flag-name  {
    font-size: 9px; font-weight: 600;
    color: #5a5a70;
    text-align: center; line-height: 1.2;
}

.ssw-onboarding-error {
    margin-top: 10px;
    padding: 9px 12px;
    background: #fff0f0;
    border: 1px solid #ffc0c0;
    border-radius: 8px;
    font-size: 12.5px;
    color: #c0392b;
}
.ssw-onboarding-submit {
    margin-top: 0;
    padding: 13px;
    background: var(--ssw-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px; font-weight: 600;
    cursor: pointer;
    transition: background 0.18s, opacity 0.18s;
    width: 100%;
}
.ssw-onboarding-submit:hover    { background: var(--ssw-primary-dark); }
.ssw-onboarding-submit:disabled { opacity: 0.55; cursor: not-allowed; }

/* Chat area */
.ssw-chatbot-chatarea {
    display: flex; flex-direction: column;
    flex: 1; min-height: 0;
    background: var(--ssw-bg-chat);
}

@media (max-width: 600px) {
    .ssw-onboarding-langs { grid-template-columns: repeat(4,1fr); gap: 6px; }
    .ssw-lang-flag-name   { font-size: 8.5px; }
    .ssw-onboarding-input { font-size: 16px; /* Cegah zoom iOS */ }
}

/* ================================================
   v2.4.0 — Satisfaction Rating
   ================================================ */

.ssw-rating-box {
    background: #f4f4f8;
    border: 1px solid #e2e2ec;
    border-radius: 12px;
    padding: 16px 14px;
    margin: 10px 0;
    text-align: center;
}

.ssw-rating-title {
    font-size: 13.5px;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 12px;
}

.ssw-rating-emojis {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.ssw-rating-emoji {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: #fff;
    border: 1.5px solid #e2e2ec;
    border-radius: 10px;
    padding: 9px 12px;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.1s ease;
    flex: 1;
}

.ssw-rating-emoji:hover {
    border-color: var(--ssw-primary, #6C63FF);
}

.ssw-rating-emoji:active {
    transform: scale(0.96);
}

.ssw-rating-emoji-active {
    border-color: var(--ssw-primary, #6C63FF);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.12);
}

.ssw-rating-emoji-char {
    font-size: 26px;
    line-height: 1;
}

.ssw-rating-emoji-label {
    font-size: 10.5px;
    font-weight: 600;
    color: #5a5a70;
}

.ssw-rating-comment {
    width: 100%;
    margin-top: 12px;
    padding: 9px 11px;
    border: 1.5px solid #e2e2ec;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
}

.ssw-rating-comment:focus {
    outline: none;
    border-color: var(--ssw-primary, #6C63FF);
}

.ssw-rating-submit {
    margin-top: 10px;
    padding: 10px 20px;
    background: var(--ssw-primary, #6C63FF);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s ease, opacity 0.18s ease;
}

.ssw-rating-submit:hover {
    background: var(--ssw-primary-dark, #5a52e0);
}

.ssw-rating-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ssw-rating-thanks {
    font-size: 13px;
    font-weight: 600;
    color: #1a7f37;
    padding: 6px 0;
}

.ssw-closing-note {
    text-align: center;
    font-size: 11.5px;
    color: #8a8a9a;
    font-style: italic;
    margin: 10px 0 6px;
    padding: 0 12px;
}

/* ── Start New Chat button (shown after conversation ends) ── */
.ssw-new-chat-btn {
    display: block;
    width: calc(100% - 28px);
    margin: 0 14px 14px;
    padding: 11px 16px;
    background: linear-gradient(135deg, var(--ssw-primary), var(--ssw-primary-dark));
    color: #fff !important;
    border: none;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    font-family: var(--ssw-font);
    cursor: pointer;
    text-align: center;
    transition: opacity 0.18s ease, transform 0.12s ease;
    animation: ssw-msg-in 0.3s ease;
}
.ssw-new-chat-btn:hover  { opacity: 0.88; transform: translateY(-1px); }
.ssw-new-chat-btn:active { transform: scale(0.97); }
