:root {
  --ink: #1f1c16;
  --muted: #6d6256;
  --accent: #1f7a8c;
  --sun: #f6aa1c;
  --rose: #f25c54;
  --canvas: #f7f1e7;
  --card: #fff8ef;
  --shadow: rgba(31, 28, 22, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #fffaf1, #f1e8da 50%, #e6d9c7 100%);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 32px;
  align-items: center;
  margin-bottom: 48px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 12px;
  color: var(--muted);
}

h1 {
  font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
  font-size: clamp(2.4rem, 5vw, 3.5rem);
  margin: 12px 0 16px;
}

h2 {
  font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
  margin: 0 0 16px;
}

/* Section heading divider — line belongs to the heading, not the content */
.section > h2 {
  display: inline-block;          /* shrink-wrap so border only spans the text width */
  width: 100%;                    /* but still fills the row */
  padding-bottom: 7px;            /* 7px gap between text baseline and divider line  */
  margin-bottom: 18px;            /* 18px gap between divider line and content below */
  border-bottom: 2px solid rgba(31, 122, 140, 0.22);
  box-sizing: border-box;
}

.subtitle {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.hero-card {
  background: var(--card);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 16px 40px var(--shadow);
}

.dropzone {
  border: 2px dashed var(--accent);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  background: rgba(31, 122, 140, 0.08);
  transition: transform 0.2s ease, background 0.2s ease;
}

.dropzone.dragging {
  background: rgba(242, 92, 84, 0.18);
  transform: scale(1.02);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
}

.btn input {
  display: none;
}

.btn.secondary {
  background: var(--rose);
}

.btn-hd-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(135deg, #1f7a8c, #1a5f72);
  color: white;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  margin-top: 12px;
  width: 100%;
  text-decoration: none;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-hd-download:hover {
  background: linear-gradient(135deg, #0d5563, #0a4555);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn-hd-download:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.meta {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 16px;
}

.loading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.section {
  margin: 48px 0;
}

.section-note {
  color: var(--muted);
  margin: 0 0 20px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  padding: 20px;
  border-radius: 18px;
  box-shadow: 0 12px 24px var(--shadow);
}

.card-title {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.7rem;
  color: var(--muted);
  margin: 0;
}

.card-value {
  font-size: 1.8rem;
  font-weight: 600;
  margin: 12px 0 8px;
}

.card-note {
  margin: 0;
  color: var(--muted);
}

.card-formula {
  margin: 8px 0 4px;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  font-family: 'Courier New', monospace;
}

/* Quality Narrative Section */
.quality-narrative {
  margin-top: 24px;
  padding: 20px;
  background: linear-gradient(135deg, rgba(31, 122, 140, 0.08) 0%, rgba(31, 122, 140, 0.04) 100%);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
}

.quality-narrative.hidden {
  display: none;
}

.narrative-box {
  margin: 0;
}

.narrative-box h3 {
  margin: 0 0 12px 0;
  color: var(--accent);
  font-size: 1rem;
}

.narrative-text {
  margin: 0;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Quality Methodology Section */
.quality-methodology {
  background: linear-gradient(135deg, rgba(31, 122, 140, 0.05) 0%, rgba(242, 92, 84, 0.05) 100%);
  border: 1px solid rgba(31, 122, 140, 0.1);
}

/* ── Methods & Standards (citations) ──────────────────────────────────── */
.methods-references {
  background: linear-gradient(135deg, rgba(31, 122, 140, 0.04) 0%, rgba(31, 122, 140, 0.02) 100%);
  border: 1px solid rgba(31, 122, 140, 0.1);
}
.reference-thresholds {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 8px 0 24px;
}
.ref-threshold-card {
  background: white;
  border-radius: 12px;
  padding: 16px 18px;
  border-left: 4px solid var(--accent);
  box-shadow: 0 4px 12px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ref-th-label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.ref-th-value {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}
.ref-th-note {
  font-size: 0.78rem;
  color: var(--muted);
}
.reference-list {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.reference-list li {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink);
}
.reference-list li a {
  color: var(--accent);
  word-break: break-word;
}
.reference-list .ref-use {
  display: block;
  margin-top: 3px;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}
.reference-footnote {
  margin: 22px 0 0;
  padding-top: 16px;
  border-top: 1px solid rgba(31, 122, 140, 0.12);
  font-size: 0.82rem;
  color: var(--muted);
}

.detected-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.detected-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 16px;
  border: 1px solid rgba(31, 28, 22, 0.08);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 24px;
  align-items: stretch;
}

.chart-card {
  background: #ffffff;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 10px 22px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chart-card h3 {
  margin: 0;
  font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
}

.chart-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.chart {
  background: #ffffff;
  border-radius: 14px;
  padding: 8px;
  min-height: 480px;
  height: auto;
  overflow: visible;
  position: relative;
}

.chart .plot-container,
.chart .svg-container {
  width: 100% !important;
  height: 100% !important;
}

.table-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 32px;
  width: 100%;
  max-width: 100%;
}

.table-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
  border: 1px solid rgba(31, 28, 22, 0.08);
  box-shadow: 0 4px 12px var(--shadow);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 320px;
}

.table-card h3 {
  margin: 0 0 16px 0;
  font-size: 1.1rem;
  color: var(--ink);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 8px;
}

.table-card table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  table-layout: fixed;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid rgba(31, 28, 22, 0.1);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

th {
  font-weight: 600;
  color: var(--accent);
  background: rgba(31, 122, 140, 0.05);
  padding: 12px 8px;
}

tr:hover {
  background: rgba(31, 122, 140, 0.02);
}

.empty {
  color: #999;
  text-align: center;
  padding: 24px;
  font-style: italic;
}

.download-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.download-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.download-group {
  background: #ffffff;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 10px 22px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.group-note {
  color: var(--muted);
  margin: 0;
}

.window-panel {
  background: var(--card);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 10px 22px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.window-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.window-controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.window-controls input {
  border: 1px solid rgba(31, 28, 22, 0.2);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.window-dashboard {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.window-downloads {
  background: #ffffff;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 10px 22px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Chart containers with descriptions */
.chart-container {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(31, 28, 22, 0.06);
  display: flex;
  flex-direction: column;
  flex: 1;
  border: 1px solid rgba(31, 28, 22, 0.05);
}

.chart-container .chart {
  background: #ffffff;
  border-radius: 0;
  padding: 12px;
  min-height: 400px;
  flex: 1;
  margin: 0;
  box-shadow: none;
}

.chart-description {
  padding: 14px 16px;
  background: #fafaf8;
  border-top: 1px solid rgba(31, 28, 22, 0.04);
  font-size: 0.85rem;
}

.chart-description h4 {
  margin: 0 0 6px 0;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.9rem;
}

.chart-description p {
  margin: 0;
  color: #555;
  line-height: 1.4;
  font-size: 0.8rem;
}

/* New chart controls and headers */
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(31, 28, 22, 0.05);
  background: #ffffff;
}

.chart-header h3 {
  margin: 0;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
}

.chart-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-icon {
  background: transparent;
  border: 1px solid rgba(31, 28, 22, 0.15);
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: rgba(242, 92, 84, 0.08);
  border-color: #f25c54;
}

.btn-icon.info-icon:hover {
  background: rgba(31, 122, 140, 0.08);
  border-color: #1f7a8c;
}

.chart-date-range {
  padding: 6px 12px;
  font-size: 0.75rem;
  color: #999;
  background: #fafaf8;
  border-top: 1px solid rgba(31, 28, 22, 0.04);
  text-align: center;
}

.chart-tooltip {
  background: #f8f6f0;
  border: 1px solid rgba(31, 122, 140, 0.2);
  border-radius: 4px;
  padding: 12px;
  margin: 8px 12px 0 12px;
  font-size: 0.85rem;
  color: #333;
  line-height: 1.5;
}

.chart-tooltip strong {
  color: #1f7a8c;
  display: block;
  margin-bottom: 6px;
}

.chart-tooltip p {
  margin: 4px 0;
}

/* Two-tier download sections */
.download-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

/* ── Community report card ────────────────────────────────────────── */
.community-report-card {
  background: linear-gradient(135deg, #e8f7f0 0%, #d4f0e3 100%);
  border: 1.5px solid #4cad7c;
  border-radius: 12px;
  padding: 24px 28px;
  margin-bottom: 28px;
  box-shadow: 0 4px 16px rgba(0, 120, 70, 0.10);
}

.community-report-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.community-report-icon {
  font-size: 2.4rem;
  line-height: 1;
  flex-shrink: 0;
}

.community-report-text {
  flex: 1;
  min-width: 220px;
}

.community-report-text h3 {
  margin: 0 0 6px 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: #0d5c32;
}

.community-report-text p {
  margin: 0;
  font-size: 0.87rem;
  color: #1a6640;
  line-height: 1.5;
}

.btn.community-btn {
  background: #1a8a4e;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 13px 22px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.18s, box-shadow 0.18s;
  box-shadow: 0 2px 8px rgba(26, 138, 78, 0.25);
}

.btn.community-btn:hover {
  background: #146b3c;
  box-shadow: 0 4px 14px rgba(26, 138, 78, 0.35);
}

.btn.community-btn:disabled {
  background: #7cc7a0;
  cursor: not-allowed;
  box-shadow: none;
}

.community-report-meta {
  margin-top: 16px;
  border-top: 1px solid #a8dfc0;
  padding-top: 14px;
}

.community-meta-row {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.community-meta-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 160px;
}

.community-meta-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #0d5c32;
}

.meta-hint {
  font-weight: 400;
  color: #3a8f60;
  font-size: 0.75rem;
}

.cr-input {
  border: 1.5px solid #7cc7a0;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.85rem;
  background: #fff;
  color: #1a2a1a;
  outline: none;
  transition: border-color 0.15s;
}

.cr-input:focus {
  border-color: #1a8a4e;
}

.cr-hint {
  margin: 8px 0 0 0;
  font-size: 0.76rem;
  color: #3a8f60;
}

/* ── end community card ───────────────────────────────────────────── */

.download-section {
  background: #ffffff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(31, 28, 22, 0.06);
  border: 1px solid rgba(31, 28, 22, 0.05);
  border-left: 3px solid var(--accent);
}

.download-section h3 {
  margin: 0 0 8px 0;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
}

.download-section p {
  margin: 0 0 14px 0;
  color: #666;
  font-size: 0.85rem;
  line-height: 1.4;
}

.chart-export-section {
  background: #ffffff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(31, 28, 22, 0.06);
  border: 1px solid rgba(31, 28, 22, 0.05);
}

.chart-export-section h3 {
  margin: 0 0 8px 0;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
}

.chart-export-section p {
  margin: 0 0 14px 0;
  color: #666;
  font-size: 0.85rem;
  line-height: 1.4;
}

.download-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.download-grid .btn {
  text-align: center;
  font-size: 0.9rem;
  padding: 10px 12px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.3;
}

.download-grid .btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.info-note {
  background: #ebe5d9;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.85rem;
  color: #555;
  margin: 12px 0 0 0;
  border-left: 4px solid var(--muted);
}

.research-btn {
  border: 1px solid rgba(31, 122, 140, 0.2);
}

.anomaly-list {
  background: #fff;
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 0 10px 22px var(--shadow);
}

/* Timeframe Selector Styling */
.timeframe-selector {
  background: linear-gradient(135deg, rgba(31, 122, 140, 0.05) 0%, rgba(242, 92, 84, 0.05) 100%);
  border: 1px solid rgba(31, 122, 140, 0.1);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 32px;
}

.timeframe-selector h2 {
  color: var(--accent);
  margin-bottom: 8px;
}

.timeframe-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
  margin-top: 20px;
}

.date-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  flex: 1;
  min-width: 300px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 160px;
}

.input-group label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
}

.date-input {
  padding: 10px 12px;
  border: 1px solid rgba(31, 28, 22, 0.2);
  border-radius: 8px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.95rem;
  background: white;
  color: var(--ink);
}

.date-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 140, 0.1);
}

#btn-refine-analysis {
  white-space: nowrap;
  font-weight: 600;
}

