/* ============================================
   Analytics Dashboard - Apple Design System
   Extends the main style.css
   ============================================ */

/* ============================================
   CSS Variables for Live Metrics
   ============================================ */

:root {
  --live-metrics-color: #ef4444;
  --live-metrics-rgba: rgba(239, 68, 68, 0.05);
  --live-metrics-border: rgba(239, 68, 68, 0.15);
  --live-metrics-shadow: rgba(239, 68, 68, 0.08);
  --live-metrics-shadow-md: rgba(239, 68, 68, 0.12);
}

/* ============================================
   Range Selector
   ============================================ */

.range-selector {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
  align-items: center;
  flex-wrap: wrap;
}

.range-spacer {
  flex: 1;
}

.range-btn {
  padding: 10px 20px;
  border: 1px solid var(--border-light);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--text-primary);
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.range-btn:hover {
  border-color: var(--border-medium);
  background: var(--bg-tertiary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.range-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.25);
}

.range-btn.active:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px rgba(0, 122, 255, 0.35);
}

/* ============================================
   Analytics Content Container
   ============================================ */

.analytics-content {
  animation: fadeIn var(--transition-slow);
}

/* ============================================
   Metrics Sections
   ============================================ */

.metrics-section {
  margin-bottom: var(--space-2xl);
}

.metrics-section h2.section-title {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: var(--space-sm);
  color: var(--text-primary);
}

.metrics-section .section-subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: var(--space-lg);
  line-height: 1.5;
}

/* ============================================
   Live Metrics Section (Highlighted)
   ============================================ */

.live-metrics-section {
  /* Glassmorphism container */
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  padding: var(--space-xl);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06),
              0 2px 8px rgba(0, 0, 0, 0.04),
              inset 0 1px 0 rgba(255, 255, 255, 0.8);
  position: relative;
}

.live-metrics-section::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-xl);
  padding: 1px;
  background: linear-gradient(135deg,
    rgba(255, 255, 255, 0.8) 0%,
    rgba(255, 255, 255, 0.2) 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.live-metrics-section h2.section-title {
  color: var(--live-metrics-color);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.live-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-lg);
}

.live-metric-card {
  /* Enhanced glassmorphism for live cards */
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.5) !important;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.08),
              0 2px 8px rgba(0, 0, 0, 0.04),
              inset 0 1px 0 rgba(255, 255, 255, 0.9) !important;
  position: relative;
  overflow: visible;
  /* Fixed grid layout for consistency */
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 180px; /* Consistent height for live metrics */
  padding: var(--space-xl);
}

.live-metric-card::before {
  /* Subtle outer glow instead of top bar */
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg,
    rgba(239, 68, 68, 0.15) 0%,
    rgba(251, 146, 60, 0.1) 100%);
  z-index: -1;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.live-metric-card:hover::before {
  opacity: 1;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

.live-metric-card .metric-value {
  color: var(--live-metrics-color);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Live metric card grid structure */
.live-metric-card .metric-label {
  grid-row: 1;
  font-size: 0.9375rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.live-metric-card .metric-value {
  grid-row: 2;
  display: flex;
  align-items: center;
  font-size: 2.5rem;
  font-weight: 700;
  min-height: 60px;
}

.live-metric-card .metric-subtitle {
  grid-row: 3;
  margin-top: auto;
  min-height: 28px;
  display: flex;
  align-items: center;
}

/* ============================================
   Metrics Grids
   ============================================ */

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--space-lg);
  align-items: stretch; /* Equal height cards */
}

.metrics-grid-large {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-lg);
  align-items: stretch; /* Equal height cards */
}

/* ============================================
   Metric Cards
   ============================================ */

.metric-card {
  /* Pure glassmorphism - no accent bars */
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  transition: all var(--transition-base);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04),
              0 1px 4px rgba(0, 0, 0, 0.02),
              inset 0 1px 0 rgba(255, 255, 255, 0.8);
  position: relative;
}

