:root {
    --primary-color: #3a7bd5;
    --secondary-color: #f5f5f5;
    --border-color: #e0e0e0;
    --text-color: #333;
    --light-text-color: #666;
    --bg-color: #ffffff;
    --sidebar-bg: #f8f9fa;
    --message-user-bg: #f0f7ff;
    --message-assistant-bg: #ffffff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    color: var(--text-color);
    background-color: var(--bg-color);
    overflow: hidden;
}

/* Sidebar styles */
.sidebar {
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    border-bottom: 1px solid var(--border-color);
}

.sidebar-content {
    overflow-y: auto;
}

#chat-history .history-item {
    padding: 10px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
}

#chat-history .history-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

#chat-history .history-item.active {
    background-color: rgba(0, 0, 0, 0.1);
}

#chat-history .history-item .btn-link {
    opacity: 0;
    transition: opacity 0.2s;
}

#chat-history .history-item:hover .btn-link {
    opacity: 1;
}

#chat-history .history-item .btn-link:hover {
    color: #dc3545 !important;
}

.sidebar-footer {
    border-top: 1px solid var(--border-color);
}

/* Main content styles */
.main-content {
    height: 100vh;
    overflow: hidden;
}

.chat-container {
    height: 100%;
}

.chat-messages {
    overflow-y: auto;
    padding-bottom: 20px;
}

.message {
    margin-bottom: 20px;
    max-width: 85%;
    border-radius: 12px;
    padding: 15px;
    position: relative;
}

.message.user {
    background-color: var(--message-user-bg);
    margin-left: auto;
    border: 1px solid #e1e8ed;
}

.message.assistant {
    background-color: var(--message-assistant-bg);
    margin-right: auto;
    border: 1px solid #e1e8ed;
}

.message .role {
    font-weight: bold;
    margin-bottom: 5px;
}

.message .content {
    line-height: 1.6;
}

.message .content pre {
    background-color: #f5f7f9;
    border-radius: 6px;
    padding: 10px;
    overflow-x: auto;
}

.message .content code {
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
}

.message .content a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px dashed var(--primary-color);
}

.message .content a:hover {
    text-decoration: none;
    border-bottom: 1px solid var(--primary-color);
}

/* Input area styles */
.chat-input-container {
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
}

#user-input {
    resize: none;
    border-radius: 20px;
    padding: 12px 15px;
    font-size: 1rem;
    max-height: 200px;
    overflow-y: auto;
}

#send-button {
    border-radius: 50%;
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
}

/* Welcome message */
.welcome-message {
    margin-top: 20vh;
    opacity: 0.8;
}

/* Typing indicator */
.typing-indicator {
    display: inline-block;
    padding: 5px 15px;
}

.typing-indicator span {
    height: 10px;
    width: 10px;
    float: left;
    margin: 0 1px;
    background-color: #9E9EA1;
    display: block;
    border-radius: 50%;
    opacity: 0.4;
}

.typing-indicator span:nth-of-type(1) {
    animation: typing 1s infinite;
}

.typing-indicator span:nth-of-type(2) {
    animation: typing 1s 0.33s infinite;
}

.typing-indicator span:nth-of-type(3) {
    animation: typing 1s 0.66s infinite;
}

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

/* Reasoning indicator */
.reasoning-indicator {
    display: flex;
    flex-direction: column;
    padding: 10px 15px;
    gap: 8px;
}

.reasoning-step {
    display: flex;
    align-items: center;
    font-size: 0.9em;
    color: #666;
    opacity: 0;
    transform: translateX(-10px);
    animation: slideIn 0.5s forwards;
}

.reasoning-step i {
    margin-right: 8px;
    color: var(--primary-color);
}

@keyframes slideIn {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.reasoning-step:nth-child(2) {
    animation-delay: 0.5s;
}

.reasoning-step:nth-child(3) {
    animation-delay: 1s;
}

.reasoning-step:nth-child(4) {
    animation-delay: 1.5s;
}

/* Reasoning content styles */
.reasoning-content {
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    border-left: 4px solid var(--primary-color);
}

.reasoning-header, .answer-header {
    display: flex;
    align-items: center;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.reasoning-header i, .answer-header i {
    margin-right: 8px;
}

.reasoning-body {
    color: var(--light-text-color);
    font-size: 0.95em;
    line-height: 1.5;
}

/* Usage stats */
.usage-stats {
    color: var(--light-text-color);
    font-size: 0.85em;
}

.usage-stats span {
    display: inline-block;
}

/* Styles for the new scraping features */
#url-input {
    font-size: 0.9em;
    border-radius: 8px;
    transition: all 0.3s ease;
}

#url-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(58, 123, 213, 0.25);
}

