/* static/css/custom.css */
:root {
    /* Modernized color palette */
    --primary-color: #065f46;    /* Dark green */
    --secondary-color: #043927;  /* Darker green accent */
    --danger-color: #e53935;     /* Flat red */
    --warning-color: #fbc02d;    /* Soft yellow */
    --success-color: #43a047;    /* Fresh green */
    --light-bg: #f8f9fa;         /* Very light gray */
    --border-color: #dee2e6;     /* Light Gray */
    --text-color: #495057;       /* Dark Gray */
    --heading-color: #2d3748;    /* Darker Gray/Blue */
    --white-color: #ffffff;
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 60px;
    --topbar-height: 65px;
    --font-family-base: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* --- Base & Layout --- */
body {
    background-color: var(--light-bg);
    color: var(--text-color);
    font-family: var(--font-family-base);
    font-size: 15px;
}

.layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    min-height: 100vh;
}

.topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    color: var(--white-color);
    border-bottom: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: var(--topbar-height);
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1030; /* Higher than sidebar */
    padding: 0 20px;
}

/* Ensure items inside the topbar use light text */
.topbar a,
.topbar button,
.topbar span,
.topbar i {
    color: var(--white-color);
}

.logo-container {
    grid-column: 1;
    display: flex;
    align-items: center;
    height: 100%;
}

/* Find this existing rule in custom.css and update it */
.header-logo {
    max-height: 45px;   /* Keep max height constraint */
    height: 45px;       /* <<< ADD explicit height */
    width: auto;        /* Let width adjust based on height and aspect ratio */
    object-fit: contain;/* Keep aspect ratio preservation */
    display: block;     /* <<< ADD ensure it's treated as a block element */
    vertical-align: middle; /* <<< ADD help alignment within the link/container */
}

.brand-link {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.brand-text {
    margin-left: 8px;
    font-weight: 600;
    font-size: 20px;
    color: var(--white-color);
}

.user-info {
    grid-column: 2;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 15px; /* Spacing between username and button */
    color: var(--white-color);
}

.logout-btn {
    padding: 5px 12px;
    color: var(--white-color);
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 4px;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-size: 14px;
}

.logout-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--white-color);
}

.sidebar {
    grid-row: 2;
    background-color: var(--white-color);
    border-right: 1px solid var(--border-color);
    padding-top: 15px; /* Added padding */
    position: sticky;
    top: var(--topbar-height);
    height: calc(100vh - var(--topbar-height));
    overflow-y: auto;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav-item {
    margin-bottom: 2px; /* Reduced margin */
}

.sidebar-nav-link {
    display: flex; /* Use flex for alignment */
    align-items: center;
    gap: 12px; /* Space between icon and text */
    padding: 10px 20px;
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 15px;
    font-weight: 500;
    border-left: 4px solid transparent;
}

.sidebar-nav-link i {
    width: 18px; /* Fixed width for icons */
    text-align: center;
    font-size: 1.1em; /* Slightly larger icons */
}

.sidebar-nav-link:hover {
    background-color: #e9ecef; /* Lighter hover */
    color: var(--primary-color);
    text-decoration: none;
}

.sidebar-nav-link.active {
    background-color: #f1f3f5;
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 600;
}

/* Collapsed sidebar styles */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}
.layout.sidebar-collapsed {
    grid-template-columns: var(--sidebar-collapsed-width) 1fr;
}
.layout.sidebar-collapsed .topbar {
    grid-template-columns: var(--sidebar-collapsed-width) 1fr;
}
.sidebar.collapsed .sidebar-nav-link {
    justify-content: center;
    padding-left: 10px;
    padding-right: 10px;
}
.sidebar.collapsed .sidebar-nav-link .link-text {
    display: none;
}

.main-content {
    grid-row: 2;
    padding: 25px;
    overflow-y: auto;
}

