/**
 * Chat Window - Premium WOW design
 * Sleek, modern, impressive
 */

/* ===== Container ===== */
.sh-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1001;
    width: 320px;
    max-width: calc(100vw - 32px);
    display: flex;
    flex-direction: column;
    background: linear-gradient(165deg, #ffffff 0%, #f8fafc 100%);
    border-radius: 10px;
    box-shadow:
        0 25px 50px -12px rgba(0, 0, 0, 0.25),
        0 0 0 1px rgba(0, 0, 0, 0.03),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition:
        opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
        visibility 0.3s;
}

.sh-chat.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ===== Header ===== */
.sh-chat__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    position: relative;
    border-radius: 10px 10px 0 0;
}

.sh-chat__header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
}

.sh-chat__header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.sh-chat__header-info {
    flex: 1;
    min-width: 0;
}

.sh-chat__header-name {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
    line-height: 1.2;
}

.sh-chat__header .sh-chat__status {
    margin-top: 2px;
}

.sh-chat__status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.8);
}

.sh-chat__status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    position: relative;
    animation: sh-chat-pulse-dot 2s ease-in-out infinite;
}

.sh-chat__status-dot::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #10b981;
    transform: translate(-50%, -50%);
    animation: sh-chat-pulse-ring 2s ease-out infinite;
}

@keyframes sh-chat-pulse-dot {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    50% { 
        transform: scale(1.1);
        box-shadow: 0 0 8px 2px rgba(16, 185, 129, 0.3);
    }
}

@keyframes sh-chat-pulse-ring {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }
    100% {
        transform: translate(-50%, -50%) scale(2.5);
        opacity: 0;
    }
}

/* Clear history button - outside chat on the left */
.sh-chat__clear-outside {
    position: absolute;
    left: -44px;
    top: 10px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(30, 41, 59, 0.9);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.sh-chat__clear-outside:hover {
    background: rgba(239, 68, 68, 0.8);
    transform: scale(1.1);
}

.sh-chat__clear-outside svg {
    width: 16px;
    height: 16px;
    stroke: rgba(255, 255, 255, 0.85);
}

/* Call button in header */
.sh-chat__call-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-right: 8px;
}

.sh-chat__call-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.sh-chat__call-btn svg {
    width: 16px;
    height: 16px;
    stroke: #ffffff;
}

.sh-chat__close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.sh-chat__close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sh-chat__close svg {
    width: 14px;
    height: 14px;
    stroke: rgba(255, 255, 255, 0.8);
}

/* ===== Messages Area ===== */
.sh-chat__messages {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 20px 16px;
    min-height: 300px;
    max-height: 380px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
}

.sh-chat__messages::-webkit-scrollbar {
    width: 6px;
}

.sh-chat__messages::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.sh-chat__messages::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 3px;
}

.sh-chat__messages::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Message bubbles */
.sh-chat__message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 20px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
}

.sh-chat__message--incoming {
    align-self: flex-start;
    background: #fff;
    color: #1e293b;
    border-bottom-left-radius: 6px;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.04),
        0 0 0 1px rgba(0, 0, 0, 0.03);
}

/* Manager message with avatar */
.sh-chat__message-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    align-self: flex-start;
    width: 100%;
    max-width: 95%;
}

.sh-chat__manager-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid #e2e8f0;
}

.sh-chat__message-row .sh-chat__message {
    max-width: none;
    flex: 1;
    background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
    border: 1px solid #bbf7d0;
}

.sh-chat__manager-name {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #059669;
    margin-bottom: 4px;
}

.sh-chat__message--outgoing {
    align-self: flex-end;
    background: rgba(254, 195, 151, 0.6);
    color: #1e293b;
    border-bottom-right-radius: 6px;
    border: 1px solid rgba(254, 184, 130, 0.8);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.sh-chat__message--error {
    opacity: 0.6;
    position: relative;
}

.sh-chat__message--error::after {
    content: '⚠';
    position: absolute;
    right: -20px;
    top: 50%;
    transform: translateY(-50%);
    color: #ef4444;
    font-size: 14px;
}

.sh-chat__message-time {
    display: block;
    margin-top: 6px;
    font-size: 10px;
    opacity: 0.5;
}

/* Welcome message */
.sh-chat__welcome {
    text-align: center;
    padding: 40px 24px;
}

.sh-chat__welcome-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border-radius: 14px;
}

.sh-chat__welcome-icon svg {
    width: 24px;
    height: 24px;
    stroke: #64748b;
}

.sh-chat__welcome-title {
    font-size: 17px;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 8px 0;
    letter-spacing: -0.02em;
}