#scrape-button {
    border-radius: 8px;
    transition: all 0.3s ease;
}

#scrape-button:disabled {
    background-color: #6c757d;
    border-color: #6c757d;
    opacity: 0.65;
}

/* URL input container styles */
#url-input-container {
    background-color: var(--bg-color);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

#url-input-container.show {
    display: block;
}

#url-input-container:not(.d-none) {
    display: block !important;
    opacity: 1;
}

#url-input-container.d-none {
    display: none !important;
    opacity: 0;
}

#url-input {
    font-size: 0.9em;
    border-radius: 8px;
    resize: vertical;
    min-height: 80px;
    max-height: 200px;
    width: 100%;
}

#scrape-button {
    transition: all 0.2s ease;
}

#scrape-button:disabled {
    cursor: not-allowed;
}

/* Workflow Styles */
.workflow-list {
    max-height: 400px;
    overflow-y: auto;
}

.workflow-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
    margin-bottom: 0.5rem;
    background: #fff;
}

.workflow-item:hover {
    background: #f8f9fa;
}

.workflow-info {
    flex: 1;
}

.workflow-actions {
    display: flex;
    gap: 0.5rem;
}

.workflow-step {
    position: relative;
    padding: 1rem;
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
    margin-bottom: 0.5rem;
    background: #fff;
}

.workflow-step::before {
    content: "";
    position: absolute;
    top: -10px;
    left: 20px;
    width: 2px;
    height: 10px;
    background: #dee2e6;
}

.workflow-step:first-child::before {
    display: none;
}

.step-handle {
    cursor: move;
    padding: 0.25rem;
}

.step-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

.workflow-execution-status {
    font-size: 0.875rem;
    margin-top: 0.5rem;
    padding: 0.5rem;
    border-radius: 0.25rem;
    background: #f8f9fa;
}

.workflow-execution-status.success {
    background: #d4edda;
    color: #155724;
}

.workflow-execution-status.error {
    background: #f8d7da;
    color: #721c24;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        z-index: 1000;
        transition: all 0.3s ease;
    }
    
    .sidebar.show {
        left: 0;
    }
    
    .main-content {
        width: 100%;
    }
    
    .message {
        max-width: 90%;
    }
}

/* Mobile Enhancements */
@media (max-width: 768px) {
    body {
        position: fixed; /* Alternative to overscroll-behavior-y for iOS < 16 */
        width: 100%;
        height: 100%;
        overflow: hidden;
        touch-action: manipulation; /* Optimize touch events */
        -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85%;
        height: 100%;
        z-index: 1000;
        transition: transform 0.3s ease;
        box-shadow: none;
        background-color: var(--sidebar-bg);
    }

    .sidebar.show {
        transform: translateX(100%);
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }

    /* Add hamburger menu button */
    .menu-toggle {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 999;
        padding: 10px;
        background: var(--bg-color);
        border-radius: 50%;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: 1px solid var(--border-color);
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding-top: 60px; /* Account for fixed menu button */
    }

    .chat-messages {
        padding: 10px;
    }

    .message {
        max-width: 95%;
        margin-left: 10px;
        margin-right: 10px;
    }

    .chat-input-container {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-color);
        padding: 10px;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }

    #user-input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 12px;
        max-height: 120px; /* Smaller max height on mobile */
    }

    /* Improve code block scrolling on mobile */
    .message pre {
        overflow-x: auto;
        padding: 8px;
        font-size: 14px;
    }

    /* Better touch targets */
    .btn, button, select, .form-check-input {
        min-height: 44px; /* Apple's recommended minimum */
    }

    /* Improve model selector on mobile */
    .model-selector {
        margin-bottom: 15px;
    }

    #model-selector {
        width: 100%;
        padding: 12px;
        font-size: 16px;
    }

    /* Make toggles more touch-friendly */
    .form-check {
        padding: 12px 0;
    }

    .form-check-input {
        width: 44px;
        height: 24px;
        margin-right: 10px;
    }

    .form-check-label {
        line-height: 24px;
    }

    /* URL input container improvements */
    #url-input-container {
        border-radius: 12px;
        margin-bottom: 10px;
    }

    #url-input {
        font-size: 16px;
        padding: 12px;
    }

    #scrape-button {
        height: 44px;
        font-size: 16px;
    }

    /* Usage stats positioning */
    .usage-stats {
        position: fixed;
        bottom: 70px;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.9);
        padding: 5px 15px;
        font-size: 12px;
        -webkit-backdrop-filter: blur(5px);
        backdrop-filter: blur(5px);
        border-top: 1px solid var(--border-color);
        z-index: 100;
    }

    /* Improved scrolling for chat messages */
    .chat-messages {
        scroll-padding-bottom: 150px; /* Account for input area */
        padding-bottom: 150px;
    }

    /* Safari fixes */
    @supports (-webkit-touch-callout: none) {
        .chat-container {
            height: -webkit-fill-available;
        }
        
        .chat-messages {
            height: -webkit-fill-available;
        }
    }
}

