/* ============================================================
   Dashboard Styles
   Dark theme, responsive grid, KPI cards, chart wrappers
   ============================================================ */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #1e2130;
  --bg-card-hover: #252839;
  --border-color: #2a2d3e;
  --text-primary: #e4e6f0;
  --text-secondary: #8b8fa3;
  --text-muted: #5c6078;
  --accent-blue: #4f8ff7;
  --accent-green: #34d399;
  --accent-red: #f87171;
  --accent-yellow: #fbbf24;
  --accent-purple: #a78bfa;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---- Layout ---- */

.dashboard-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.dashboard-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.dashboard-header .subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ---- KPI Cards ---- */

.kpi-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-container.hidden {
  display: none;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

.kpi-card:hover {
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-md);
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.kpi-trend {
  font-size: 0.8rem;
  font-weight: 600;
}

.kpi-trend.trend-up {
  color: var(--accent-green);
}

.kpi-trend.trend-down {
  color: var(--accent-red);
}

.kpi-sparkline {
  width: 100%;
  height: 40px;
  margin-top: 8px;
}

/* ---- Chart Grid ---- */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.chart-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  overflow: hidden;
  transition: box-shadow var(--transition-fast);
}

.chart-wrapper:hover {
  box-shadow: var(--shadow-md);
}

.chart-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.chart-canvas {
  width: 100%;
  height: 350px;
}

/* Full-width chart variant */
.chart-wrapper.full-width {
  grid-column: span 2;
}

.chart-wrapper.full-width .chart-canvas {
  height: 450px;
}

/* Tall chart variant */
.chart-wrapper.tall .chart-canvas {
  height: 500px;
}

/* ---- Gallery Grid ---- */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.gallery-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  overflow: hidden;
}

.gallery-item .gallery-chart {
  width: 100%;
  height: 400px;
}

.gallery-item.large {
  grid-column: span 2;
}

.gallery-item.large .gallery-chart {
  height: 500px;
}

.gallery-item .gallery-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---- Loading Overlay ---- */

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 1000;
  transition: opacity var(--transition-normal);
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  margin-top: 16px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ---- Error Overlay ---- */

.error-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.error-message {
  font-size: 0.9rem;
  color: var(--text-secondary);
  max-width: 400px;
  text-align: center;
}

.error-retry {
  margin-top: 16px;
  padding: 8px 20px;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: opacity var(--transition-fast);
}

.error-retry:hover {
  opacity: 0.85;
}

/* ---- Navigation (hub page) ---- */

.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 32px;
}

.nav-card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-decoration: none;
  color: inherit;
  transition: background var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}

.nav-card:hover {
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.nav-card h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.nav-card p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.nav-card .nav-icon {
  font-size: 1.5rem;
  margin-bottom: 12px;
}

/* ---- Back Link ---- */

.back-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
}

.back-link:hover {
  color: var(--text-primary);
}

/* ---- Section Heading ---- */

.section-heading {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

.section-heading + .gallery-grid {
  margin-bottom: 32px;
}

/* ---- Responsive ---- */

@media (max-width: 1024px) {
  .chart-grid,
  .gallery-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrapper.full-width,
  .gallery-item.large {
    grid-column: span 1;
  }
}

@media (max-width: 640px) {
  .dashboard-container {
    padding: 12px 16px;
  }

  .kpi-container {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-canvas {
    height: 280px;
  }

  .dashboard-header h1 {
    font-size: 1.2rem;
  }
}

@media (max-width: 400px) {
  .kpi-container {
    grid-template-columns: 1fr;
  }
}
