/* Mobile-First CSS Custom Properties */
:root {
  /* Existing gradients and shadows */
  --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --warning-gradient: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
  --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  --card-hover-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
  --border-radius: 12px;

  /* Mobile-specific spacing */
  --mobile-padding: 1rem;
  --mobile-margin: 0.5rem;
  --mobile-border-radius: 8px;
  --mobile-container-padding: 1rem;
  --mobile-card-spacing: 1rem;

  /* Touch target sizes */
  --touch-target-min: 44px;
  --button-height-mobile: 48px;

  /* Mobile typography */
  --mobile-font-base: 16px;
  --mobile-font-small: 14px;
  --mobile-font-large: 1.25rem;
  --mobile-header-font: 1.5rem; /* Reduced for more compact mobile header */
  --mobile-header-secondary: 1.3rem; /* For secondary headers like fitness analytics */

  /* Mobile layout breakpoints */
  --breakpoint-xs: 320px;
  --breakpoint-sm: 480px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
}

/* Mobile-first base typography with loading optimizations */
html {
  font-size: var(--mobile-font-base); /* 16px for mobile */
  /* Optimize initial page load */
  font-display: swap;
  /* Prevent layout shifts during font loading */
  font-synthesis: none;
  /* Optimize text rendering performance */
  text-rendering: optimizeSpeed;
}

@media (min-width: 480px) {
  html {
    font-size: 16px; /* Maintain 16px for small mobile+ */
  }
}

@media (min-width: 768px) {
  html {
    font-size: 16px; /* Standard desktop size */
    /* Enhanced text rendering on larger screens */
    text-rendering: optimizeLegibility;
  }
}

/* Mobile-first body styling with loading optimizations */
body {
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: var(--mobile-font-base);
  line-height: 1.5;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  /* Remove bottom margin on mobile for better space utilization */
  margin-bottom: 2rem;
  /* Optimize initial rendering */
  contain: layout style;
  /* Prevent layout shifts during loading */
  overflow-anchor: auto;
  /* Optimize mobile performance */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (min-width: 768px) {
  body {
    margin-bottom: 60px; /* Restore desktop margin */
  }
}

/* Enhanced Focus States */
.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #667eea;
}

/* Mobile-first Main Container Styling with loading optimizations */
.container {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: var(--mobile-border-radius);
  box-shadow: var(--card-shadow);
  margin: var(--mobile-margin);
  padding: var(--mobile-container-padding);
  /* Prevent layout shifts during loading */
  min-height: 400px;
  /* Optimize rendering performance */
  contain: layout style paint;
  /* Optimize loading sequence */
  content-visibility: auto;
  contain-intrinsic-size: 0 400px;
}

@media (min-width: 768px) {
  .container {
    border-radius: var(--border-radius);
    margin: 1rem auto;
    padding: 1.5rem;
    min-height: 500px;
    contain-intrinsic-size: 0 500px;
    max-width: 1200px;
  }
}

@media (min-width: 1400px) {
  .container {
    max-width: 1320px;
  }
}