.page-title {
    color: var(--heading-color);
    font-size: 1.75rem; /* Larger title */
    font-weight: 600;
    margin-bottom: 25px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

footer {
    margin-top: 30px;
    padding-top: 20px;
    text-align: center;
    color: #6c757d; /* Bootstrap secondary text color */
    border-top: 1px solid var(--border-color);
    font-size: 0.85em;
}

/* --- Cards --- */
.card {
    background-color: var(--white-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 25px;
}

.card-header {
    background-color: #f8f9fa; /* Light background for headers */
    border-bottom: 1px solid var(--border-color);
    padding: 12px 18px;
    font-weight: 600;
    color: var(--heading-color);
    font-size: 1.05em;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 6px 6px 0 0; /* Match card radius */
}

.card-body {
    padding: 18px;
}

.card-footer {
     background-color: #f8f9fa;
     border-top: 1px solid var(--border-color);
     padding: 12px 18px;
     border-radius: 0 0 6px 6px;
}

/* --- Forms --- */
.form-label {
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 0.9em;
    color: var(--heading-color);
}

.form-control, .form-select {
    border-radius: 4px;
    border: 1px solid #ced4da; /* Standard Bootstrap border */
    padding: 8px 12px;
    font-size: 0.95em;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(11, 122, 46, 0.2); /* Primary color focus */
}

.form-text {
    font-size: 0.85em;
    color: #6c757d;
}

.form-check-label {
    font-size: 0.95em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.input-group-text {
     background-color: #e9ecef; /* Lighter background for input group addons */
     border: 1px solid #ced4da;
}

/* --- Buttons --- */
.btn {
    border-radius: 4px;
    padding: 8px 16px;
    font-size: 0.95em;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex; /* Align icon and text */
    align-items: center;
    justify-content: center;
    gap: 6px; /* Space between icon and text */
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.85em;
    gap: 4px;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--white-color);
}
.btn-primary:hover {
    background-color: #096a25;
    border-color: #085f21;
    color: var(--white-color);
}

.btn-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
    color: var(--white-color);
}
.btn-secondary:hover {
    background-color: #5a6268;
    border-color: #545b62;
    color: var(--white-color);
}

.btn-danger {
    background-color: var(--danger-color);
    border-color: var(--danger-color);
    color: var(--white-color);
}
.btn-danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
    color: var(--white-color);
}

.btn-warning {
    background-color: var(--warning-color);
    border-color: var(--warning-color);
    color: #212529; /* Dark text for yellow */
}
.btn-warning:hover {
    background-color: #e0a800;
    border-color: #d39e00;
    color: #212529;
}

.btn-outline-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
}
.btn-outline-primary:hover {
    background-color: var(--primary-color);
    color: var(--white-color);
}

.btn-outline-secondary {
    color: #6c757d;
    border-color: #6c757d;
}
.btn-outline-secondary:hover {
    background-color: #6c757d;
    color: var(--white-color);
}

.btn-outline-danger {
    color: var(--danger-color);
    border-color: var(--danger-color);
}
.btn-outline-danger:hover {
    background-color: var(--danger-color);
    color: var(--white-color);
}