.metric-card::after {
  /* Subtle border gradient - no colored bars */
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  padding: 1px;
  background: linear-gradient(135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.1) 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.metric-card:hover {
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08),
              0 2px 12px rgba(0, 0, 0, 0.04),
              inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.5);
}

.metric-card:hover::after {
  opacity: 1;
}

.metric-card.critical-metric {
  /* Critical cards get enhanced glow, not colored bars */
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 4px 20px rgba(255, 149, 0, 0.08),
              0 2px 8px rgba(0, 0, 0, 0.04),
              inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.metric-card.critical-metric::after {
  background: linear-gradient(135deg,
    rgba(255, 149, 0, 0.2) 0%,
    rgba(255, 149, 0, 0.05) 100%);
}

.metric-card.critical-metric:hover {
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 40px rgba(255, 149, 0, 0.12),
              0 4px 16px rgba(0, 0, 0, 0.06),
              inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

/* ============================================
   Metric Card Content - Fixed Layout Structure
   ============================================ */

.metric-card {
  /* Fixed grid layout for consistency */
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  min-height: 240px; /* Consistent minimum height */
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  grid-row: 1;
}

.metric-label {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.metric-icon {
  font-size: 1.75rem;
  opacity: 0.4;
  transition: all var(--transition-base);
  flex-shrink: 0;
}

.metric-card:hover .metric-icon {
  opacity: 0.7;
  transform: scale(1.1);
}

.metric-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary-color);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  grid-row: 2;
  display: flex;
  align-items: center;
  min-height: 60px; /* Fixed height for value area */
}

.metric-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  grid-row: 3;
  min-height: 24px; /* Reserved space even if empty */
  display: flex;
  align-items: center;
}

.metric-details {
  display: flex;
  gap: var(--space-lg);
  font-size: 0.875rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
  grid-row: 4;
  min-height: 32px; /* Fixed space for details */
  align-items: center;
  padding: var(--space-sm) 0;
}

.metric-details:empty {
  /* Maintain space even when empty */
  min-height: 32px;
}

.metric-details strong {
  color: var(--text-primary);
  font-weight: 600;
}

.metric-target {
  padding-top: var(--space-md);
  border-top: 1px solid var(--separator);
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  grid-row: 5;
  margin-top: auto; /* Push to bottom */
  min-height: 40px; /* Consistent footer height */
}

/* ============================================
   Target Status Indicators
   ============================================ */

.target-indicator {
  font-size: 1.25rem;
  line-height: 1;
}

.target-indicator.status-good {
  color: var(--success-color);
}

.target-indicator.status-warning {
  color: var(--warning-color);
}

.target-indicator.status-critical {
  color: var(--danger-color);
}

/* Status text colors */
.status-normal {
  color: var(--success-color);
}

.status-high {
  color: var(--warning-color);
}

.status-critical {
  color: var(--danger-color);
}

/* ============================================
   Summary Stats Grid
   ============================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-lg);
  align-items: stretch; /* Equal height for all stat cards */
}

/* Add subtle icon/emoji styling for better visual appeal */
.stat-value::first-line {
  line-height: 1.1;
}

.stat-item {
  /* Glassmorphism stat cards */
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04),
              0 1px 4px rgba(0, 0, 0, 0.02),
              inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: all var(--transition-base);
  position: relative;
}

.stat-item::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  padding: 1px;
  background: linear-gradient(135deg,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.1) 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.stat-item:hover {
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08),
              0 2px 12px rgba(0, 0, 0, 0.04),
              inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.5);
}

.stat-item:hover::before {
  opacity: 1;
}

/* Subtle scale animation on value when card is hovered */
.stat-item:hover .stat-value {
  transform: scale(1.05);
  transition: transform var(--transition-base);
}

.stat-value {
  transition: transform var(--transition-base);
}

