/* ==========================================
   BRAND + BOOTSTRAP VARIABLE OVERRIDES
   ========================================== */
/* Bootstrap 5 (5.3+) supports theming via CSS variables.
   We override the brand color here and rely on Bootstrap components/utilities. */
:root,
[data-bs-theme="light"] {
  /* Overall UI density: slightly smaller typography than Bootstrap defaults. */
  --bs-body-font-size: 0.95rem;

  /* Brand */
  /* Replace Bootstrap default primary with MCADS brand primary. */
  --bs-primary: #572437;
  --bs-primary-rgb: 87, 36, 55;

  /* Brand accents (hover/active). Keep the previous palette feel. */
  --mcads-primary-hover: #7b3349;
  --mcads-primary-hover-rgb: 123, 51, 73;
  --mcads-primary-dark: #3e1926;

  /* Legacy aliases (kept for backwards compatibility inside this stylesheet). */
  --primary: var(--bs-primary);
  --primary-rgb: var(--bs-primary-rgb);
  --primary-hover: var(--mcads-primary-hover);
  --primary-dark: var(--mcads-primary-dark);

  /* Make links follow brand primary (Bootstrap defaults are blue). */
  --bs-link-color: var(--bs-primary);
  --bs-link-color-rgb: var(--bs-primary-rgb);
  --bs-link-hover-color: var(--mcads-primary-hover);
  --bs-link-hover-color-rgb: var(--mcads-primary-hover-rgb);

  /* Keep the "blue" token aligned with our primary as well. */
  --bs-blue: var(--bs-primary);

  /* Focus ring should match brand (avoid default blue focus flash). */
  --bs-focus-ring-color: rgba(var(--bs-primary-rgb), 0.25);

  /* Bootstrap palette aliases used throughout this stylesheet. */
  --secondary: var(--bs-secondary);
  --danger: var(--bs-danger);
  --warning: var(--bs-warning);
  --success: var(--bs-success);
  --info: var(--bs-info);
  --info-rgb: var(--bs-info-rgb);
  --light: var(--bs-light);
  --dark: var(--bs-dark);
  --white: var(--bs-white);

  /* Background helpers (used by a few custom components). */
  --light-bg: #f8f9fa;
  --dark-bg: #212529;

  /* Local layout helpers */
  --light-border: var(--bs-border-color);
  --border-radius: var(--bs-border-radius);
  --border-radius-lg: var(--bs-border-radius-lg);
  --box-shadow: var(--bs-box-shadow);
  --box-shadow-lg: var(--bs-box-shadow-lg);

  /* Spacing (legacy, used widely across templates). */
  --spacing-xs: 0.2rem;
  --spacing-sm: 0.4rem;
  --spacing-md: 0.6rem;
  --spacing-lg: 0.8rem;
  --spacing-xl: 1rem;
  --spacing-xxl: 1.2rem;

  /* Typography (legacy) */
  --font-size-xs: 0.6rem;
  --font-size-sm: 0.75rem;
  --font-size-md: 0.875rem;
  --font-size-lg: 0.95rem;
  --font-weight-normal: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Motion (legacy) */
  --transition-fast: 0.15s ease-in-out;
  --transition-normal: 0.3s ease;

  /* Component specific */
  --card-padding: var(--spacing-xl);

  /* Star/save button styles */
  --star-color-empty: var(--bs-warning);
  --star-color-filled: var(--bs-danger);
}

/* Dropdown interaction colors (avoid default Bootstrap blue on active/focus). */
.dropdown-menu {
  --bs-dropdown-link-hover-bg: rgba(var(--bs-primary-rgb), 0.08);
  --bs-dropdown-link-active-bg: rgba(var(--bs-primary-rgb), 0.16);
  --bs-dropdown-link-active-color: var(--bs-body-color);
}

/* Results page: metadata header uses `thead.table-light`. In dark mode Bootstrap keeps it white,
   so remap it to a theme-friendly background. */
[data-bs-theme="dark"] .image-metadata-table thead.table-light {
  --bs-table-bg: var(--bs-tertiary-bg);
  --bs-table-color: var(--bs-body-color);
  --bs-table-border-color: var(--bs-border-color);
}

/* Mobile tap highlight can briefly flash blue in some browsers. Keep it on-brand. */
a,
button,
.dropdown-item {
  -webkit-tap-highlight-color: rgba(var(--bs-primary-rgb), 0.2);
}

