/* Base variables */
:root {
    --primary: #336699;
    --primary-dark: #003366;
    --primary-light: #6699cc;
    --hover-light: rgba(51, 102, 153, 0.08);
    --text: #212529;
    --border-light: rgba(51, 102, 153, 0.1);
    --shadow-light: 0 2px 8px rgba(0, 51, 102, 0.05);
    --shadow-medium: 0 4px 12px rgba(0, 51, 102, 0.1);
    --border-radius: 1.5rem;
    --transition: all 0.2s ease;
}

/* Layout structure */
.content-container {
    display: flex;
    flex-direction: column;
    flex: 1; /* Allow it to fill the scrollable parent */
}

.scrollable-area {
    flex: 1;
    padding: 1rem;
    background: linear-gradient(180deg, rgba(245, 247, 250, 0.5) 0%, rgba(255, 255, 255, 1) 100%);
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-bottom: calc(60px + env(safe-area-inset-bottom)); /* Adjust 60px to the actual resting height of your input-footer */
    overflow-y: auto;
    overscroll-behavior: contain; /* Prevents pull-to-refresh issues on chat scroll */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scroll-behavior: smooth;
    /* If .input-footer is outside .scrollable-area, ensure .scrollable-area doesn't get hidden */
}

/* Ensure the container above the input footer has enough padding */
/* This might be .chat-container or .scrollable-area */
.chat-container { /* Or the direct parent of .scrollable-area and .input-footer */
    /* Adjust padding to prevent overlap if .input-footer is sticky */
    padding-bottom: calc(70px + env(safe-area-inset-bottom)); /* Adjust 70px based on actual .input-footer height */
}

main.scrollable-area {
    flex: 1; /* Allow message area to grow */
    padding-bottom: 0; /* Remove padding if footer is separate */
}

/* Webkit scrollbar styling */
.scrollable-area::-webkit-scrollbar {
    width: 8px;
}

.scrollable-area::-webkit-scrollbar-track {
    background: transparent;
}

.scrollable-area::-webkit-scrollbar-thumb {
    background-color: rgba(51, 102, 153, 0.2);
    border-radius: 4px;
}

.scrollable-area::-webkit-scrollbar-thumb:hover {
    background-color: rgba(51, 102, 153, 0.3);
}

.input-footer {
    display: flex;
    align-items: center;
    padding: 10px 15px; /* Your existing horizontal and top padding */
    /* Add base bottom padding + safe area inset */
    padding-bottom: calc(10px + env(safe-area-inset-bottom)); /* Adjust 10px if your base bottom padding is different */
    background-color: var(--background-color-card, #fff); /* Ensure it has a background */
    border-top: 1px solid var(--border-color, #e0e0e0);
    position: sticky; /* Or 'fixed' if it's relative to the viewport */
    bottom: 0;
    left: 0;
    right: 0; /* Or width: 100%; */
    z-index: 1000; /* Ensure it's above other content */
}

/* Ensure the textarea or input inside adapts well */
.input-footer textarea,
.input-footer input[type="text"] {
    flex-grow: 1;
    /* other existing styles */
}

/* Form elements */
.input-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.input-form #message-input {
    flex: 1;
    min-width: 0; /* Allows proper flex shrinking */
    border-radius: var(--border-radius-pill);
    padding: 10px 15px;
    border: 1px solid var(--bs-border-color);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 8px;
}

.btn-control {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--bs-light);
    border: 1px solid var(--bs-border-color);
    padding: 0;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.btn-control:hover {
    background-color: var(--bs-primary-bg-subtle);
    transform: translateY(-1px);
    box-shadow: var(--shadow-light);
}

.btn-control:hover .model-icon {
    transform: scale(1.1);
}

#send-button {
    border-radius: var(--border-radius-pill);
    padding: 8px 20px;
}

.form-control {
    flex: 1;
    border: 2px solid var(--border-light);
    border-radius: var(--border-radius);
    padding: 1rem 1.5rem;
    font-size: 1rem;
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(51, 102, 153, 0.1);
}

.btn-primary {
    background: var(--primary);
    border-radius: var(--border-radius);
    padding: 1rem 2rem;
    font-weight: 600;
    border: none;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 51, 102, 0.2);
}

/* Message containers */
#messages-container {
    flex: 1;
    min-height: 200px;
    padding-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.message-container {
    width: 100%;
    margin-bottom: 1.5rem;
    opacity: 1;
    position: relative;
    will-change: transform;
}

.message-group {
    width: 100%;
    margin-bottom: 2rem;
    position: relative;
}

.message-group.new-exchange {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(0,0,0,0.1);
    position: relative;
    animation: newExchangeFadeIn 0.3s ease-out forwards;
}

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

.message-group:last-child {
    margin-bottom: 0;
    padding-bottom: 2rem;
}

