/* =================================================================== */
/*  STYLES FOR THE INTELLIGENT EXTRACTION PAGE                        */
/* =================================================================== */

/* --- 1. GENERAL & SHARED COMPONENTS --- */

.info-card { 
    cursor: pointer; 
    border: 1px solid var(--bs-border-color);
    transition: all 0.2s ease-in-out; 
}
.info-card:hover { 
    transform: translateY(-3px); 
    box-shadow: var(--bs-box-shadow-sm);
    border-color: var(--bs-primary); 
}
.info-card.active {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
}
.info-card .card-icon { 
    font-size: 2rem; 
    color: var(--bs-primary);
    margin-bottom: 0.5rem;
}
.info-card .card-count {
    font-size: 1.25rem;
    font-weight: bold;
    min-height: 24px;
}

/* The chevron icon for the collapse button in output sections */
.collapse-icon {
    transition: transform 0.2s ease-in-out;
}
.collapse-icon.collapsed {
    transform: rotate(180deg);
}

/* The AI model toggle buttons (Gemini/LLAVA) */
.insight-toggle-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.insight-toggle-container label {
    cursor: pointer;
    padding: 6px 12px;
    border: 1px solid #0d6efd;
    border-radius: 0.375rem;
    font-size: 14px;
    font-weight: 500;
    color: #0d6efd;
    transition: background-color 0.2s ease, color 0.2s ease;
}
.insight-toggle-container input[type="radio"] { 
    display: none; 
}
.insight-toggle-container input[type="radio"]:checked + label {
    background-color: #0d6efd;
    color: white;
}


/* --- 2. "EXTRACT" TAB - SPECIFIC STYLES --- */

/* For displaying extracted text and annotations */
.text-display-container {
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 16px;
    line-height: 1.6;
    color: #333;
    background-color: #fcfcfc;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    padding: 24px 28px;
    white-space: pre-wrap;
    text-align: justify;
}

/* For the grid of extracted figures/images */
.image-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    padding: 1rem 0;
}
.image-card {
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    padding: 1rem;
    width: 260px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.image-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.image-card .image-wrapper {
    height: 180px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    margin-bottom: 1rem;
    cursor: pointer;
    background-color: #f8f9fa;
    border-radius: 0.375rem;
}
.image-card .image-wrapper img {
    max-height: 100%; 
    width: auto;
}
.image-caption {
    font-size: 14px; 
    color: #6c757d; 
    text-align: left; 
    flex-grow: 1;
    margin-bottom: 1rem;
}
.image-card .insight-text {
    display: none; 
    font-size: 14px; 
    line-height: 1.5; 
    color: #495057;
    background-color: #f8f9fa; 
    border: 1px solid #dee2e6; 
    border-radius: 0.375rem;
    padding: 0.75rem; 
    width: 100%; 
    text-align: left;
    margin-top: 0.75rem;
    max-height: 200px; 
    overflow-y: auto;
}
.image-card .insight-text.active { 
    display: block; 
}

/* For tables generated inside an insight */
.insight-text .generated-table, 
#overlay-insight .generated-table {
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 1rem;
    font-size: 14px; 
    table-layout: fixed; 
    border: 1px solid #dee2e6;
}
.insight-text .generated-table th, 
.insight-text .generated-table td,
#overlay-insight .generated-table th, 
#overlay-insight .generated-table td {
    border: 1px solid #dee2e6; 
    padding: 0.5rem 0.75rem;
    text-align: left; 
    word-break: break-word;
}
.insight-text .generated-table th,
#overlay-insight .generated-table th {
    background-color: #f8f9fa;
}