/* Enhanced Mobile Styles */
@media (max-width: 768px) {
    /* Core Mobile Optimizations */
    body {
        height: var(--vh, 100vh);
        touch-action: pan-y;
        overscroll-behavior: none;
        position: fixed; /* Fallback for iOS < 16 */
        overflow: hidden; /* Fallback for iOS < 16 */
        position: fixed; /* Fallback for iOS < 16 */
        overflow: hidden; /* Fallback for iOS < 16 */
        position: fixed; /* Fallback for iOS < 16 */
        overflow: hidden; /* Fallback for iOS < 16 */
        position: fixed; /* Fallback for iOS < 16 */
        overflow: hidden; /* Fallback for iOS < 16 */
    }

    /* Floating Action Button for New Chat */
    #new-chat-fab {
        position: fixed;
        bottom: 80px;
        right: 16px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--primary-color);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        z-index: 99;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: transform 0.2s;
        border: none;
        color: white;
    }

    #new-chat-fab:active {
        transform: scale(0.95);
    }

    /* Enhanced Sidebar Animation */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: transform;
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    }

    /* Improved Chat Input Area */
    .chat-input-container {
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        background: rgba(255, 255, 255, 0.95);
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        padding: 12px 16px;
        margin-bottom: env(safe-area-inset-bottom, 0);
    }

    .input-group {
        background: white;
        border-radius: 24px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        padding: 4px;
    }

    #user-input {
        border: none;
        padding: 12px 16px;
        line-height: 1.4;
        font-size: 16px;
        max-height: 120px;
        border-radius: 20px;
    }

    #user-input:focus {
        box-shadow: none;
    }

    #send-button {
        width: 40px;
        height: 40px;
        padding: 0;
        margin: 0 4px;
    }

    /* Message Bubble Improvements */
    .message {
        max-width: 88%;
        padding: 12px 16px;
        animation: messageSlide 0.3s ease-out;
        margin-bottom: 12px;
    }

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

    /* Enhanced Model Selector */
    .model-selector-container {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 20px;
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
        transform: translateY(100%);
        transition: transform 0.3s ease-out;
        z-index: 1000;
    }

    .model-selector-container.show {
        transform: translateY(0);
    }

    /* Quick Actions Bar */
    .quick-actions {
        position: fixed;
        bottom: 70px;
        left: 0;
        right: 0;
        padding: 8px 16px;
        background: rgba(255, 255, 255, 0.95);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        display: flex;
        gap: 8px;
        overflow-x: auto;
            scrollbar-width: none; /* Firefox */
            -ms-overflow-style: none; /* Internet Explorer 10+ */
        }
    
        .quick-actions::-webkit-scrollbar {
            display: none; /* Safari */
        border-top: 1px solid rgba(0, 0, 0, 0.1);
    }

    .quick-actions::-webkit-scrollbar {
        display: none;
    }

    .quick-action-btn {
        flex: 0 0 auto;
        padding: 6px 12px;
        border-radius: 16px;
        font-size: 14px;
        white-space: nowrap;
        background: white;
        border: 1px solid var(--border-color);
        color: var(--text-color);
    }

    /* Pull to Refresh Indicator */
    .pull-to-refresh {
        position: absolute;
        top: -50px;
        left: 0;
        right: 0;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--light-text-color);
        transform: translateY(0);
        transition: transform 0.2s;
    }

    .pull-to-refresh.pulling {
        transform: translateY(50px);
    }

    /* Loading States */
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.8);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 2000;
        backdrop-filter: blur(5px);
        -webkit-backdrop-filter: blur(5px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s;
    }

    .loading-overlay.show {
        opacity: 1;
        pointer-events: auto;
    }

    /* Safari-specific fixes */
    @supports (-webkit-touch-callout: none) {
        .chat-container {
            height: -webkit-fill-available;
        }

        .chat-input-container {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}

/* Mobile Enhancements */
@media (max-width: 768px) {
    body {
        /* Alternative to overscroll-behavior-y for iOS < 16 */
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* Improved scrolling for all browsers */
    .chat-messages {
        overflow-y: auto;
        scroll-behavior: smooth;
        /* Modern scroll behavior */
        scrollbar-gutter: stable;
        overscroll-behavior: contain;
        /* For older iOS */
        position: relative;
        z-index: 1;
        height: 100%;
    }

    /* Enhanced blur effects with Safari support */
    .chat-input-container {
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        background: rgba(255, 255, 255, 0.95);
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        padding: 12px 16px;
        margin-bottom: env(safe-area-inset-bottom, 0);
    }

    /* Quick Actions Bar with Safari support */
    .quick-actions {
        position: fixed;
        bottom: 70px;
        left: 0;
        right: 0;
        padding: 8px 16px;
        background: rgba(255, 255, 255, 0.95);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        display: flex;
        gap: 8px;
        overflow-x: auto;
        /* Modern scrolling behavior */
        scroll-snap-type: x mandatory;
        /* Hide scrollbar for all browsers */
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .quick-actions::-webkit-scrollbar {
        display: none;
    }

    /* Loading overlay with Safari support */
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.8);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 2000;
        -webkit-backdrop-filter: blur(5px);
        backdrop-filter: blur(5px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s;
    }

    /* Smooth scrolling alternative for iOS */
    .smooth-scroll {
        -webkit-overflow-scrolling: touch; /* Only for older iOS */
        scroll-behavior: smooth;
    }

    /* Enhanced scroll container */
    .scroll-container {
        overflow-y: auto;
        /* Enable momentum scrolling on iOS */
        -webkit-overflow-scrolling: touch;
        /* Prevent overscroll on modern browsers */
        overscroll-behavior: contain;
        /* Smooth scrolling for modern browsers */
        scroll-behavior: smooth;
    }

    /* iOS-specific optimizations */
    @supports (-webkit-touch-callout: none) {
        .chat-container {
            /* Fix for iOS viewport height */
            height: -webkit-fill-available;
        }
        
        .chat-input-container {
            /* Account for iOS safe areas */
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }

        /* Fix for iOS momentum scrolling */
        .chat-messages {
            position: relative;
            z-index: 1;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
    }
}

/* Loading overlay base styles */
.loading-overlay {
    display: none; /* Hide by default */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

/* Show loading overlay only on mobile when needed */
@media (max-width: 768px) {
    .loading-overlay {
        -webkit-backdrop-filter: blur(5px);
        backdrop-filter: blur(5px);
    }
    
    .loading-overlay.show {
        display: flex;
        opacity: 1;
        pointer-events: auto;
    }
}

/* Hide loading overlay on desktop */
@media (min-width: 769px) {
    .loading-overlay {
        display: none !important;
    }
}

/* Add these styles at the end of the file */

.document-preview-modal .modal-body {
    max-height: 70vh;
    overflow-y: auto;
}

.document-preview-modal pre.document-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 0.25rem;
}

.document-upload .btn {
    transition: all 0.3s ease;
}

.document-upload .btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

#document-upload-form {
    position: absolute;
    visibility: hidden;
}

/* Excel table styles */
.document-preview-modal pre.document-content {
    font-family: 'Consolas', monospace;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre;
    tab-size: 4;
}

.document-preview-modal .table-separator {
    color: #ccc;
    opacity: 0.7;
}

/* Table row hover effect */
.document-preview-modal pre.document-content:hover {
    cursor: text;
    background: #fafafa;
}

/* Make tables more readable */
.message .content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
    background: white;
}

.message .content table th,
.message .content table td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

.message .content table tr:nth-child(even) {
    background-color: #f8f9fa;
}

.message .content table th {
    background-color: #f1f3f5;
    font-weight: bold;
}

/* Table scrolling for mobile */
@media (max-width: 768px) {
    .message .content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}