/* Ensure Bootstrap's primary buttons use our brand primary (not the default blue). */
.btn-primary {
  --bs-btn-bg: var(--bs-primary);
  --bs-btn-border-color: var(--bs-primary);
  --bs-btn-hover-bg: var(--mcads-primary-hover);
  --bs-btn-hover-border-color: var(--mcads-primary-hover);
  --bs-btn-active-bg: var(--mcads-primary-dark);
  --bs-btn-active-border-color: var(--mcads-primary-dark);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

.btn-outline-primary {
  --bs-btn-color: var(--bs-primary);
  --bs-btn-border-color: var(--bs-primary);
  --bs-btn-hover-bg: var(--bs-primary);
  --bs-btn-hover-border-color: var(--bs-primary);
  --bs-btn-active-bg: var(--mcads-primary-dark);
  --bs-btn-active-border-color: var(--mcads-primary-dark);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

/* Soft primary button (matches compact card-header look: light brand tint + brand text). */
.btn-soft-primary {
  --bs-btn-color: var(--bs-primary);
  --bs-btn-bg: rgba(var(--bs-primary-rgb), 0.08);
  --bs-btn-border-color: rgba(var(--bs-primary-rgb), 0.22);
  --bs-btn-hover-color: var(--bs-primary);
  --bs-btn-hover-bg: rgba(var(--bs-primary-rgb), 0.12);
  --bs-btn-hover-border-color: rgba(var(--bs-primary-rgb), 0.28);
  --bs-btn-active-color: var(--bs-primary);
  --bs-btn-active-bg: rgba(var(--bs-primary-rgb), 0.16);
  --bs-btn-active-border-color: rgba(var(--bs-primary-rgb), 0.34);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

[data-bs-theme="dark"] .btn-soft-primary {
  --bs-btn-bg: rgba(var(--bs-primary-rgb), 0.18);
  --bs-btn-border-color: rgba(var(--bs-primary-rgb), 0.34);
  --bs-btn-hover-bg: rgba(var(--bs-primary-rgb), 0.24);
  --bs-btn-hover-border-color: rgba(var(--bs-primary-rgb), 0.42);
  --bs-btn-active-bg: rgba(var(--bs-primary-rgb), 0.3);
  --bs-btn-active-border-color: rgba(var(--bs-primary-rgb), 0.5);
}

/* Star/save button styling */
.save-toggle-btn {
  transition: all var(--transition-fast);
}

.save-toggle-btn:hover {
  transform: scale(1.05);
}

.save-toggle-btn .fa-star {
  color: var(--star-color-empty);
  transition: color var(--transition-fast);
}

.save-toggle-btn[data-saved="true"] .fa-star {
  color: var(--star-color-filled);
}

.save-toggle-btn:disabled {
  opacity: 0.6;
  transform: none;
}

/* Ensure consistent button widths in action button groups */
.btn-group .btn-sm {
  min-width: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Specific width consistency for table action buttons */
.table .btn-group .btn-sm {
  width: 2.25rem;
  height: 2rem;
}

[data-bs-theme="dark"] {
  /* Keep brand consistent across color modes. */
  --bs-primary: #572437;
  --bs-primary-rgb: 87, 36, 55;
  --mcads-primary-hover: #7b3349;
  --mcads-primary-hover-rgb: 123, 51, 73;
  --mcads-primary-dark: #3e1926;

  /* Legacy aliases */
  --primary: var(--bs-primary);
  --primary-rgb: var(--bs-primary-rgb);
  --primary-hover: var(--mcads-primary-hover);
  --primary-dark: var(--mcads-primary-dark);

  --bs-link-color: var(--bs-primary);
  --bs-link-color-rgb: var(--bs-primary-rgb);
  --bs-link-hover-color: var(--mcads-primary-hover);
  --bs-link-hover-color-rgb: var(--mcads-primary-hover-rgb);
  --bs-blue: var(--bs-primary);

  --bs-focus-ring-color: rgba(var(--bs-primary-rgb), 0.25);

  --light-border: var(--bs-border-color);
}

/* ==========================================
   SMALL GLOBAL HELPERS (KEEP MINIMAL)
   ========================================== */
/* Bootstrap already ships resets/utilities; avoid overriding core classes here. */

/* Bootstrap button variants already cover primary/warning/success/etc.
   Avoid globally overriding `.btn-*` classes to keep Bootstrap predictable. */

/* ==========================================
   GLOBAL UI DENSITY (COMPACT)
   ========================================== */
/* Use low-specificity selectors so component-specific utilities can still override. */
:where(.btn) {
  --bs-btn-padding-y: 0.25rem;
  --bs-btn-padding-x: 0.6rem;
  --bs-btn-font-size: var(--bs-body-font-size);
  --bs-btn-line-height: 1.2;
}

:where(.alert) {
  --bs-alert-padding-y: 0.5rem;
  --bs-alert-padding-x: 0.75rem;
  --bs-alert-margin-bottom: 0.5rem;
}

:where(.dropdown-menu) {
  --bs-dropdown-padding-y: 0.25rem;
  --bs-dropdown-padding-x: 0.25rem;
  --bs-dropdown-item-padding-y: 0.35rem;
  --bs-dropdown-item-padding-x: 0.75rem;
  --bs-dropdown-font-size: var(--bs-body-font-size);
}

:where(.modal) {
  --bs-modal-padding: 0.75rem;
  --bs-modal-header-padding: 0.5rem 0.75rem;
  --bs-modal-footer-gap: 0.5rem;
  --bs-modal-margin: 0.75rem;
}

:where(.form-label) {
  margin-bottom: 0.2rem;
}

:where(.form-control, .form-select, .input-group-text) {
  padding: 0.3rem 0.6rem;
  font-size: var(--bs-body-font-size);
}

/* Slightly denser navbar to match the app's compact UI. */
.navbar {
  --bs-navbar-padding-y: 0.25rem;
}

/* ==========================================
   FORM STYLES - INPUT GROUPS
   ========================================== */

/* File input group - ensure Browse button and text input have same height */
.input-group #custom-file-button,
.input-group #file-name-display {
  height: calc(2.125rem + 2px) !important;
  line-height: 1.3 !important;
  padding: 0.3rem 0.6rem !important;
  border: 1px solid var(--light-border) !important;
  display: flex !important;
  align-items: center !important;
}

.input-group #custom-file-button {
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

.input-group #file-name-display {
  border-top-left-radius: 0 !important;
  border-bottom-left-radius: 0 !important;
  border-left: none !important;
}

/* Ensure consistent font size and spacing */
.input-group #custom-file-button,
.input-group #file-name-display {
  font-size: var(--bs-body-font-size) !important;
  font-weight: 400 !important;
  vertical-align: middle !important;
}

/* Icon spacing inside Browse button */
.input-group #custom-file-button i {
  margin-right: 0.35rem !important;
}

/* Password toggle button styles */
.input-group #togglePassword {
  border-color: var(--light-border) !important;
  background-color: transparent !important;
  color: var(--secondary) !important;
  transition: all var(--transition-fast);
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-width: 2.25rem !important;
  height: calc(2.125rem + 2px) !important;
}

.input-group #togglePassword:hover {
  background-color: var(--light-bg) !important;
  border-color: var(--secondary) !important;
  color: var(--secondary) !important;
}

.input-group #togglePassword:focus {
  box-shadow: 0 0 0 0.25rem rgba(var(--secondary), 0.25) !important;
  border-color: var(--secondary) !important;
  outline: none !important;
}

.input-group #togglePassword:active {
  background-color: var(--secondary) !important;
  border-color: var(--secondary) !important;
  color: white !important;
}

.input-group #togglePassword i {
  font-size: 1rem !important;
  transition: color var(--transition-fast);
}

/* Ensure password input and toggle button have same height */
.input-group .form-control {
  height: calc(2.125rem + 2px) !important;
  border-right: none !important;
}

.input-group .form-control:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 0.25rem rgba(var(--primary-rgb), 0.25) !important;
}

