/* Design tokens and global font stack for the dashboard. */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #d9deeb;
  --text: #1f2933;
  --muted: #5b6878;
  --accent: #3f6ae0;
  --accent-soft: rgba(63, 106, 224, 0.1);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Ensure consistent box sizing for layout calculations. */
* {
  box-sizing: border-box;
}

/* Base page background with subtle gradients and typography. */
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 20%, rgba(63, 106, 224, 0.18), transparent 55%),
    radial-gradient(circle at 85% 12%, rgba(168, 85, 247, 0.16), transparent 50%),
    radial-gradient(circle at 50% 78%, rgba(46, 184, 138, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Constrain content width and add responsive horizontal padding. */
.layout-shell {
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
  padding-left: clamp(1rem, 4vw, 2rem);
  padding-right: clamp(1rem, 4vw, 2rem);
}

/* Hero header styling with gradient background and layered flare. */
.page-header {
  position: relative;
  padding: 2.5rem 0 1.5rem;
  background: linear-gradient(120deg, #26418f, #3f6ae0);
  color: #fff;
  box-shadow: 0 4px 20px rgba(36, 64, 143, 0.2);
  overflow: hidden;
  isolation: isolate;
}

.page-header::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: clamp(120px, 18vw, 220px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0));
  clip-path: polygon(0% 68%, 12% 74%, 25% 62%, 38% 76%, 52% 60%, 66% 72%, 80% 57%, 92% 70%, 100% 62%, 100% 100%, 0% 100%);
  opacity: 0.6;
  pointer-events: none;
}

.page-header h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
}

.page-header .layout-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.subtitle {
  margin-top: 0.5rem;
  max-width: 52rem;
  color: rgba(255, 255, 255, 0.85);
}

/* Vertical spacing between major dashboard sections. */
.main-content {
  padding: 2rem 0 4rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Keep the data source card full-width while allowing layout tweaks later. */
.data-management {
  display: flex;
}

/* Card shell shared by the data source panel. */
.data-card {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 1rem;
  box-shadow: 0 16px 32px rgba(31, 41, 51, 0.08);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

.data-card h2 {
  margin: 0;
  font-size: 1.15rem;
}

/* Pill-shaped status badge that surfaces dataset feedback. */
.dataset-status {
  --status-color: var(--accent);
  --status-bg: rgba(63, 106, 224, 0.12);
  --status-border: rgba(63, 106, 224, 0.22);
  --status-icon-bg: rgba(255, 255, 255, 0.95);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  background: var(--status-bg);
  color: var(--status-color);
  font-weight: 600;
  border: 1px solid var(--status-border);
  line-height: 1.2;
}

.dataset-status::before {
  content: 'ⓘ';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: var(--status-icon-bg);
  color: var(--status-color);
  font-size: 0.95rem;
  box-shadow: 0 4px 10px rgba(31, 41, 51, 0.12);
}

.dataset-status.success {
  --status-color: #1f6f57;
  --status-bg: rgba(46, 184, 138, 0.16);
  --status-border: rgba(46, 184, 138, 0.32);
}

.dataset-status.success::before {
  content: '✔';
}

.dataset-status.error {
  --status-color: #b63b3b;
  --status-bg: rgba(239, 91, 91, 0.18);
  --status-border: rgba(239, 91, 91, 0.32);
}

.dataset-status.error::before {
  content: '⚠';
}

/* Align upload, reset, and download controls on a flexible row. */
.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

/* Custom styled file input that hides the default browser control. */
.file-upload {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: rgba(63, 106, 224, 0.08);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.file-upload input[type='file'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-upload:focus-within {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Primary button appearance shared by several CTAs. */
.pill-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
}

.pill-button:hover,
.pill-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(63, 106, 224, 0.25);
}

.pill-button:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

.pill-button.secondary {
  background: rgba(63, 106, 224, 0.08);
  color: var(--accent);
  box-shadow: none;
  border: 1px solid rgba(63, 106, 224, 0.2);
}

.pill-button.secondary:hover,
.pill-button.secondary:focus-visible {
  box-shadow: none;
}

/* Disclosure widget for CSV formatting tips. */
.guidelines summary {
  font-weight: 600;
  cursor: pointer;
}

.guidelines ul {
  margin-top: 0.75rem;
  margin-bottom: 0;
  padding-left: 1.2rem;
  color: var(--muted);
}

.guidelines li {
  margin-bottom: 0.5rem;
}

/* Glassmorphism-inspired container for the filter toggles. */
.controls {
  position: relative;
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.82));
  padding: 1.75rem;
  border-radius: 1rem;
  border: 1px solid rgba(63, 106, 224, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 10px 30px rgba(31, 41, 51, 0.08);
  overflow: hidden;
  isolation: isolate;
}

.controls::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(
      rgba(63, 106, 224, 0.06) 1px,
      transparent 1px
    ),
    linear-gradient(
      90deg,
      rgba(63, 106, 224, 0.06) 1px,
      transparent 1px
    );
  background-size: 120px 120px;
  opacity: 0.55;
  pointer-events: none;
}

.controls > * {
  position: relative;
  z-index: 1;
}

/* Label badge that titles the filters section. */
.controls__badge {
  grid-column: 1 / -1;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  background: rgba(63, 106, 224, 0.16);
  border: 1px solid rgba(63, 106, 224, 0.28);
  color: var(--accent);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(63, 106, 224, 0.18);
}

.controls__badge::before {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(63, 106, 224, 0.18);
}

/* Layout primitives shared by toggle groups and radio blocks. */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.toggle-group {
  gap: 0.6rem;
}

.control-group .control-label,
.metric-toggle span {
  font-weight: 600;
  font-size: 0.9rem;
}

/* Allow toggle buttons to wrap gracefully on smaller widths. */
.toggle-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Base toggle button style reused across multi- and single-select controls. */
.toggle-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-weight: 600;
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
}

