/* Chat Widget Styles */
.chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10001;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    pointer-events: none; /* Allow clicks to pass through container when chat is closed */
}

.chat-widget-container > * {
    pointer-events: auto; /* Re-enable clicks on child elements (button and window) */
}

.chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #0d9488; /* Teal-600 */
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background-color 0.2s;
}

.chat-button:hover {
    transform: scale(1.05);
    background-color: #0f766e; /* Teal-700 */
}

.chat-button svg {
    width: 30px;
    height: 30px;
}

.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 100px);
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none; /* Don't block clicks when closed */
    transition: opacity 0.3s, transform 0.3s;
    z-index: 10001;
}

/* Ensure chat messages area can scroll but input stays fixed */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0; /* Allow flexbox to shrink */
}

.chat-input-area {
    flex-shrink: 0; /* Never shrink input area */
}

.chat-window.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all; /* Allow clicks when open */
}

.chat-header {
    background-color: #0d9488;
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #0f766e;
}

.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.close-button {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: #f8fafc;
    min-height: 0; /* Critical: allows flexbox to shrink and enable scrolling */
}

.message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.4;
}

.message.user {
    align-self: flex-end;
    background-color: #0d9488;
    color: white;
    border-bottom-right-radius: 2px;
}

.message.assistant {
    align-self: flex-start;
    background-color: #e2e8f0;
    color: #1e293b;
    border-bottom-left-radius: 2px;
}

.message.assistant p {
    margin: 4px 0;
}

.message.assistant ul,
.message.assistant ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message.assistant li {
    margin: 4px 0;
}

.message.assistant code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
}

.message.assistant a {
    color: #0d9488;
    text-decoration: underline;
}

.message.assistant a:hover {
    color: #14b8a6;
}

.message.assistant strong {
    font-weight: 600;
}

.message.assistant em {
    font-style: italic;
}

.message.assistant hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.2);
    margin: 12px 0;
}

.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
    margin: 8px 0 4px;
    font-weight: 600;
}

.chat-input-area {
    padding: 16px;
    background-color: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 8px;
    flex-shrink: 0 !important; /* Never shrink - always visible */
    flex-grow: 0; /* Don't grow */
    min-height: 60px; /* Ensure minimum height */
    width: 100%;
}

.chat-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    outline: none;
    font-size: 0.95rem;
    color: #1e293b;
    background-color: white;
}

.chat-input::placeholder {
    color: #94a3b8;
}

.chat-input:focus {
    border-color: #0d9488;
}

.send-button {
    background-color: #0d9488;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.send-button:hover {
    background-color: #0f766e;
}

.send-button:disabled {
    background-color: #94a3b8;
    cursor: not-allowed;
    opacity: 0.6;
}

.chat-input:disabled {
    opacity: 0.7;
    background-color: #f1f5f9;
}

/* Ensure input area is always visible on mobile */
@media (max-width: 480px) {
    .chat-input-area {
        position: relative;
        z-index: 10004;
        padding: 12px;
        min-height: 60px;
    }
    
    .chat-input {
        min-height: 40px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

.typing-indicator {
    font-size: 0.8rem;
    color: #64748b;
    margin-left: 10px;
    margin-bottom: 5px;
    display: none;
}

.typing-indicator.active {
    display: block;
}

.quick-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    margin-bottom: 8px;
}

.quick-btn {
    background-color: #e2e8f0;
    color: #1e293b;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-btn:hover {
    background-color: #0d9488;
    color: white;
    border-color: #0d9488;
}

.action-btn {
    margin-top: 12px;
    padding: 10px 16px;
    background-color: #0d9488;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.action-btn:hover {
    background-color: #0f766e;
}

.send-estimate-btn {
    display: inline-block;
}

@media (max-width: 480px) {
    .chat-widget-container {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        z-index: 10001;
    }
    
    .chat-button {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        z-index: 10002;
    }
    
    /* Hide chat button when chat is open on mobile */
    .chat-button.chat-open {
        display: none !important;
    }
    
    .chat-window {
        position: fixed;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        z-index: 10003;
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Prevent overflow */
    }
    
    /* Ensure messages area scrolls but input stays fixed */
    .chat-messages {
        flex: 1;
        min-height: 0; /* Critical for flexbox scrolling */
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        padding-bottom: 8px;
    }
    
    /* Input area always visible at bottom - never shrinks */
    .chat-input-area {
        flex-shrink: 0 !important; /* Never shrink */
        flex-grow: 0; /* Don't grow */
        position: relative;
        z-index: 10004;
        background-color: white;
        border-top: 1px solid #e2e8f0;
        padding: 12px;
        min-height: 60px;
        display: flex;
        align-items: center;
        width: 100%;
    }
    
    .chat-input {
        min-height: 40px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .quick-btn {
        font-size: 0.8rem;
        padding: 5px 10px;
    }
}