.input-group .form-control:focus + #togglePassword {
  border-color: var(--primary) !important;
}

/* Dark mode adjustments for password toggle */
[data-bs-theme="dark"] .input-group #togglePassword {
  border-color: var(--light-border) !important;
  background-color: transparent !important;
  color: var(--light) !important;
}

[data-bs-theme="dark"] .input-group #togglePassword:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
  border-color: var(--light) !important;
  color: var(--light) !important;
}

[data-bs-theme="dark"] .input-group #togglePassword:focus {
  box-shadow: 0 0 0 0.25rem rgba(255, 255, 255, 0.25) !important;
  border-color: var(--light) !important;
}

[data-bs-theme="dark"] .input-group #togglePassword:active {
  background-color: var(--light) !important;
  border-color: var(--light) !important;
  color: var(--dark) !important;
}

[data-bs-theme="dark"] .input-group .form-control {
  border-color: var(--light-border) !important;
}

[data-bs-theme="dark"] .input-group .form-control:focus + #togglePassword {
  border-color: var(--primary) !important;
}

/* ==========================================
   CARD STYLES
   ========================================== */
.card {
  /* Make cards slightly denser than Bootstrap defaults (less whitespace). */
  --bs-card-spacer-y: 0.6rem;
  --bs-card-spacer-x: 0.75rem;
  --bs-card-cap-padding-y: 0.4rem;
  --bs-card-cap-padding-x: 0.75rem;
  /* Subtle branded header background for default headers. */
  --bs-card-cap-bg: rgba(var(--bs-primary-rgb), 0.06);

  border-radius: var(--border-radius-lg);
  box-shadow: var(--box-shadow);
}

[data-bs-theme="dark"] .card {
  --bs-card-cap-bg: rgba(var(--bs-primary-rgb), 0.12);
}

.card-header {
  border-bottom-color: var(--light-border);
  font-weight: var(--font-weight-semibold);
}

/* Keep card header titles aligned and compact. */
.card-header h2,
.card-header h3,
.card-header h4,
.card-header h5,
.card-header h6 {
  font-weight: var(--font-weight-semibold);
  margin: 0;
}

/* Default card header title color (match "Advanced filters"). */
.card-header:not(.text-white):not(.text-dark) h2,
.card-header:not(.text-white):not(.text-dark) h3,
.card-header:not(.text-white):not(.text-dark) h4,
.card-header:not(.text-white):not(.text-dark) h5,
.card-header:not(.text-white):not(.text-dark) h6 {
  color: var(--bs-primary);
}

/* Header icons (opt-in via `header-*` class). */
.card-header[class*="header-"] h2:before,
.card-header[class*="header-"] h3:before,
.card-header[class*="header-"] h4:before,
.card-header[class*="header-"] h5:before,
.card-header[class*="header-"] h6:before {
  content: '\f0b0';
  /* Keep in sync with the vendored Font Awesome version (currently 6.x). */
  font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free';
  margin-right: var(--spacing-sm);
  font-weight: 900;
}

/* Specific card header icons */
.card-header.header-mcads h2:before, .card-header.header-mcads h5:before { content: '\f7e6'; }
.card-header.header-patient h5:before { content: '\f007'; }
.card-header.header-severity h5:before { content: '\f071'; }
.card-header.header-xray h5:before { content: '\f0fa'; }
.card-header.header-prediction h5:before { content: '\f200'; }
.card-header.header-history h5:before { content: '\f1da'; }
.card-header.header-account h5:before, .card-header.header-account h4:before { content: '\f013'; }
.card-header.header-interpretability h5:before { content: '\f06e'; }
.card-header.header-filters h5:before { content: '\f0b0'; }
.card-header.header-danger h5:before { content: '\f06a'; color: var(--danger); }

/* ==========================================
   SMALL UI HELPERS
   ========================================== */
/* Flag images in the language dropdown. */
.flag-img {
  width: 1.33em;
  height: 1em;
  vertical-align: middle;
  display: inline-block;
  object-fit: cover;
  border-radius: 0.2rem;
}

/* Hover affordance for clickable X-ray images (kept small and scoped). */
.xray-image {
  cursor: pointer;
  max-height: 800px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Results page: show the same 1:1 center-crop the model sees.
   We keep a fixed max width so the square doesn't become overwhelmingly large
   on ultra-wide screens, but still scales down cleanly on mobile. */
.model-view-frame {
  width: min(100%, 800px);
  margin: 0 auto;
}

.xray-image.model-crop {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: center;
}

.xray-image:hover {
  transform: scale(1.02);
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}

.position-relative .bi-zoom-in {
  transition: transform 0.3s ease;
}

.position-relative:hover .bi-zoom-in {
  transform: scale(1.2);
}

/* ==========================================
   TABLE STYLES
   ========================================== */
.table {
  --bs-table-hover-bg: rgba(var(--primary-rgb), 0.05);
}

/* Slightly denser tables by default (use `.table-sm` for extra density). */
.table:not(.table-sm) {
  --bs-table-cell-padding-y: 0.35rem;
  --bs-table-cell-padding-x: 0.5rem;
}

/* ==========================================
   MODERN LOADING SYSTEM
   ========================================== */

/* Modern loading animations */
@keyframes modern-flow {
  0% { 
    background-position: -200% center; 
    opacity: 0.8;
  }
  50% { 
    opacity: 1;
  }
  100% { 
    background-position: 200% center; 
    opacity: 0.8;
  }
}

@keyframes modern-pulse {
  0%, 100% { 
    /* Keep container border/size static; only allow subtle opacity change. */
    opacity: 1;
  }
  50% { 
    opacity: 1;
  }
}

/* Modern progress container */
.modern-progress {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 12px;
  padding: 3px;
  position: relative;
  overflow: hidden;
  box-shadow: 
    inset 0 2px 4px rgba(0, 0, 0, 0.06),
    0 1px 3px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(var(--primary-rgb), 0.1);
}

.modern-progress-bar {
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    rgba(var(--primary-rgb), 0.9) 25%,
    var(--primary) 50%,
    rgba(var(--primary-rgb), 0.9) 75%,
    var(--primary) 100%
  );
  background-size: 200% 100%;
  height: 100%;
  border-radius: 10px;
  position: relative;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 
    0 2px 8px rgba(var(--primary-rgb), 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.modern-progress-bar.animated {
  animation: modern-flow 2s ease-in-out infinite;
}

.modern-progress.pulsing {
  animation: modern-pulse 2s ease-in-out infinite;
}

.modern-progress-bar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.2) 50%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: modern-flow 1.5s ease-in-out infinite;
}