/* For the preview of extracted tables from the backend */
.tf-table-card {
    max-width: 900px; 
    width: 100%; 
    margin: 0 auto 1.5rem auto;
    background: white; 
    border-radius: 0.5rem;
    padding: 1.5rem;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.tf-split-container { 
    overflow-x: auto; 
    max-height: 700px;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
}
.tf-split-table { 
    width: 100%; 
    border-collapse: collapse; 
}
.tf-split-table th, 
.tf-split-table td { 
    border: 1px solid #dee2e6; 
    padding: 0.5rem; 
    text-align: center; 
}
.tf-preview-insight {
    margin-top: 1rem; 
    padding: 1rem; 
    background: #e9ecef;
    border-radius: 0.375rem; 
    font-size: 15px; 
    text-align: justify;
}

/* Image Overlay (Lightbox) */
.overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(33, 37, 41, 0.85);
    display: none; justify-content: center; align-items: center; z-index: 1060;
}
.overlay .close-btn {
    position: absolute; top: 15px; right: 35px; font-size: 40px;
    font-weight: bold; color: #f8f9fa; cursor: pointer;
    transition: color 0.2s ease;
}
.overlay .close-btn:hover { color: #adb5bd; }
.overlay-content {
    background: #fff; border-radius: 0.5rem; padding: 1.5rem;
    max-width: 90vw; max-height: 90vh; overflow-y: auto; text-align: center;
}
.overlay-content img { max-width: 100%; max-height: 60vh; height: auto; margin-bottom: 1rem; }
.overlay-insight {
    font-size: 1rem; line-height: 1.6; color: #212529; background-color: #f8f9fa;
    border-radius: 0.375rem; padding: 1rem; margin-top: 1rem; text-align: justify;
    max-height: 300px; overflow-y: auto;
}

/* Custom Table Modals (from backend HTML) */
.tf-modal {
  display: none; position: fixed; z-index: 1055;
  left: 0; top: 0; width: 100%; height: 100%;
  overflow: auto; background-color: rgba(0,0,0,0.5);
  justify-content: center; align-items: center;
}
.tf-modal-content {
  background-color: #fefefe; margin: auto; padding: 0;
  border: 1px solid #888; width: 90%; max-width: 1140px;
  border-radius: 0.5rem; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
  animation: fadeIn 0.3s;
}
@keyframes fadeIn {
  from {opacity: 0; transform: translateY(-20px);}
  to {opacity: 1; transform: translateY(0);}
}
.tf-close {
  color: white; float: right; font-size: 28px; font-weight: bold;
  position: absolute; top: 5px; right: 15px;
  transition: color 0.2s ease-in-out;
}
.tf-close:hover, .tf-close:focus { color: #ddd; text-decoration: none; cursor: pointer; }
.tf-full-table-container { padding: 1rem; overflow-x: auto; }


/* --- 3. "BROWSE" TAB - SPECIFIC STYLES --- */

/* Highlight for searched row */
.table > tbody > tr.highlight-row > td {
  background-color: #fff3cd !important;
  transition: background-color 0.5s ease-out;
}

/* Styles for the table injected from the server */
.split-table1-container {
    overflow-x: auto;
}
.split-table1 {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.split-table1 th, .split-table1 td {
    border: 1px solid #ddd;
    padding: 0.5rem;
    text-align: center;
    white-space: nowrap;
}
.split-table1 th {
    background-color: #f8f9fa;
    font-weight: 600;
}
.pagination-list { /* For the custom server-rendered pagination */
    list-style: none; padding: 0; display: inline-block;
}
.pagination-list li { display: inline; margin: 0 5px; }
.pagination-list a { text-decoration: none; padding: 5px 10px; border: 1px solid #0d6efd; border-radius: 4px; color: #0d6efd;}
.active-page a { background-color: #0d6efd; color: white; }

/* Target the gallery container inside our new modal */
#browse-content-modal .modal-image-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
}

/* Style each image's container div */
#browse-content-modal .image-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 150px;
}

/* **THE CORE FIX**: Style the images themselves inside the modal */
#browse-content-modal .image-item img {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    background-color: #f8f9fa;
    margin-bottom: 0.5rem;
}

/* Style for the filename caption under each image */
#browse-content-modal .image-item-caption {
    font-size: 0.8rem;
    color: #6c757d;
    word-break: break-all;
    text-align: center;
}

.tier-summary-card {
    border: 1px solid var(--bs-border-color); /* Subtle default Bootstrap border */
    border-radius: var(--bs-border-radius); /* Default Bootstrap border radius */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    height: 100%; /* Ensure cards in a row have equal height */
    cursor: default; /* Not clickable like category cards, so no pointer */
    text-align: center; /* Center text */
    border-left-width: 4px;
}

/* If you want a subtle hover effect (optional, as they aren't clickable) */
.tier-summary-card:hover {
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); /* Slight shadow on hover */
}

.category-card {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    height: 100%;
    /* NEW: Add a subtle left border for all cards */
    border-left-width: 4px;
}

.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
}

/* Tier 1 - Primary */
.category-card.bg-primary-subtle { border-color: var(--bs-primary-border-subtle); }
.category-card.bg-primary-subtle:hover { border-color: var(--bs-primary); }
.category-card .card-title.text-primary { color: var(--bs-primary-text-emphasis) !important; }

.tier-summary-card.bg-primary-subtle { border-color: var(--bs-primary-border-subtle); }
.tier-summary-card.bg-primary-subtle:hover { border-color: var(--bs-primary); }
.tier-summary-card .card-title.text-primary { color: var(--bs-primary-text-emphasis) !important; }

/* Tier 2 - Success */
.category-card.bg-success-subtle { border-color: var(--bs-success-border-subtle); }
.category-card.bg-success-subtle:hover { border-color: var(--bs-success); }
.category-card .card-title.text-success { color: var(--bs-success-text-emphasis) !important; }

.tier-summary-card.bg-success-subtle { border-color: var(--bs-success-border-subtle); }
.tier-summary-card.bg-success-subtle:hover { border-color: var(--bs-success); }
.tier-summary-card .card-title.text-success { color: var(--bs-success-text-emphasis) !important; }

/* Tier 3 - Warning */
.category-card.bg-warning-subtle { border-color: var(--bs-warning-border-subtle); }
.category-card.bg-warning-subtle:hover { border-color: var(--bs-warning); }
.category-card .card-title.text-warning { color: var(--bs-warning-text-emphasis) !important; }

