/**
 * Salt Seller Chat Widget Styles
 * Version: 1.0.0
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Chat Button */
#chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: white;
    border: 3px solid #1e293b;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    overflow: hidden;
    padding: 8px;
}

#chat-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    background: #f8fafc;
}

#chat-button .logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

#chat-button.open .logo-img {
    display: none;
}

#chat-button svg {
    display: none;
}

#chat-button .close-icon {
    display: none;
    width: 28px;
    height: 28px;
    stroke: #1e293b;
    stroke-width: 2.5;
}

#chat-button.open .close-icon {
    display: block;
}

/* Chat Container */
#chat-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: none;
    flex-direction: column;
    z-index: 9998;
    overflow: hidden;
    touch-action: auto; /* Re-enable touch events inside chat container */
}

#chat-container.open {
    display: flex;
}

/* Close button in header */
#chat-close {
    position: absolute;
    top: 8px;
    right: 16px;
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 24px;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 1;
    transition: color 0.2s;
    z-index: 10;
}

#chat-close:hover {
    color: #64748b;
}

/* Chat Header */
#chat-header {
    background: white;
    padding: 10px 20px;
    border-bottom: 2px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 12px;
}

#chat-header img {
    max-width: 50px;
    height: auto;
    flex-shrink: 0;
}

#chat-header h3 {
    font-size: 13px;
    margin: 0;
    color: #1e293b;
    font-weight: 600;
    line-height: 1.3;
    flex: 1;
}

/* Chat Messages */
#chat-messages {
    flex: 1;
    min-height: 100px; /* Ensure it doesn't collapse when empty */
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    overscroll-behavior: contain; /* Prevent scroll chaining to parent/body */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.message {
    margin-bottom: 16px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.bot {
    text-align: left;
}

.message.user {
    text-align: right;
}

.message-bubble {
    display: inline-block;
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
}

.message.bot .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
}

.message.user .message-bubble {
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 4px;
}

/* Button Grid */
.button-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 12px;
}

.option-button {
    background: white;
    border: 2px solid #2563eb;
    color: #2563eb;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    text-align: left;
    font-weight: 500;
}

.option-button:hover {
    background: #2563eb;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

/* Input Area */
#chat-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-wrap: nowrap !important;
    gap: 8px;
    align-items: center;
    position: relative;
}

/* Honeypot field - ensure it doesn't affect layout */
#salt-chat-website {
    position: absolute !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0;
    pointer-events: none;
}

#chat-input {
    flex: 1 1 auto;
    min-width: 100px;
    max-width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

#chat-input:focus {
    outline: none;
    border-color: #2563eb;
}

#chat-input::placeholder {
    color: #999;
}

#send-button {
    height: 44px;
    min-width: 60px;
    padding: 0 20px;
    background: #2563eb;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    color: white;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
}

#send-button:hover {
    background: #1d4ed8;
    transform: scale(1.05);
}

.typing-indicator {
    display: inline-block;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2563eb;
    margin: 0 2px;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Success Message */
.success-message {
    text-align: center;
    padding: 20px;
}

.success-message svg {
    width: 64px;
    height: 64px;
    stroke: #10b981;
    margin-bottom: 16px;
}

.success-message h4 {
    color: #10b981;
    margin-bottom: 8px;
    font-size: 18px;
}

.success-message p {
    color: #666;
    font-size: 14px;
    line-height: 1.5;
}

/* Loading Spinner */
.loading-message {
    text-align: center;
    padding: 30px 20px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-message p {
    color: #666;
    font-size: 14px;
}

/* Skip Button */
.skip-button {
    background: white;
    border: 2px solid #2563eb;
    color: #2563eb;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    text-align: left;
    font-weight: 500;
    margin-top: 8px;
    width: 100%;
}

.skip-button:hover {
    background: #2563eb;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

/* Welcome Bubble */
#welcome-bubble {
    position: fixed;
    bottom: 90px;
    right: 20px;
    background: white;
    border: 2px solid #1e293b;
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-width: 200px;
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#welcome-bubble.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    animation: slideInBounce 0.6s ease-out;
}

#welcome-bubble::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 20px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #1e293b;
}

#welcome-bubble p {
    margin: 0;
    font-size: 14px;
    color: #1e293b;
    line-height: 1.4;
}

#welcome-bubble .close-welcome {
    position: absolute;
    top: 4px;
    right: 6px;
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    width: 20px;
    height: 20px;
    line-height: 1;
}