#refine-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--muted);
  width: 100%;
}

#refine-loading.hidden {
  display: none;
}

.hidden {
  display: none;
}

.empty {
  color: var(--muted);
}

/* ──────────────────────────────────────────────────────────────────────────
   Dashboard flow — reorder sections into a logical reading order without
   moving any HTML (preserves every element id the JS depends on).
   Reference material (methodology, detected columns) drops below the results;
   the reports/downloads block is pulled up near the analysis it summarizes.
   ────────────────────────────────────────────────────────────────────────── */
.dashboard:not(.hidden) {
  display: flex;
  flex-direction: column;
}
.dashboard > .section {
  margin-top: 0;
  margin-bottom: 40px;
}
.dashboard > .comparison          { order: 0; }
.dashboard > .overview            { order: 10; }
.dashboard > .narrative-section   { order: 20; }
.dashboard > .charts              { order: 30; }
.dashboard > .correction-section  { order: 40; }
.dashboard > .tables              { order: 50; }
.dashboard > .custom-notes-section{ order: 60; }
.dashboard > .downloads           { order: 70; }
.dashboard > .timeframe-selector  { order: 80; }
.dashboard > .quality-methodology { order: 90; }
.dashboard > .methods-references  { order: 95; }
.dashboard > .detected            { order: 100; }
.dashboard > .anomalies           { order: 110; }