/* Modern loading text */
.modern-progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--dark);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
  z-index: 3;
  pointer-events: none;
  letter-spacing: 0.5px;
}

/* Static progress bars with modern styling */
.progress {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: visible;
  position: relative;
  height: 1.25rem;
}

.progress-bar {
  border-radius: 6px;
  position: relative;
  transition: width 0.3s ease;
  box-shadow: 
    0 1px 3px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.progress-bar.bg-success { 
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%) !important;
}

.progress-bar.bg-warning { 
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
}

.progress-bar.bg-danger { 
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
}

.progress-bar.bg-info { 
  background: linear-gradient(135deg, var(--info) 0%, #0bb5d6 100%) !important;
}

.progress-bar.bg-primary:not(.modern-progress-bar) { 
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%) !important;
}

.progress-bar.bg-secondary { 
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%) !important;
}

/* Legacy support for existing progress bars */
.progress-bar.bg-loading {
  background: var(--primary) !important;
}

.progress-bar.bg-loading.progress-bar-animated {
  animation: modern-flow 2s ease-in-out infinite;
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    rgba(var(--primary-rgb), 0.9) 25%,
    var(--primary) 50%,
    rgba(var(--primary-rgb), 0.9) 75%,
    var(--primary) 100%
  ) !important;
  background-size: 200% 100%;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: 600;
  font-size: 0.8rem;
  color: #333;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
  z-index: 2;
  letter-spacing: 0.3px;
}

/* Button loading states */
.btn.loading {
  /* Keep feedback simple (no spinners). */
  cursor: wait;
  opacity: 0.75;
  pointer-events: none;
}

/* Accessibility improvements */
.modern-progress[role="progressbar"] {
  position: relative;
}