/* New screen section styling */
.message-group.new-screen-section {
    position: relative;
    padding-top: 2rem;
    border-top: 1px solid rgba(0,0,0,0.1);
    animation: newScreenFadeIn 0.7s ease-out forwards;
}

/* Time divider for new conversation sections - simplified */
.time-divider {
    display: none; /* Hide time dividers for maximum simplicity */
}

/* Simplified screen section */
.message-group.new-screen-section:after {
    display: none; /* Remove visual effects for maximum simplicity */
}

/* Message bubbles */
.user-bubble {
    /* Extends .message-bubble */
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 var(--border-radius-lg);
    box-shadow: var(--shadow-medium);
    align-self: flex-end;
}

.ai-bubble {
    /* Extends .message-bubble */
    background: white;
    color: var(--text);
    border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) var(--border-radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-light);
    align-self: flex-start;
}

/* Actions containers */
.actions-container {
    width: 100%;
    padding-left: 15px;
    padding-top: 0.5rem;
    border-top: 1px solid var(--bs-border-color-translucent);
    margin-top: 0.75rem !important; /* Ensure consistent margin */
}

.message-container .d-flex.justify-content-end + .actions-container {
    padding-right: 15px;
    padding-left: 0;
    text-align: right;
}

/* Keywords and questions */
.keywords-section, 
.questions-section {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem; /* Add some space below each section on mobile */
}

.keywords-section .text-muted,
.questions-section .text-muted {
    font-size: 0.8rem; /* Slightly smaller title */
    display: flex; /* Align icon and text */
    align-items: center; /* Align icon and text */
}

.keyword-badge {
    background: rgba(51, 102, 153, 0.1);
    background-color: var(--bs-secondary-bg);
    color: var(--primary);
    color: var(--bs-body-color);
    border-radius: var(--border-radius-pill);
    border-radius: 1rem;
    padding: 0.25rem 0.75rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.875rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
    transition: background-color 0.2s ease;
    display: inline-block;
    margin: 0.25rem;
    border: 1px solid var(--bs-border-color-translucent);
}

.keyword-badge:hover {
    background: rgba(51, 102, 153, 0.2);
    background-color: var(--bs-tertiary-bg);
    transform: translateY(-1px);
}

.question-badge {
    background: transparent;
    background-color: transparent;
    border: none;
    color: var(--primary);
    color: var(--bs-primary);
    padding: 0.25rem 0;
    padding: 0.2rem 0; /* Minimal padding */
    text-align: left;
    font-size: 0.95rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    transition: background-color 0.2s ease, color 0.2s ease;
    text-decoration: underline;
    text-decoration-color: rgba(51, 102, 153, 0.3);
    text-decoration-thickness: 1px;
    display: block; /* Make it block level */
    width: 100%; /* Take full width */
    border-radius: 0.25rem;
}

.question-badge:hover {
    color: var(--primary-dark);
    color: var(--bs-primary-text-emphasis);
    text-decoration-color: var(--primary);
    background-color: rgba(0, 123, 255, 0.05);
    background-color: var(--bs-tertiary-bg);
}

/* Initial suggestions */
.initial-suggestions {
    max-width: 95%;
    margin: 2rem auto;
    padding: 1.25rem;
    animation: fadeIn 0.5s ease-out forwards;
}

.suggestions-header {
    text-align: center;
    margin-bottom: 1.75rem;
    font-weight: 600;
    color: var(--primary);
    font-size: 1.1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.suggestions-header:after {
    content: '';
    width: 40px;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--primary-light), transparent);
    margin-top: 0.75rem;
    border-radius: 3px;
}

.suggestions-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
}

.suggestion-btn {
    /* Manually apply suggestion-base properties */
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--border-color);
    color: var(--text);
    text-align: left;
    text-decoration: none;
    display: inline-flex; /* Use flex for alignment */
    align-items: center;
    gap: 0.75rem; /* Consistent gap */
    position: relative;

    /* Chat-specific overrides/additions */
    background-color: white;
    border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) var(--border-radius-lg); /* AI bubble style */
    padding: 0.9rem 1.2rem;
    font-size: 0.95rem;
    width: auto;
    max-width: 280px;
    line-height: 1.5;
    box-shadow: var(--shadow-light);
    opacity: 0; /* Keep for animation */
    animation-fill-mode: forwards; /* Keep for animation */
}

.suggestion-btn:hover {
    /* Apply suggestion-base:hover properties */
    border-color: rgba(51, 102, 153, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 51, 102, 0.1);
    text-decoration: none;
    color: var(--primary-dark);
    background-color: var(--hover-light);
    /* Add chat-specific hover changes if needed */
    transform: translateY(-2px); /* Override base hover transform */
    box-shadow: var(--shadow-medium); /* Override base hover shadow */
}