/* Action Buttons (Small icon-only style) */
.btn-action {
    padding: 5px;
    width: 32px;
    height: 32px;
    font-size: 1em; /* Adjust icon size */
    line-height: 1;
    border: 1px solid var(--border-color);
    background-color: transparent;
    color: var(--text-color);
}
.btn-action:hover {
    background-color: #e9ecef;
}
.btn-action.edit { color: #0d6efd; border-color: #0d6efd; } /* Bootstrap blue */
.btn-action.edit:hover { background-color: #0d6efd; color: var(--white-color); }
.btn-action.delete { color: var(--danger-color); border-color: var(--danger-color); }
.btn-action.delete:hover { background-color: var(--danger-color); color: var(--white-color); }
.btn-action.compare { color: var(--primary-color); border-color: var(--primary-color); }
.btn-action.compare:hover { background-color: var(--primary-color); color: var(--white-color); }
.btn-action.view { color: #6f42c1; border-color: #6f42c1; } /* Bootstrap purple */
.btn-action.view:hover { background-color: #6f42c1; color: var(--white-color); }


/* --- Tables --- */
.table {
    margin-bottom: 0; /* Remove default margin if inside card */
    background-color: var(--white-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

/* Allow dropdowns inside dashboard tables to escape clipping */
.dashboard-table {
    overflow: visible;
}

.table th {
    font-weight: 600;
    background-color: #f8f9fa;
    border-bottom: 2px solid var(--border-color);
    padding: 10px 12px;
    font-size: 0.9em;
    color: var(--heading-color);
    text-align: left;
}

.table td {
    padding: 10px 12px;
    vertical-align: middle;
    border-top: 1px solid var(--border-color);
    font-size: 0.95em;
    text-align: left;
}

.table-hover tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.03); /* Subtle hover */
}

.action-buttons-cell {
    display: flex;
    gap: 6px;
    align-items: center;
    white-space: nowrap; /* Prevent wrapping */
}

/* --- Modals (Using Bootstrap JS) --- */
.modal-header {
    border-bottom: 1px solid var(--border-color);
}
.modal-footer {
    border-top: 1px solid var(--border-color);
    background-color: #f8f9fa;
}
.modal-title {
    font-weight: 600;
    color: var(--heading-color);
}

/* --- Alerts --- */
.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 4px;
    font-size: 0.95em;
}
.alert .btn-close {
    margin-left: auto; /* Push close button to the right */
    padding: 0.5rem;
}
/* Standard Bootstrap alert colors used */


/* --- Specific Component Styles --- */

/* Project List Status Badge */
.status-badge {
    font-size: 0.8em;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.status-indexed { background-color: var(--success-color); color: var(--white-color); }
.status-not-indexed { background-color: var(--warning-color); color: #212529; }

/* Document Upload Area */
.document-upload-card .card-body {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Results Page Styling */
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    color: var(--heading-color);
    font-weight: 600;
}
.markdown-content h1 { font-size: 1.6rem; }
.markdown-content h2 { font-size: 1.4rem; }
.markdown-content h3 { font-size: 1.2rem; }
.markdown-content h4 { font-size: 1.1rem; }

.markdown-content p { line-height: 1.6; margin-bottom: 1rem; }
.markdown-content ul, .markdown-content ol { padding-left: 2rem; margin-bottom: 1rem; }
.markdown-content li { margin-bottom: 0.4rem; }
.markdown-content strong { font-weight: 600; }

.markdown-content pre {
    background-color: #f1f3f5; /* Lighter code background */
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    overflow-x: auto;
    border: 1px solid var(--border-color);
}
.markdown-content code:not(pre code) {
    background-color: #e9ecef;
    padding: 0.15rem 0.3rem;
    border-radius: 3px;
    font-size: 0.9em;
}
.markdown-content pre code {
    background-color: transparent;
    padding: 0;
    border: none;
}

.markdown-content hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

.markdown-content table { /* Style tables generated from markdown */
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
    font-size: 0.95em;
    display: block;       /* Allow horizontal scrolling if needed */
    overflow-x: auto;
    white-space: nowrap;  /* Prevent overly squished columns */
}
.markdown-content th, .markdown-content td {
    border: 1px solid var(--border-color);
    padding: 8px 10px;
    text-align: left;
    white-space: nowrap;
}
.markdown-content th {
    background-color: #f8f9fa;
    font-weight: 600;
}

/* Loading/Processing Indicators */
.processing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-style: italic;
    color: var(--text-color);
}
.animate-spin {
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Responsive Adjustments --- */
@media (max-width: 992px) {
    .layout {
        grid-template-columns: 1fr; /* Single column */
    }
    .topbar {
        grid-template-columns: auto 1fr; /* Logo takes auto width */
        padding: 0 15px;
    }
    .logo-container {
        grid-column: 1;
    }
    .user-info {
        grid-column: 2;
    }
    .sidebar {
        display: none; /* Hide sidebar by default */
        position: fixed;
        width: var(--sidebar-width);
        z-index: 1020;
        top: var(--topbar-height);
        height: calc(100vh - var(--topbar-height));
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    }
    .sidebar.show { /* Class to show sidebar */
        display: block;
    }
    .main-content {
        grid-column: 1; /* Take full width */
        padding: 15px;
    }

}

/* Sidebar toggle button visible on all screens */
.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--white-color);
    cursor: pointer;
    padding: 0 10px;
}

@media (max-width: 992px) {
    .sidebar-toggle {
        display: block;
        order: -1; /* Place it before the logo if needed */
    }
}

@media (min-width: 993px) {
    .sidebar-toggle {
        display: inline-block;
    }
}

/* --- Login Page Styles (Add/Modify in custom.css) --- */

body.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: #e9ecef;
    padding: 1rem;
}

.login-container {
    max-width: 480px;
    width: 100%;
    margin: auto;
}

.login-card {
    border: none;
    border-radius: 8px;
    overflow: hidden;
}

/* --- UPDATED HEADER STYLES --- */
.login-card-header {
    background-color: var(--white-color);
    padding: 2rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    /* Force column layout and center items horizontally */
    display: flex;             /* <<< ADDED */
    flex-direction: column;    /* <<< ADDED */
    align-items: center;       /* <<< ADDED (Centers items horizontally) */
}

.login-card-header .login-logo {
    display: block;          /* Keep as block */
    max-width: 220px;
    height: auto;
    margin-bottom: 1rem;     /* Space below logo */
    /* No need for margin-left/right auto with align-items: center */
}

.login-card-header .login-title {
    display: block;          /* Keep as block */
    font-weight: 600;
    color: var(--heading-color);
    margin-bottom: 0.25rem;
    text-align: center;      /* <<< Ensure text is centered */
}

.login-card-header .login-subtitle {
    display: block;          /* Keep as block */
    font-size: 1rem;
    margin-bottom: 0;
    color: var(--text-color); /* Ensure text color */
    text-align: center;      /* <<< Ensure text is centered */
}
/* --- END UPDATED HEADER STYLES --- */


.login-card-body {
    padding: 2rem;
    background-color: var(--white-color);
}

.login-page .form-control {
    padding: 12px 15px;
    border-radius: 6px;
    border: 1px solid #ced4da;
    font-size: 1rem;
}
.login-page .form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(11, 122, 46, 0.2);
}


.login-page .input-group-text {
    background-color: #f8f9fa;
    border: 1px solid #ced4da;
    border-right: none;
    border-radius: 6px 0 0 6px;
    padding: 0 12px;
}
.login-page .input-group .form-control {
    border-left: none;
     border-radius: 0 6px 6px 0;
}
.login-page .input-group-text i {
    font-size: 1.1rem;
    color: var(--text-color);
}


.login-button {
    padding: 12px;
    font-size: 1.05rem;
    font-weight: 600;
    transition: all 0.2s ease;
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.login-button:hover {
    background-color: #096a25;
    border-color: #085f21;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.login-footer {
    color: #6c757d;
}

/* Add to custom.css - Scrollable table styles */

/* Table container with fixed height and scrolling */
.table-scroll-container {
    max-height: 250px;  /* Height for about 3-4 rows plus header */
    overflow-y: auto;
    border-bottom: 1px solid var(--border-color);
}

/* Keep header fixed while scrolling body */
.table-scroll-container table {
    position: relative;
    border-collapse: separate;
    border-spacing: 0;
}

.table-scroll-container thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.table-scroll-container thead th {
    background-color: #f8f9fa;
    box-shadow: 0 1px 0 var(--border-color); /* Bottom border for header */
}

/* Make sure table rows are properly aligned in scroll mode */
.table-scroll-container tbody tr:first-child td {
    border-top: none;
}

/* Ensure cards with tables don't have overflow issues */
.card .table-responsive {
    overflow: visible; /* Allow our custom scrollable area to handle overflow */
}

/* Additional style for scrollbar appearance */
.table-scroll-container::-webkit-scrollbar {
    width: 8px;
}

.table-scroll-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-scroll-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.table-scroll-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Add these styles to custom.css for fixed project table scrolling */

/* Target specific project tables - more specific selectors */
.card .table-responsive {
    max-height: 200px;
    overflow-y: auto;
}

/* Keep the header fixed while scrolling */
.card .table-responsive table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #f8f9fa;
}

/* Ensure header appears above content when scrolling */
.card .table-responsive table thead th {
    background-color: #f8f9fa;
    box-shadow: 0 1px 0 var(--border-color);
    position: sticky;
    top: 0;
}

/* Ensure borders look consistent */
.card .table-responsive table {
    border-collapse: separate;
    border-spacing: 0;
}

/* Custom scrollbar styling */
.card .table-responsive::-webkit-scrollbar {
    width: 8px;
}

.card .table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.card .table-responsive::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.card .table-responsive::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Fix for Firefox scrollbar */
.card .table-responsive {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

/* --- End Login Page Styles --- */

/* Add to custom.css - Search bar styling */

.search-container {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    position: relative;
}

.search-container .form-control {
    padding-left: 35px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.search-container .search-icon {
    position: absolute;
    left: 10px;
    color: #6c757d;
    font-size: 1.1em;
}

.search-container .clear-search {
    position: absolute;
    right: 10px;
    color: #6c757d;
    border: none;
    background: transparent;
    font-size: 0.9em;
    cursor: pointer;
    display: none;
}

.search-container .clear-search:hover {
    color: var(--danger-color);
}

/* Match highlighting */
.highlight-match {
    background-color: rgba(255, 243, 148, 0.5);
    padding: 0 2px;
    border-radius: 2px;
}

/* No results message */
.no-results-message {
    display: none;
    padding: 15px;
    text-align: center;
    color: #6c757d;
    background-color: #f8f9fa;
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    margin-top: 10px;
}

/* Function selection page */
.function-card {
    border-radius: 0.75rem;
    border: none;
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.05);
    transition: transform 0.2s, box-shadow 0.2s;
}

.function-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.1);
}

.function-icon {
    font-size: 2.5rem;
    color: var(--primary-color);
}

/* Disabled function styling */
.function-card.blurred {
    filter: blur(1px);
    opacity: 0.4;
}

.disabled-link {
    pointer-events: none;
    cursor: not-allowed;
}

/* --- Tasks Dropdown Styling --- */
.btn-tasks {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.tasks-menu {
    max-height: 260px;
    overflow-y: auto;
    min-width: 14rem;
}

.tasks-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 1rem;
}

.tasks-menu .dropdown-item i {
    color: var(--secondary-color);

}



/* Quick Insights Modal */
#quickInsightsModal .modal-dialog { max-width: 800px; }
#quickInsightsModal .list-group-item { display: flex; align-items: center; }