.modern-progress[role="progressbar"]::after {
  content: attr(aria-label);
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .modern-progress-bar.animated,
  .progress-bar.bg-loading.progress-bar-animated,
  .modern-progress.pulsing {
    animation: none !important;
  }
  
  .modern-progress-bar::before {
    display: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .modern-progress {
    background: white;
    border: 2px solid black;
  }
  
  .modern-progress-bar {
    background: black !important;
  }
}

/* Focus states for accessibility */
.modern-progress:focus-within,
.progress:focus-within {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn.loading:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ==========================================
   MOBILE OPTIMIZATIONS
   ========================================== */

/* Mobile-first responsive design */
@media (max-width: 768px) {
  /* Larger progress bars for touch devices */
  .modern-progress {
    min-height: 24px;
    border-radius: 14px;
    padding: 4px;
  }
  
  .modern-progress-bar {
    border-radius: 10px;
    min-height: 16px;
  }
  
  .progress {
    min-height: 18px;
  }
  
  .progress-bar {
    min-height: 14px;
  }
  
  /* Touch-friendly progress text */
  .modern-progress-text {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.3px;
  }
  
  .progress-text {
    font-size: 0.85rem;
    font-weight: 700;
  }
  
  /* Mobile-specific spacing */
  #progress-wrapper {
    padding: 0.75rem;
  }
  
  #interpretation-progress .card-body {
    padding: 1rem;
  }
  
  /* Larger touch targets for buttons */
  .btn.loading {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Small mobile devices */
@media (max-width: 576px) {
  /* Even larger progress elements for small screens */
  .modern-progress {
    min-height: 26px;
    border-radius: 16px;
    padding: 4px;
  }
  
  .modern-progress-bar {
    border-radius: 11px;
    min-height: 18px;
  }
  
  .progress {
    min-height: 20px;
  }
  
  .progress-bar {
    min-height: 16px;
  }
  
  /* Simplified animations for performance */
  .modern-progress-bar.animated {
    animation-duration: 3s;
  }
  
  /* Larger text for readability */
  .modern-progress-text {
    font-size: 1rem;
    font-weight: 800;
  }
  
  .progress-text {
    font-size: 0.9rem;
    font-weight: 700;
  }
  
  /* Compact layout adjustments */
  .alert.medical-warning {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
  }
  
  .alert.medical-warning .row {
    --bs-gutter-x: 0.75rem;
  }
  
  /* Stack severity level info vertically on small screens (scoped). */
  .mobile-severity-layout {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.75rem;
  }
  
  .mobile-severity-layout .mobile-severity-label {
    min-width: auto !important;
    margin-bottom: 0.35rem;
  }
  
  /* Pathology table mobile optimization */
  .table-responsive {
    font-size: 0.875rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .mobile-pathology-progress {
    min-width: 140px !important;
    max-width: 160px !important;
  }
  
  .mobile-pathology-progress .progress {
    height: 16px !important;
  }
  
  .mobile-pathology-progress .progress-text {
    font-size: 0.7rem !important;
  }
  
  .mobile-pathology-progress .d-flex {
    margin-bottom: 0.25rem !important;
  }
  
  .mobile-pathology-progress .d-flex small {
    font-size: 0.65rem !important;
  }
  
  .mobile-pathology-progress .d-flex .badge {
    font-size: 0.6rem !important;
    padding: 0.2rem 0.4rem !important;
    margin-right: 0.25rem;
  }
  
  .badge.small {
    font-size: 0.6rem;
    padding: 0.2rem 0.4rem;
  }
  
  /* Mobile table layout optimization */
  .prediction-results-table td:first-child { width: 30% !important; }
  .prediction-results-table td:nth-child(2) { width: 50% !important; }
  .prediction-results-table td:last-child { width: 20% !important; }
  
  /* Override any inline min-width styles on mobile */
  .mobile-pathology-progress[style*="min-width"] {
    min-width: 140px !important;
    max-width: 160px !important;
    width: 100% !important;
  }
}

/* Ultra-small devices (phones in portrait) */
@media (max-width: 375px) {
  /* Maximum touch-friendly sizing */
  .modern-progress {
    min-height: 28px;
    padding: 4px;
  }
  
  .modern-progress-bar {
    min-height: 18px;
  }
  
  .progress {
    min-height: 22px;
  }
  
  .progress-bar {
    min-height: 18px;
  }
  
  /* Reduced animation complexity for very small devices */
  .modern-progress.pulsing {
    animation: none;
  }
  
  .modern-progress-bar::before {
    display: none;
  }
  
  /* Larger, clearer text */
  .modern-progress-text {
    font-size: 1rem;
    font-weight: 900;
  }
  
  .progress-text {
    font-size: 0.9rem;
    font-weight: 800;
  }
  
  /* Simplified card headers */
  .card-header .d-flex {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }
  
  /* Ultra-compact pathology progress bars */
  .mobile-pathology-progress {
    min-width: 100px !important;
    max-width: 120px !important;
  }
  
  .mobile-pathology-progress .progress {
    height: 14px !important;
  }
  
  .mobile-pathology-progress .progress-text {
    font-size: 0.6rem !important;
    font-weight: 900 !important;
  }
  
  .mobile-pathology-progress .d-flex .badge {
    font-size: 0.55rem !important;
    padding: 0.15rem 0.3rem !important;
    margin-right: 0.2rem !important;
  }
  
  .mobile-pathology-progress .d-flex small {
    font-size: 0.7rem !important;
    font-weight: 800 !important;
  }
  
  .badge.small {
    font-size: 0.55rem;
    padding: 0.15rem 0.3rem;
  }
  
  /* Ultra-compact table layout */
  .prediction-results-table td:first-child { 
    width: 35% !important; 
    font-size: 0.8rem !important;
    padding-right: 0.25rem !important;
  }
  .prediction-results-table td:nth-child(2) { 
    width: 45% !important; 
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
  .prediction-results-table td:last-child { 
    width: 20% !important; 
    padding-left: 0.25rem !important;
  }
  
  /* Ensure proper alignment for compact badge layout */
  .mobile-pathology-progress .d-flex {
    align-items: center !important;
    gap: 0.25rem;
  }
}

/* Medium-small devices (most phones) */
@media (max-width: 414px) and (min-width: 360px) {
  .mobile-pathology-progress {
    min-width: 120px !important;
    max-width: 140px !important;
  }
  
  .mobile-pathology-progress .progress {
    height: 15px !important;
  }
  
  .mobile-pathology-progress .progress-text {
    font-size: 0.65rem !important;
  }
  
  .mobile-pathology-progress .d-flex small {
    font-size: 0.6rem !important;
  }
  
  .mobile-pathology-progress .d-flex .badge {
    font-size: 0.58rem !important;
    padding: 0.18rem 0.35rem !important;
    margin-right: 0.25rem;
  }
  
  .badge.small {
    font-size: 0.58rem;
    padding: 0.18rem 0.35rem;
  }
  
  /* Optimize table spacing for common phone sizes */
  .prediction-results-table td:first-child { width: 32% !important; }
  .prediction-results-table td:nth-child(2) { width: 48% !important; }
  .prediction-results-table td:last-child { width: 20% !important; }
}

/* Battery optimization for mobile devices */
@media (max-device-width: 768px) {
  /* Reduce animation complexity on actual mobile devices */
  .modern-progress-bar.animated {
    animation-iteration-count: 3;
    animation-direction: alternate;
  }
}

/* Dark mode mobile optimizations */
@media (max-width: 768px) and (prefers-color-scheme: dark) {
  .modern-progress {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    border-color: rgba(var(--primary-rgb), 0.3);
  }
  
  .modern-progress-text,
  .progress-text {
    color: #e2e8f0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  }
  
  .alert.medical-warning {
    background-color: rgba(var(--primary-rgb), 0.15) !important;
    border-color: rgba(var(--primary-rgb), 0.4) !important;
    color: #e2e8f0 !important;
  }
}

/* High DPI/Retina mobile displays */
@media (max-width: 768px) and (-webkit-min-device-pixel-ratio: 2) {
  .modern-progress,
  .progress {
    border-width: 0.5px;
  }
  
}

/* Landscape mobile orientation */
@media (max-width: 768px) and (orientation: landscape) {
  /* Reduce vertical spacing in landscape */
  .modern-progress {
    min-height: 24px;
  }
  
  .progress {
    min-height: 18px;
  }
  
  #progress-wrapper,
  #interpretation-progress .card-body {
    padding: 0.75rem;
  }
  
  .alert.medical-warning {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
  }
  
  /* Horizontal layout for severity levels in landscape */
  .mobile-severity-layout {
    flex-direction: row !important;
  }
}

/* Mobile-specific component styling */
.mobile-optimized {
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.mobile-pathology-progress {
  touch-action: manipulation;
}

.mobile-progress-bar {
  -webkit-tap-highlight-color: transparent;
  height: 18px;
}

.mobile-risk-badge {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Badge positioning improvements for desktop and mobile */
.mobile-pathology-progress .d-flex {
  align-items: center;
  gap: 0.5rem;
}

.mobile-pathology-progress .d-flex .badge {
  flex-shrink: 0;
  margin-right: 0;
}

/* Desktop badge styling */
@media (min-width: 769px) {
  .mobile-pathology-progress .d-flex .badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }
}

/* Desktop: give "Probability" column more room so bars are longer */
@media (min-width: 992px) {
  /* Fix column widths for consistent desktop layout */
  .prediction-results-table {
    table-layout: fixed;
    width: 100%;
  }

  /* Desktop: keep pathology names on one line (incl. help icon). */
  .prediction-results-table th:nth-child(1),
  .prediction-results-table td:nth-child(1) {
    width: 35%;
    white-space: nowrap;
  }

  /* Keep action buttons readable without dominating the table */
  .prediction-results-table th:nth-child(3),
  .prediction-results-table td:nth-child(3) {
    width: 220px;
  }

  /* Ensure the progress UI expands to the full cell width */
  .prediction-results-table .mobile-pathology-progress {
    width: 100%;
  }
}

/* Custom risk level badge colors (MTS compatible) */
.badge.bg-very-high {
  background-color: #dc2626 !important; /* Red - Immediate */
  color: white !important;
}

.badge.bg-high {
  background-color: #fd7e14 !important; /* Orange - Very Urgent */
  color: white !important;
}

.badge.bg-medium {
  background-color: #ffc107 !important; /* Yellow - Urgent */
  color: #212529 !important;
}

.badge.bg-low {
  background-color: #198754 !important; /* Green - Standard */
  color: white !important;
}

.badge.bg-very-low {
  background-color: #0dcaf0 !important; /* Blue - Non-urgent */
  color: white !important; /* White text on blue for better contrast */
}

/* Progress bar colors to match badge colors (MTS) */
.progress-bar.bg-very-high {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
}

.progress-bar.bg-high {
  background: linear-gradient(135deg, #fd7e14 0%, #e67e22 100%) !important;
}

.progress-bar.bg-medium {
  background: linear-gradient(135deg, #ffc107 0%, #ffca2c 100%) !important;
  color: #212529 !important;
}

.progress-bar.bg-low {
  background: linear-gradient(135deg, #198754 0%, #157347 100%) !important;
}

.progress-bar.bg-very-low {
  background: linear-gradient(135deg, #0dcaf0 0%, #0aa2c0 100%) !important;
}

/* MTS Text Colors */
.text-danger { color: #dc2626 !important; }
.text-orange { color: #fd7e14 !important; }
.text-warning { color: #ffc107 !important; }
.text-success { color: #198754 !important; }
.text-info { color: #0dcaf0 !important; }

/* High contrast mode support for custom badges */
@media (prefers-contrast: high) {
  .badge.bg-very-high {
    background-color: #b91c1c !important;
    border: 2px solid #ffffff !important;
  }
  
  .badge.bg-high {
    background-color: #e67e22 !important;
    border: 2px solid #ffffff !important;
  }
  
  .badge.bg-medium {
    background-color: #ffc107 !important;
    border: 2px solid #000000 !important;
    color: #000000 !important;
  }
  
  .badge.bg-low {
    background-color: #198754 !important;
    border: 2px solid #ffffff !important;
  }
  
  .badge.bg-very-low {
    background-color: #0dcaf0 !important;
    border: 2px solid #000000 !important;
    color: #000000 !important;
  }
}

/* Dark mode support for custom badges */
@media (prefers-color-scheme: dark) {
  .badge.bg-very-high {
    background-color: #ef4444 !important;
  }
  
  .badge.bg-high {
    background-color: #f97316 !important;
  }
  
  .badge.bg-medium {
    background-color: #fbbf24 !important;
    color: #111827 !important;
  }
  
  .badge.bg-low {
    background-color: #22c55e !important;
  }
  
  .badge.bg-very-low {
    background-color: #0ea5e9 !important;
    color: #ffffff !important;
  }
  
  .text-orange { color: #f97316 !important; }
}

/* Mobile touch optimizations */
.mobile-severity-label {
  touch-action: manipulation;
}

/* Performance optimizations for mobile */
@media (max-width: 768px) {
  /* Use hardware acceleration for smooth animations */
  .modern-progress-bar {
    transform: translateZ(0);
    will-change: transform;
  }
  
  /* Reduce repaints by containing layout */
  .modern-progress,
  .progress {
    contain: layout style paint;
  }
  
  /* Optimize text rendering on mobile */
  .modern-progress-text,
.progress-text {
    text-rendering: optimizeSpeed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* iOS Safari specific optimizations */
@supports (-webkit-touch-callout: none) {
  .modern-progress,
  .progress {
    -webkit-transform: translateZ(0);
    -webkit-backface-visibility: hidden;
  }
  
}

/* Android Chrome specific optimizations */
@media (max-width: 768px) and (-webkit-min-device-pixel-ratio: 1.5) {
  .modern-progress-bar.animated {
    animation-timing-function: ease-out;
  }
  
}

/* Touch device optimizations */
@media (pointer: coarse) {
  /* Larger touch targets for coarse pointers (fingers) */
  .btn.loading {
    min-height: 48px;
    min-width: 48px;
    padding: 0.75rem 1rem;
  }
  
  /* Increase tap target size for interactive elements */
  .mobile-pathology-progress {
    padding: 0.25rem;
    margin: -0.25rem;
  }
  
  /* Better touch feedback */
  .modern-progress:active,
  .progress:active {
    transform: scale(0.99);
    transition: transform 0.1s ease;
  }
}

/* Network-aware animations */
@media (prefers-reduced-data: reduce) {
  /* Reduce animation complexity for slow connections */
  .modern-progress-bar.animated {
    animation-duration: 2s;
    animation-iteration-count: 2;
  }
  
  .modern-progress-bar::before {
    display: none;
  }
}

/* Font size utilities for better mobile typography */
@media (max-width: 576px) {
  .fs-7 { font-size: 0.75rem !important; }
  .fs-sm-6 { font-size: 0.8rem !important; }
  .fs-sm-5 { font-size: 0.9rem !important; }
  .fs-sm-4 { font-size: 1rem !important; }
  .fs-sm-3 { font-size: 1.1rem !important; }
}

@media (min-width: 577px) {
  .fs-sm-6 { font-size: 0.875rem !important; }
  .fs-sm-5 { font-size: 1rem !important; }
  .fs-sm-4 { font-size: 1.25rem !important; }
  .fs-sm-3 { font-size: 1.5rem !important; }
}

/* ==========================================
   ALERT & BADGE STYLES
   ========================================== */
.medical-warning, .no-records-info {
  background-color: rgba(var(--primary-rgb), 0.1) !important;
  border-color: rgba(var(--primary-rgb), 0.3) !important;
  color: var(--primary) !important;
}

.no-records-info {
  position: relative;
  padding-left: 2.5rem !important;
}

.no-records-info:before {
  content: '\f059';
  /* Keep in sync with the vendored Font Awesome version (currently 6.x). */
  font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free';
  font-weight: 900;
  position: absolute;
  left: var(--spacing-md);
  top: 50%;
  transform: translateY(-50%);
  color: var(--primary);
}

/* ==========================================
   FORM & FILTER STYLES
   ========================================== */
.advanced-filters {
  background-color: var(--bs-body-bg);
  border-radius: var(--border-radius-lg);
  transition: all var(--transition-normal);
}

.advanced-filters .card-body {
  /* Keep filters compact on desktop too (mobile already overrides). */
  padding: var(--spacing-lg);
}

.advanced-filters .form-label {
  font-weight: var(--font-weight-normal);
  font-size: var(--font-size-md);
  margin-bottom: var(--spacing-xs);
  color: var(--bs-body-color);
}

.advanced-filters select.form-select,
.advanced-filters input.form-control {
  border-radius: var(--border-radius);
  border: 1px solid var(--light-border);
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 0.9rem;
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.advanced-filters select.form-select:focus,
.advanced-filters input.form-control:focus {
  border-color: rgba(var(--primary-rgb), 0.5);
  box-shadow: 0 0 0 0.25rem rgba(var(--primary-rgb), 0.25);
}

/* ==========================================
   VISUALIZATION STYLES
   ========================================== */
.visualization-image {
  max-width: 100%;
  height: auto;
  object-fit: contain;
  max-height: 600px;
  margin: 0 auto;
  display: block;
  border: 1px solid var(--light-border);
  box-shadow: var(--box-shadow);
  border-radius: 4px;
  padding: var(--spacing-sm);
  background-color: white;
  transition: transform var(--transition-normal);
}

.visualization-image.model-crop {
  /* Display the same centered square crop the model sees (TorchXRayVision
     `XRayCenterCrop()` -> `XRayResizer()` pipeline). This keeps GRAD-CAM / PLI
     overlays faithful: we crop the *display* to the model's 1:1 input view
     instead of stretching the heatmap to regions the model never saw. */
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: center;
  /* Keep crop size bounded similarly to the default visualization images. */
  width: 100%;
  max-width: 600px;
}


.visualization-image:hover {
  transform: scale(1.02);
  cursor: pointer;
  box-shadow: var(--box-shadow-lg);
}

#pli-card .visualization-image {
  width: 100%;
  height: 400px;
  object-fit: contain;
  max-height: 400px;
}

/* ==========================================
   ACCOUNT SETTINGS TABS
   ========================================== */
#settingsTabs .nav-link {
  background-color: rgba(var(--primary-rgb), 0.1) !important;
  border: 1px solid var(--light-border) !important;
  color: var(--primary) !important;
  font-weight: var(--font-weight-semibold);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  margin-right: var(--spacing-xs);
  transition: all var(--transition-normal);
}

#settingsTabs .nav-link:hover {
  background-color: rgba(var(--primary-rgb), 0.15) !important;
}

#settingsTabs .nav-link.active {
  background-color: rgba(var(--primary-rgb), 0.2) !important;
  border-bottom-color: transparent !important;
}

#settingsTabs .nav-link i {
  margin-right: var(--spacing-sm);
}

/* ==========================================
   INTERPRETATION STYLES
   ========================================== */
.btn-info-pathology {
  background: none;
  border: none;
  color: var(--secondary);
  font-size: var(--font-size-md);
  padding: var(--spacing-xs);
  margin-left: var(--spacing-sm);
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.btn-info-pathology:hover {
  color: var(--info);
  background-color: rgba(var(--info-rgb, 13, 202, 240), 0.1);
  transform: scale(1.1);
}

/* ==========================================
   COMPACT HOME PAGE STYLES
   ========================================== */
.compact-card { margin-bottom: var(--spacing-md); }
.compact-card-body { padding: var(--spacing-md); }
.compact-info-card { margin-bottom: var(--spacing-md) !important; }
.compact-card-header { padding: var(--spacing-xs) var(--spacing-sm); font-size: 0.85rem; font-weight: var(--font-weight-semibold); }
.compact-info-body { padding: var(--spacing-sm); }
.compact-button-group { margin-bottom: var(--spacing-sm); }
.compact-button-group .btn { margin-bottom: var(--spacing-sm); }
.compact-warning { margin-bottom: 0 !important; padding: var(--spacing-sm) var(--spacing-md); }

.compact-card-body .form-label { margin-bottom: var(--spacing-xs); font-size: var(--font-size-md); }
.compact-card-body .form-control, .compact-card-body .form-select { margin-bottom: var(--spacing-sm); padding: var(--spacing-sm) var(--spacing-md); }
.compact-card-body .form-text { margin-top: 0.125rem; margin-bottom: var(--spacing-xs); font-size: var(--font-size-sm); }
.compact-card-body .lead { font-size: var(--font-size-lg); margin-bottom: var(--spacing-md) !important; }

.compact-info-card .card-header { background-color: rgba(var(--primary-rgb), 0.08) !important; border-bottom: 1px solid var(--light-border); }
.compact-info-body .row { margin-bottom: var(--spacing-xs); }

/* ==========================================
   DARK MODE ADJUSTMENTS
   ========================================== */
[data-bs-theme="dark"] .medical-warning, [data-bs-theme="dark"] .no-records-info {
  background-color: rgba(var(--primary-rgb), 0.2) !important;
  border-color: rgba(var(--primary-rgb), 0.4) !important;
}

[data-bs-theme="dark"] .visualization-image {
  background-color: var(--dark-bg);
  border-color: var(--light-border);
}

[data-bs-theme="dark"] .progress-text {
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}

[data-bs-theme="dark"] .btn-info-pathology { color: #adb5bd; }
[data-bs-theme="dark"] .btn-info-pathology:hover { color: var(--info); background-color: rgba(var(--info-rgb, 13, 202, 240), 0.1); }

/* ==========================================
   FILTER ACTION BUTTONS - EQUAL HEIGHT
   ========================================== */
/* Ensure equal height for filter action buttons on all screen sizes */
.advanced-filters .filter-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-sm);
}

.advanced-filters .filter-actions .btn {
  height: auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem 0.75rem;
  line-height: 1.5;
}

/* ==========================================
   RESPONSIVE DESIGN - MOBILE OPTIMIZATIONS
   ========================================== */
@media (max-width: 768px) {
  /* Ensure cards have minimal padding to reach near screen edges */
  .card {
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-bottom: var(--spacing-lg);
  }
  
  /* Base mobile adjustments */
  .advanced-filters .card-body { padding: var(--spacing-lg); }
  
  /* Filter action buttons: stack and fill on mobile. */
  .advanced-filters .filter-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .advanced-filters .filter-actions .btn {
    width: 100%;
  }

  /* Generic "action bar" stacking (opt-in via `.stack-mobile`). */
  .stack-mobile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
  }

  .stack-mobile > .btn,
  .stack-mobile > .btn-group {
    width: 100%;
    max-width: 320px;
  }

  .stack-mobile > .btn-group > .btn {
    width: 100%;
  }

  .compact-button-group .btn {
    width: 100%;
    max-width: 320px;
    margin: 0 !important;
    margin-bottom: var(--spacing-md) !important;
  }
  
  /* Account settings mobile spacing - ensure proper spacing between Save profile button and Account information */
  button[name="update_profile"] {
    margin-bottom: var(--spacing-lg) !important;
  }
  
  /* Create visual separation for Account Information card on mobile */
  .col-md-6 .card.border {
    margin-top: var(--spacing-lg) !important;
  }
}

/* Extra mobile adjustments for very small screens */
@media (max-width: 480px) {
  /* Account settings tabs */
  #settingsTabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm) var(--spacing-xs);
    justify-content: center;
    border-bottom: none !important;
  }
  
  #settingsTabs .nav-link {
    margin-right: 0 !important;
    margin-bottom: var(--spacing-xs);
    border-radius: var(--border-radius) !important;
    border-bottom: 1px solid var(--light-border) !important;
  }
  
  /* Account settings mobile spacing for password form */
  button[name="change_password"] {
    margin-bottom: calc(var(--spacing-lg) * 2) !important;
  }
  
  /* Create visual separation for Danger Zone card on very small screens */
  .card.border-warning {
    margin-top: var(--spacing-lg) !important;
  }
  
  /* History cards mobile layout */
  .history-card-mobile {
    border: 1px solid var(--light-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--box-shadow);
    transition: box-shadow var(--transition-fast);
  }
  
  .history-card-mobile:hover { box-shadow: var(--box-shadow-lg); }
  .history-card-mobile .card-title { color: var(--primary); font-weight: var(--font-weight-semibold); border-bottom: 1px solid var(--light-border); padding-bottom: var(--spacing-sm); margin-bottom: var(--spacing-md) !important; }
  .history-card-mobile .text-muted { font-size: var(--font-size-sm); font-weight: var(--font-weight-normal); text-transform: uppercase; letter-spacing: 0.5px; }
  .history-card-mobile .card-body { padding: var(--spacing-lg); }
  .history-card-mobile .btn-sm { padding: var(--spacing-sm) var(--spacing-md); font-size: var(--font-size-md); min-width: 64px; }
  
  /* Image metadata table mobile optimization */
  .image-metadata-table .table thead th {
    display: block !important;
    width: 100% !important;
    padding: var(--spacing-sm) !important;
    font-size: var(--font-size-md) !important;
    font-weight: var(--font-weight-semibold) !important;
    text-align: center !important;
    background-color: rgba(var(--primary-rgb), 0.1) !important;
    color: var(--primary) !important;
    border: 1px solid var(--light-border) !important;
    border-radius: var(--border-radius) !important;
    margin-bottom: var(--spacing-sm) !important;
  }
  
  .image-metadata-table .table tbody tr {
    display: block !important;
    border: 1px solid var(--light-border) !important;
    border-radius: var(--border-radius) !important;
    margin-bottom: 0 !important;
    background-color: var(--bs-body-bg) !important;
  }
  
  .image-metadata-table .table tbody tr td {
    display: block !important;
    width: 100% !important;
    padding: var(--spacing-xs) var(--spacing-sm) !important;
    border: none !important;
    border-bottom: 1px solid var(--light-border) !important;
    font-size: var(--font-size-sm) !important;
    line-height: 1.2 !important;
    text-align: left !important;
  }
  
  .image-metadata-table .table tbody tr td strong {
    display: inline-block !important;
    width: 35% !important;
    margin-right: var(--spacing-sm) !important;
    font-weight: var(--font-weight-semibold) !important;
    color: var(--primary) !important;
  }
  
  /* Interpretability page optimizations */
  .btn-group {
    flex-wrap: wrap !important;
    gap: var(--spacing-xs) !important;
  }
  
  .btn-group .btn {
    font-size: 0.65rem !important;
    padding: var(--spacing-xs) var(--spacing-sm) !important;
    margin: 0 !important;
    border-radius: 0.2rem !important;
    flex: 1 1 auto !important;
    min-width: 80px !important;
  }
  
  /* Visualization images */
  .visualization-image {
    max-width: 100% !important;
    height: auto !important;
  }
  
  #pli-card .visualization-image {
    width: 100%;
    height: 300px;
    object-fit: contain;
    max-height: 300px !important;
  }
  
  /* Compact styles adjustments */
  .compact-card-body { padding: var(--spacing-md); }
  .compact-info-body { padding: var(--spacing-sm); }
  .compact-card-header { padding: var(--spacing-xs) var(--spacing-sm); font-size: 0.85rem; }
  .compact-card-body .lead { font-size: 0.95rem; }
  
  /* Dark mode mobile adjustments */
  [data-bs-theme="dark"] .history-card-mobile {
    border-color: #495057;
    background-color: var(--dark-bg);
  }
  
  [data-bs-theme="dark"] .history-card-mobile:hover {
    box-shadow: var(--box-shadow-lg);
  }
  
  [data-bs-theme="dark"] .image-metadata-table .table tbody tr {
    background-color: var(--dark-bg) !important;
    border-color: var(--light-border) !important;
  }
  
  [data-bs-theme="dark"] .image-metadata-table .table thead th {
    background-color: rgba(var(--primary-rgb), 0.2) !important;
    color: var(--primary) !important;
    border-color: var(--light-border) !important;
  }
  
  /* Mobile responsive adjustments for input groups */
  .input-group #custom-file-button,
  .input-group #file-name-display {
    font-size: 0.9rem !important;
    height: calc(2.05rem + 2px) !important;
    padding: 0.28rem 0.55rem !important;
  }
  
  .input-group #custom-file-button i {
    margin-right: 0.35rem !important;
  }
}

/* Larger screen optimizations */
@media (min-width: 992px) {
  .col-md-12 .card-body.text-center img.visualization-image {
    max-height: 800px !important;
  }
}