/* ===== CSS VARIABLES & THEMES ===== */
:root {
  /* Default Theme (Forest) */
  --primary-color: #2f3e46;
  --secondary-color: #52796f;
  --accent-color: #84a98c;
  --light-color: #cad2c5;
  --background-color: #f8f9fa;
  --surface-color: #ffffff;
  --text-primary: #2f3e46;
  --text-secondary: #6c757d;
  --text-light: #f8f9fa;
  --border-color: #e9ecef;
  --success-color: #28a745;
  --warning-color: #ffc107;
  --danger-color: #dc3545;
  --info-color: #17a2b8;
  --shadow: 0 5px 20px rgba(0,0,0,0.08);
  --sidebar-gradient: linear-gradient(180deg, #2f3e46 0%, #1e2a32 100%);
  --header-gradient: linear-gradient(135deg, #2f3e46 0%, #52796f 100%);
}

[data-theme="ocean"] {
  --primary-color: #1a535c;
  --secondary-color: #4ecdc4;
  --accent-color: #6fffe9;
  --light-color: #f7fff7;
  --background-color: #f0f7ff;
  --surface-color: #ffffff;
  --text-primary: #1a535c;
  --text-secondary: #457b9d;
  --text-light: #f7fff7;
  --border-color: #d8e2e8;
  --success-color: #2a9d8f;
  --warning-color: #e9c46a;
  --danger-color: #e76f51;
  --info-color: #4a90e2;
  --shadow: 0 5px 20px rgba(26, 83, 92, 0.1);
  --sidebar-gradient: linear-gradient(180deg, #1a535c 0%, #0d2b30 100%);
  --header-gradient: linear-gradient(135deg, #1a535c 0%, #4ecdc4 100%);
}

[data-theme="sunset"] {
  --primary-color: #6d213c;
  --secondary-color: #e56b6f;
  --accent-color: #eaac8b;
  --light-color: #ffd6d6;
  --background-color: #fff5f5;
  --surface-color: #ffffff;
  --text-primary: #6d213c;
  --text-secondary: #b5838d;
  --text-light: #ffd6d6;
  --border-color: #f8d7da;
  --success-color: #38b000;
  --warning-color: #ff9e00;
  --danger-color: #d00000;
  --info-color: #4361ee;
  --shadow: 0 5px 20px rgba(109, 33, 60, 0.1);
  --sidebar-gradient: linear-gradient(180deg, #6d213c 0%, #451527 100%);
  --header-gradient: linear-gradient(135deg, #6d213c 0%, #e56b6f 100%);
}

[data-theme="midnight"] {
  --primary-color: #0d1b2a;
  --secondary-color: #1b263b;
  --accent-color: #415a77;
  --light-color: #e0e1dd;
  --background-color: #0a0f1a;
  --surface-color: #1b263b;
  --text-primary: #e0e1dd;
  --text-secondary: #a0a4b8;
  --text-light: #e0e1dd;
  --border-color: #2d3748;
  --success-color: #4ade80;
  --warning-color: #fbbf24;
  --danger-color: #ef4444;
  --info-color: #60a5fa;
  --shadow: 0 5px 20px rgba(0,0,0,0.3);
  --sidebar-gradient: linear-gradient(180deg, #0d1b2a 0%, #050a12 100%);
  --header-gradient: linear-gradient(135deg, #0d1b2a 0%, #1b263b 100%);
}

/* ===== BASE STYLES ===== */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden; /* Prevent body scrolling */
  transition: background-color 0.3s ease, color 0.3s ease;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--background-color);
  color: var(--text-primary);
  line-height: 1.6;
}

/* ===== FULL SCREEN LAYOUT ===== */
.full-screen-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

/* Sidebar - Fixed Height */
#sidebar {
  width: 280px;
  background: var(--sidebar-gradient);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  padding: 0;
  box-shadow: 3px 0 15px rgba(0,0,0,0.1);
  z-index: 1000;
  overflow-y: auto; /* Sidebar scrolls independently */
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 25px 20px;
  background: rgba(0,0,0,0.2);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.sidebar-header h2 {
  margin: 0;
  font-weight: 700;
  font-size: 1.4rem;
  text-align: center;
  color: var(--text-light);
}

#sidebar ul {
  list-style: none;
  flex-grow: 1;
  padding: 20px 0;
  margin: 0;
  overflow-y: auto;
}

#sidebar ul li {
  margin: 5px 15px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

#sidebar ul li a {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.3s ease;
  font-size: 0.95rem;
}

#sidebar ul li i {
  margin-right: 12px;
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
}

#sidebar ul li.active,
#sidebar ul li:hover {
  background: rgba(255,255,255,0.1);
}

#sidebar ul li.active a,
#sidebar ul li:hover a {
  color: var(--text-light);
  transform: translateX(5px);
}

/* Theme Controls */
.theme-controls {
  padding: 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.theme-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.theme-option {
  padding: 8px 12px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  color: var(--text-light);
  cursor: pointer;
  text-align: center;
  font-size: 0.8rem;
  transition: all 0.3s ease;
}

.theme-option.active {
  border-color: var(--accent-color);
  background: rgba(255,255,255,0.2);
}

.theme-option:hover {
  background: rgba(255,255,255,0.15);
}

/* Main Content - This is the single scrollable area */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: transparent;
  transition: all 0.3s ease;
}

/* This container should scroll everything */
.main-content {
  flex: 1;
  overflow-y: auto; /* This enables the single scroll for entire page */
  display: flex;
  flex-direction: column;
}

/* Make all sections flow naturally without fixed heights */
.dashboard-header,
.filter-section,
.dashboard-summary,
.ai-explanation,
.table-section {
  flex-shrink: 0; /* Prevent these from shrinking */
}

/* Charts container should grow and scroll if needed, but we want single page scroll */
.charts-container {
  flex: 1;
  min-height: 0; /* Important for flex child to respect overflow */
  padding: 0 40px 40px;
  display: flex;
  flex-direction: column;
  gap: 25px;
}

/* Individual chart sections */
.chart-section {
  display: flex;
  flex-direction: column;
  min-height: 400px; /* Minimum height for charts */
}

.chart-container {
  background: var(--surface-color);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 400px;
  transition: all 0.3s ease;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
  flex-shrink: 0;
}

.chart-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.chart-switcher {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chart-switcher button {
  padding: 6px 12px;
  font-size: 0.8rem;
  background: var(--background-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.chart-switcher button.active {
  background: var(--secondary-color);
  color: var(--text-light);
  border-color: var(--secondary-color);
}

.chart-canvas-container {
  flex: 1;
  position: relative;
  min-height: 300px;
}

/* Remove any max-height restrictions that might be causing issues */
.dashboard-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  padding: 25px 40px;
  background: transparent;
}

.summary-card {
  background: var(--surface-color);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
  position: relative;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.summary-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--secondary-color), var(--accent-color));
}

.summary-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.summary-card h3 {
  margin-bottom: 12px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-card .value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 8px 0;
  line-height: 1.2;
}

.summary-card .subtext {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.4;
}

.ai-insight {
  position: absolute;
  top: 12px;
  left: 12px;
  color: var(--accent-color);
  font-size: 0.9rem;
  cursor: pointer;
  transition: color 0.3s ease;
}

.ai-insight:hover {
  color: var(--secondary-color);
}

.progress-container {
  margin: 12px 0 8px;
  background: var(--border-color);
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
  position: relative;
}

.progress-bar {
  height: 100%;
  border-radius: 10px;
  transition: width 0.8s ease;
  position: relative;
  background: linear-gradient(90deg, var(--secondary-color), var(--accent-color));
}

.progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(255,255,255,0.3) 50%, 
    transparent 100%);
  animation: shimmer 2s infinite;
}

