/* CaloriesSnap - Ultimate Polish v2.17 */
/* Fixes: FAB positioning, smaller nav icons, enhanced stats functionality */

@media (max-width: 768px) {
  
  /* ===== FIX 1: FAB BUTTON - EXACTLY BETWEEN NAV ICONS ===== */
  
  /* Bottom nav with proper spacing */
  .bottom-nav {
    display: flex !important;
    align-items: center !important;
    justify-content: space-around !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 65px !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
    background: white !important;
    border-top: 1px solid #e5e7eb !important;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08) !important;
    z-index: 98 !important;
  }
  
  /* ===== FIX 2: SMALLER NAVIGATION ICONS ===== */
  
  .nav-item {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 6px 4px !important;
    font-size: 9px !important; /* Smaller text */
    border: none !important;
    background: transparent !important;
    color: #9ca3af !important;
    transition: all 0.2s ease !important;
    cursor: pointer !important;
    min-height: 50px !important;
  }
  
  .nav-item i {
    font-size: 18px !important; /* Was 22px - now smaller */
    margin-bottom: 2px !important;
  }
  
  .nav-item span {
    font-size: 9px !important; /* Smaller label */
    font-weight: 500 !important;
  }
  
  .nav-item.active {
    color: #667eea !important;
  }
  
  .nav-item:active {
    transform: scale(0.95) !important;
  }
  
  /* Center placeholder for FAB */
  .nav-item.nav-center {
    flex: 1 !important;
    pointer-events: none !important;
  }
  
  .nav-center-placeholder {
    width: 56px !important;
    height: 56px !important;
  }
  
  /* ===== FAB BUTTON - PUSHED DOWN TO INTERSECT NAV ===== */
  
  .floating-add-btn {
    /* Position - Pushed down to intersect with nav */
    position: fixed !important;
    bottom: 32px !important; /* Was 45px - now lower to intersect nav icons */
    left: 50% !important;
    transform: translateX(-50%) !important;
    
    /* Size - Slightly smaller */
    width: 56px !important; /* Was 60px */
    height: 56px !important;
    
    /* Shape - Perfect circle */
    border-radius: 50% !important;
    
    /* Background - White gradient */
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%) !important;
    
    /* Border - Purple with slight shadow inside */
    border: 2px solid #667eea !important;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1) inset !important;
    
    /* Icon - Purple */
    color: #667eea !important;
    font-size: 26px !important; /* Slightly smaller */
    
    /* Outer shadow - More prominent */
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.35), 
                0 4px 12px rgba(0, 0, 0, 0.2),
                0 0 0 4px rgba(255, 255, 255, 0.9) !important;
    
    /* Layout */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    
    /* Z-index - Above nav */
    z-index: 999 !important;
    
    /* Transitions */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    
    /* Remove animations */
    animation: none !important;
    
    /* Ensure clickable */
    pointer-events: auto !important;
    cursor: pointer !important;
  }
  
  /* FAB active state */
  .floating-add-btn:active {
    transform: translateX(-50%) scale(0.9) !important;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3), 
                0 2px 6px rgba(0, 0, 0, 0.15),
                0 0 0 4px rgba(255, 255, 255, 0.9) !important;
  }
  
  /* FAB hover */
  .floating-add-btn:hover {
    transform: translateX(-50%) scale(1.05) !important;
  }
  
  /* ===== FIX 3: ENHANCED STATISTICS PAGE ===== */
  
  /* Stats tab container - smooth scrolling */
  #stats-tab {
    padding: 12px !important;
    padding-bottom: 90px !important; /* Space for nav + FAB */
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important; /* Smooth iOS scrolling */
    scroll-behavior: smooth !important;
  }
  
  /* Stats header - compact and clear */
  .stats-header {
    text-align: center !important;
    margin-bottom: 16px !important;
    padding: 12px !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    border-radius: 12px !important;
    color: white !important;
  }
  
  .stats-header h2 {
    font-size: 22px !important;
    font-weight: 700 !important;
    margin-bottom: 8px !important;
    color: white !important;
  }
  
  /* Time range selector - improved UX */
  .stats-time-range {
    display: flex !important;
    gap: 6px !important;
    justify-content: center !important;
    margin-top: 8px !important;
  }
  
  .time-range-btn {
    padding: 6px 12px !important;
    border-radius: 20px !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    background: rgba(255, 255, 255, 0.15) !important;
    color: white !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    backdrop-filter: blur(10px) !important;
  }
  
  .time-range-btn.active {
    background: white !important;
    color: #667eea !important;
    border-color: white !important;
    transform: scale(1.05) !important;
  }
  
  .time-range-btn:active {
    transform: scale(0.95) !important;
  }
  
  /* Chart containers - better spacing and loading */
  .chart-container {
    background: white !important;
    border-radius: 12px !important;
    padding: 14px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
    position: relative !important;
    min-height: 280px !important; /* Prevent jumping */
  }
  
  .chart-container h3 {
    font-size: 16px !important;
    font-weight: 600 !important;
    color: #333 !important;
    margin-bottom: 12px !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
  }
  
  .chart-container canvas {
    max-height: 240px !important;
    width: 100% !important;
    display: block !important;
  }
  
  /* Loading state for charts */
  .chart-container.loading::after {
    content: "Loading..." !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    color: #9ca3af !important;
    font-size: 14px !important;
  }
  
  /* Stats sections - improved spacing */
  .stats-section {
    background: white !important;
    border-radius: 12px !important;
    padding: 14px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
  }
  
  .stats-section h3 {
    font-size: 16px !important;
    font-weight: 600 !important;
    color: #333 !important;
    margin-bottom: 12px !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
  }
  
  /* Activity Calendar - Enhanced */
  .streak-calendar {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 4px !important;
    padding: 8px !important;
    background: #f9fafb !important;
    border-radius: 8px !important;
    min-height: 180px !important;
  }
  
  .calendar-day {
    aspect-ratio: 1 !important;
    min-height: 28px !important;
    min-width: 28px !important;
    background: #e5e7eb !important;
    border-radius: 4px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
    transition: all 0.2s ease !important;
    cursor: pointer !important;
  }
  
  .calendar-day:active {
    transform: scale(0.9) !important;
  }
  
  .calendar-day.logged {
    background: #10b981 !important;
    animation: popIn 0.3s ease !important;
  }
  
  @keyframes popIn {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
  }
  
  .calendar-day.today {
    border: 2px solid #667eea !important;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2) !important;
  }
  
  .day-dot {
    width: 6px !important;
    height: 6px !important;
    border-radius: 50% !important;
    background: white !important;
    opacity: 0 !important;
    transition: opacity 0.2s ease !important;
  }
  
  .calendar-day.logged .day-dot {
    opacity: 1 !important;
  }
  
  /* Calendar legend - improved */
  .calendar-legend {
    display: flex !important;
    gap: 12px !important;
    margin-top: 10px !important;
    padding: 8px !important;
    font-size: 11px !important;
    color: #6b7280 !important;
    justify-content: center !important;
  }
  
  .legend-item {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
  }
  
  .legend-box {
    width: 12px !important;
    height: 12px !important;
    border-radius: 3px !important;
  }
  
  .legend-box.empty {
    background: #e5e7eb !important;
  }
  
  .legend-box.logged {
    background: #10b981 !important;
  }
  
  /* Summary grid - improved layout */
  .stats-summary-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  
  .summary-stat {
    background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%) !important;
    padding: 12px !important;
    border-radius: 10px !important;
    text-align: center !important;
    border: 1px solid #e5e7eb !important;
    transition: all 0.2s ease !important;
  }
  
  .summary-stat:active {
    transform: scale(0.97) !important;
  }
  
  .stat-label {
    font-size: 11px !important;
    color: #6b7280 !important;
    margin-bottom: 4px !important;
    font-weight: 500 !important;
  }
  
  .stat-value {
    font-size: 20px !important;
    font-weight: 700 !important;
    color: #667eea !important;
  }
  
  /* Chart header with action button */
  .chart-header-with-action {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    margin-bottom: 12px !important;
  }
  
  .chart-header-with-action h3 {
    margin-bottom: 0 !important;
  }
  
  .icon-btn {
    width: 32px !important;
    height: 32px !important;
    border-radius: 8px !important;
    border: 1px solid #e5e7eb !important;
    background: white !important;
    color: #667eea !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
  }
  
  .icon-btn:active {
    transform: scale(0.9) !important;
    background: #667eea !important;
    color: white !important;
  }
  
  /* Empty state messages */
  .empty-stats {
    text-align: center !important;
    padding: 40px 20px !important;
    color: #9ca3af !important;
  }
  
  .empty-stats-icon {
    font-size: 48px !important;
    margin-bottom: 12px !important;
    opacity: 0.5 !important;
  }
  
  .empty-stats-text {
    font-size: 14px !important;
    margin-bottom: 8px !important;
  }
  
  .empty-stats-hint {
    font-size: 12px !important;
    color: #d1d5db !important;
  }
  
  /* Smooth transitions for tab switching */
  .tab-content {
    opacity: 0 !important;
    transition: opacity 0.3s ease !important;
    pointer-events: none !important;
  }
  
  .tab-content.active {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  
  /* Page content spacing */
  .page-content {
    padding: 12px !important;
    padding-bottom: 90px !important; /* Space for nav */
  }
  
  /* Ensure smooth scrolling everywhere */
  * {
    scroll-behavior: smooth !important;
  }
  
  /* Touch feedback */
  button, .nav-item, .calendar-day, .summary-stat {
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
  }
}