.sh-chat__welcome-text {
    font-size: 13px;
    color: #64748b;
    margin: 0;
    line-height: 1.6;
}

/* File attachment preview in messages */
.sh-chat__attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    margin-top: 8px;
    font-size: 11px;
}

.sh-chat__message--outgoing .sh-chat__attachment {
    background: rgba(255, 255, 255, 0.15);
}

.sh-chat__attachment-icon {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    opacity: 0.7;
}

.sh-chat__attachment-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Input Area ===== */
.sh-chat__input-area {
    padding: 16px;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    border-radius: 0 0 10px 10px;
}

/* Mango Brand Logo (Jivo style) */
.sh-chat__brand {
    display: flex;
    justify-content: center;
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.sh-chat__brand-logo {
    width: 80px;
    height: 28px;
}

/* Attachment preview bar */
.sh-chat__attachments-preview {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.sh-chat__attachments-preview.has-files {
    display: flex;
}

.sh-chat__file-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 11px;
    color: #475569;
}

.sh-chat__file-preview-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sh-chat__file-remove {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.sh-chat__file-remove:hover {
    opacity: 1;
}

.sh-chat__file-remove svg {
    width: 12px;
    height: 12px;
    stroke: #64748b;
}

/* Input row */
.sh-chat__input-row {
    display: flex;
    align-items: flex-end;
    gap: 0;
}

.sh-chat__input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    background: #f1f5f9;
    border-radius: 24px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    padding-right: 6px;
}

.sh-chat__input-wrapper:focus-within {
    background: #fff;
    border-color: #94a3b8;
}

/* Override global green focus styles for chat */
[data-page="shop"] .sh-chat input:focus-visible,
[data-page="shop"] .sh-chat textarea:focus-visible,
[data-page="shop"] .sh-chat button:focus-visible,
[data-page="shop"] .sh-chat *:focus-visible {
    outline: none !important;
}

.sh-chat__input {
    flex: 1;
    padding: 10px 14px;
    border: none;
    background: transparent;
    font-size: 13px;
    line-height: 1.4;
    color: #1e293b;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    font-family: inherit;
}

.sh-chat__input::placeholder {
    color: #94a3b8;
}

.sh-chat__input:focus {
    outline: none;
}

/* Action buttons */
.sh-chat__actions {
    display: flex;
    align-items: center;
    gap: 0;
    padding-right: 4px;
}

.sh-chat__action-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s;
}

.sh-chat__action-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.sh-chat__action-btn:hover svg {
    stroke: #1e293b;
}

.sh-chat__action-btn svg {
    width: 20px;
    height: 20px;
    stroke: #94a3b8;
    transition: all 0.2s;
}

/* Hidden file input */
.sh-chat__file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Send button */
.sh-chat__send {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: #1e293b;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.sh-chat__send:hover {
    background: #334155;
}

.sh-chat__send:active {
    background: #0f172a;
}

.sh-chat__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sh-chat__send svg {
    width: 14px;
    height: 14px;
    fill: #fff;
    margin-left: 1px;
}

/* ===== Emoji Picker ===== */
.sh-chat__emoji-picker {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    width: 200px;
    background: #fff;
    border-radius: 12px;
    box-shadow:
        0 12px 32px rgba(0, 0, 0, 0.12),
        0 0 0 1px rgba(0, 0, 0, 0.04);
    padding: 8px;
    display: none;
    z-index: 10;
}

.sh-chat__emoji-picker.is-open {
    display: block;
    animation: sh-chat-emoji-in 0.2s ease;
}

@keyframes sh-chat-emoji-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.sh-chat__emoji-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
}

.sh-chat__emoji {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    padding: 4px;
    transition: all 0.15s;
}

.sh-chat__emoji img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.sh-chat__emoji:hover {
    background: #f1f5f9;
    transform: scale(1.1);
}

/* ===== Typing indicator ===== */
.sh-chat__typing-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 0 16px;
    margin-bottom: 8px;
}

.sh-chat__typing {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #fff;
    border-radius: 20px;
    border-bottom-left-radius: 6px;
    align-self: flex-start;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.04),
        0 0 0 1px rgba(0, 0, 0, 0.03);
}

.sh-chat__typing.is-visible {
    display: flex;
}

.sh-chat__typing-dots {
    display: flex;
    gap: 4px;
}

.sh-chat__typing-dot {
    width: 6px;
    height: 6px;
    background: #cbd5e1;
    border-radius: 50%;
    animation: sh-chat-typing 1.4s ease-in-out infinite;
}