/* Loading state optimizations */
.container.loading {
  /* Show loading state to prevent layout shifts */
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Critical above-the-fold optimizations */
.page-header,
.stats-table {
  /* Prioritize above-the-fold content */
  content-visibility: visible;
  contain-intrinsic-size: none;
}

/* Below-the-fold optimizations */
.history-card {
  /* Optimize below-the-fold content loading */
  content-visibility: auto;
  contain-intrinsic-size: 0 200px;
}

/* ===== RESPONSIVE HEADER AND NAVIGATION ===== */

/* Mobile-first Header Styling - Optimized for smaller screens */
.page-header {
  background: var(--primary-gradient);
  color: white;
  padding: 0.75rem; /* Reduced from 1rem for more compact mobile header */
  border-radius: var(--mobile-border-radius);
  margin-bottom: var(--mobile-card-spacing);
  text-align: center;
  box-shadow: var(--card-shadow);
  /* Minimize vertical space usage on mobile */
  min-height: auto;
}

.page-header h2 {
  margin: 0;
  font-weight: 400; /* Slightly heavier for better mobile readability */
  font-size: 1.5rem; /* Reduced from 1.8rem for more compact mobile header */
  line-height: 1.1; /* Tighter line height for mobile */
  margin-bottom: 0.4rem; /* Small spacing before date badge */
}

.page-header .date-badge {
  background: rgba(255, 255, 255, 0.25);
  padding: 0.3rem 0.6rem; /* Reduced padding for more compact mobile design */
  border-radius: 16px; /* Smaller border radius for mobile */
  display: inline-block;
  margin-top: 0.25rem; /* Reduced margin for tighter spacing */
  font-size: 0.8rem; /* Smaller font size for mobile */
  font-weight: 500;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Small mobile adjustments (480px+) */
@media (min-width: 480px) {
  .page-header {
    padding: 0.875rem;
  }

  .page-header h2 {
    font-size: 1.6rem;
  }

  .page-header .date-badge {
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
  }
}

/* Tablet and larger screens */
@media (min-width: 768px) {
  .page-header {
    padding: 1rem; /* More compact padding */
    border-radius: var(--border-radius);
    margin-bottom: 1rem; /* Reduced margin for tighter spacing */
  }

  .page-header h2 {
    font-size: 2.2rem; /* Slightly reduced from 2.5rem */
    font-weight: 300;
    line-height: 1.2;
    margin-bottom: 0.5rem;
  }

  .page-header .date-badge {
    padding: 0.45rem 0.9rem; /* Slightly reduced from 0.5rem 1rem */
    border-radius: 22px; /* Slightly smaller than 25px */
    font-size: 0.85rem; /* Slightly smaller than 0.9rem */
    margin-top: 0.5rem;
  }
}

/* Large desktop screens */
@media (min-width: 1024px) {
  .page-header {
    padding: 2rem;
    margin-bottom: 2rem;
  }

  .page-header h2 {
    font-size: 2.5rem;
  }

  .page-header .date-badge {
    padding: 0.5rem 1rem;
    border-radius: 25px;
    font-size: 0.9rem;
  }
}

/* Fitness Analytics Header - Mobile Optimized */
.page-header[style*="background: linear-gradient(135deg, #28a745 0%, #20c997 100%)"] {
  /* Target the fitness analytics header specifically */
  padding: 0.6rem; /* Even more compact for secondary headers */
  margin-bottom: 0.75rem;
}

.page-header[style*="background: linear-gradient(135deg, #28a745 0%, #20c997 100%)"]
  h3 {
  margin: 0;
  font-size: 1.3rem; /* Smaller than main header */
  font-weight: 500;
  line-height: 1.1;
}

@media (min-width: 480px) {
  .page-header[style*="background: linear-gradient(135deg, #28a745 0%, #20c997 100%)"] {
    padding: 0.75rem;
  }

  .page-header[style*="background: linear-gradient(135deg, #28a745 0%, #20c997 100%)"]
    h3 {
    font-size: 1.4rem;
  }
}

@media (min-width: 768px) {
  .page-header[style*="background: linear-gradient(135deg, #28a745 0%, #20c997 100%)"] {
    padding: 1.25rem;
    margin-bottom: 1rem;
  }

  .page-header[style*="background: linear-gradient(135deg, #28a745 0%, #20c997 100%)"]
    h3 {
    font-size: 1.6rem;
  }
}

@media (min-width: 1024px) {
  .page-header[style*="background: linear-gradient(135deg, #28a745 0%, #20c997 100%)"] {
    padding: 1.5rem;
  }

  .page-header[style*="background: linear-gradient(135deg, #28a745 0%, #20c997 100%)"]
    h3 {
    font-size: 1.8rem;
  }
}

/* Enhanced mobile header accessibility */
@media (max-width: 767px) {
  /* Ensure header content is easily readable on mobile */
  .page-header {
    /* Improve contrast for mobile viewing */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
    overflow: hidden;
  }

  /* Hardware-accelerated shimmer animation for mobile header */
  .page-header::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
      90deg,
      transparent,
      rgba(255, 255, 255, 0.1),
      transparent
    );
    animation: shimmer 3s infinite;
    pointer-events: none;
    /* Hardware acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    will-change: transform;
  }

  /* Ensure text remains above the shimmer effect */
  .page-header h2,
  .page-header .date-badge {
    position: relative;
    z-index: 1;
  }

  /* Improve date badge visibility on mobile */
  .page-header .date-badge {
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  /* Hardware-accelerated touch-friendly interaction feedback */
  .page-header:active {
    transform: translate3d(0, 0, 0) scale(0.995);
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    backface-visibility: hidden;
  }
}

/* Enhanced Table Styling */
.stats-table {
  background: white;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
  margin-bottom: 1rem;
}

.stats-table thead {
  background: var(--primary-gradient);
  color: white;
}

.stats-table thead th {
  border: none;
  padding: 1rem;
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.stats-table tbody tr {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  /* Hardware acceleration */
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  will-change: transform, background-color, box-shadow;
}

.stats-table tbody tr:hover {
  background-color: #f8f9ff;
  transform: translate3d(0, -2px, 0);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.stats-table td {
  padding: 1rem;
  border: none;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}

/* Mobile-first Enhanced Form Controls */
.form-control {
  border: 2px solid #e9ecef;
  border-radius: var(--mobile-border-radius);
  padding: 0.75rem;
  min-height: var(--touch-target-min); /* Ensure 44px minimum touch target */
  font-size: var(--mobile-font-base);
  transition: all 0.3s ease;
  background: #f8f9fa;
  box-sizing: border-box;
}

.form-control:focus {
  border-color: #667eea;
  background: white;
  box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
  /* Prevent zoom on iOS */
  font-size: var(--mobile-font-base);
}

@media (min-width: 768px) {
  .form-control {
    border-radius: 8px;
  }
}

/* Mobile-first Enhanced Buttons */
.btn-primary {
  background: var(--primary-gradient);
  border: none;
  border-radius: var(--mobile-border-radius);
  padding: 0.75rem 1.5rem;
  min-height: var(--button-height-mobile); /* 48px minimum for mobile */
  font-size: var(--mobile-font-base);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.btn-primary:hover {
  transform: translate3d(
    0,
    -1px,
    0
  ); /* Hardware-accelerated transform for mobile */
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

@media (min-width: 768px) {
  .btn-primary {
    border-radius: 8px;
  }

  .btn-primary:hover {
    transform: translate3d(0, -2px, 0); /* Hardware-accelerated transform */
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
  }
}

/* History Cards */
.history-card {
  background: white;
  border-radius: var(--border-radius);
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  height: 100%;
  /* Hardware acceleration */
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  will-change: transform, box-shadow;
}

.history-card:hover {
  box-shadow: var(--card-hover-shadow);
  transform: translate3d(0, -5px, 0);
}

.history-card h4 {
  color: #333;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid transparent;
  background: var(--primary-gradient);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 600;
}

.history-card .text-muted {
  background: none !important;
  -webkit-text-fill-color: #6c757d !important;
  font-size: 0.85rem;
}

.history-table {
  margin: 0;
}

.history-table th {
  background: #f8f9fa;
  color: #495057;
  font-weight: 600;
  border: none;
  padding: 0.75rem;
  font-size: 0.9rem;
}

.history-table td {
  border: none;
  padding: 0.75rem;
  border-bottom: 1px solid #f1f3f4;
}

/* Stat Badges - Consolidated and Clean */
.stat-badge {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  border-radius: 16px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-left: 0.5rem;
  margin-top: 0.25rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: all 0.2s ease;
  vertical-align: middle;
  white-space: nowrap;
}

.stat-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.stat-badge.positive {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
  color: white;
}

.stat-badge.negative {
  background: linear-gradient(135deg, #dc3545 0%, #fd7e14 100%);
  color: white;
}

.stat-badge.neutral {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
  color: white;
}

/* Mobile-first responsive base styles are now in main selectors above */
/* Additional mobile optimizations */
.stats-table {
  font-size: var(--mobile-font-small);
  border-radius: var(--mobile-border-radius);
}

.history-card {
  margin-bottom: var(--mobile-card-spacing);
  border-radius: var(--mobile-border-radius);
}

@media (min-width: 768px) {
  .stats-table {
    font-size: 1rem;
    border-radius: var(--border-radius);
  }

  .history-card {
    margin-bottom: 0;
    border-radius: var(--border-radius);
  }
}

/* ===== HARDWARE-ACCELERATED ANIMATIONS FOR MOBILE PERFORMANCE ===== */

/* Optimize CSS animations using transform3d for mobile performance */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate3d(
      0,
      30px,
      0
    ); /* Hardware acceleration with transform3d */
  }
  to {
    opacity: 1;
    transform: translate3d(
      0,
      0,
      0
    ); /* Hardware acceleration with transform3d */
  }
}

/* Enhanced page load animation with hardware acceleration */
.container > * {
  animation: fadeInUp 0.6s ease-out;
  /* Force hardware acceleration for smooth mobile performance */
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  perspective: 1000px;
}

.container > *:nth-child(2) {
  animation-delay: 0.1s;
}

.container > *:nth-child(3) {
  animation-delay: 0.2s;
}

/* Hardware-accelerated shimmer animation for mobile header */
@keyframes shimmer {
  0% {
    transform: translate3d(-100%, 0, 0);
  }
  100% {
    transform: translate3d(100%, 0, 0);
  }
}

/* Hardware-accelerated card hover animations */
@keyframes cardFloat {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(0, -5px, 0);
  }
}

/* Hardware-accelerated button press animation */
@keyframes buttonPress {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(0, 1px, 0) scale(0.98);
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
}

/* Hardware-accelerated ripple effect */
@keyframes ripple {
  0% {
    transform: translate3d(-50%, -50%, 0) scale(0);
    opacity: 1;
  }
  100% {
    transform: translate3d(-50%, -50%, 0) scale(4);
    opacity: 0;
  }
}

/* Hardware-accelerated pulse animation for interactive elements */
@keyframes pulse {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
    box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.7);
  }
  70% {
    transform: translate3d(0, 0, 0) scale(1.05);
    box-shadow: 0 0 0 10px rgba(102, 126, 234, 0);
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
    box-shadow: 0 0 0 0 rgba(102, 126, 234, 0);
  }
}

/* Hardware-accelerated slide-in animation for mobile cards */
@keyframes slideInLeft {
  0% {
    transform: translate3d(-100%, 0, 0);
    opacity: 0;
  }
  100% {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

@keyframes slideInRight {
  0% {
    transform: translate3d(100%, 0, 0);
    opacity: 0;
  }
  100% {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

/* Smooth scrolling performance optimizations */
html {
  scroll-behavior: smooth;
  /* Enable hardware acceleration for scrolling */
  -webkit-overflow-scrolling: touch;
}

/* ===== MOBILE LOADING AND RENDERING OPTIMIZATIONS ===== */

/* Minimize layout shifts during page load on mobile */
.container {
  /* Reserve space to prevent layout shift */
  min-height: 100vh;
  /* Optimize rendering performance */
  contain: layout style paint;
  /* Prevent layout thrashing */
  will-change: auto;
}

/* Optimize image and icon sizes for mobile bandwidth */
img,
svg,
.fa,
.fas,
.far,
.fab {
  /* Optimize image rendering */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  /* Prevent layout shift from images */
  max-width: 100%;
  height: auto;
  /* Hardware acceleration for images */
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
}

/* Mobile-specific image optimizations */
@media (max-width: 767px) {
  img {
    /* Optimize for mobile bandwidth */
    image-rendering: auto;
    /* Note: loading and decoding are HTML attributes, not CSS properties */
    /* Use loading="lazy" and decoding="async" in HTML img tags */
  }

  /* Optimize icon rendering on mobile */
  .fa,
  .fas,
  .far,
  .fab {
    /* Prevent font icon layout shifts */
    display: inline-block;
    width: 1em;
    text-align: center;
    /* Optimize font rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-display: swap;
  }
}

/* Implement immediate visual feedback for touch interactions */
@media (max-width: 767px) {
  /* Immediate feedback for button touches */
  .btn-primary:active {
    transform: translate3d(0, 1px, 0) scale(0.98);
    transition: transform 0.05s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
  }

  /* Immediate feedback for form control touches */
  .form-control:active,
  .form-control:focus {
    transform: translate3d(0, 0, 0) scale(1.02);
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
  }

  /* Immediate feedback for table row touches */
  .stats-table tbody tr:active,
  .history-table tbody tr:active {
    background-color: #e3f2fd;
    transform: translate3d(0, 0, 0) scale(0.995);
    transition: all 0.05s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Immediate feedback for card touches */
  .history-card:active,
  .metric-card:active {
    transform: translate3d(0, 2px, 0) scale(0.98);
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  /* Immediate feedback for badge and status touches */
  .stat-badge:active,
  .percentage-badge:active,
  .goal-status:active,
  .rank-badge:active {
    transform: translate3d(0, 0, 0) scale(0.95);
    transition: transform 0.05s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Immediate feedback for header touches */
  .page-header:active {
    transform: translate3d(0, 1px, 0) scale(0.995);
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
  }
}

/* Optimize critical rendering path */
.page-header,
.container,
.stats-table,
.history-card {
  /* Optimize paint performance */
  contain: layout style paint;
  /* Prevent unnecessary repaints */
  will-change: auto;
}

/* Prevent layout shifts from dynamic content */
.stats-table tbody tr,
.history-table tbody tr {
  /* Reserve minimum height to prevent shifts */
  min-height: 60px;
  /* Optimize layout performance */
  contain: layout;
}

.metric-card {
  /* Reserve minimum height for metric cards */
  min-height: 120px;
  /* Optimize layout performance */
  contain: layout style;
}

.history-card {
  /* Reserve minimum height for history cards */
  min-height: 200px;
  /* Optimize layout performance */
  contain: layout style paint;
}

/* Optimize font loading and rendering */
/* Note: Segoe UI is a system font, no need for @font-face declaration */
/* Font optimization is handled in the body and html selectors */

body {
  /* Optimize text rendering */
  text-rendering: optimizeSpeed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent font-related layout shifts */
  font-display: swap;
}

/* Optimize scrolling performance */
.table-responsive {
  /* Optimize scrolling on mobile */
  -webkit-overflow-scrolling: touch;
  /* Optimize scroll performance */
  contain: layout style;
  /* Hardware acceleration for scrolling */
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
}

/* Global hardware acceleration for smooth mobile performance */
* {
  /* Enable hardware acceleration for all elements */
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-perspective: 1000px;
  perspective: 1000px;
}

/* Optimize CSS containment for better performance */
@media (max-width: 767px) {
  /* Optimize mobile rendering performance */
  .container {
    contain: layout style paint;
    isolation: isolate;
  }

  .stats-table {
    contain: layout style;
    isolation: isolate;
  }

  .history-card {
    contain: layout style paint;
    isolation: isolate;
  }

  .metric-card {
    contain: layout style paint;
    isolation: isolate;
  }

  /* Optimize table rendering */
  .stats-table tbody,
  .history-table tbody {
    contain: layout;
  }

  /* Optimize form rendering */
  .form-control {
    contain: layout style;
  }

  /* Optimize button rendering */
  .btn-primary {
    contain: layout style paint;
  }
}

/* Prevent cumulative layout shift (CLS) optimizations */
.page-header {
  /* Reserve space for header to prevent CLS */
  min-height: 80px;
}

@media (min-width: 768px) {
  .page-header {
    min-height: 120px;
  }
}

@media (min-width: 1024px) {
  .page-header {
    min-height: 140px;
  }
}

/* Optimize badge and status indicator rendering */
.stat-badge,
.percentage-badge,
.goal-status,
.rank-badge {
  /* Prevent layout shifts from badges */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Optimize rendering */
  contain: layout style paint;
  /* Hardware acceleration */
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
}

/* Optimize animation performance for mobile */
@media (max-width: 767px) {
  /* Reduce motion for users who prefer it */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }

  /* Optimize animations for low-end devices */
  @media (max-resolution: 150dpi) {
    .container > * {
      animation-duration: 0.3s;
    }

    .history-card,
    .metric-card,
    .stats-table tbody tr {
      transition-duration: 0.15s;
    }
  }
}

/* Critical resource hints for performance */
.page-header::before {
  /* Optimize shimmer animation performance */
  will-change: transform;
  contain: layout style paint;
}

/* Optimize table performance */
.stats-table,
.history-table {
  /* Optimize table rendering */
  table-layout: fixed;
  /* Prevent layout thrashing */
  contain: layout;
}

/* Optimize mobile viewport performance */
@media (max-width: 767px) {
  html {
    /* Optimize mobile viewport */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    /* Optimize touch performance */
    touch-action: manipulation;
  }

  body {
    /* Optimize mobile body rendering */
    -webkit-overflow-scrolling: touch;
    /* Prevent horizontal scroll performance issues */
    overflow-x: hidden;
  }
}

/* Optimize animations for mobile devices with proper timing */
@media (max-width: 767px) {
  /* Reduce animation duration on mobile for better performance */
  .container > * {
    animation-duration: 0.4s; /* Faster animations on mobile */
  }

  /* Optimize card animations for mobile */
  .history-card,
  .metric-card,
  .stats-table tbody tr {
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
      box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease;
    /* Force hardware acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
  }

  /* Optimize button animations for mobile touch */
  .btn-primary {
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
      box-shadow 0.15s cubic-bezier(0.4, 0, 0.2, 1), background 0.15s ease;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
  }

  /* Optimize form control animations for mobile */
  .form-control {
    transition: border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
      background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
      transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
  }

  /* Optimize table row animations for mobile */
  .stats-table tbody tr,
  .history-table tbody tr {
    transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
      transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
  }

  /* Optimize badge and status indicator animations */
  .stat-badge,
  .percentage-badge,
  .goal-status,
  .rank-badge {
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
      box-shadow 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
  }
}

/* Enhanced hardware-accelerated hover effects for desktop */
@media (min-width: 768px) {
  .history-card:hover {
    animation: cardFloat 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  }

  .btn-primary:hover {
    transform: translate3d(0, -2px, 0);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .stats-table tbody tr:hover {
    transform: translate3d(0, -2px, 0);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }
}

/* Form Floating Enhancements */
.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* Fix visibility issues */
/* Make history table icons more visible */
.history-table th i {
  color: #495057 !important;
  margin-right: 0.5rem;
  font-size: 1rem;
  opacity: 0.8;
}

/* Fix the gradient text issue in history card headers */
.history-card h4 {
  color: #333 !important;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid #667eea;
  background: none !important;
  background-clip: initial !important;
  -webkit-background-clip: initial !important;
  -webkit-text-fill-color: initial !important;
  font-weight: 600;
}

/* Make the progress summary text more readable */
.history-card .text-muted {
  background: none !important;
  -webkit-text-fill-color: #495057 !important;
  color: #495057 !important;
  font-size: 0.85rem;
}

/* Improve stat badge contrast and readability */
.stat-badge {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-left: 0.5rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.stat-badge.positive {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(79, 172, 254, 0.3);
}

.stat-badge.negative {
  background: linear-gradient(135deg, #dc3545 0%, #fd7e14 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.stat-badge.neutral {
  background: #6c757d;
  color: white;
  box-shadow: 0 2px 8px rgba(108, 117, 125, 0.3);
}

/* Fitness Analytics Styling */
.metric-card {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  height: 100%;
  /* Hardware acceleration */
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  will-change: transform, box-shadow;
}

.metric-card:hover {
  transform: translate3d(0, -3px, 0);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.calories-card {
  border-left: 4px solid #fd7e14;
}

.activity-card {
  border-left: 4px solid #28a745;
}

.bmr-card {
  border-left: 4px solid #6f42c1;
}

.metric-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 0.5rem;
  line-height: 1;
}

.metric-label {
  font-size: 0.9rem;
  color: #6c757d;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.75rem;
}

.goal-status {
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-weight: 600;
  display: inline-block;
}

.goal-status i {
  margin-right: 0.3rem;
}

.goal-met {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.goal-missed {
  background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(255, 193, 7, 0.3);
}

.goal-status.neutral {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(108, 117, 125, 0.3);
}

/* Enhanced fitness analytics table */
.history-table tbody tr:hover {
  background-color: #f8f9ff;
}

.history-table strong {
  color: #495057;
  font-weight: 600;
}

/* ===== MOBILE-FRIENDLY FITNESS ANALYTICS METRIC CARDS ===== */

/* Mobile-first: Transform side-by-side metric cards to single column */
@media (max-width: 767px) {
  /* Force single-column layout for fitness analytics metric cards */
  .history-card .row .col-6 {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    margin-bottom: var(--mobile-card-spacing);
    padding: 0;
  }

  .history-card .row .col-6:last-child {
    margin-bottom: 0;
  }

  /* Optimize metric displays for touch interaction */
  .metric-card {
    margin-bottom: var(--mobile-card-spacing);
    padding: var(--mobile-padding);
    border-radius: var(--mobile-border-radius);
    min-height: var(--touch-target-min);
    cursor: pointer;
    transition: all 0.3s ease;

    /* Enhanced touch-friendly styling */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
  }

  /* Touch interaction feedback */
  .metric-card:hover,
  .metric-card:focus {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: rgba(102, 126, 234, 0.3);
  }

  .metric-card:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  }

  /* Optimize metric value display for mobile */
  .metric-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 0.4rem;
    line-height: 1;
    text-align: center;
  }

  /* Optimize metric label for mobile */
  .metric-label {
    font-size: 0.85rem;
    color: #6c757d;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.6rem;
    text-align: center;
    line-height: 1.2;
  }

  /* Optimize goal status for mobile touch interaction */
  .goal-status {
    font-size: 0.75rem;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-weight: 600;
    display: inline-block;
    min-height: 32px;
    min-width: 80px;
    text-align: center;
    line-height: 1.2;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .goal-status:hover {
    transform: scale(1.05);
  }

  /* Enhanced calories card styling for mobile */
  .calories-card {
    border-left: 4px solid #fd7e14;
    background: linear-gradient(135deg, #fff8f0 0%, #fef3e8 100%);
  }

  .calories-card .metric-value {
    color: #fd7e14;
  }

  .calories-card:hover {
    border-left-color: #e8690b;
    background: linear-gradient(135deg, #fff5eb 0%, #fdeee0 100%);
  }

  /* Enhanced activity card styling for mobile */
  .activity-card {
    border-left: 4px solid #28a745;
    background: linear-gradient(135deg, #f0f8f0 0%, #e8f5e8 100%);
  }

  .activity-card .metric-value {
    color: #28a745;
  }

  .activity-card:hover {
    border-left-color: #1e7e34;
    background: linear-gradient(135deg, #ebf7eb 0%, #e0f2e0 100%);
  }

  /* Add subtle animation for metric cards */
  .metric-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
      90deg,
      transparent,
      rgba(255, 255, 255, 0.2),
      transparent
    );
    transition: left 0.5s ease;
    pointer-events: none;
  }

  .metric-card:hover::before {
    left: 100%;
  }

  /* Ensure proper spacing in fitness analytics section */
  .history-card .row.mb-3 {
    margin-bottom: 1rem !important;
  }

  /* Responsive grid implementation for fitness analytics section */
  .fitness-analytics-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--mobile-card-spacing);
    margin-bottom: 1rem;
  }

  /* Apply grid to existing fitness analytics rows */
  .history-card .row.mb-3 {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--mobile-card-spacing);
    margin-left: 0;
    margin-right: 0;
  }

  .history-card .row.mb-3 .col-6 {
    padding: 0;
    margin-bottom: 0;
  }
}

/* Small mobile adjustments (480px+) */
@media (min-width: 480px) and (max-width: 767px) {
  /* Allow side-by-side metric cards on larger mobile screens */
  .history-card .row .col-6 {
    width: 50% !important;
    max-width: 50% !important;
    flex: 0 0 50% !important;
    margin-bottom: var(--mobile-card-spacing);
    padding: 0 0.375rem;
  }

  .history-card .row .col-6:first-child {
    padding-left: 0;
  }

  .history-card .row .col-6:last-child {
    padding-right: 0;
    margin-bottom: 0;
  }

  .metric-card {
    padding: 1.1rem;
  }

  .metric-value {
    font-size: 2.3rem;
  }

  .metric-label {
    font-size: 0.9rem;
  }

  .goal-status {
    font-size: 0.8rem;
    padding: 0.45rem 0.9rem;
  }

  /* Use CSS Grid for better responsive layout */
  .history-card .row.mb-3 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--mobile-card-spacing);
  }
}

/* Tablet optimizations (768px to 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .metric-card {
    padding: 1.3rem;
    margin-bottom: 0;
  }

  .metric-value {
    font-size: 2.4rem;
  }

  .metric-label {
    font-size: 0.95rem;
  }

  .goal-status {
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
  }
}

/* Desktop: Restore original two-column layout with enhancements */
@media (min-width: 1024px) {
  .metric-card {
    margin-bottom: 0;
    padding: 1.5rem;
    border-radius: 12px;
  }

  .metric-value {
    font-size: 2.5rem;
  }

  .metric-label {
    font-size: 0.9rem;
  }

  .goal-status {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
  }

  /* Restore original hover effects on desktop */
  .metric-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  }
}
/* Weight Loss Rankings Styling */
.ranking-row {
  transition: all 0.3s ease;
}

.ranking-row:hover {
  background-color: #f8f9ff !important;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.ranking-row.gold {
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
  background-size: 100% 4px;
  background-repeat: no-repeat;
  background-position: bottom;
}

.ranking-row.silver {
  background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
  background-size: 100% 4px;
  background-repeat: no-repeat;
  background-position: bottom;
}

.ranking-row.bronze {
  background: linear-gradient(135deg, #cd7f32 0%, #daa520 100%);
  background-size: 100% 4px;
  background-repeat: no-repeat;
  background-position: bottom;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-weight: bold;
  font-size: 1.1rem;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.rank-1 {
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
  box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
}

.rank-2 {
  background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
  box-shadow: 0 4px 15px rgba(192, 192, 192, 0.4);
  color: #333;
}

.rank-3 {
  background: linear-gradient(135deg, #cd7f32 0%, #daa520 100%);
  box-shadow: 0 4px 15px rgba(205, 127, 50, 0.4);
}

.rank-badge:not(.rank-1):not(.rank-2):not(.rank-3) {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
  box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
}

.weight-loss-amount {
  font-size: 1.1rem;
}

.percentage-badge {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.percentage-badge.positive {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.percentage-badge.negative {
  background: linear-gradient(135deg, #dc3545 0%, #fd7e14 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.percentage-badge.neutral {
  background: #6c757d;
  color: white;
  box-shadow: 0 2px 8px rgba(108, 117, 125, 0.3);
}

.weight-progress {
  font-size: 0.9rem;
}

.bmi-change {
  text-align: center;
}

.journey-info {
  text-align: center;
}

.journey-info strong {
  color: #495057;
  font-size: 1rem;
}

/* Mobile-first ranking styles */
.rank-badge {
  width: 35px;
  height: 35px;
  font-size: 1rem;
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
}

.weight-loss-amount {
  font-size: 1rem;
}

.percentage-badge {
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  min-height: 32px; /* Adequate touch target for badges */
  display: inline-flex;
  align-items: center;
}

.ranking-row td {
  padding: 0.75rem 0.5rem;
  font-size: var(--mobile-font-small);
}

@media (min-width: 768px) {
  .rank-badge {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }

  .weight-loss-amount {
    font-size: 1.1rem;
  }

  .percentage-badge {
    font-size: 0.9rem;
    padding: 0.4rem 0.8rem;
  }

  .ranking-row td {
    padding: 1rem;
    font-size: 1rem;
  }
}

/* Trophy icons styling */
.rank-badge i {
  font-size: 1.2rem;
}

.rank-1 i {
  color: #b8860b;
}

.rank-2 i {
  color: #708090;
}

.rank-3 i {
  color: #8b4513;
}

/* Mobile-specific optimizations and touch target enhancements */

/* Ensure all clickable elements meet minimum touch target size */
.btn,
button,
input[type="button"],
input[type="submit"],
input[type="reset"] {
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
}

/* Optimize table interactions for mobile */
.stats-table td,
.history-table td {
  min-height: var(--touch-target-min);
  vertical-align: middle;
}

/* Prevent horizontal scrolling on mobile */
.container-fluid {
  overflow-x: hidden;
}

/* Optimize focus states for mobile */
.form-control:focus,
.btn:focus {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* Improve text readability on mobile */
p,
.text-muted,
small {
  font-size: var(--mobile-font-base);
  line-height: 1.5;
}

@media (min-width: 768px) {
  p,
  .text-muted,
  small {
    font-size: inherit;
  }
}

/* Mobile-specific spacing utilities */
.mobile-spacing {
  margin: var(--mobile-margin);
  padding: var(--mobile-padding);
}

/* Ensure proper spacing between interactive elements on mobile */
.btn + .btn,
.form-control + .form-control,
.form-group + .form-group {
  margin-top: var(--mobile-margin);
}

@media (min-width: 768px) {
  .btn + .btn,
  .form-control + .form-control,
  .form-group + .form-group {
    margin-top: 0;
  }
}

/* ===== SIMPLE MOBILE TABLE - CLEAN APPROACH ===== */

/* Mobile: Just make the table scroll horizontally, keep it simple */
@media (max-width: 767px) {
  .stats-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 2rem;
  }

  .stats-table table {
    min-width: 700px; /* Force horizontal scroll */
    width: auto;
  }

  .stats-table th,
  .stats-table td {
    padding: 0.75rem 0.5rem;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  .stats-table .form-control {
    min-width: 100px;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  .stats-table .btn-primary {
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
  }
}

/* Tablet and desktop: maintain table layout */
@media (min-width: 768px) {
  .stats-table table {
    display: table;
  }

  .stats-table thead,
  .stats-table tbody {
    display: table-header-group;
  }

  .stats-table tbody {
    display: table-row-group;
  }

  .stats-table tr {
    display: table-row;
  }

  .stats-table th,
  .stats-table td {
    display: table-cell;
  }

  /* Ensure proper table styling on larger screens */
  .stats-table thead {
    display: table-header-group;
  }
}

/* ===== MOBILE FORM INPUT OPTIMIZATIONS ===== */

/* Prevent horizontal scrolling when inputs are focused on mobile */
@media (max-width: 767px) {
  /* Prevent viewport zoom on input focus for iOS */
  input[type="number"],
  input[type="text"],
  input[type="email"],
  input[type="password"],
  textarea,
  select {
    font-size: var(
      --mobile-font-base
    ) !important; /* 16px prevents zoom on iOS */
    -webkit-appearance: none;
    -moz-appearance: textfield;
    appearance: none;
  }

  /* Remove spinner arrows on number inputs for cleaner mobile appearance */
  input[type="number"]::-webkit-outer-spin-button,
  input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
  }

  /* Ensure container doesn't overflow on mobile */
  .container-fluid {
    overflow-x: hidden;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .container {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Prevent form elements from causing horizontal scroll */
  .stats-table .form-control {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Enhanced mobile form validation feedback */
  .form-control:invalid {
    border-color: #dc3545;
    background-color: #fff5f5;
  }

  .form-control:valid {
    border-color: #28a745;
    background-color: #f8fff8;
  }

  /* Visual feedback for form interactions */
  .form-control:focus {
    transform: scale(1.02);
    transition: all 0.2s ease;
  }

  /* Improve touch feedback for buttons */
  .btn-primary:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }

  /* Add subtle animation for form validation states */
  .form-control {
    transition: border-color 0.3s ease, background-color 0.3s ease,
      transform 0.2s ease;
  }

  /* Ensure proper spacing to prevent accidental touches */
  .stats-table td {
    padding: 0.75rem 0;
    margin-bottom: 0.5rem;
  }

  /* Add visual feedback for successful form submission */
  .btn-primary:focus {
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.5);
    outline: none;
  }
}

/* Desktop form enhancements */
@media (min-width: 768px) {
  .form-control:focus {
    transform: none;
  }

  .btn-primary:active {
    transform: translateY(-1px);
  }
}

/* ===== MOBILE SAVE BUTTON ACCESSIBILITY ===== */

/* Ensure save buttons are properly accessible on mobile */
@media (max-width: 767px) {
  /* Style save buttons with adequate touch targets */
  .stats-table .btn-primary {
    width: 100%;
    min-height: var(--button-height-mobile); /* 48px minimum */
    min-width: var(--touch-target-min); /* 44px minimum */
    font-size: var(--mobile-font-base);
    font-weight: 600;
    padding: 0.875rem 1.5rem; /* Generous padding for touch */
    border-radius: var(--mobile-border-radius);
    margin-top: 1rem; /* Space from other elements */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-sizing: border-box;

    /* Prevent button from causing horizontal scroll */
    max-width: 100%;
    overflow: hidden;

    /* Enhanced touch feedback */
    transition: all 0.2s ease;
    position: relative;
  }

  /* Add proper spacing between interactive elements */
  .stats-table .btn-primary {
    margin-top: 1.5rem; /* Increased spacing from form inputs */
  }

  /* Ensure buttons don't overlap with virtual keyboard */
  .stats-table tbody tr:last-child .btn-primary {
    margin-bottom: 2rem; /* Extra space at bottom for keyboard */
  }

  /* Add visual separation between button and form fields */
  .stats-table td:last-child {
    border-top: 2px solid #f1f3f4;
    padding-top: 1.5rem;
    margin-top: 1rem;
  }

  /* Improve button icon spacing */
  .stats-table .btn-primary i {
    font-size: 1rem;
    margin-right: 0.5rem;
  }

  /* Add touch ripple effect for better feedback */
  .stats-table .btn-primary::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
    pointer-events: none;
  }

  .stats-table .btn-primary:active::after {
    width: 100%;
    height: 100%;
  }

  /* Ensure adequate spacing between multiple buttons if present */
  .stats-table .btn + .btn {
    margin-top: 1rem;
  }

  /* Prevent button text from wrapping */
  .stats-table .btn-primary {
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  /* Add focus ring for accessibility */
  .stats-table .btn-primary:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
  }

  /* Improve button contrast for better visibility */
  .stats-table .btn-primary {
    background: var(--primary-gradient);
    border: none;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
  }

  .stats-table .btn-primary:hover,
  .stats-table .btn-primary:focus {
    background: var(--primary-gradient);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
    transform: translateY(-1px);
  }

  .stats-table .btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  }
}

/* Desktop save button styling */
@media (min-width: 768px) {
  .stats-table .btn-primary {
    width: auto;
    min-width: auto;
    margin-top: 0;
    padding: 0.75rem 1.5rem;
  }

  .stats-table td:last-child {
    border-top: none;
    padding-top: 1rem;
    margin-top: 0;
  }

  .stats-table tbody tr:last-child .btn-primary {
    margin-bottom: 0;
  }
}

/* ===== RESPONSIVE LEADERBOARD WITH HORIZONTAL SCROLLING ===== */

/* Mobile-first: Horizontal scrolling leaderboard implementation */
@media (max-width: 767px) {
  /* Leaderboard container with horizontal scroll */
  .history-card .table-responsive {
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    border-radius: var(--mobile-border-radius);

    /* Visible scroll indicators */
    scrollbar-width: thin;
    scrollbar-color: #667eea #f1f3f4;
  }

  /* Custom scrollbar styling for webkit browsers */
  .history-card .table-responsive::-webkit-scrollbar {
    height: 8px;
  }

  .history-card .table-responsive::-webkit-scrollbar-track {
    background: #f1f3f4;
    border-radius: 4px;
  }

  .history-card .table-responsive::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
  }

  .history-card .table-responsive::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  }

  /* Leaderboard table mobile optimization */
  .history-card .table {
    min-width: 600px; /* Minimum width to trigger horizontal scroll */
    margin-bottom: 0;
    white-space: nowrap;
  }

  /* Sticky first column (Name) for better navigation */
  .history-card .table th:first-child,
  .history-card .table td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    background: white;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
    min-width: 120px; /* Ensure adequate width for names */
  }

  /* Header sticky styling */
  .history-card .table thead th:first-child {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.15);
  }

  /* Optimize column widths for mobile viewing */
  .history-card .table th,
  .history-card .table td {
    padding: 0.75rem 0.5rem;
    font-size: var(--mobile-font-small);
    vertical-align: middle;
  }

  /* Specific column width optimizations */
  .history-card .table th:nth-child(1), /* Rank */
  .history-card .table td:nth-child(1) {
    min-width: 120px; /* Name column - sticky */
  }

  .history-card .table th:nth-child(2), /* Name */
  .history-card .table td:nth-child(2) {
    min-width: 80px; /* Rank column */
  }

  .history-card .table th:nth-child(3), /* Weight Lost */
  .history-card .table td:nth-child(3) {
    min-width: 100px;
  }

  .history-card .table th:nth-child(4), /* % Lost */
  .history-card .table td:nth-child(4) {
    min-width: 80px;
  }

  .history-card .table th:nth-child(5), /* Progress */
  .history-card .table td:nth-child(5) {
    min-width: 120px;
  }

  .history-card .table th:nth-child(6), /* BMI Change */
  .history-card .table td:nth-child(6) {
    min-width: 90px;
  }

  .history-card .table th:nth-child(7), /* Journey */
  .history-card .table td:nth-child(7) {
    min-width: 100px;
  }

  /* Improve mobile table header styling */
  .history-card .table thead th {
    background: var(--primary-gradient);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.75rem 0.5rem;
    border: none;
    position: sticky;
    top: 0;
    z-index: 5;
  }

  /* Mobile table body styling */
  .history-card .table tbody tr {
    border-bottom: 1px solid #f1f3f4;
  }

  .history-card .table tbody tr:hover {
    background-color: #f8f9ff;
  }

  /* Ensure proper text alignment in mobile table */
  .history-card .table td {
    text-align: center;
    border: none;
    border-bottom: 1px solid #f8f9fa;
  }

  /* Name column left-aligned for better readability */
  .history-card .table th:first-child,
  .history-card .table td:first-child {
    text-align: left;
    padding-left: 1rem;
  }

  /* Compact mobile rank badges */
  .history-card .rank-badge {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
    min-width: 32px;
    min-height: 32px;
  }

  .history-card .rank-badge i {
    font-size: 1rem;
  }

  /* Compact mobile percentage badges */
  .history-card .percentage-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
  }

  /* Compact weight loss amount display */
  .history-card .weight-loss-amount {
    font-size: 0.9rem;
  }

  /* Compact progress and journey info */
  .history-card .weight-progress,
  .history-card .bmi-change,
  .history-card .journey-info {
    font-size: 0.8rem;
    line-height: 1.3;
  }

  .history-card .journey-info strong {
    font-size: 0.85rem;
  }

  /* Add subtle border to separate sticky column */
  .history-card .table th:first-child::after,
  .history-card .table td:first-child::after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(0, 0, 0, 0.1);
  }
}

/* Tablet adjustments (768px to 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .history-card .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .history-card .table {
    min-width: 800px;
  }

  .history-card .table th,
  .history-card .table td {
    padding: 0.875rem 0.75rem;
    font-size: 0.9rem;
  }

  /* Maintain sticky first column on tablets */
  .history-card .table th:first-child,
  .history-card .table td:first-child {
    position: sticky;
    left: 0;
    background: white;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
    z-index: 10;
  }

  .history-card .table thead th:first-child {
    background: var(--primary-gradient);
    color: white;
  }
}

/* Desktop: Full table layout without horizontal scroll */
@media (min-width: 1024px) {
  .history-card .table-responsive {
    overflow-x: visible;
  }

  .history-card .table {
    min-width: auto;
    width: 100%;
  }

  /* Remove sticky positioning on desktop */
  .history-card .table th:first-child,
  .history-card .table td:first-child {
    position: static;
    box-shadow: none;
  }

  .history-card .table th,
  .history-card .table td {
    padding: 1rem;
    font-size: 1rem;
  }

  /* Hide scroll hint on desktop */
  .history-card .table-responsive::after {
    display: none;
  }
}

/* ===== MOBILE LEADERBOARD CONTENT OPTIMIZATION ===== */

/* Mobile-first: Optimize leaderboard content for readability and accessibility */
@media (max-width: 767px) {
  /* Reduce font sizes while maintaining readability */
  .history-card h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    line-height: 1.2;
  }

  /* Optimize table header text */
  .history-card .table thead th {
    font-size: 0.7rem;
    line-height: 1.2;
    padding: 0.6rem 0.4rem;
    text-align: center;
  }

  .history-card .table thead th:first-child {
    text-align: left;
    padding-left: 0.8rem;
  }

  /* Optimize table body text */
  .history-card .table tbody td {
    font-size: 0.8rem;
    line-height: 1.3;
    padding: 0.6rem 0.4rem;
  }

  .history-card .table tbody td:first-child {
    text-align: left;
    padding-left: 0.8rem;
  }

  /* Condense ranking badges for mobile */
  .history-card .rank-badge {
    width: 28px;
    height: 28px;
    font-size: 0.8rem;
    min-width: 28px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .history-card .rank-badge i {
    font-size: 0.9rem;
  }

  .history-card .rank-badge span {
    font-weight: 700;
    font-size: 0.8rem;
  }

  /* Enhanced contrast for rank badges - accessibility compliance */
  .history-card .rank-1 {
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 2px 8px rgba(243, 156, 18, 0.4);
  }

  .history-card .rank-2 {
    background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 2px 8px rgba(149, 165, 166, 0.4);
  }

  .history-card .rank-3 {
    background: linear-gradient(135deg, #d35400 0%, #c0392b 100%);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 2px 8px rgba(211, 84, 0, 0.4);
  }

  .history-card .rank-badge:not(.rank-1):not(.rank-2):not(.rank-3) {
    background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 2px 8px rgba(52, 73, 94, 0.4);
  }

  /* Condense weight loss amount display */
  .history-card .weight-loss-amount {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
  }

  .history-card .weight-loss-amount strong {
    font-size: 0.9rem;
    font-weight: 700;
  }

  /* Enhanced contrast for weight loss indicators */
  .history-card .text-success {
    color: #155724 !important; /* Darker green for better contrast */
    font-weight: 600;
  }

  .history-card .text-danger {
    color: #721c24 !important; /* Darker red for better contrast */
    font-weight: 600;
  }

  .history-card .text-muted {
    color: #495057 !important; /* Darker gray for better contrast */
    font-weight: 500;
  }

  /* Condense percentage badges with improved contrast */
  .history-card .percentage-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    min-height: 24px;
    font-weight: 700;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  }

  .history-card .percentage-badge.positive {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(39, 174, 96, 0.3);
  }

  .history-card .percentage-badge.negative {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(231, 76, 60, 0.3);
  }

  .history-card .percentage-badge.neutral {
    background: linear-gradient(135deg, #7f8c8d 0%, #95a5a6 100%);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 2px 6px rgba(127, 140, 141, 0.3);
  }

  /* Condense progress information */
  .history-card .weight-progress {
    font-size: 0.75rem;
    line-height: 1.2;
    color: #495057;
    font-weight: 500;
  }

  .history-card .weight-progress small {
    font-size: 0.7rem;
    color: #6c757d;
  }

  /* Condense BMI change display */
  .history-card .bmi-change {
    font-size: 0.75rem;
    line-height: 1.2;
    text-align: center;
  }

  .history-card .bmi-change span {
    font-weight: 600;
    font-size: 0.8rem;
  }

  .history-card .bmi-change small {
    font-size: 0.7rem;
    color: #6c757d;
    display: block;
    margin-top: 0.2rem;
  }

  /* Condense journey information */
  .history-card .journey-info {
    font-size: 0.75rem;
    line-height: 1.2;
    text-align: center;
  }

  .history-card .journey-info strong {
    font-size: 0.8rem;
    font-weight: 600;
    color: #495057;
    display: block;
    margin-bottom: 0.2rem;
  }

  .history-card .journey-info small {
    font-size: 0.7rem;
    color: #6c757d;
    line-height: 1.1;
  }

  /* Improve overall table readability on mobile */
  .history-card .table tbody tr {
    border-bottom: 1px solid #dee2e6;
  }

  .history-card .table tbody tr:nth-child(odd) {
    background-color: #f8f9fa;
  }

  .history-card .table tbody tr:hover {
    background-color: #e3f2fd !important;
    transition: background-color 0.2s ease;
  }

  /* Ensure adequate spacing between elements */
  .history-card .table td > * {
    margin-bottom: 0.1rem;
  }

  .history-card .table td > *:last-child {
    margin-bottom: 0;
  }

  /* Add subtle animations for better user experience */
  .history-card .rank-badge,
  .history-card .percentage-badge {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }

  .history-card .rank-badge:hover,
  .history-card .percentage-badge:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }
}

/* Small mobile adjustments (480px+) */
@media (min-width: 480px) and (max-width: 767px) {
  .history-card h3 {
    font-size: 1.4rem;
  }

  .history-card .table thead th {
    font-size: 0.75rem;
    padding: 0.7rem 0.5rem;
  }

  .history-card .table tbody td {
    font-size: 0.85rem;
    padding: 0.7rem 0.5rem;
  }

  .history-card .rank-badge {
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
  }

  .history-card .percentage-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    min-height: 26px;
  }

  .history-card .weight-loss-amount {
    font-size: 0.9rem;
  }

  .history-card .weight-progress,
  .history-card .bmi-change,
  .history-card .journey-info {
    font-size: 0.8rem;
  }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 1023px) {
  .history-card .table thead th {
    font-size: 0.85rem;
  }

  .history-card .table tbody td {
    font-size: 0.9rem;
  }

  .history-card .rank-badge {
    width: 35px;
    height: 35px;
    font-size: 1rem;
  }

  .history-card .percentage-badge {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
  }
}

/* Desktop: Restore full sizing */
@media (min-width: 1024px) {
  .history-card h3 {
    font-size: 1.8rem;
  }

  .history-card .table thead th {
    font-size: 0.85rem;
    padding: 1rem;
  }

  .history-card .table tbody td {
    font-size: 1rem;
    padding: 1rem;
  }

  .history-card .rank-badge {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }

  .history-card .percentage-badge {
    font-size: 0.9rem;
    padding: 0.4rem 0.8rem;
  }

  .history-card .weight-loss-amount {
    font-size: 1.1rem;
  }

  .history-card .weight-progress,
  .history-card .bmi-change,
  .history-card .journey-info {
    font-size: 0.9rem;
  }
}

/* ===== RESPONSIVE PROGRESS CARDS SINGLE-COLUMN LAYOUT ===== */

/* Mobile-first: Transform progress cards to single-column stack on mobile */
@media (max-width: 767px) {
  /* Force single-column layout for progress cards on mobile */
  .row .col-md-6 {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    margin-bottom: var(--mobile-card-spacing);
  }

  /* Optimize progress card padding and spacing for mobile screens */
  .history-card {
    padding: var(--mobile-padding);
    margin-bottom: var(--mobile-card-spacing);
    border-radius: var(--mobile-border-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

    /* Ensure full-width utilization on mobile devices */
    width: 100%;
    box-sizing: border-box;
  }

  /* Optimize progress card headers for mobile */
  .history-card h4 {
    font-size: var(--mobile-font-large);
    margin-bottom: 0.75rem;
    line-height: 1.2;
    color: #333 !important;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.5rem;
  }

  /* Optimize progress card subheadings and summary text */
  .history-card h4 br + small {
    display: block;
    margin-top: 0.5rem;
    font-size: var(--mobile-font-small);
    line-height: 1.3;
  }

  /* Ensure proper spacing between progress cards */
  .row .col-md-6:not(:last-child) {
    margin-bottom: 1.5rem;
  }

  /* Remove any negative margins that might cause horizontal scroll */
  .row {
    margin-left: 0;
    margin-right: 0;
  }

  .row .col-md-6 {
    padding-left: 0;
    padding-right: 0;
  }

  /* Optimize progress card content spacing */
  .history-card .table {
    margin-bottom: 0;
  }

  .history-card .table th,
  .history-card .table td {
    padding: 0.6rem 0.75rem;
    font-size: var(--mobile-font-small);
  }

  /* Improve stat badge readability in progress cards */
  .history-card .stat-badge {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    margin-left: 0.25rem;
    margin-top: 0.25rem;
    display: inline-block;
  }

  /* Optimize metric cards within progress cards for mobile */
  .history-card .metric-card {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    border-radius: var(--mobile-border-radius);
  }

  .history-card .metric-value {
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
  }

  .history-card .metric-label {
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
  }

  .history-card .goal-status {
    font-size: 0.7rem;
    padding: 0.3rem 0.6rem;
  }

  /* Ensure progress cards don't cause horizontal overflow */
  .history-card {
    overflow-x: hidden;
  }

  /* Add subtle mobile-specific styling */
  .history-card:hover {
    transform: none; /* Remove hover transform on mobile */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }

  /* Optimize row spacing within progress cards */
  .history-card .row {
    margin-bottom: 0.75rem;
  }

  .history-card .row:last-child {
    margin-bottom: 0;
  }

  /* Ensure metric cards within progress cards stack properly */
  .history-card .row .col-6 {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    margin-bottom: 0.75rem;
    padding: 0;
  }

  .history-card .row .col-6:last-child {
    margin-bottom: 0;
  }
}

/* Small mobile adjustments (480px+) */
@media (min-width: 480px) and (max-width: 767px) {
  .history-card {
    padding: 1.25rem;
  }

  .history-card h4 {
    font-size: 1.3rem;
  }

  .history-card .table th,
  .history-card .table td {
    padding: 0.7rem 0.875rem;
    font-size: 0.9rem;
  }

  .history-card .metric-card {
    padding: 1rem;
  }

  .history-card .metric-value {
    font-size: 2rem;
  }

  /* Allow side-by-side metric cards on larger mobile screens */
  .history-card .row .col-6 {
    width: 50% !important;
    max-width: 50% !important;
    flex: 0 0 50% !important;
    margin-bottom: 0;
    padding: 0 0.375rem;
  }

  .history-card .row .col-6:first-child {
    padding-left: 0;
  }

  .history-card .row .col-6:last-child {
    padding-right: 0;
  }
}

/* Tablet optimizations (768px to 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  /* Allow two-column layout on tablets but with optimized spacing */
  .row .col-md-6 {
    margin-bottom: 1.5rem;
  }

  .history-card {
    padding: 1.25rem;
  }

  .history-card h4 {
    font-size: 1.4rem;
  }
}

/* Desktop: Restore original two-column layout */
@media (min-width: 1024px) {
  .row .col-md-6 {
    margin-bottom: 0;
  }

  .history-card {
    padding: 1.5rem;
  }

  .history-card h4 {
    font-size: 1.5rem;
  }

  /* Restore original hover effects on desktop */
  .history-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--card-hover-shadow);
  }
}

/* ===== MOBILE HISTORICAL DATA TABLES OPTIMIZATION ===== */

/* Mobile-first: Optimize historical data tables for mobile viewing */
@media (max-width: 767px) {
  /* Condense historical data table layouts to show essential information */
  .history-card .history-table {
    font-size: var(--mobile-font-small);
    margin: 0;
  }

  .history-card .history-table th {
    background: #f8f9fa;
    color: #495057;
    font-weight: 600;
    border: none;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    line-height: 1.2;
    vertical-align: middle;
  }

  .history-card .history-table td {
    border: none;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f1f3f4;
    font-size: var(--mobile-font-small);
    line-height: 1.3;
    vertical-align: middle;
  }

  /* Optimize table header icons for mobile */
  .history-card .history-table th i {
    font-size: 0.9rem;
    margin-right: 0.4rem;
    opacity: 0.8;
    color: #495057 !important;
  }

  /* Maintain data hierarchy and readability on small screens */
  .history-card .history-table th {
    width: 35%; /* Fixed width for consistency */
    text-align: left;
    font-weight: 600;
    color: #495057;
  }

  .history-card .history-table td {
    width: 65%; /* Remaining width for data */
    text-align: left;
  }

  /* Optimize stat badges within historical tables */
  .history-card .history-table .stat-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    margin-left: 0.25rem;
    margin-top: 0.1rem;
    border-radius: 12px;
    display: inline-block;
    vertical-align: middle;
  }

  /* Improve readability of data values */
  .history-card .history-table strong {
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
  }

  .history-card .history-table small {
    font-size: 0.75rem;
    color: #6c757d;
    line-height: 1.2;
    display: block;
    margin-top: 0.2rem;
  }

  /* Optimize multi-line data display */
  .history-card .history-table td div {
    margin-bottom: 0.2rem;
  }

  .history-card .history-table td div:last-child {
    margin-bottom: 0;
  }

  /* Improve spacing between table rows */
  .history-card .history-table tbody tr {
    border-bottom: 1px solid #f1f3f4;
  }

  .history-card .history-table tbody tr:last-child {
    border-bottom: none;
  }

  .history-card .history-table tbody tr:nth-child(odd) {
    background-color: #fafbfc;
  }

  .history-card .history-table tbody tr:hover {
    background-color: #f0f4ff;
    transition: background-color 0.2s ease;
  }

  /* Condense complex data displays */
  .history-card .history-table td span.ms-1 {
    margin-left: 0.2rem !important;
    font-size: 0.7rem;
  }

  /* Optimize BMI and weight change indicators */
  .history-card .history-table .stat-badge.positive {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    color: white;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  }

  .history-card .history-table .stat-badge.negative {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  }

  .history-card .history-table .stat-badge.neutral {
    background: #6c757d;
    color: white;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  }

  /* Ensure proper text wrapping for long content */
  .history-card .history-table th,
  .history-card .history-table td {
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
  }

  /* Optimize table container for mobile */
  .history-card .table-responsive {
    border-radius: var(--mobile-border-radius);
    overflow-x: hidden; /* Prevent horizontal scroll in progress cards */
  }

  /* Add subtle mobile-specific table styling */
  .history-card .history-table {
    border-radius: var(--mobile-border-radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  /* Improve accessibility and touch targets */
  .history-card .history-table tbody tr {
    min-height: var(--touch-target-min);
    cursor: default;
  }

  /* Optimize spacing for better mobile readability */
  .history-card .history-table th:first-child,
  .history-card .history-table td:first-child {
    padding-left: 1rem;
  }

  .history-card .history-table th:last-child,
  .history-card .history-table td:last-child {
    padding-right: 1rem;
  }

  /* Ensure consistent alignment */
  .history-card .history-table th {
    vertical-align: middle;
    text-align: left;
  }

  .history-card .history-table td {
    vertical-align: top;
    text-align: left;
  }

  /* Handle long text content gracefully */
  .history-card .history-table td {
    max-width: 0; /* Allow flexible width */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal; /* Allow wrapping */
  }

  /* Special handling for date ranges and complex content */
  .history-card .history-table small.text-muted {
    font-size: 0.7rem;
    color: #6c757d !important;
    line-height: 1.1;
    margin-top: 0.1rem;
  }
}

/* Small mobile adjustments (480px+) */
@media (min-width: 480px) and (max-width: 767px) {
  .history-card .history-table {
    font-size: 0.9rem;
  }

  .history-card .history-table th {
    padding: 0.6rem 0.875rem;
    font-size: 0.85rem;
  }

  .history-card .history-table td {
    padding: 0.6rem 0.875rem;
    font-size: 0.9rem;
  }

  .history-card .history-table .stat-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
  }

  .history-card .history-table strong {
    font-size: 0.95rem;
  }

  .history-card .history-table small {
    font-size: 0.8rem;
  }
}

/* Tablet optimizations (768px to 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .history-card .history-table th {
    padding: 0.7rem;
    font-size: 0.9rem;
  }

  .history-card .history-table td {
    padding: 0.7rem;
    font-size: 0.95rem;
  }

  .history-card .history-table .stat-badge {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
  }
}

/* Desktop: Restore original table styling */
@media (min-width: 1024px) {
  .history-card .history-table th {
    padding: 0.75rem;
    font-size: 0.9rem;
  }

  .history-card .history-table td {
    padding: 0.75rem;
    font-size: 1rem;
  }

  .history-card .history-table .stat-badge {
    font-size: 0.8rem;
    padding: 0.25rem 0.75rem;
  }

  .history-card .history-table strong {
    font-size: inherit;
  }

  .history-card .history-table small {
    font-size: 0.85rem;
  }

  /* Restore hover effects on desktop */
  .history-card .history-table tbody tr:hover {
    background-color: #f8f9ff;
  }
}

/* ===== ADVANCED MOBILE FEATURES ===== */

/* Swipe gesture indicators for horizontal scrolling */
@media (max-width: 767px) {
  /* Enhanced swipe indicators for horizontal scrolling tables */
  .table-responsive {
    position: relative;
  }

  .table-responsive::before {
    content: "👈 Swipe";
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    z-index: 15;
    opacity: 0;
    animation: swipeIndicatorPulse 2s infinite;
    pointer-events: none;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .table-responsive::after {
    content: "Swipe 👉";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    z-index: 15;
    opacity: 0;
    animation: swipeIndicatorPulse 2s infinite 1s;
    pointer-events: none;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  /* Show swipe indicators on first load */
  .table-responsive:not(.scrolled):not(.touched)::before,
  .table-responsive:not(.scrolled):not(.touched)::after {
    opacity: 1;
  }

  /* Hide indicators after user interaction */
  .table-responsive.scrolled::before,
  .table-responsive.scrolled::after,
  .table-responsive.touched::before,
  .table-responsive.touched::after {
    opacity: 0;
    transition: opacity 0.5s ease;
  }

  /* Swipe indicator animation */
  @keyframes swipeIndicatorPulse {
    0%,
    100% {
      opacity: 0.7;
      transform: translateY(-50%) scale(1);
    }
    50% {
      opacity: 1;
      transform: translateY(-50%) scale(1.05);
    }
  }

  /* Enhanced scroll hint with gesture icons */
  .history-card .table-responsive::after {
    content: "← Swipe to see more →";
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: #6c757d;
    font-style: italic;
    pointer-events: none;
    opacity: 0.8;
    background: rgba(255, 255, 255, 0.9);
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    animation: scrollHintBounce 3s infinite;
  }

  @keyframes scrollHintBounce {
    0%,
    100% {
      transform: translateX(-50%) translateY(0);
    }
    50% {
      transform: translateX(-50%) translateY(-2px);
    }
  }
}

/* Collapsible sections for content organization */
@media (max-width: 767px) {
  /* Collapsible progress cards */
  .history-card {
    position: relative;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
  }

  .history-card.collapsible {
    cursor: pointer;
  }

  .history-card.collapsible .collapse-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(102, 126, 234, 0.1);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #667eea;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    z-index: 10;
  }

  .history-card.collapsible .collapse-toggle:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: scale(1.1);
  }

  .history-card.collapsible .collapse-toggle i {
    transition: transform 0.3s ease;
  }

  .history-card.collapsible.collapsed .collapse-toggle i {
    transform: rotate(180deg);
  }

  /* Collapsible content */
  .history-card .collapsible-content {
    transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.3s ease;
    overflow: hidden;
  }

  .history-card.collapsed .collapsible-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    margin-bottom: 0;
  }

  .history-card.collapsed {
    max-height: 80px;
  }

  /* Collapsible header styling */
  .history-card.collapsible h4 {
    padding-right: 3rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    position: relative;
  }

  .history-card.collapsible h4::after {
    content: "";
    position: absolute;
    bottom: -0.5rem;
    left: 0;
    right: 3rem;
    height: 2px;
    background: var(--primary-gradient);
    border-radius: 1px;
    transition: all 0.3s ease;
  }

  .history-card.collapsible.collapsed h4::after {
    opacity: 0.5;
    height: 1px;
  }

  /* Smooth expand/collapse animations */
  .history-card.collapsible:not(.collapsed) .collapsible-content {
    max-height: 1000px;
    opacity: 1;
  }

  /* Add subtle visual cues for collapsible sections */
  .history-card.collapsible {
    border-left: 4px solid transparent;
    transition: border-left-color 0.3s ease;
  }

  .history-card.collapsible:hover {
    border-left-color: rgba(102, 126, 234, 0.3);
  }

  .history-card.collapsible.collapsed {
    border-left-color: rgba(102, 126, 234, 0.6);
  }

  /* Collapsible fitness analytics sections */
  .fitness-section {
    margin-bottom: 1rem;
  }

  .fitness-section.collapsible .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: var(--mobile-border-radius);
    cursor: pointer;
    margin-bottom: 0.5rem;
    transition: all 0.3s ease;
  }

  .fitness-section.collapsible .section-header:hover {
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .fitness-section.collapsible .section-header h5 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #495057;
  }

  .fitness-section.collapsible .section-toggle {
    background: none;
    border: none;
    color: #667eea;
    font-size: 1rem;
    transition: transform 0.3s ease;
  }

  .fitness-section.collapsible.collapsed .section-toggle {
    transform: rotate(180deg);
  }
}

/* Mobile-specific accessibility enhancements */
@media (max-width: 767px) {
  /* Enhanced focus states for mobile */
  .btn:focus,
  .form-control:focus,
  .history-card.collapsible:focus,
  .table-responsive:focus {
    outline: 3px solid rgba(102, 126, 234, 0.6);
    outline-offset: 2px;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
  }

  /* High contrast mode support */
  @media (prefers-contrast: high) {
    .history-card {
      border: 2px solid #000;
    }

    .btn-primary {
      background: #000;
      border-color: #000;
      color: #fff;
    }

    .stat-badge,
    .percentage-badge,
    .goal-status {
      border: 1px solid #000;
    }

    .table-responsive::before,
    .table-responsive::after {
      background: #000;
      color: #fff;
    }
  }

  /* Reduced motion support */
  @media (prefers-reduced-motion: reduce) {
    .history-card,
    .collapsible-content,
    .collapse-toggle,
    .table-responsive::before,
    .table-responsive::after {
      animation: none;
      transition: none;
    }

    .swipeIndicatorPulse,
    .scrollHintBounce {
      animation: none;
    }
  }

  /* Enhanced touch targets for accessibility */
  .history-card.collapsible,
  .fitness-section.collapsible .section-header,
  .collapse-toggle,
  .section-toggle {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
  }

  /* Screen reader enhancements */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* ARIA live regions for dynamic content */
  .live-region {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
  }

  /* Enhanced color contrast for text */
  .text-muted {
    color: #495057 !important;
  }

  .history-card .text-muted {
    color: #495057 !important;
    font-weight: 500;
  }

  /* Improved link and button contrast */
  .btn-primary {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
    border: none;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  }

  .btn-primary:hover,
  .btn-primary:focus {
    background: linear-gradient(135deg, #4c63d2 0%, #5d3a84 100%);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  }

  /* Enhanced table accessibility */
  .table th {
    font-weight: 600;
    color: #333;
  }

  .table td {
    color: #495057;
  }

  /* Improved form accessibility */
  .form-control {
    border: 2px solid #ced4da;
    color: #495057;
  }

  .form-control:focus {
    border-color: #667eea;
    color: #333;
    background-color: #fff;
  }

  .form-control::placeholder {
    color: #6c757d;
    opacity: 1;
  }

  /* Enhanced badge and status indicator accessibility */
  .stat-badge,
  .percentage-badge,
  .goal-status {
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  }

  .stat-badge.positive,
  .percentage-badge.positive {
    background: linear-gradient(135deg, #1e7e34 0%, #155724 100%);
  }

  .stat-badge.negative,
  .percentage-badge.negative {
    background: linear-gradient(135deg, #bd2130 0%, #721c24 100%);
  }

  /* Keyboard navigation enhancements */
  .history-card.collapsible:focus-within {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
  }

  /* Touch feedback improvements */
  .history-card.collapsible:active {
    transform: scale(0.995);
  }

  .btn-primary:active {
    transform: scale(0.98);
  }

  /* Enhanced visual hierarchy */
  .page-header h2,
  .page-header h3 {
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  }

  .history-card h4 {
    color: #333 !important;
    font-weight: 600;
    text-shadow: none;
  }

  /* Improved spacing for better readability */
  .history-card {
    line-height: 1.6;
  }

  .history-card .table th,
  .history-card .table td {
    line-height: 1.5;
  }

  /* Enhanced mobile typography */
  body {
    font-size: var(--mobile-font-base);
    line-height: 1.6;
    color: #333;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    line-height: 1.3;
    color: #333;
  }

  /* Improved mobile scrolling */
  html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }

  /* Enhanced mobile performance */
  .history-card,
  .metric-card,
  .stats-table {
    will-change: transform;
    contain: layout style paint;
  }
}

/* ===== MOBILE FITNESS DATA TABLES OPTIMIZATION ===== */

/* Mobile-first: Optimize fitness analytics tables for mobile viewing */
@media (max-width: 767px) {
  /* Condense fitness analytics tables for mobile viewing */
  .history-card .history-table {
    font-size: var(--mobile-font-small);
    margin: 0;
    border-radius: var(--mobile-border-radius);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  /* Optimize table headers for fitness analytics */
  .history-card .history-table th {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    color: #495057;
    font-weight: 600;
    border: none;
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    line-height: 1.2;
    vertical-align: middle;
    text-align: left;
    width: 40%; /* Consistent width for fitness data labels */
  }

  /* Optimize table data cells for fitness analytics */
  .history-card .history-table td {
    border: none;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid #f1f3f4;
    font-size: var(--mobile-font-small);
    line-height: 1.4;
    vertical-align: middle;
    text-align: left;
    width: 60%; /* Remaining width for fitness data values */
    word-wrap: break-word;
  }

  /* Enhanced fitness table header icons */
  .history-card .history-table th i {
    font-size: 1rem;
    margin-right: 0.5rem;
    opacity: 0.9;
    color: #495057 !important;
    vertical-align: middle;
  }

  /* Ensure goal status indicators remain visible and accessible */
  .history-card .history-table .goal-status {
    font-size: 0.7rem;
    padding: 0.3rem 0.6rem;
    border-radius: 16px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    min-width: 60px;
    margin-top: 0.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .history-card .history-table .goal-status i {
    font-size: 0.8rem;
    margin-right: 0.3rem;
    margin-left: 0;
  }

  /* Enhanced goal status styling for better visibility */
  .history-card .history-table .goal-met {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(40, 167, 69, 0.3);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  }

  .history-card .history-table .goal-missed {
    background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(255, 193, 7, 0.3);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  }

  /* Touch interaction feedback for goal status indicators */
  .history-card .history-table .goal-status:hover,
  .history-card .history-table .goal-status:focus {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }

  .history-card .history-table .goal-status:active {
    transform: scale(0.98);
  }

  /* Implement proper spacing for mobile touch interaction */
  .history-card .history-table tbody tr {
    border-bottom: 1px solid #f1f3f4;
    min-height: var(--touch-target-min);
    cursor: default;
  }

  .history-card .history-table tbody tr:last-child {
    border-bottom: none;
  }

  .history-card .history-table tbody tr:nth-child(odd) {
    background-color: #fafbfc;
  }

  .history-card .history-table tbody tr:hover {
    background-color: #f0f8ff;
    transition: background-color 0.2s ease;
  }

  /* Optimize fitness data value display */
  .history-card .history-table strong {
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
    display: inline-block;
    margin-right: 0.5rem;
  }

  .history-card .history-table small {
    font-size: 0.75rem;
    color: #6c757d;
    line-height: 1.2;
    display: block;
    margin-top: 0.2rem;
  }

  /* Special styling for fitness metrics */
  .history-card .history-table td div {
    margin-bottom: 0.3rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .history-card .history-table td div:last-child {
    margin-bottom: 0;
  }

  /* Optimize calorie and activity data display */
  .history-card .history-table td strong:first-child {
    color: #fd7e14; /* Calories color */
  }

  .history-card .history-table td br + strong {
    color: #28a745; /* Activity color */
  }

  /* Ensure proper spacing between fitness data elements */
  .history-card .history-table td {
    padding: 0.75rem;
  }

  .history-card .history-table th:first-child,
  .history-card .history-table td:first-child {
    padding-left: 1rem;
  }

  .history-card .history-table th:last-child,
  .history-card .history-table td:last-child {
    padding-right: 1rem;
  }

  /* Add visual hierarchy for different fitness data types */
  .history-card .history-table th[title*="Avg"] {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    color: #1976d2;
  }

  .history-card .history-table th[title*="Records"] {
    background: linear-gradient(135deg, #fff3e0 0%, #ffcc02 100%);
    color: #f57c00;
  }

  .history-card .history-table th[title*="Best"] {
    background: linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%);
    color: #388e3c;
  }

  /* Improve accessibility with better focus states */
  .history-card .history-table tbody tr:focus-within {
    outline: 2px solid #667eea;
    outline-offset: 2px;
    background-color: #f0f4ff;
  }

  /* Optimize table container for mobile fitness analytics */
  .history-card .table-responsive {
    border-radius: var(--mobile-border-radius);
    overflow-x: hidden;
    margin-bottom: 1rem;
  }

  /* Add subtle mobile-specific fitness table styling */
  .history-card .history-table {
    border: 1px solid #e9ecef;
    border-radius: var(--mobile-border-radius);
    background: white;
  }

  /* Ensure consistent spacing in fitness analytics cards */
  .history-card h4 + .row {
    margin-top: 1rem;
  }

  .history-card .row + .table {
    margin-top: 1rem;
  }

  /* Optimize multi-line fitness data display */
  .history-card .history-table td span.ms-1 {
    margin-left: 0.3rem !important;
    font-size: 0.7rem;
    color: #6c757d;
    font-weight: normal;
  }

  /* Special handling for weekly activity goals */
  .history-card .history-table .goal-status:contains("Weekly") {
    font-size: 0.65rem;
    padding: 0.25rem 0.5rem;
    min-width: 80px;
    text-align: center;
  }

  /* Improve readability of fitness averages and records */
  .history-card .history-table td strong + br + strong {
    margin-top: 0.2rem;
    display: inline-block;
  }

  /* Add visual separation for different fitness metrics */
  .history-card .history-table tbody tr:nth-child(3n) {
    border-bottom: 2px solid #e9ecef;
  }

  /* Ensure proper touch targets for all interactive elements */
  .history-card .history-table .goal-status,
  .history-card .history-table tbody tr {
    min-height: var(--touch-target-min);
  }
}

/* Small mobile adjustments for fitness tables (480px+) */
@media (min-width: 480px) and (max-width: 767px) {
  .history-card .history-table {
    font-size: 0.9rem;
  }

  .history-card .history-table th {
    padding: 0.7rem 0.875rem;
    font-size: 0.85rem;
  }

  .history-card .history-table td {
    padding: 0.7rem 0.875rem;
    font-size: 0.9rem;
  }

  .history-card .history-table .goal-status {
    font-size: 0.75rem;
    padding: 0.35rem 0.7rem;
    min-height: 30px;
    min-width: 70px;
  }

  .history-card .history-table strong {
    font-size: 0.95rem;
  }

  .history-card .history-table small {
    font-size: 0.8rem;
  }
}

/* Tablet optimizations for fitness tables (768px to 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .history-card .history-table th {
    padding: 0.8rem;
    font-size: 0.9rem;
  }

  .history-card .history-table td {
    padding: 0.8rem;
    font-size: 0.95rem;
  }

  .history-card .history-table .goal-status {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    min-height: 32px;
    min-width: 75px;
  }
}

/* Desktop: Enhanced fitness table styling */
@media (min-width: 1024px) {
  .history-card .history-table .goal-status {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    min-height: auto;
    min-width: auto;
  }

  .history-card .history-table .goal-status:hover {
    transform: scale(1.05);
  }

  /* Restore desktop hover effects for fitness tables */
  .history-card .history-table tbody tr:hover {
    background-color: #f8f9ff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
}

/* ===== ESSENTIAL MOBILE FEATURES (DESKTOP-SAFE) ===== */

/* Swipe gesture indicators - MOBILE ONLY */
@media (max-width: 767px) {
  /* Enhanced swipe indicators for horizontal scrolling tables */
  .table-responsive {
    position: relative;
  }

  .table-responsive::before {
    content: "👈 Swipe";
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    z-index: 15;
    opacity: 0;
    animation: swipeIndicatorPulse 2s infinite;
    pointer-events: none;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .table-responsive::after {
    content: "Swipe 👉";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    z-index: 15;
    opacity: 0;
    animation: swipeIndicatorPulse 2s infinite 1s;
    pointer-events: none;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  /* Show swipe indicators on first load */
  .table-responsive:not(.scrolled):not(.touched)::before,
  .table-responsive:not(.scrolled):not(.touched)::after {
    opacity: 1;
  }

  /* Hide indicators after user interaction */
  .table-responsive.scrolled::before,
  .table-responsive.scrolled::after,
  .table-responsive.touched::before,
  .table-responsive.touched::after {
    opacity: 0;
    transition: opacity 0.5s ease;
  }

  /* Swipe indicator animation */
  @keyframes swipeIndicatorPulse {
    0%,
    100% {
      opacity: 0.7;
      transform: translateY(-50%) scale(1);
    }
    50% {
      opacity: 1;
      transform: translateY(-50%) scale(1.05);
    }
  }
}

/* Collapsible sections - MOBILE ONLY */
@media (max-width: 767px) {
  /* Collapsible progress cards */
  .history-card.collapsible {
    position: relative;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    cursor: pointer;
  }

  .history-card.collapsible .collapse-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(102, 126, 234, 0.1);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #667eea;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    z-index: 10;
  }

  .history-card.collapsible .collapse-toggle:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: scale(1.1);
  }

  .history-card.collapsible .collapse-toggle i {
    transition: transform 0.3s ease;
  }

  .history-card.collapsible.collapsed .collapse-toggle i {
    transform: rotate(180deg);
  }

  /* Collapsible content */
  .history-card .collapsible-content {
    transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.3s ease;
    overflow: hidden;
  }

  .history-card.collapsed .collapsible-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    margin-bottom: 0;
  }

  .history-card.collapsed {
    max-height: 80px;
  }

  /* Collapsible header styling */
  .history-card.collapsible h4 {
    padding-right: 3rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    position: relative;
  }

  .history-card.collapsible:not(.collapsed) .collapsible-content {
    max-height: 1000px;
    opacity: 1;
  }
}

/* Enhanced accessibility - MOBILE ONLY */
@media (max-width: 767px) {
  /* Enhanced focus states for mobile */
  .btn:focus,
  .form-control:focus,
  .history-card.collapsible:focus {
    outline: 3px solid rgba(102, 126, 234, 0.6);
    outline-offset: 2px;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
  }

  /* Screen reader enhancements */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* ARIA live regions for dynamic content */
  .live-region {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
  }

  /* Enhanced touch targets for accessibility */
  .history-card.collapsible,
  .collapse-toggle {
    min-height: 44px;
    min-width: 44px;
  }
}

/* DESKTOP FIXES - Ensure no mobile artifacts on desktop */
@media (min-width: 768px) {
  /* Remove all mobile-specific pseudo elements on desktop */
  .table-responsive::before,
  .table-responsive::after {
    display: none !important;
  }

  /* Ensure no collapsible artifacts on desktop */
  .history-card {
    position: static;
    overflow: visible;
    max-height: none;
    cursor: default;
  }

  .history-card .collapse-toggle {
    display: none !important;
  }

  .history-card .collapsible-content {
    max-height: none;
    opacity: 1;
    overflow: visible;
  }

  .history-card h4 {
    padding-right: 0;
    cursor: default;
  }

  /* Ensure proper desktop focus states */
  .btn:focus,
  .form-control:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
  }
}
/* ===== STAT BADGE FIXES FOR PROGRESS BUBBLES ===== */

/* Mobile stat badge optimizations */
@media (max-width: 767px) {
  .history-card .stat-badge {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    margin-left: 0.25rem;
    margin-top: 0.2rem;
    border-radius: 12px;
    display: inline-block;
    vertical-align: middle;
  }
}

/* Tablet stat badge optimizations */
@media (min-width: 768px) and (max-width: 1023px) {
  .history-card .stat-badge {
    font-size: 0.8rem;
    padding: 0.35rem 0.7rem;
    margin-left: 0.4rem;
    border-radius: 14px;
  }
}

/* Desktop stat badge optimizations */
@media (min-width: 1024px) {
  .history-card .stat-badge {
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
    margin-left: 0.5rem;
    border-radius: 16px;
  }
}

/* Progress section specific stat badge styling */
.history-card h4 .stat-badge {
  margin-left: 0.5rem;
  margin-right: 0.25rem;
  vertical-align: middle;
  line-height: 1.2;
}

/* Ensure consistent spacing in progress headers */
.history-card h4 br + small .stat-badge {
  margin-left: 0.25rem;
  margin-right: 0.25rem;
}

/* Fix stat badge alignment in table cells */
.history-card .history-table .stat-badge {
  margin-left: 0.5rem;
  margin-top: 0.1rem;
  vertical-align: baseline;
}

/* Override any conflicting mobile styles for desktop */
@media (min-width: 768px) {
  .history-card .stat-badge {
    /* Ensure clean desktop appearance */
    transform: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  }

  .history-card .stat-badge:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }
}
/* ===== MOBILE SECTION REORDERING ===== */

/* Put user 2 first on mobile */
@media (max-width: 767px) {
  /* Make the row a flex container */
  .row.mt-4 {
    display: flex;
    flex-direction: column;
  }

  /* Put the second column (right person) first on mobile */
  .row.mt-4 .col-md-6:nth-child(2) {
    order: 1;
  }

  .row.mt-4 .col-md-6:nth-child(1) {
    order: 2;
  }

  /* Also apply to nutrition sections */
  .row.mt-3 {
    display: flex;
    flex-direction: column;
  }

  .row.mt-3 .col-md-6:nth-child(2) {
    order: 1;
  }

  .row.mt-3 .col-md-6:nth-child(1) {
    order: 2;
  }
}

/* ===== MOBILE TABLE SCROLL ENHANCEMENTS ===== */

/* Add JavaScript hooks for mobile table scrolling */
@media (max-width: 767px) {
  .stats-table {
    position: relative;
  }

  /* Add touch-friendly scroll indicators */
  .stats-table.has-scroll::after {
    content: "👈 Swipe to see more 👉";
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: #667eea;
    font-weight: 600;
    background: rgba(102, 126, 234, 0.1);
    padding: 0.4rem 0.8rem;
    border-radius: 16px;
    animation: pulseGlow 2s infinite;
    pointer-events: none;
    z-index: 5;
  }

  .stats-table.scrolled::after {
    opacity: 0;
    transition: opacity 0.5s ease;
  }

  @keyframes pulseGlow {
    0%,
    100% {
      opacity: 0.7;
      transform: translateX(-50%) scale(1);
    }
    50% {
      opacity: 1;
      transform: translateX(-50%) scale(1.05);
    }
  }
}
/* ===== VERTICAL-ONLY MOBILE LAYOUT ===== */

/* Transform everything to vertical layout on mobile - NO horizontal scrolling */
@media (max-width: 767px) {
  /* Transform data input table to vertical cards */
  .stats-table table,
  .stats-table thead,
  .stats-table tbody,
  .stats-table th,
  .stats-table td,
  .stats-table tr {
    display: block;
  }

  /* Hide table headers */
  .stats-table thead {
    display: none;
  }

  /* Each table row becomes a vertical card */
  .stats-table tbody tr {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    margin-bottom: 1rem;
    padding: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  /* Each table cell becomes a vertical field */
  .stats-table td {
    border: none;
    padding: 0.75rem 0;
    display: block;
    border-bottom: 1px solid #f1f3f4;
  }

  .stats-table td:last-child {
    border-bottom: none;
    padding-top: 1rem;
  }

  /* Add field labels */
  .stats-table td:nth-child(1)::before {
    content: "👤 Name";
    display: block;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    text-transform: uppercase;
  }

  .stats-table td:nth-child(2)::before {
    content: "⚖️ Weight (lbs)";
    display: block;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    text-transform: uppercase;
  }

  .stats-table td:nth-child(3)::before {
    content: "📊 BMI";
    display: block;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    text-transform: uppercase;
  }

  .stats-table td:nth-child(4)::before {
    content: "🔥 Calories";
    display: block;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    text-transform: uppercase;
  }

  .stats-table td:nth-child(5)::before {
    content: "🏃 Active Minutes";
    display: block;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    text-transform: uppercase;
  }

  /* Style form inputs */
  .stats-table .form-control {
    width: 100%;
    font-size: 16px; /* Prevent iOS zoom */
    padding: 0.75rem;
    border-radius: 8px;
    border: 2px solid #e9ecef;
    background: #f8f9fa;
  }

  .stats-table .form-control:focus {
    border-color: #667eea;
    background: white;
  }

  /* Style save button */
  .stats-table .btn-primary {
    width: 100%;
    padding: 0.75rem;
    font-size: 16px;
    margin-top: 0.5rem;
  }

  /* Transform leaderboard to vertical cards */
  .history-card .table-responsive {
    overflow: visible;
  }

  .history-card .table,
  .history-card .table thead,
  .history-card .table tbody,
  .history-card .table th,
  .history-card .table td,
  .history-card .table tr {
    display: block;
  }

  .history-card .table thead {
    display: none;
  }

  .history-card .table tbody tr {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    margin-bottom: 1rem;
    padding: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .history-card .table td {
    border: none;
    padding: 0.5rem 0;
    display: block;
    text-align: left;
  }

  /* Add labels for leaderboard fields */
  .history-card .table td:nth-child(1)::before {
    content: "🏆 Rank: ";
    font-weight: 600;
  }
  .history-card .table td:nth-child(2)::before {
    content: "👤 Name: ";
    font-weight: 600;
  }
  .history-card .table td:nth-child(3)::before {
    content: "⚖️ Weight Lost: ";
    font-weight: 600;
  }
  .history-card .table td:nth-child(4)::before {
    content: "📊 % Lost: ";
    font-weight: 600;
  }
  .history-card .table td:nth-child(5)::before {
    content: "📈 Progress: ";
    font-weight: 600;
  }
  .history-card .table td:nth-child(6)::before {
    content: "🧮 BMI Change: ";
    font-weight: 600;
  }
  .history-card .table td:nth-child(7)::before {
    content: "📅 Journey: ";
    font-weight: 600;
  }

  /* Basic mobile typography */
  body {
    font-size: 16px;
  }

  .history-card h3,
  .history-card h4 {
    font-size: 1.2rem;
  }

  /* Simple mobile spacing */
  .container {
    padding: 1rem;
    margin: 0.5rem;
  }

  /* Ensure no horizontal overflow anywhere */
  body {
    overflow-x: hidden;
  }

  .container,
  .stats-table,
  .history-card,
  .table-responsive {
    overflow-x: visible;
    max-width: 100%;
  }
}

/* Desktop fixes to ensure no mobile artifacts */
@media (min-width: 768px) {
  .stats-table {
    overflow-x: visible;
  }

  .stats-table table {
    min-width: auto;
    width: 100%;
  }

  .history-card .table-responsive {
    overflow-x: visible;
  }

  .history-card .table {
    min-width: auto;
    width: 100%;
  }
}
/* ===== KILL ALL SWIPE NONSENSE ===== */

/* Remove all swipe indicators and scroll hints */
@media (max-width: 767px) {
  .table-responsive::before,
  .table-responsive::after,
  .history-card .table-responsive::before,
  .history-card .table-responsive::after,
  .stats-table::before,
  .stats-table::after,
  .stats-table.has-scroll::after {
    display: none !important;
    content: none !important;
  }
}

/* Also remove on desktop just in case */
@media (min-width: 768px) {
  .table-responsive::before,
  .table-responsive::after,
  .history-card .table-responsive::before,
  .history-card .table-responsive::after,
  .stats-table::before,
  .stats-table::after {
    display: none !important;
    content: none !important;
  }
}