/* Add subtle pulse animation to numbers on load */
@keyframes statAppear {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.stat-item {
  animation: statAppear 0.6s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

/* Stagger the animation for each stat */
.stat-item:nth-child(1) { animation-delay: 0.1s; }
.stat-item:nth-child(2) { animation-delay: 0.2s; }
.stat-item:nth-child(3) { animation-delay: 0.3s; }
.stat-item:nth-child(4) { animation-delay: 0.4s; }

.stat-item {
  /* Fixed grid structure for consistent layout */
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 120px; /* Consistent height for all stat cards */
  align-content: center;
  gap: var(--space-sm);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  grid-row: 1;
  min-height: 36px; /* Fixed space for label */
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.3;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  grid-row: 2;
  min-height: 50px; /* Fixed space for value */
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  text-align: center;
  word-break: break-word; /* Handle long date ranges */
  hyphens: auto;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
  .range-selector {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-sm);
  }

  .range-spacer {
    display: none;
  }

  .range-btn {
    width: 100%;
  }

  .metrics-grid,
  .metrics-grid-large,
  .live-metrics-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
  }

  .stat-item {
    min-height: 100px; /* Adjusted for mobile */
  }

  .stat-label {
    font-size: 0.75rem;
    min-height: 32px;
  }

  .stat-value {
    font-size: 1.5rem;
    min-height: 40px;
  }

  .metric-value {
    font-size: 2rem;
  }

  .metric-card {
    padding: var(--space-lg);
    min-height: 220px; /* Adjusted for mobile */
  }

  .live-metric-card {
    min-height: 160px; /* Adjusted for mobile */
  }

  .live-metrics-section {
    padding: var(--space-lg);
  }

  .metrics-section h2.section-title {
    font-size: 1.375rem;
  }

  .metrics-section .section-subtitle {
    font-size: 0.875rem;
  }
}

/* iPad and Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  .metrics-grid-large,
  .live-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Large Desktop */
@media (min-width: 1440px) {
  .metrics-grid-large {
    grid-template-columns: repeat(3, 1fr);
  }

  .live-metrics-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ============================================
   Analytics Footer
   ============================================ */

.analytics-footer {
  margin-top: var(--space-2xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--separator);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  color: var(--text-tertiary);
  flex-wrap: wrap;
  gap: var(--space-md);
}

/* ============================================
   Cache Status Badge
   ============================================ */

#cacheStatus {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  font-style: italic;
}

/* ============================================
   Print Styles
   ============================================ */

/* ============================================
   Button Styles - Danger Button
   ============================================ */

.btn-danger {
  background: var(--danger-color);
  color: white;
  box-shadow: 0 2px 8px rgba(255, 59, 48, 0.25);
}

.btn-danger:hover {
  background: #E8342A;
  box-shadow: 0 4px 16px rgba(255, 59, 48, 0.35);
  transform: translateY(-1px);
}

.btn-danger:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(255, 59, 48, 0.2);
}

/* ============================================
   Accessibility - Reduced Motion Support
   ============================================ */

@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;
  }

  .live-metric-card::before {
    animation: none;
  }

  .spinner {
    animation: none;
    border-top-color: var(--primary-color);
  }

  .stat-item {
    animation: none;
  }

  .stat-item:hover .stat-value {
    transform: none;
  }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  .header,
  .footer,
  .range-selector {
    display: none;
  }

  .metric-card,
  .stat-item {
    break-inside: avoid;
  }

  .live-metrics-section {
    border: 2px solid var(--live-metrics-color);
    background: none;
  }
}

/* Risk Tier Breakdown Styles - Apple Glassmorphism */
.metric-breakdown {
  display: flex;
  flex-direction: row;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: nowrap;
  font-size: 0.9em;
}

.risk-tier {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 12px;

  /* Glassmorphism base */
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);

  /* Refined border with gradient */
  border: 1px solid rgba(255, 255, 255, 0.18);

  /* Soft depth shadow */
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.08),
    0 1px 2px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);

  /* Smooth transitions */
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Prevent text selection on interaction */
  user-select: none;
  -webkit-user-select: none;
}