#welcome-bubble .close-welcome:hover {
    color: #64748b;
}

@keyframes slideInBounce {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.8);
    }
    60% {
        opacity: 1;
        transform: translateY(-5px) scale(1.05);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Scrollbar */
#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Lock body scroll when chat is open on mobile */
body.salt-chat-open {
    overflow: hidden !important;
    /* Note: Don't use position:fixed or touch-action:none here - they cause issues */
}

/* Mobile Responsive - Full Screen Chat */
@media (max-width: 480px) {
    #chat-container {
        /* Full screen on mobile - use dvh for dynamic viewport (accounts for browser UI) */
        width: 100vw;
        height: 100dvh; /* Dynamic viewport height - adjusts for browser bars */
        height: 100vh; /* Fallback for older browsers */
        max-height: 100dvh;
        max-height: -webkit-fill-available; /* iOS Safari fallback */
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        border-radius: 0; /* Remove rounded corners for full-screen */
        position: fixed;
        /* Ensure solid background - prevents seeing through */
        background: #ffffff;
    }

    #chat-container.open {
        display: flex;
    }

    /* Ensure messages area has solid background */
    #chat-container #chat-messages {
        background: #f8f9fa;
    }

    /* Hide the floating button when chat is open */
    #chat-button.open {
        display: none;
    }

    #chat-button {
        right: 10px;
        bottom: 10px;
    }

    /* Adjust input area for keyboard and safe areas */
    #chat-input-area {
        padding: 12px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        background: #ffffff; /* Solid background for input area */
    }

    /* Adjust header for notched phones */
    #chat-header {
        padding-top: max(10px, env(safe-area-inset-top));
        background: #ffffff; /* Solid background for header */
    }

    #welcome-bubble {
        right: 10px;
        bottom: 80px;
        max-width: calc(100vw - 100px);
    }
}

/* Reset Button */
#reset-chat {
    padding: 10px 16px;
    background: #f1f5f9;
    border: 2px solid #cbd5e1;
    color: #475569;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    margin: 12px 16px;
    transition: all 0.2s;
    display: none;
    font-weight: 500;
}

#reset-chat.show {
    display: block;
}

#reset-chat:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

/* Back Button */
.back-button {
    background: #f1f5f9;
    border: 2px solid #cbd5e1;
    color: #475569;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    margin-top: 8px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.back-button:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
    transform: translateY(-1px);
}

.back-button svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    stroke-width: 2;
}

/* Toast Notification - Backup confirmation outside chat */
.salt-chat-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #10b981;
    color: white;
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(16, 185, 129, 0.3);
    z-index: 99999;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    font-weight: 500;
    max-width: 400px;
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    animation: toastSlideIn 0.4s ease-out forwards;
}

.salt-chat-toast.toast-hiding {
    animation: toastSlideOut 0.3s ease-in forwards;
}

.salt-chat-toast-icon {
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.salt-chat-toast-icon::after {
    content: '✓';
    color: #10b981;
    font-size: 14px;
    font-weight: bold;
}

.salt-chat-toast-content {
    flex: 1;
}

.salt-chat-toast-title {
    font-weight: 600;
    margin-bottom: 2px;
}

.salt-chat-toast-message {
    font-size: 13px;
    opacity: 0.9;
}

.salt-chat-toast-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    opacity: 0.7;
    transition: opacity 0.2s;
    line-height: 1;
}

.salt-chat-toast-close:hover {
    opacity: 1;
}

@keyframes toastSlideIn {
    0% {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toastSlideOut {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
}

/* Mobile responsive for toast */
@media (max-width: 480px) {
    .salt-chat-toast {
        left: 10px;
        right: 10px;
        max-width: none;
    }
}

/* Google Places Autocomplete Dropdown - must appear above chat widget */
.pac-container {
    z-index: 99999 !important;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    border: 1px solid #e0e0e0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin-top: 4px;
}

.pac-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 14px;
    border-top: 1px solid #f0f0f0;
}

.pac-item:first-child {
    border-top: none;
}

.pac-item:hover {
    background-color: #f5f5f5;
}

.pac-item-selected {
    background-color: #e8f0fe;
}

.pac-icon {
    margin-right: 8px;
}

.pac-item-query {
    font-weight: 500;
    color: #1a1a1a;
}

/* Mobile: Style the dropdown but let Google handle positioning */
@media (max-width: 480px) {
    .pac-container {
        /* Let Google handle positioning - don't override with position:fixed */
        max-height: 200px;
        overflow-y: auto;
    }
}