.toggle-button.small {
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
}

.toggle-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.toggle-button:focus-visible {
  outline: none;
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.toggle-button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 10px 20px rgba(63, 106, 224, 0.2);
}

.toggle-button.active:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-soft), 0 10px 20px rgba(63, 106, 224, 0.2);
}

/* Capsule-styled radio group for switching between metrics. */
.metric-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.metric-toggle label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  background: rgba(63, 106, 224, 0.08);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 600;
}

.metric-toggle input[type='radio'] {
  accent-color: var(--accent);
}

/* Container for the textual summary of active filters. */
.filters-summary {
  display: flex;
  padding: 0 0.5rem;
  color: var(--muted);
}

.filters-summary__content {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: rgba(63, 106, 224, 0.1);
  border: 1px solid rgba(63, 106, 224, 0.22);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--text);
  box-shadow: 0 8px 18px rgba(31, 41, 51, 0.08);
}

.filters-summary__content::before {
  content: '🎯';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-size: 0.9rem;
  box-shadow: 0 4px 10px rgba(31, 41, 51, 0.12);
}

.filters-summary__label {
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.8rem;
}

#activeFilters {
  font-weight: 600;
  color: var(--text);
}

/* Responsive grid for the headline statistic cards. */
.summaries {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

/* Shared appearance and hover effect for each summary card. */
.summary-card {
  --summary-accent: #3f6ae0;
  --summary-accent-soft: rgba(63, 106, 224, 0.18);
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.96), var(--summary-accent-soft));
  padding: 1.5rem;
  border-radius: 1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 18px 36px rgba(31, 41, 51, 0.1);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.summary-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 0.45rem;
  background: linear-gradient(90deg, var(--summary-accent), rgba(255, 255, 255, 0));
  opacity: 0.85;
  pointer-events: none;
}

.summary-card::after {
  content: '';
  position: absolute;
  width: 170px;
  height: 110px;
  right: -50px;
  bottom: -40px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, rgba(255, 255, 255, 0), var(--summary-accent));
  background-blend-mode: screen;
  clip-path: polygon(0% 68%, 12% 52%, 28% 60%, 44% 40%, 62% 58%, 78% 32%, 90% 44%, 100% 34%, 100% 100%, 0% 100%);
  opacity: 0.35;
  pointer-events: none;
}

.summary-card:hover {
  transform: translateY(-4px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 22px 42px rgba(31, 41, 51, 0.16);
}

.summary-card__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.summary-card__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  background: var(--summary-accent-soft);
  color: var(--summary-accent);
  font-size: 1.25rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 8px 16px rgba(31, 41, 51, 0.1);
}

.summary-card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: rgba(31, 41, 51, 0.78);
}

.summary-value {
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
}

.summary-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.summary-card.summary-total {
  --summary-accent: #3f6ae0;
  --summary-accent-soft: rgba(63, 106, 224, 0.2);
}

.summary-card.summary-average {
  --summary-accent: #2eb88a;
  --summary-accent-soft: rgba(46, 184, 138, 0.22);
}

.summary-card.summary-peak {
  --summary-accent: #f4a261;
  --summary-accent-soft: rgba(244, 162, 97, 0.24);
}