/* Special animation for fresh screen effect */
@keyframes newScreenFadeIn {
    from {
        opacity: 0.5;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Keep delayed animation for suggestions */
.suggestion-btn:nth-child(1) { animation: slideInRight 0.35s ease-out forwards; }
.suggestion-btn:nth-child(2) { animation: slideInRight 0.35s ease-out 0.05s forwards; }
.suggestion-btn:nth-child(3) { animation: slideInRight 0.35s ease-out 0.1s forwards; }
.suggestion-btn:nth-child(4) { animation: slideInRight 0.35s ease-out 0.15s forwards; }
.suggestion-btn:nth-child(5) { animation: slideInRight 0.35s ease-out 0.2s forwards; }
.suggestion-btn:nth-child(6) { animation: slideInRight 0.35s ease-out 0.25s forwards; }
.suggestion-btn:nth-child(7) { animation: slideInRight 0.35s ease-out 0.3s forwards; }
.suggestion-btn:nth-child(8) { animation: slideInRight 0.35s ease-out 0.35s forwards; }
.suggestion-btn:nth-child(9) { animation: slideInRight 0.35s ease-out 0.4s forwards; }
.suggestion-btn:nth-child(10) { animation: slideInRight 0.35s ease-out 0.45s forwards; }

/* Dropdown styling */
.dropdown-menu {
    border: none;
    box-shadow: var(--shadow-medium);
    border-radius: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
}

.dropdown-item {
    transition: var(--transition);
    border-radius: 0.5rem;
    margin: 0.25rem;
}

.dropdown-item:hover {
    background-color: var(--hover-light);
    color: var(--primary);
}

/* Chat history dropdown styling */
#conversationHistory {
    width: 320px;
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
    border: none;
    box-shadow: var(--shadow-medium);
    border-radius: 0.75rem;
}

#conversationHistory .dropdown-item {
    padding: 0.75rem;
    border-radius: var(--border-radius-sm);
    transition: var(--transition);
    margin-bottom: 0.25rem;
    white-space: normal;
}

#conversationHistory .dropdown-item:hover {
    background-color: var(--hover-light);
    transform: translateY(-1px);
}

.history-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.history-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background-color: var(--hover-light);
    border-radius: 50%;
    color: var(--primary);
    flex-shrink: 0;
}

.history-content {
    flex: 1;
    min-width: 0;
}

.history-message {
    font-weight: 500;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.history-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--bs-secondary);
}

.history-meta i {
    font-size: 0.875rem;
}

/* Responsive design */
@media (max-width: 768px) {
    .scrollable-area {
        padding: 0.75rem;
    }
    
    .message-bubble {
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    .input-footer {
        padding: 0.75rem;
    }
    
    .input-form {
        gap: 0.5rem;
    }
    
    .input-form #message-input {
        padding: 0.75rem 1rem;
    }
    
    #send-button {
        padding: 0.75rem 1.25rem;
    }
    
    .suggestion-btn {
        max-width: 100%;
    }
}

/* Only chat-specific styles */
.chat-message {
  border-radius: 1rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.user-message {
  background-color: var(--primary-light);
  align-self: flex-end;
}

/* Chat-specific responsive adjustments */
@media (max-width: 576px) {
  .chat-container {
    padding: 0.5rem;
  }
}

/* Model selector in chat input */
.model-select-dropdown {
    position: relative;
}

.model-select-toggle {
    color: var(--primary);
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius-sm);
    background-color: var(--hover-light);
    border: 1px solid var(--border-light);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.model-select-toggle:hover {
    background-color: rgba(51, 102, 153, 0.12);
}

.model-select-toggle .model-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-select-dropdown .dropdown-menu {
    width: 280px;
    padding: 0.5rem;
}

.model-select-dropdown .dropdown-item {
    border-radius: var(--border-radius-sm);
    padding: 0.75rem;
    margin-bottom: 0.25rem;
}

.model-select-dropdown .dropdown-item:hover {
    background-color: var(--hover-light);
}

.model-select-dropdown .dropdown-item.active {
    background-color: rgba(var(--bs-primary-rgb), 0.1);
    color: inherit;
}

.model-option i.fa-robot,
.model-option i.fa-bolt,
.model-option i.fa-flask,
.model-option i.fa-microchip {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.model-option i.fa-robot {
    background-color: rgba(29, 155, 240, 0.1);
    color: #1d9bf0;
}

.model-option i.fa-bolt {
    background-color: rgba(242, 201, 76, 0.1);
    color: #f2c94c;
}

.model-option i.fa-flask {
    background-color: rgba(155, 81, 224, 0.1);
    color: #9b51e0;
}

.model-option i.fa-microchip {
    background-color: rgba(51, 102, 153, 0.1);
    color: var(--primary);
}

/* Responsive adjustments for model selector */
@media (max-width: 576px) {
    .model-select-toggle {
        padding: 0.5rem;
    }
    
    .model-select-toggle .model-name {
        display: none;
    }
    
    .model-select-dropdown .dropdown-menu {
        width: 260px;
    }
}

/* System message styling */
.system-message {
    display: flex;
    justify-content: center;
    margin: 1rem 0;
}

.system-notification {
    background-color: rgba(51, 102, 153, 0.08);
    color: var(--text);
    border-radius: 1rem;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
}

.system-notification i {
    color: var(--primary);
}

.provider-favicon {
    width: 16px;
    height: 16px;
    object-fit: contain;
    background-color: transparent;
    border-radius: 2px;
}

/* Model selector icon styling */
.model-favicon {
    width: 20px;
    height: 20px;
    object-fit: contain;
    border-radius: 4px;
}

/* Model icon styling */
.model-icon, .ai-response-icon {
    object-fit: contain;
    border-radius: 3px;
    transition: transform 0.2s ease;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.05));
}