.risk-tier:hover {
  transform: translateY(-2px) scale(1.02);
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.12),
    0 4px 8px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.risk-tier:active {
  transform: translateY(0) scale(0.98);
  transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
}

.risk-tier strong {
  font-size: 1.15em;
  font-weight: 600;
  min-width: 24px;
  text-align: center;
  letter-spacing: -0.01em;
  color: rgba(0, 0, 0, 0.9);
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.3);
}

.risk-icon {
  font-size: 1.3em;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.risk-tier:hover .risk-icon {
  transform: scale(1.1);
}

.risk-label {
  font-size: 0.82em;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.75);
}

/* Risk tier accent glows with refined colors */
.risk-critical {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.12), rgba(220, 38, 38, 0.08));
}

.risk-critical:hover {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.18), rgba(220, 38, 38, 0.12));
  box-shadow:
    0 8px 24px rgba(239, 68, 68, 0.15),
    0 4px 8px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    0 0 20px rgba(239, 68, 68, 0.2);
}

.risk-warning {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(234, 179, 8, 0.08));
}

.risk-warning:hover {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.18), rgba(234, 179, 8, 0.12));
  box-shadow:
    0 8px 24px rgba(245, 158, 11, 0.15),
    0 4px 8px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    0 0 20px rgba(245, 158, 11, 0.2);
}

.risk-safe {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(5, 150, 105, 0.08));
}

.risk-safe:hover {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.18), rgba(5, 150, 105, 0.12));
  box-shadow:
    0 8px 24px rgba(16, 185, 129, 0.15),
    0 4px 8px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    0 0 20px rgba(16, 185, 129, 0.2);
}

/* Mobile responsiveness - maintain glassmorphism */
@media (max-width: 768px) {
  .metric-breakdown {
    flex-direction: column;
    gap: 8px;
  }

  .risk-tier {
    justify-content: space-between;
    width: 100%;
  }

  .risk-tier:hover {
    transform: scale(1.01);
  }
}

/* ============================================
   KPI Tooltip Component - Apple Design System
   v2.5.2: Enhanced KPI Explanations
   ============================================ */

.metric-label-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.kpi-info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 122, 255, 0.1);
  color: var(--primary-color);
  font-size: 11px;
  cursor: help;
  transition: all var(--transition-base);
  position: relative;
  flex-shrink: 0;
  margin-bottom: 3px;
}

.kpi-info-icon:hover {
  background: rgba(0, 122, 255, 0.2);
  transform: scale(1.1);
  z-index: 10;
}

.kpi-tooltip {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15),
              0 4px 12px rgba(0, 0, 0, 0.08);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  z-index: 1000;
  pointer-events: none;
  text-align: left;
}

.kpi-info-icon:hover .kpi-tooltip {
  opacity: 1;
  visibility: visible;
}

.kpi-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: rgba(255, 255, 255, 0.95);
}

/* Tooltip opens downward — for cards near the top of the page */
.kpi-tooltip.tooltip-down {
  bottom: auto;
  top: calc(100% + 12px);
}

.kpi-tooltip.tooltip-down::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: rgba(255, 255, 255, 0.95);
}

.kpi-tooltip-section {
  margin-bottom: 12px;
}

.kpi-tooltip-section:last-child {
  margin-bottom: 0;
}

.kpi-tooltip-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.kpi-tooltip-content {
  font-size: 0.8125rem;
  color: var(--text-primary);
  line-height: 1.5;
  font-weight: 400;
}

.kpi-tooltip-formula {
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  background: rgba(0, 0, 0, 0.04);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: block;
}