/* A subtle "reference" treatment for the lower informational sections */
.dashboard > .quality-methodology,
.dashboard > .methods-references,
.dashboard > .detected {
  opacity: 0.96;
}

/* ── Landing / Data Import polish ──────────────────────────────────────── */
.import-group-label {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  margin: 4px 0 10px;
}
.dropzone p {
  font-weight: 600;
  font-size: 1.02rem;
  margin: 0 0 6px;
}
.dropzone:hover {
  background: rgba(31, 122, 140, 0.13);
}
.hero-card .meta {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Data Completeness panel ──────────────────────────────────────────── */
.dc-banner {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 14px;
}
.dc-banner.ok   { background: rgba(0, 166, 81, 0.10); color: #0a6b3a; border: 1px solid rgba(0, 166, 81, 0.30); }
.dc-banner.warn { background: rgba(246, 170, 28, 0.12); color: #8a5a00; border: 1px solid rgba(246, 170, 28, 0.40); }
.dc-list { display: flex; flex-direction: column; gap: 8px; }
.dc-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid #ece7e0;
  border-radius: 10px;
}
.dc-row.missing { border-color: rgba(242, 92, 84, 0.45); background: rgba(242, 92, 84, 0.05); }
.dc-icon { font-weight: 700; font-size: 1rem; line-height: 1.4; flex-shrink: 0; width: 16px; text-align: center; }
.dc-row.present .dc-icon { color: #00a651; }
.dc-row.missing .dc-icon { color: #f25c54; }
.dc-row.absent  .dc-icon { color: var(--muted); }
.dc-main { flex: 1; }
.dc-name { font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dc-level {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 700;
}
.dc-level.required    { background: #f25c54; color: #fff; }
.dc-level.important   { background: #f6aa1c; color: #fff; }
.dc-level.recommended { background: #1f7a8c; color: #fff; }
.dc-level.optional    { background: #d8d2c8; color: #4a443b; }
.dc-found { font-family: monospace; font-size: 0.78rem; color: var(--muted); }
.dc-impact { font-size: 0.82rem; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.dc-status { font-size: 0.78rem; font-weight: 600; flex-shrink: 0; }
.dc-status.present { color: #00a651; }
.dc-status.missing { color: #f25c54; }
.dc-status.absent  { color: var(--muted); }

@media (max-width: 768px) {
  .app {
    padding: 24px 16px 64px;
  }
  .hero {
    gap: 20px;
  }
  .chart {
    min-height: 260px;
    height: 320px;
  }
  .download-sections {
    grid-template-columns: 1fr;
  }
}

/* ── Device info section ─────────────────────────────────────────────── */
.device-info-section {
  margin-bottom: 16px;
}

.device-info-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.input-group-inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group-inline label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.text-input {
  padding: 8px 12px;
  border: 1.5px solid #d0ccc6;
  border-radius: 10px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.9rem;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.2s;
  outline: none;
}

.text-input:focus {
  border-color: var(--accent);
}

@media (max-width: 500px) {
  .device-info-row {
    grid-template-columns: 1fr;
  }
}

/* ── Comparison file list (one-by-one) ───────────────────────────────── */
.compare-file-list {
  min-height: 48px;
  max-height: 280px;
  overflow-y: auto;
  border: 1.5px solid #e0dbd4;
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 12px;
  background: #fdfaf6;
}

.compare-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #ece7e0;
  margin-bottom: 6px;
  font-size: 0.85rem;
}

.compare-file-row:last-child {
  margin-bottom: 0;
}

.compare-file-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.compare-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.compare-file-size {
  color: var(--muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.btn-remove-file {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--rose);
  font-size: 0.9rem;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.15s;
}

.btn-remove-file:hover {
  background: rgba(242, 92, 84, 0.12);
}

/* Control House row + per-house naming */
.compare-file-row.is-control {
  border-color: #0a1f47;
  background: #f4f7fc;
  box-shadow: inset 3px 0 0 #0a1f47;
}

.compare-role-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  flex-shrink: 0;
  white-space: nowrap;
}

.compare-role-badge.control {
  background: #0a1f47;
  color: #fff;
}

.compare-role-badge.house {
  background: var(--accent);
  color: #fff;
}

.compare-name-input {
  flex: 0 1 150px;
  min-width: 90px;
  padding: 4px 8px;
  border: 1px solid #d8d2c8;
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--ink);
  background: #fff;
}

.compare-name-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 122, 140, 0.15);
}

.btn-set-control {
  background: transparent;
  border: 1px solid #0a1f47;
  color: #0a1f47;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.btn-set-control:hover {
  background: #0a1f47;
  color: #fff;
}

.compare-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.add-file-btn {
  cursor: pointer;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1.5px solid #d0ccc6;
}

.btn.ghost:hover {
  background: rgba(0, 0, 0, 0.04);
}

/* ── Narrative Summary ─────────────────────────────── */
.narrative-section { margin-top: 0; }
.narrative-card {
  background: linear-gradient(135deg, #f0f7fa 0%, #fafaf8 100%);
  border: 1px solid rgba(31,122,140,0.2);
  border-left: 4px solid #1f7a8c;
  border-radius: 8px;
  padding: 20px 24px;
}
.narrative-card p {
  margin: 0;
  font-size: 0.97rem;
  line-height: 1.75;
  color: #2a2a2a;
}

/* ── Calendar full-width ───────────────────────────── */
.chart-full-width {
  grid-column: 1 / -1;
}

/* ── Correction Formula Section ────────────────────── */
.correction-section .section-note { margin-bottom: 12px; }
.correction-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.correction-controls label { font-size: 0.9rem; color: #555; }
.correction-dropdown {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #ccc;
  font-size: 0.9rem;
  cursor: pointer;
}
.formula-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.formula-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 6px;
  background: #f8f8f6;
  border: 1px solid #e8e8e4;
  flex-wrap: wrap;
}
.formula-row.active-row {
  background: #edf6f8;
  border-color: #1f7a8c;
}
.formula-name {
  font-weight: 600;
  font-size: 0.88rem;
  min-width: 160px;
  color: #444;
}
.formula-name.active-formula { color: #1f7a8c; }
.formula-row code {
  font-family: monospace;
  font-size: 0.88rem;
  background: #fff;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid #ddd;
  color: #c0392b;
}
.formula-note {
  font-size: 0.82rem;
  color: #777;
  flex: 1;
}

/* ── Site Footer ─────────────────────────────────── */
.site-footer {
  background: #1a2233;
  color: #c8cdd8;
  margin-top: 64px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 48px 32px 32px;
}
.footer-top {
  margin-bottom: 36px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 20px;
}
.footer-platform {
  font-size: 1.05rem;
  font-weight: 600;
  color: #e8eaf0;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}
.footer-tagline {
  font-size: 0.82rem;
  color: #7a8199;
  margin: 0;
}
.footer-team {
  display: flex;
  align-items: flex-start;
  gap: 0;
  margin-bottom: 36px;
  flex-wrap: wrap;
}
.footer-person {
  flex: 1;
  min-width: 220px;
  padding: 0 28px 0 0;
}
.footer-divider {
  width: 1px;
  background: rgba(255,255,255,0.1);
  align-self: stretch;
  margin: 0 28px 0 0;
  min-height: 80px;
}
.footer-role {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5b9bd5;
  margin: 0 0 6px;
}
.footer-name {
  font-size: 0.97rem;
  font-weight: 600;
  color: #e8eaf0;
  margin: 0 0 4px;
}
.footer-affil {
  font-size: 0.82rem;
  color: #9aa3b8;
  margin: 0 0 2px;
}
.footer-contact {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.82rem;
  color: #5b9bd5;
  text-decoration: none;
  border-bottom: 1px solid rgba(91,155,213,0.3);
  transition: color 0.15s, border-color 0.15s;
}
.footer-contact:hover {
  color: #8dc4f0;
  border-color: rgba(141,196,240,0.5);
}
.footer-disclaimer {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 20px;
}
.footer-disclaimer p {
  font-size: 0.78rem;
  color: #636b80;
  line-height: 1.65;
  margin: 0 0 8px;
}
.footer-copy {
  font-size: 0.75rem;
  color: #4a5068;
  margin: 0 !important;
}
@media (max-width: 600px) {
  .footer-team { flex-direction: column; gap: 24px; }
  .footer-divider { display: none; }
  .footer-person { padding: 0; }
}

/* ── Custom Notes ───────────────────────────────────────────────────────────── */
.custom-notes-section { margin-bottom: 32px; }

.note-card {
  background: var(--card);
  border: 1px solid #e0d6c8;
  border-radius: 10px;
  padding: 14px 16px 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px var(--shadow);
}

.note-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.note-card-num {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.note-heading-input {
  width: 100%;
  border: 1px solid #d5ccbf;
  border-radius: 6px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  background: #fff;
  color: var(--ink);
  margin-bottom: 8px;
  outline: none;
  transition: border-color 0.15s;
}
.note-heading-input:focus { border-color: var(--accent); }

.note-content-input {
  width: 100%;
  border: 1px solid #d5ccbf;
  border-radius: 6px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 0.88rem;
  background: #fff;
  color: var(--ink);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.5;
}
.note-content-input:focus { border-color: var(--accent); }

.note-remove-btn {
  background: none;
  border: none;
  color: #b0a090;
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.note-remove-btn:hover { color: var(--rose); background: #fde8e8; }

/* ── AQI Calendar SVG tooltip ────────────────────────────────────────────────── */
.aqi-cal-tip {
  position: fixed;
  display: none;
  background: rgba(30, 28, 22, 0.9);
  color: #fff;
  font-size: 0.82rem;
  line-height: 1.45;
  padding: 7px 11px;
  border-radius: 7px;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.aqi-cal-cell { cursor: crosshair; transition: opacity 0.1s; }
.aqi-cal-cell:hover { opacity: 0.78; }

/* AQI Calendar scroll + note */
.aqi-cal-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
}
.aqi-cal-note {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Scrollable statistics tables ──────────────────────────────────────────── */
.table-scroll {
  max-height: 340px;
  overflow-y: auto;
  border-radius: 6px;
  border: 1px solid rgba(31, 28, 22, 0.08);
}

.table-scroll table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.table-scroll thead th {
  position: sticky;
  top: 0;
  background: #f5f2ec;
  z-index: 1;
  padding: 8px 10px;
  text-align: left;
  font-size: 0.8rem;
  color: var(--ink);
  border-bottom: 2px solid var(--accent);
  white-space: nowrap;
}

.table-scroll tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(31, 28, 22, 0.06);
  vertical-align: top;
}

.table-scroll tbody tr:last-child td { border-bottom: none; }
.table-scroll tbody tr:hover { background: #fafaf8; }

/* ── Pollution event type legend ────────────────────────────────────────────── */
.event-type-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin-bottom: 8px;
  font-size: 0.83rem;
  color: var(--muted);
  line-height: 1.5;
}
.event-type-legend.compact { margin-bottom: 6px; font-size: 0.8rem; }
.event-type-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.event-type-badge.spike {
  background: #fff0e0;
  color: #b85c00;
  border: 1px solid #f6aa1c;
}
.event-type-badge.sustained {
  background: #fde8e8;
  color: #a01010;
  border: 1px solid #f25c54;
}
.event-type-desc { flex: 1; min-width: 160px; }
.event-range-note {
  font-size: 0.81rem;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.5;
}

/* ── Mobile / responsive refinements ──────────────────────────────────── */
@media (max-width: 640px) {
  .hero { padding: 20px 16px; }
  .app { padding-left: 12px; padding-right: 12px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .card-value { font-size: 1.15rem; }
  .section { padding: 18px 14px; }
  .device-info-row { flex-direction: column; }
  .table-scroll { overflow-x: auto; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.15rem; }
}
@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
}

/* "Try it with sample data" affordance in the dropzone */
.sample-cta {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--muted, #6b7280);
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent, #2c7fb8);
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover:not(:disabled) { opacity: 0.8; }
.link-btn:disabled { opacity: 0.55; cursor: progress; text-decoration: none; }

/* Essentials / Advanced view switch.
   Essentials is the default so a first-time visitor sees the headline results
   rather than every statistical panel at once. Purely client-side. */
.view-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 18px;
  padding: 10px 14px;
  border: 1px solid var(--border, #e4e7ec);
  border-radius: 10px;
  background: var(--surface-alt, #f8fafc);
}
.view-switch-label {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted, #6b7280);
}
.view-switch-buttons { display: inline-flex; border: 1px solid var(--border, #d8dce3); border-radius: 8px; overflow: hidden; }
.view-btn {
  border: none;
  background: transparent;
  padding: 6px 16px;
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  color: var(--muted, #55606e);
}
.view-btn + .view-btn { border-left: 1px solid var(--border, #d8dce3); }
.view-btn.is-active { background: var(--accent, #1b3a5b); color: #fff; font-weight: 600; }
.view-switch-note { font-size: 0.78rem; color: var(--muted, #6b7280); flex: 1 1 260px; }

/* Hidden unless Advanced is selected. */
body:not(.show-advanced) [data-advanced] { display: none !important; }
