/**
 * Public CSS for the ItinAI Chatbot plugin.
 * 
 * Implements a Material Design-inspired chatbot UI.
 */

/* CSS Custom Properties (Variables) */
:root {
    /* Default values that will be overridden by inline styles */
    --itinai-font-size: 14px;
    --itinai-title-size: 16px;
    --itinai-font-color: #000000;
    --itinai-title-color: #ffffff;
    --itinai-background-color: #ffffff;
    --itinai-header-color: #2196F3;
    --itinai-button-color: #2196F3;
    --itinai-icon-color: #ffffff;
    --itinai-input-background: #f5f5f5;
    --itinai-input-border: #e0e0e0;
    --itinai-user-message-background: #e3f2fd;
    --itinai-ai-message-background: #f1f1f1;
    --itinai-chat-border-radius: 8px;
    --itinai-container-border-radius: 8px;
    --itinai-input-height: 50px;
    --itinai-input-border-radius: 24px;
}

/* Container */
.itinai-chatbot-container {
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    line-height: 1.5;
    z-index: 9999;
    font-size: var(--itinai-font-size);
    color: var(--itinai-font-color);
}

/* Chatbox */
.itinai-chatbot-box {
    width: 100%;
    display: flex;
    flex-direction: column;
    border-radius: var(--itinai-container-border-radius);
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    background-color: var(--itinai-background-color);
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Chat Header */
.itinai-chatbot-header {
    background-color: var(--itinai-header-color);
    color: var(--itinai-title-color);
    padding: 16px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.itinai-chatbot-header p {
    margin: 0;
    padding: 0;
    font-size: var(--itinai-title-size);
}

/* Messages Container */
.itinai-chatbot-messages {
    padding: 16px;
    overflow-y: auto;
    flex-grow: 1;
    background-color: #f5f5f5;
    scrollbar-width: thin;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.itinai-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.itinai-chatbot-messages::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* Message Bubbles */
.itinai-chatbot-message {
    display: flex;
    margin-bottom: 16px;
    align-items: flex-start;
}

.itinai-chatbot-message.user {
    flex-direction: row-reverse;
}

.itinai-chatbot-bubble {
    border-radius: 18px;
    padding: 12px 16px;
    max-width: 80%;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.itinai-chatbot-bubble.assistant-bubble {
    background-color: var(--itinai-ai-message-background);
    border-top-left-radius: 4px;
    margin-right: 8px;
}

.itinai-chatbot-bubble.user-bubble {
    background-color: var(--itinai-user-message-background);
    border-top-right-radius: 4px;
    margin-left: 8px;
}

.itinai-chatbot-bubble.error-bubble {
    background-color: #ffebee;
    color: #d32f2f;
}

/* Avatars */
.itinai-chatbot-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    overflow: hidden;
    flex-shrink: 0;
}

.itinai-chatbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.itinai-chatbot-message.assistant .itinai-chatbot-avatar {
    margin-right: 8px;
}

.itinai-chatbot-message.user .itinai-chatbot-avatar {
    margin-left: 8px;
}

.itinai-chatbot-avatar.assistant-avatar {
    background-color: rgba(33, 150, 243, 0.1);
    color: var(--itinai-icon-color);
}

.itinai-chatbot-avatar.user-avatar {
    background-color: rgba(227, 242, 253, 0.9);
    color: var(--itinai-icon-color);
}

/* Input Container */
.itinai-chatbot-input-container {
    padding: 16px 20px 16px 16px; /* Increased right padding to prevent clipping */
    background-color: #ffffff;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: flex-end; /* Changed from center to flex-end to align with textarea bottom */
    width: 100%;
    position: relative;
    box-sizing: border-box; /* Ensure padding is included in width calculation */
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}

/* Fix for unwanted WP paragraph tags and gray border */
body > div:nth-child(2) > div:nth-child(1) > div > div > div:nth-child(2) > div > div > div:nth-child(3) {
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    background: transparent !important;
}

/* Fix for WordPress auto-generated paragraph tags */
.itinai-chatbot p:empty {
    display: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.itinai-chatbot p > div {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* Fix for unwanted <br> tags in inputs and buttons */
.itinai-chatbot-input-container br,
.itinai-chatbot input + br,
.itinai-chatbot button + br {
    display: none !important;
}

/* Important: This is the key section that was causing input field styling issues */
.itinai-chatbot-input {
    flex-grow: 1;
    flex-shrink: 1;
    /* Use CSS variables for these styles */
    border: 1px solid var(--itinai-input-border);
    border-radius: var(--itinai-input-border-radius);
    outline: none;
    background: var(--itinai-input-background);
    font-size: var(--itinai-font-size);
    padding: 12px 16px;
    margin-right: 16px;
    color: var(--itinai-font-color);
    min-height: var(--itinai-input-height);
    max-height: 150px;
    overflow-y: auto;
    box-sizing: border-box;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: all 0.3s cubic-bezier(.25,.8,.25,1);
    min-width: 0; /* Prevent flex items from overflowing */
    resize: none; /* Disable manual resizing */
    line-height: 1.4; /* Better line spacing */
    word-wrap: break-word; /* Break words for better text wrapping */
    font-family: inherit; /* Inherit font family */
}

/* Support for multiline input with textarea */
textarea.itinai-chatbot-input {
    display: block;
    width: 100%;
}

.itinai-chatbot-input:focus {
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border-color: #bdbdbd;
}

.itinai-chatbot-send-button {
    border: none;
    background: var(--itinai-button-color);
    color: white;
    cursor: pointer;
    outline: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    min-width: 40px; /* Ensure minimum width for proper display */
    padding: 0;
    margin: 0; /* Remove all margins to prevent clipping */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    align-self: flex-end; /* Align with the bottom of the input */
    flex-shrink: 0; /* Prevent the button from shrinking */
}

.itinai-chatbot-send-button .material-icons {
    font-size: 20px; /* Control icon size */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Perfect centering */
    color: var(--itinai-icon-color);
}

.itinai-chatbot-send-button:hover {
    transform: scale(1.05);
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

.itinai-chatbot-send-button:active {
    transform: scale(0.95);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.itinai-chatbot-send-button:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

/* Loading Animation */
.itinai-chatbot-loading .itinai-chatbot-bubble {
    min-width: 60px;
    padding: 16px;
    display: flex;
    justify-content: center;
}

.itinai-chatbot-loading .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #bdbdbd;
    margin: 0 3px;
    animation: dot-pulse 1.5s infinite ease-in-out;
}

.itinai-chatbot-loading .dot:nth-child(2) {
    animation-delay: 0.3s;
}

.itinai-chatbot-loading .dot:nth-child(3) {
    animation-delay: 0.6s;
}

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

/* Responsive Styles */
@media (max-width: 480px) {
    .itinai-chatbot-box {
        width: 100%;
    }
    
    .itinai-chatbot-bubble {
        max-width: 85%;
    }
}

/* Typing indicator for loading state */
.typing-indicator {
    display: flex;
    justify-content: center;
    margin: 10px 0;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #bdbdbd;
    border-radius: 50%;
    margin: 0 2px;
    animation: typing-pulse 1.5s infinite ease-in-out;
}

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

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

@keyframes typing-pulse {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

/* Disable button style */
.itinai-chatbot-send-button.disabled {
    background-color: #cccccc !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    transform: none !important;
}

.itinai-chatbot-send-button.disabled:hover {
    transform: none !important;
    box-shadow: none !important;
}

/* Fix for Material Icons color */
.itinai-chatbot .material-icons {
    color: var(--itinai-icon-color);
}

/* Markdown styling */
.itinai-chatbot-bubble a {
    color: #2196F3;
    text-decoration: underline;
}

.itinai-chatbot-bubble a:hover {
    color: #0D47A1;
}

.itinai-chatbot-bubble pre {
    background-color: #f5f5f5;
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid #e0e0e0;
}

.itinai-chatbot-bubble code {
    font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
    font-size: 90%;
}

.itinai-chatbot-bubble blockquote {
    border-left: 4px solid #e0e0e0;
    padding-left: 8px;
    margin-left: 0;
    margin-right: 0;
    color: #666;
}

.itinai-chatbot-bubble ul, 
.itinai-chatbot-bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}

.itinai-chatbot-bubble h1, 
.itinai-chatbot-bubble h2, 
.itinai-chatbot-bubble h3, 
.itinai-chatbot-bubble h4, 
.itinai-chatbot-bubble h5, 
.itinai-chatbot-bubble h6 {
    margin: 8px 0;
    line-height: 1.2;
}

/* Markdown formatting styles */
.itinai-chatbot-bubble {
    /* Add margin bottom to list items */
    line-height: 1.5;
}

.itinai-chatbot-bubble h1,
.itinai-chatbot-bubble h2,
.itinai-chatbot-bubble h3,
.itinai-chatbot-bubble h4,
.itinai-chatbot-bubble h5,
.itinai-chatbot-bubble h6 {
    margin: 0.5em 0;
    line-height: 1.3;
    font-weight: 600;
}

.itinai-chatbot-bubble h1 { font-size: 1.8em; }
.itinai-chatbot-bubble h2 { font-size: 1.6em; }
.itinai-chatbot-bubble h3 { font-size: 1.4em; }
.itinai-chatbot-bubble h4 { font-size: 1.2em; }
.itinai-chatbot-bubble h5 { font-size: 1.1em; }
.itinai-chatbot-bubble h6 { font-size: 1em; }

.itinai-chatbot-bubble ul,
.itinai-chatbot-bubble ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.itinai-chatbot-bubble ul {
    list-style-type: disc;
}

.itinai-chatbot-bubble ol {
    list-style-type: decimal;
}

.itinai-chatbot-bubble li {
    margin-bottom: 0.3em;
}

.itinai-chatbot-bubble p {
    margin: 0.5em 0;
}

.itinai-chatbot-bubble a {
    color: #0366d6;
    text-decoration: none;
}

.itinai-chatbot-bubble a:hover {
    text-decoration: underline;
}

.itinai-chatbot-bubble code {
    font-family: monospace;
    background-color: rgba(0, 0, 0, 0.05);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 0.9em;
}

.itinai-chatbot-bubble pre {
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    padding: 0.5em;
    overflow-x: auto;
    margin: 0.5em 0;
}

.itinai-chatbot-bubble pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    display: block;
    white-space: pre;
}

.itinai-chatbot-bubble blockquote {
    border-left: 4px solid #dfe2e5;
    padding-left: 1em;
    color: #6a737d;
    margin: 0.5em 0;
}

.itinai-chatbot-bubble img {
    max-width: 100%;
    height: auto;
}

.itinai-chatbot-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5em 0;
}

.itinai-chatbot-bubble table th,
.itinai-chatbot-bubble table td {
    padding: 0.4em 0.5em;
    border: 1px solid #dfe2e5;
}

.itinai-chatbot-bubble table th {
    background-color: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

.itinai-chatbot-bubble hr {
    height: 1px;
    background-color: #dfe2e5;
    border: none;
    margin: 0.5em 0;
}

/* Ensure chat images fill bubble width */
.itinai-chatbot-bubble img {
    width: 100%;
    height: auto;
    display: block;
    margin: 8px 0;
}

.itinai-chatbot-image,
.itinai-chatbot-video {
    max-width: 100%;
    display: block;
    margin: 0.5em auto;
    border-radius: var(--itinai-chat-border-radius, 8px);
}

/* Start message slider styles */
.itinai-start-slider {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: auto; /* Push slider to bottom of messages container */
    height: 60px;
    position: relative;
    overflow: hidden;
    padding: 10px 0;
    /* No borders */
    border: none;
    margin-bottom: 5px;
}

.itinai-start-bubble {
    /* Match user bubble styling using CSS variables */
    background-color: var(--itinai-user-message-background, #e3f2fd);
    color: var(--itinai-font-color, #333333);
    border-radius: var(--itinai-chat-border-radius, 18px);
    padding: 10px 15px;
    white-space: normal;
    max-width: 80%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    font-size: var(--itinai-font-size, 14px);
    line-height: 1.5;
    word-wrap: break-word;
    text-align: center;
    cursor: pointer;
    border: none !important; /* Ensure no borders */
    
    /* Animation properties */
    position: absolute;
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.5s ease, transform 0.5s ease, box-shadow 0.3s ease;
    pointer-events: none;
}

.itinai-start-bubble.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.itinai-start-bubble.slide-left {
    transform: translateX(-30px);
}

.itinai-start-bubble.slide-right {
    transform: translateX(30px);
}

.itinai-start-bubble:hover {
    transform: translateY(-2px) translateX(0);
    box-shadow: 0 3px 5px rgba(0, 0, 0, 0.15);
}