/* ===== DESKTOP ADJUSTMENTS ===== */
@media (min-width: 769px) {
  
  /* FAB on desktop */
  .floating-add-btn {
    bottom: 40px !important;
  }
  
  /* Stats page wider on desktop */
  #stats-tab {
    max-width: 900px !important;
    margin: 0 auto !important;
  }
  
  /* Summary grid 4 columns on desktop */
  .stats-summary-grid {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

/* ===== DARK THEME SUPPORT ===== */
body.dark-theme .stats-header {
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%) !important;
}

body.dark-theme .chart-container,
body.dark-theme .stats-section {
  background: #1f2937 !important;
  border-color: #374151 !important;
}

body.dark-theme .chart-container h3,
body.dark-theme .stats-section h3 {
  color: white !important;
}

body.dark-theme .streak-calendar {
  background: #111827 !important;
}

body.dark-theme .calendar-day {
  background: #374151 !important;
}

body.dark-theme .calendar-day.logged {
  background: #10b981 !important;
}

body.dark-theme .summary-stat {
  background: #111827 !important;
  border-color: #374151 !important;
}

body.dark-theme .stat-value {
  color: #818cf8 !important;
}

body.dark-theme .bottom-nav {
  background: #1f2937 !important;
  border-top-color: #374151 !important;
}

body.dark-theme .icon-btn {
  background: #374151 !important;
  border-color: #4b5563 !important;
  color: #818cf8 !important;
}

body.dark-theme .time-range-btn {
  border-color: rgba(255, 255, 255, 0.2) !important;
  background: rgba(255, 255, 255, 0.1) !important;
}

body.dark-theme .time-range-btn.active {
  background: rgba(255, 255, 255, 0.9) !important;
  color: #4f46e5 !important;
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* Use GPU acceleration for animations */
.floating-add-btn,
.nav-item,
.calendar-day,
.time-range-btn {
  will-change: transform !important;
  transform: translateZ(0) !important;
  backface-visibility: hidden !important;
}

/* Optimize chart rendering */
canvas {
  image-rendering: -webkit-optimize-contrast !important;
  image-rendering: crisp-edges !important;
}