.summary-card.summary-growth {
  --summary-accent: #a855f7;
  --summary-accent-soft: rgba(168, 85, 247, 0.24);
}

/* Grid layout that positions the trio of chart cards responsively. */
.charts {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

/* The distribution card switches between single and triple chart layouts. */
.chart-card--distribution .chart-area {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: clamp(200px, 70vw, 340px);
  height: clamp(220px, 75vw, 360px);
}

.chart-card--distribution .distribution-single {
  position: relative;
  flex: 1;
  display: flex;
}

.chart-card--distribution .distribution-grid {
  display: none;
  gap: 1rem;
}

.chart-card--distribution .distribution-grid__item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: clamp(200px, 18vw, 260px);
  height: clamp(220px, 20vw, 280px);
}

.chart-card--distribution .distribution-grid__label {
  margin: 0;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
}

.chart-card--distribution .distribution-grid__item canvas {
  flex: 1;
}

/* Generic card styling applied to every chart container. */
.chart-card {
  position: relative;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 1rem;
  border: 1px solid rgba(63, 106, 224, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 16px 32px rgba(31, 41, 51, 0.08);
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.chart-card::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 4px;
  background: linear-gradient(90deg, rgba(63, 106, 224, 0.85), rgba(168, 85, 247, 0.55), rgba(46, 184, 138, 0.5));
  pointer-events: none;
}

.chart-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 12px 24px rgba(36, 64, 143, 0.08);
  pointer-events: none;
}

/* Responsive canvas container that also surfaces empty states. */
.chart-area {
  position: relative;
  min-height: 240px;
  height: clamp(240px, 35vw, 420px);
}

.chart-area canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-area.is-empty canvas {
  opacity: 0.2;
  filter: grayscale(0.6);
}

.chart-area.is-empty::after {
  content: 'No data matches your filters yet—try widening them.';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 2rem;
  font-weight: 500;
  color: var(--muted);
  pointer-events: none;
}

/* Title and subtitle styling for chart headings. */
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.chart-title {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chart-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.chart-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.chart-toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* On wide screens show all distribution charts simultaneously. */
@media (min-width: 1024px) {
  .charts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-card--distribution {
    grid-column: 1 / -1;
  }

  .chart-card--distribution .chart-area {
    height: auto;
    min-height: 0;
  }

  .chart-card--distribution .distribution-single {
    display: none;
  }

  .chart-card--distribution .distribution-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
  }

  .chart-card--distribution .chart-toggle-group {
    display: none;
  }
}

/* Card styling for the detailed data table. */
.table-section {
  position: relative;
  background: var(--surface);
  border-radius: 1rem;
  border: 1px solid rgba(63, 106, 224, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 16px 32px rgba(31, 41, 51, 0.08);
  padding: 1.5rem;
  overflow: hidden;
}

.table-section::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 4px;
  background: linear-gradient(90deg, rgba(63, 106, 224, 0.85), rgba(168, 85, 247, 0.55), rgba(46, 184, 138, 0.5));
  pointer-events: none;
}

.table-section::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 12px 24px rgba(36, 64, 143, 0.08);
  pointer-events: none;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1rem;
}

.table-header h2 {
  margin: 0;
}

.table-header p {
  margin: 0;
  color: var(--muted);
}

/* Allow the data table to scroll horizontally on narrow screens. */
.table-wrapper {
  border-radius: 0.75rem;
  overflow: hidden;
  overflow-x: auto;
  border: 1px solid rgba(217, 222, 235, 0.6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

/* Core table layout shared by the weekly detail grid. */
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

thead {
  background: linear-gradient(135deg, rgba(63, 106, 224, 0.22), rgba(63, 106, 224, 0.1));
}

thead th {
  text-align: left;
  padding: 0.9rem 1rem;
  font-weight: 600;
  color: rgba(31, 41, 51, 0.78);
}

tbody td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(217, 222, 235, 0.45);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Gentle hover interactions for table rows. */
tbody tr {
  transition: background 0.2s ease;
}

tbody tr:nth-child(even) {
  background: rgba(63, 106, 224, 0.04);
}

tbody tr:hover {
  background: rgba(63, 106, 224, 0.12);
}

.table-empty-state,
.table-empty-state:hover {
  background: none !important;
}

.table-empty-state td {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-weight: 500;
}

/* Centered footer with muted supporting text. */
.page-footer {
  padding: 1.5rem 0 3rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

/* Stack controls and soften chart headers on small devices. */
@media (max-width: 768px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .metric-toggle {
    align-self: flex-start;
  }

  .chart-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}