.sh-chat__typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.sh-chat__typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes sh-chat-typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    .sh-chat {
        transition: opacity 0.1s, visibility 0.1s;
        transform: none;
    }
    .sh-chat.is-open {
        transform: none;
    }
    .sh-chat__typing-dot {
        animation: none;
        opacity: 0.6;
    }
    .sh-chat__status-dot {
        animation: none;
    }
    .sh-chat__send:hover,
    .sh-chat__emoji:hover {
        transform: none;
    }
    .sh-chat__emoji-picker.is-open {
        animation: none;
    }
}

/* ===== Quick Action Buttons ===== */
.sh-chat__quick-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 16px 16px;
}

.sh-chat__quick-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    color: #1e293b;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.sh-chat__quick-btn:hover {
    border-color: #f97316;
    background: #fff7ed;
    color: #ea580c;
}

.sh-chat__quick-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    stroke: #64748b;
    transition: stroke 0.2s;
}

.sh-chat__quick-btn:hover svg {
    stroke: #f97316;
}

/* ===== Name Form ===== */
.sh-chat__name-form {
    display: flex;
    gap: 6px;
    padding: 4px 16px 12px;
    margin-left: 50px;
    max-width: calc(100% - 66px);
    box-sizing: border-box;
}

.sh-chat__name-input {
    flex: 1;
    min-width: 120px;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    color: #1e293b;
    background: #fff;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.sh-chat__name-input:focus {
    outline: none;
    border-color: #94a3b8;
}

.sh-chat__name-input::placeholder {
    color: #94a3b8;
}

.sh-chat__name-submit {
    padding: 8px 14px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #475569;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.sh-chat__name-submit:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #1e293b;
}

/* ===== Callback Modal ===== */
.sh-chat__callback-modal {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    border-radius: inherit;
}

.sh-chat__callback-modal.is-open {
    opacity: 1;
    visibility: visible;
}

.sh-chat__callback-content {
    background: #ffffff;
    border-radius: 16px;
    padding: 24px 20px;
    margin: 16px;
    max-width: 300px;
    width: 100%;
    text-align: center;
    position: relative;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.sh-chat__callback-modal.is-open .sh-chat__callback-content {
    transform: scale(1) translateY(0);
}

.sh-chat__callback-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: #f1f5f9;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sh-chat__callback-close:hover {
    background: #e2e8f0;
}

.sh-chat__callback-close svg {
    width: 14px;
    height: 14px;
    stroke: #64748b;
}

.sh-chat__callback-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: sh-chat-phone-ring 1.5s ease-in-out infinite;
}

@keyframes sh-chat-phone-ring {
    0%, 100% { transform: rotate(0deg); }
    10% { transform: rotate(-10deg); }
    20% { transform: rotate(10deg); }
    30% { transform: rotate(-10deg); }
    40% { transform: rotate(10deg); }
    50% { transform: rotate(0deg); }
}

.sh-chat__callback-icon svg {
    width: 28px;
    height: 28px;
    stroke: #ffffff;
}

.sh-chat__callback-title {
    font-size: 18px;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 6px 0;
}

.sh-chat__callback-subtitle {
    font-size: 13px;
    color: #64748b;
    margin: 0 0 20px 0;
    line-height: 1.4;
}

.sh-chat__callback-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sh-chat__callback-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    text-align: center;
    transition: all 0.2s ease;
    outline: none;
}

.sh-chat__callback-input:focus {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.sh-chat__callback-input::placeholder {
    color: #94a3b8;
}

.sh-chat__callback-consent {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    text-align: left;
    font-size: 11px;
    color: #64748b;
    line-height: 1.4;
    cursor: pointer;
}

.sh-chat__callback-consent input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-top: 1px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #10b981;
}

.sh-chat__callback-consent a {
    color: #10b981;
    text-decoration: none;
}

.sh-chat__callback-consent a:hover {
    text-decoration: underline;
}

.sh-chat__callback-submit {
    width: 100%;
    padding: 14px 20px;
    border: none;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sh-chat__callback-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.35);
}

.sh-chat__callback-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ===== Mobile ===== */
@media (max-width: 599px) {
    .sh-chat {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: auto;
        width: 100%;
        max-width: 100%;
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
        z-index: 1001;
    }

    .sh-chat__header {
        border-radius: 20px 20px 0 0;
        padding: 14px 16px;
    }

    .sh-chat__input-area {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .sh-chat__messages {
        max-height: calc(85vh - 140px);
        min-height: 200px;
    }
    
    /* Ensure chat is above the floating button */
    .sh-chat.is-open ~ .sh-chat-btn {
        opacity: 0;
        pointer-events: none;
    }
}