/* AI Response icon styling */
.ai-response-icon {
    opacity: 0.85;
}

.ai-response-icon:hover {
    opacity: 1;
}

/* Streaming mode styles */
.streaming-active {
    background-color: rgba(var(--bs-primary-rgb), 0.15) !important;
    color: var(--primary) !important;
}

.streaming-active i {
    color: var(--primary);
}

.streaming-message {
    min-height: 24px;
    /* Make sure streaming content has the same styling as regular content */
    font-size: inherit;
    line-height: inherit;
    color: inherit;
    width: 100%;
}

/* Match the message-content class exactly to ensure consistency */
.streaming-message.message-content {
    padding: 0;
}

/* Style paragraphs inside streaming messages the same as regular messages */
.streaming-message p {
    margin-bottom: 1rem;
}

.streaming-message p:last-child {
    margin-bottom: 0;
}

/* Ensure lists match regular content */
.streaming-message ul, 
.streaming-message ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

/* Ensure headings match */
.streaming-message h1, .streaming-message h2, .streaming-message h3,
.streaming-message h4, .streaming-message h5, .streaming-message h6 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

/* Match table styling */
.streaming-message table {
    border-collapse: collapse;
    margin-bottom: 1rem;
    width: 100%;
}

.streaming-message table th,
.streaming-message table td {
    border: 1px solid rgba(0,0,0,0.1);
    padding: 0.5rem;
}

/* Make sure code blocks look the same */
.streaming-message pre,
.streaming-message code {
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    padding: 0.2em 0.4em;
    font-family: monospace;
}

.streaming-message pre {
    padding: 1rem;
    margin-bottom: 1rem;
    overflow-x: auto;
}

.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background-color: currentColor;
    margin-left: 2px;
    animation: blink 1s infinite;
    vertical-align: text-bottom;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Button controls are already defined above */

/* Model dropdown menu styling */
.model-menu {
    min-width: 260px;
    padding: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
}

.model-option {
    padding: 0.75rem;
    border-radius: 8px;
    margin-bottom: 0.25rem;
    transition: background-color 0.15s ease;
}

.model-option:hover {
    background-color: var(--bs-light);
}

/* Input controls layout already defined above */

/* Responsive adjustments */
@media (max-width: 576px) {
    .input-form {
        flex-direction: column;
        gap: 8px;
    }
    
    .input-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .btn-control {
        width: 36px;
        height: 36px;
    }
    
    .model-icon {
        width: 20px;
        height: 20px;
    }
    
    .model-menu {
        min-width: 220px;
    }

    .input-footer {
        /* Ensure footer is fixed to the viewport bottom on small screens */
        position: fixed; 
        bottom: 0;
        left: 0;
        right: 0;
        padding: 0.75rem; /* Adjust padding as needed */
        background: white; /* Ensure background is set */
        border-top: 1px solid var(--border-light); /* Add border */
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05); /* Add shadow */
        z-index: 100; /* Ensure it's above other content */
    }

    .scrollable-area {
        /* Add padding to the bottom to avoid content being hidden by the fixed footer */
        padding-bottom: 120px; /* Adjust based on footer height */
    }

    .actions-container .col-md-6:not(:last-child) {
        margin-bottom: 0.75rem; /* Add space between stacked columns */
    }
}

/* AI model info styling */
.ai-model-info {
    margin-bottom: 4px;
    opacity: 0.8;
}

.ai-model-info:hover {
    opacity: 1;
}

.ai-response-icon {
    border-radius: 4px;
    margin-right: 6px;
    width: 20px;
    height: 20px;
    object-fit: cover;
}

.ai-model-details {
    line-height: 1;
}

.ai-model-details small {
    font-size: 11px;
    color: #6c757d;
}

.model-provider {
    font-weight: 500;
}

.model-name {
    font-weight: 400;
}