.kpi-tooltip-benchmarks {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.kpi-benchmark {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 600;
  white-space: nowrap;
}

.kpi-benchmark.good {
  background: rgba(52, 199, 89, 0.12);
  color: var(--success-color);
}

.kpi-benchmark.warning {
  background: rgba(255, 149, 0, 0.12);
  color: var(--warning-color);
}

.kpi-benchmark.critical {
  background: rgba(255, 59, 48, 0.12);
  color: var(--danger-color);
}

/* Mobile responsive tooltips */
@media (max-width: 768px) {
  .kpi-tooltip {
    width: 260px;
    left: 0;
    transform: translateX(-20px);
    padding: 12px;
  }

  .kpi-tooltip::after {
    left: 30px;
    transform: none;
  }

  .kpi-info-icon {
    width: 16px;
    height: 16px;
    font-size: 10px;
  }
}

/* ============================================
   Time Range Selector - Enhanced UI
   v2.5.3: GA4-style Comparison Dropdown
   ============================================ */

.range-buttons {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

/* Compare Selector - GA4-style Dropdown */
.compare-selector {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.compare-selector label {
  font-weight: 500;
  white-space: nowrap;
}

.compare-dropdown {
  padding: 8px 32px 8px 14px;
  border: 1px solid var(--border-light);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 180px;
}

.compare-dropdown:hover {
  border-color: var(--border-medium);
  background-color: var(--bg-tertiary);
  box-shadow: var(--shadow-md);
}

.compare-dropdown:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

/* Active state when comparison is selected */
.compare-dropdown.active {
  background-color: rgba(0, 122, 255, 0.08);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.compare-dropdown option {
  padding: 8px 12px;
  background: white;
  color: var(--text-primary);
}

/* Today (Live) indicator pulse */
.range-btn[data-range="today"].active::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--danger-color);
  border-radius: 50%;
  margin-right: 6px;
  animation: livePulse 2s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.9); }
}

/* ============================================
   Comparison Badges - Percentage Change
   v2.5.2: Show +12% / -5% indicators
   ============================================ */

.metric-change {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 8px;
  white-space: nowrap;
}

.metric-change.positive {
  background: rgba(52, 199, 89, 0.12);
  color: var(--success-color);
}

.metric-change.negative {
  background: rgba(255, 59, 48, 0.12);
  color: var(--danger-color);
}

.metric-change.neutral {
  background: rgba(142, 142, 147, 0.12);
  color: var(--text-secondary);
}

/* For metrics where lower is better (e.g., late delivery rate, delays) */
.metric-change.positive.inverted {
  background: rgba(255, 59, 48, 0.12);
  color: var(--danger-color);
}

.metric-change.negative.inverted {
  background: rgba(52, 199, 89, 0.12);
  color: var(--success-color);
}

