/* Main Container */
#ai-chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    left: auto;
    z-index: 9999;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    --ai-chat-safe-area: env(safe-area-inset-bottom, 0px);
}

/* Toggle Button */
#ai-chat-toggle-btn {
    background-color: #ffffff;
    color: #2563eb;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    width: auto;
    height: auto;
    padding: 12px 16px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    transition: transform 0.3s ease, box-shadow 0.3s;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    line-height: 1.4;
    position: relative;
    z-index: 3;
}

#ai-chat-toggle-btn:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.ai-chat-text {
    display: inline-block;
}

.ai-chat-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #2563eb;
    color: white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

/* Backdrop */
#ai-chat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1;
}

#ai-chat-backdrop.hidden {
    display: none;
}

/* Chat Window */
#ai-chat-window {
    position: fixed;
    bottom: calc(80px + var(--ai-chat-safe-area));
    right: 20px;
    width: 350px;
    max-width: calc(100vw - 20px);
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform-origin: bottom right;
    z-index: 2;
}

#ai-chat-window.hidden {
    display: none;
}

/* Header */
.ai-chat-header {
    background-color: #2563eb;
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    background: none !important;
    color: inherit;
    padding: 0;
}

#ai-chat-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

/* Messages Area */
#ai-chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Message Bubbles */
.ai-chat-message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.ai-chat-message a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}

.ai-chat-message.bot {
    background-color: #e2e8f0;
    color: #334155;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.ai-chat-message.user {
    background-color: #2563eb;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

/* Input Area */
.ai-chat-input-area {
    padding: 15px;
    border-top: 1px solid #e2e8f0;
    background: white;
    display: flex;
    gap: 10px;
}

#ai-chat-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
}

#ai-chat-input:focus {
    border-color: #2563eb;
}

#ai-chat-send-btn {
    background-color: #2563eb;
    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;
}

#ai-chat-send-btn:hover {
    background-color: #1d4ed8;
}

#ai-chat-send-btn:disabled {
    background-color: #94a3b8;
    cursor: not-allowed;
}

body.ai-chat-open {
    overflow: hidden;
}

body.ai-chat-open #ai-chat-toggle-btn {
    display: none;
}

/* Responsive - Mobile */
@media (max-width: 480px) {
    #ai-chat-widget-container {
        right: 12px;
        left: 12px;
        bottom: 12px;
        width: auto;
        max-width: none;
    }

    #ai-chat-toggle-btn {
        width: auto;
        max-width: min(200px, 85%);
        margin-left: auto;
        font-size: 12px;
        padding: 8px 10px;
        gap: 8px;
        justify-content: flex-start;
    }

    .ai-chat-text {
        font-size: 11px;
    }

    .ai-chat-icon-wrapper {
        width: 28px;
        height: 28px;
    }

    #ai-chat-window {
        left: 12px;
        right: 12px;
        bottom: calc(12px + var(--ai-chat-safe-area));
        width: auto;
        height: min(70vh, 560px);
        max-height: calc(100vh - 40px);
        transform-origin: bottom center;
        max-width: none;
        margin: 0 auto;
        border-radius: 16px 16px 12px 12px;
    }

    .ai-chat-header h3 {
        font-size: 14px;
    }

    #ai-chat-messages {
        padding: 12px;
    }

    .ai-chat-input-area {
        padding: 12px;
        padding-bottom: calc(12px + var(--ai-chat-safe-area));
    }
}