.tier-summary-card.bg-warning-subtle { border-color: var(--bs-warning-border-subtle); }
.tier-summary-card.bg-warning-subtle:hover { border-color: var(--bs-warning); }
.tier-summary-card .card-title.text-warning { color: var(--bs-warning-text-emphasis) !important; }

/* Tier 4 - Secondary/Grey */
.category-card.bg-secondary-subtle { border-color: var(--bs-secondary-border-subtle); }
.category-card.bg-secondary-subtle:hover { border-color: var(--bs-secondary); }
.category-card .card-title.text-secondary { color: var(--bs-secondary-text-emphasis) !important; }

.tier-summary-card.bg-secondary-subtle { border-color: var(--bs-secondary-border-subtle); }
.tier-summary-card.bg-secondary-subtle:hover { border-color: var(--bs-secondary); }
.tier-summary-card .card-title.text-secondary { color: var(--bs-secondary-text-emphasis) !important; }

/* Default for sub-levels */
.category-card.bg-white:hover { border-color: #0d6efd; }

/* Default card title color */
.category-card .card-title {
    font-weight: 600;
    color: #0d6efd; /* Fallback for sub-levels */
    margin-bottom: 0.5rem;
}

.category-card .card-body {
    padding: 1rem;
}

.category-card .card-title {
    font-weight: 600;
    color: #0d6efd;
    margin-bottom: 0.5rem;
}

.breadcrumb-item a {
    text-decoration: none;
}

.article-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
    height: 100%;
}

.article-card {
    border: 1px solid #e9ecef;
    border-radius: 0.5rem;
    background-color: #fff;
    height: 100%;
    transition: all 0.2s ease-in-out;
    display: flex;
    flex-direction: column;
}

.article-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
    border-color: #0d6efd;
}

.article-card .card-body {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    flex-grow: 1; /* This is already good, it allows the body to fill the space */
}

.article-card .card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    flex-grow: 1;
}

.article-card .card-subtitle {
    font-size: 0.8rem;
}

.article-card .specific-category-text {
    font-size: 0.85rem;
    font-style: italic;
    color: #6c757d;
}

.article-card .badge {
    align-self: flex-start;
    /* Add the following rules to prevent overflow */
    white-space: normal; /* Allows text to wrap to a new line */
    word-break: break-word; /* Breaks a long word if it can't fit */
    text-align: center; /* Align wrapped text to the left */
}
/* =================================================================== */
/* GLOBAL OVERRIDES - Make these more specific than Bootstrap's classes */
/* =================================================================== */

.display-5.fw-bold {
    font-size: 1.75rem !important;
}

.lead.text-muted {
    font-size: 0.9rem !important;
}

/* If you also want to reduce the icon size (which uses display-4), you can add:
*/
.display-4 {
    font-size: 2rem !important; /* Adjust this value */
}

/* =================================================================== */
/* MEDIA QUERIES FOR LARGER SCREENS                                   */
/* =================================================================== */
/* Update font size for the "Overall Statistics" and "Article Categories" headings */
.card-header h5 {
    font-size: 1rem;
}

/* Update font sizes for labels and form placeholders */
.form-label,
#doi-search-input::placeholder {
    font-size: 0.9rem;
}

/* Adjust button font sizes */
.btn {
    font-size: 0.85rem;
}

/* Small adjustments to elements inside info-cards */
.info-card .card-title {
    font-size: 0.8rem;
}
.info-card .card-count {
    font-size: 0.9rem;
}

/* Adjust font size for filter labels */
.form-check-label {
    font-size: 0.85rem;
}

/* Adjust font size for the placeholder text in the search input */
#doi-search-input {
    font-size: 0.8rem;
}
#doi-input.form-control-lg {
    font-size: 0.9rem; /* Adjust this value to be slightly larger than the placeholder */
}
@media (min-width: 576px) {
    .display-5.fw-bold {
        font-size: 1.8rem !important;
    }
    
    .lead.text-muted {
        font-size: 1rem !important;
    }
    
    /* Icon size for larger screens */
    .display-4 {
        font-size: 2.2rem !important; /* Adjust this value */
    }
    /* Larger font for the main card headings */
    .card-header h5 {
        font-size: 1.15rem;
    }
    
    /* Larger font for form labels */
    .form-label,
    #doi-search-input::placeholder {
        font-size: 1rem;
    }
    
    /* Larger font for buttons */
    .btn {
        font-size: 0.95rem;
    }
    
    /* Larger font for info card titles and counts */
    .info-card .card-title {
        font-size: 0.9rem;
    }
    .info-card .card-count {
        font-size: 1rem;
    }
    
    /* Larger font for filter labels */
    .form-check-label {
        font-size: 0.95rem;
    }
    
    /* Larger font for search input */
    #doi-search-input {
        font-size: 0.9rem;
    }
}