/* Feature #16: Simplified good/bad comparison badges */
.metric-change.good {
  background: rgba(52, 199, 89, 0.12);
  color: var(--success-color, #34c759);
}

.metric-change.bad {
  background: rgba(255, 59, 48, 0.12);
  color: var(--danger-color, #ff3b30);
}

/* Comparison period indicator */
.comparison-period {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.comparison-period::before {
  content: '↔';
  font-style: normal;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .range-selector {
    flex-direction: column;
    gap: var(--space-md);
  }

  .range-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }

  .compare-selector {
    width: 100%;
    flex-direction: column;
    gap: var(--space-xs);
    align-items: stretch;
  }

  .compare-dropdown {
    width: 100%;
    min-width: unset;
  }

  .metric-change {
    margin-left: 0;
    margin-top: 4px;
  }
}

/* ============================================
   Queue Pipeline (Feature #8)
   ============================================ */

.queue-pipeline {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--card-bg, #fff);
  border-radius: 10px;
  border: 1px solid var(--border-color, #e5e7eb);
}

.pipeline-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #6b7280);
  margin: 0 0 0.5rem 0;
}

.pipeline-stages {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.pipeline-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary, #f3f4f6);
  border-radius: 8px;
  min-width: 70px;
  flex: 1;
}

.stage-count {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
}

.stage-label {
  font-size: 0.65rem;
  color: var(--text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 2px;
}

.stage-delivered {
  background: var(--accent-green-bg, #dcfce7);
}

.stage-delivered .stage-count {
  color: var(--accent-green, #16a34a);
}

.pipeline-arrow {
  color: var(--text-muted, #9ca3af);
  font-size: 1rem;
  flex-shrink: 0;
}

.pressure-high .stage-count {
  color: var(--warning-color, #f59e0b);
}

.pressure-critical .stage-count {
  color: var(--danger-color, #ef4444);
}

/* ============================================
   Staffing Card (Phase 3 — Shyfter)
   ============================================ */

.staffing-card {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--card-bg, #fff);
  border-radius: 10px;
  border: 1px solid var(--border-color, #e5e7eb);
}

.staffing-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #6b7280);
  margin: 0 0 0.5rem 0;
}

.staffing-summary {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.staffing-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary, #f3f4f6);
  border-radius: 8px;
  min-width: 65px;
  flex: 1;
}

.staffing-stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
}

.staffing-stat-label {
  font-size: 0.65rem;
  color: var(--text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 2px;
}

/* Adherence coloring */
.adherence-good { color: var(--accent-green, #16a34a); }
.adherence-warning { color: var(--warning-color, #f59e0b); }
.adherence-critical { color: var(--danger-color, #ef4444); }

/* Role badges */
.staffing-roles {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.role-badge {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--bg-secondary, #f3f4f6);
  color: var(--text-secondary, #6b7280);
}

.role-driver { background: #ede9fe; color: #7c3aed; }
.role-kitchen { background: #fef3c7; color: #d97706; }
.role-manager { background: #fce7f3; color: #db2777; }
.role-allRound { background: #dbeafe; color: #2563eb; }
.role-customerService { background: #d1fae5; color: #059669; }

/* Ending soon */
.staffing-ending-soon {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--warning-color, #f59e0b);
}

.ending-soon-label {
  font-weight: 600;
}

.ending-soon-item {
  display: inline;
}

/* Source indicator */
.staffing-source {
  margin-top: 0.375rem;
  font-size: 0.6rem;
  color: var(--text-muted, #9ca3af);
  text-align: right;
}

/* ============================================
   Orders Per Hour Chart (Feature #5)
   ============================================ */

.chart-section {
  margin-top: 1.5rem;
}

.chart-container {
  background: var(--card-bg, #fff);
  border-radius: 12px;
  padding: 1rem;
  height: 280px;
  border: 1px solid var(--border-color, #e5e7eb);
}

/* ============================================
   Wait Time Breakdown Bar (Feature #7)
   ============================================ */

/* Override grid layout for breakdown card — no metric-value or metric-target rows needed */
.metric-card[data-metric="waitTimeBreakdown"] {
  grid-template-rows: auto auto auto;
  min-height: unset;
}
.metric-card[data-metric="waitTimeBreakdown"] .breakdown-bar {
  grid-row: 2;
}
.metric-card[data-metric="waitTimeBreakdown"] .metric-details {
  grid-row: 3;
  min-height: unset;
  padding-bottom: var(--space-sm);
}

.breakdown-bar {
  display: flex;
  height: 48px;
  border-radius: 6px;
  overflow: hidden;
  margin: var(--space-sm) 0;
}

.breakdown-segment {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  min-width: 60px;
  overflow: hidden;
  transition: width 0.3s ease;
}

.breakdown-pre-pickup {
  background: var(--accent-blue, #3b82f6);
  color: #fff;
}

.breakdown-driving {
  background: var(--accent-green, #22c55e);
  color: #fff;
}

.breakdown-label {
  font-size: 0.65rem;
  opacity: 0.9;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.breakdown-value {
  font-size: 0.8rem;
  font-weight: 600;
}

/* ── Expected Wait — utilization states ───────────────────────────── */
.metric-value.dimmed {
  opacity: 0.45;
}

.metric-value.wait-overloaded {
  color: #dc2626;  /* red-600 */
  font-size: 1.1rem;
  font-weight: 700;
}