.progress-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.progress-percentage {
  font-weight: 600;
  color: var(--text-primary);
}

.stacked-progress {
  display: flex;
  height: 20px;
  border-radius: 10px;
  overflow: hidden;
  margin: 10px 0;
  background: var(--border-color);
}

.stacked-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: white;
  font-weight: bold;
  transition: width 0.8s ease;
}

.rate-visualization {
  height: 20px;
  background: #f8f9fa;
  border-radius: 10px;
  margin: 10px 0;
  position: relative;
  border: 1px solid var(--border-color);
}

.rate-bar {
  height: 100%;
  border-radius: 10px;
  transition: width 0.8s ease;
  position: relative;
}

.rate-label {
  position: absolute;
  right: -35px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  font-weight: bold;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.ai-explanation {
  margin: 15px 40px;
  padding: 15px 20px;
  background: linear-gradient(135deg, var(--background-color) 0%, rgba(255,255,255,0.1) 100%);
  border-left: 4px solid var(--secondary-color);
  border-radius: 8px;
  font-size: 0.9rem;
  display: none;
}

.ai-explanation.show {
  display: block;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Table Section */
.table-section {
  padding: 0 40px 25px;
}

.table-container {
  background: var(--surface-color);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  background: var(--surface-color);
  color: var(--text-primary);
  border-color: var(--border-color);
  margin-bottom: 0;
}

.table-dark {
  background: var(--primary-color);
}

/* Responsive design */
@media (max-width: 1200px) {
  .dashboard-summary {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    padding: 20px 30px;
  }
  
  .charts-container,
  .table-section {
    padding-left: 30px;
    padding-right: 30px;
  }
}

@media (max-width: 992px) {
  #sidebar {
    width: 250px;
  }
  
  .dashboard-header,
  .filter-section {
    padding: 20px 30px;
  }
  
  .dashboard-summary {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}

@media (max-width: 768px) {
  .full-screen-container {
    flex-direction: column;
    height: 100vh;
  }
  
  #sidebar {
    width: 100%;
    height: auto;
    max-height: 50vh;
    order: 2;
  }
  
  main {
    order: 1;
    flex: 1;
    min-height: 50vh;
  }
  
  .dashboard-header,
  .filter-section {
    padding: 15px 20px;
  }
  
  .dashboard-summary {
    padding: 15px 20px;
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .charts-container,
  .table-section {
    padding: 0 20px 20px;
  }
  
  .chart-container {
    padding: 15px;
    min-height: 350px;
  }
  
  .chart-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .chart-switcher {
    width: 100%;
    justify-content: flex-start;
  }

  .theme-options {
    grid-template-columns: 1fr;
  }
  
  .ai-explanation {
    margin: 10px 20px;
    padding: 12px 15px;
  }
}

@media (max-width: 480px) {
  .dashboard-header h1 {
    font-size: 1.6rem;
  }
  
  .summary-card .value {
    font-size: 1.8rem;
  }
  
  .summary-card {
    padding: 15px;
  }
  
  .chart-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .chart-switcher {
    width: 100%;
    margin-top: 8px;
  }
  
  .charts-container {
    gap: 15px;
  }
}

/* Utility classes */
.data-source-badge {
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 600;
}

.source-surveillance {
  background: rgba(33, 150, 243, 0.1);
  color: #2196f3;
}

.source-nutrition {
  background: rgba(255, 152, 0, 0.1);
  color: #ff9800;
}

.loading-spinner {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 20px 30px;
  border-radius: 10px;
  z-index: 9999;
  font-weight: 600;
}

.loading-spinner.show {
  display: block;
}

.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;
}

button:focus,
select:focus,
a:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--background-color);
}

::-webkit-scrollbar-thumb {
  background: var(--secondary-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-color);
}