/* =============================================
   STEPIN Live Chat — Frontend Widget
   ============================================= */

/* Bubble button */
.stepin-chat-bubble {
    position: fixed;
    bottom: 24px;
    z-index: 99999;
    cursor: pointer;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    transform: scale(0.5);
}
.stepin-chat-bubble.visible {
    opacity: 1;
    transform: scale(1);
}
.stepin-chat-bubble[data-pos="right"] { right: 24px; }
.stepin-chat-bubble[data-pos="left"] { left: 24px; }

.stepin-chat-bubble-btn {
    width: 60px !important;
    height: 60px !important;
    min-width: 60px !important;
    min-height: 60px !important;
    border-radius: 50% !important;
    background: #f5a623 !important;
    background-color: #f5a623 !important;
    border: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25) !important;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    line-height: 1;
}
.stepin-chat-bubble-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}
.stepin-chat-bubble-btn svg { color: #fff; }

/* Notification dot */
.stepin-chat-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #ff3b30;
    border-radius: 50%;
    border: 3px solid #fff;
    display: none;
    animation: stepin-dot-pulse 2s infinite;
}
.stepin-chat-dot.visible { display: block; }

@keyframes stepin-dot-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Hint tooltip */
.stepin-chat-hint {
    position: absolute;
    bottom: 70px;
    right: 0;
    background: #fff;
    color: #1a1a1a;
    padding: 10px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(8px);
    transition: all 0.3s ease;
    pointer-events: none;
}
.stepin-chat-hint.visible {
    opacity: 1;
    transform: translateY(0);
}
.stepin-chat-hint::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 24px;
    width: 12px;
    height: 12px;
    background: #fff;
    transform: rotate(45deg);
    box-shadow: 2px 2px 4px rgba(0,0,0,0.05);
}
[data-pos="left"] .stepin-chat-hint {
    right: auto;
    left: 0;
}
[data-pos="left"] .stepin-chat-hint::after {
    right: auto;
    left: 24px;
}

/* ── Chat Window ── */
.stepin-chat-window {
    position: fixed;
    bottom: 96px;
    z-index: 99999;
    width: 380px;
    max-height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
    pointer-events: none;
}
.stepin-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.stepin-chat-window[data-pos="right"] { right: 24px; }
.stepin-chat-window[data-pos="left"] { left: 24px; }

/* Header */
.stepin-chat-header {
    background: #12203b;
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.stepin-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}
.stepin-chat-header-info { flex: 1; min-width: 0; }
.stepin-chat-header-name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}
.stepin-chat-header-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
}
.stepin-chat-online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
}
.stepin-chat-close,
.stepin-chat-close:focus,
.stepin-chat-close:active,
.stepin-chat-close:visited {
    background: none !important;
    background-color: transparent !important;
    border: none !important;
    color: #ff4444 !important;
    cursor: pointer;
    padding: 4px !important;
    opacity: 0.85;
    transition: opacity 0.2s;
    box-shadow: none !important;
    outline: none !important;
    min-width: 0 !important;
    min-height: 0 !important;
    width: auto !important;
    height: auto !important;
    line-height: 1 !important;
}
.stepin-chat-close:hover { opacity: 1; }
.stepin-chat-close svg {
    stroke: #ff4444 !important;
    color: #ff4444 !important;
}

/* Messages area */
.stepin-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 200px;
    max-height: 300px;
    background: #f8f9fa;
}

.stepin-chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}
.stepin-chat-msg-manager {
    background: #fff;
    color: #1a1a1a;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.stepin-chat-msg-visitor {
    background: var(--stepin-chat-color, #0088cc);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

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

/* Input area */
.stepin-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    background: #fff;
}
.stepin-chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}
.stepin-chat-input:focus {
    border-color: var(--stepin-chat-color, #0088cc);
}
.stepin-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--stepin-chat-color, #0088cc);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
.stepin-chat-send:hover { opacity: 0.85; }
.stepin-chat-send svg { color: #fff; }

/* ── Pre-chat form ── */
.stepin-chat-form {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
    flex: 1;
}
.stepin-chat-form-title {
    font-size: 14px;
    font-weight: 500;
    color: #1a1a1a;
    margin-bottom: 4px;
}
.stepin-chat-form input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
}
.stepin-chat-form input:focus {
    border-color: var(--stepin-chat-color, #0088cc);
}
.stepin-chat-form-btn,
.stepin-chat-form-btn:focus,
.stepin-chat-form-btn:active,
.stepin-chat-form-btn:visited {
    width: 100% !important;
    padding: 12px !important;
    background: #12203b !important;
    background-color: #12203b !important;
    color: #fff !important;
    border: none !important;
    border-radius: 8px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    cursor: pointer;
    transition: opacity 0.2s;
    font-family: inherit;
    box-shadow: none !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    line-height: 1.4 !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}
.stepin-chat-form-btn:hover {
    opacity: 0.85;
    background: #12203b !important;
    color: #fff !important;
}

/* Typing indicator */
.stepin-chat-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: #fff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}
.stepin-chat-typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ccc;
    margin: 0 1px;
    animation: stepin-typing 1.4s infinite;
}
.stepin-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.stepin-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes stepin-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Hide chat bubble when cart sidebar is open */
.wd-side-hidden.wd-opened ~ #stepin-chat-root .stepin-chat-bubble,
body.wd-opened-side-cart #stepin-chat-root .stepin-chat-bubble {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Mobile — above sticky toolbar (55px + labels) */
@media (max-width: 1024px) {
    .stepin-chat-bubble {
        bottom: 80px;
    }
    .stepin-chat-bubble[data-pos="right"] { right: 16px; }
    .stepin-chat-bubble[data-pos="left"] { left: 16px; }
    .stepin-chat-window {
        width: calc(100vw - 16px);
        right: 8px !important;
        left: 8px !important;
        bottom: 148px;
        max-height: 60vh;
    }
}

/* Hide on mobile if configured */
.stepin-chat-hide-mobile .stepin-chat-bubble,
.stepin-chat-hide-mobile .stepin-chat-window {
    display: none !important;
}
@media (min-width: 769px) {
    .stepin-chat-hide-mobile .stepin-chat-bubble,
    .stepin-chat-hide-mobile .stepin-chat-window {
        display: flex !important;
    }
}
