:root {
  --bg: #f3f6fb;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: #ffffff;
  --surface-accent: #e9f1ff;
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.14);
  --text: #172033;
  --muted: #5d6a82;
  --accent: #0f5bd4;
  --accent-dark: #093d8c;
  --shadow: 0 18px 40px rgba(15, 35, 95, 0.08);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --danger: #c53a30;
  --success: #15803d;
  --neutral-cell: #f1f3f7;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(15, 91, 212, 0.12), transparent 30%),
    radial-gradient(circle at top right, rgba(16, 185, 129, 0.08), transparent 24%),
    linear-gradient(180deg, #eef4ff 0%, #f7f9fc 34%, #f3f6fb 100%);
}

button,
input,
select {
  font: inherit;
}

.page-shell {
  width: calc(100% - 32px);
  max-width: none;
  margin: 0 auto;
  padding: 28px 0 40px;
}

.hero {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
  align-items: center;
  margin-bottom: 24px;
  padding: 10px 28px;
  min-height: 120px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 28px;
  background:
    linear-gradient(135deg, rgba(8, 26, 62, 0.95), rgba(15, 91, 212, 0.92)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  box-shadow: var(--shadow);
  color: #f8fbff;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hero h1,
.panel h2 {
  margin: 0;
  line-height: 1.05;
}

.hero h1 {
  max-width: none;
  white-space: nowrap;
  font-size: clamp(1.5rem, 2.2vw, 2.35rem);
}


.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
}

.dashboard {
  display: grid;
  gap: 20px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel-filters,
.panel-insights,
.panel-visual,
.panel-table,
.panel-rankings {
  padding: 24px;
}

.panel-heading {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 20px;
}

.panel-kicker {
  color: var(--accent);
}

.inline-actions,
.table-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.button,
.mini-button,
.segment {
  border: none;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, color 180ms ease;
}

.button:hover,
.mini-button:hover,
.segment:hover {
  transform: translateY(-1px);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  font-weight: 700;
  text-decoration: none;
}

.button-primary {
  background: #ffffff;
  color: #0c387f;
}

.button-secondary {
  background: rgba(15, 91, 212, 0.1);
  color: var(--accent-dark);
}

.button-ghost {
  background: rgba(15, 23, 42, 0.04);
  color: var(--text);
}

.file-button {
  position: relative;
  overflow: hidden;
}

#csvFileInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.filter-card {
  grid-column: span 3;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
}

.filter-card-wide {
  grid-column: span 6;
}


.filter-label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--muted);
}

.filter-help {
  margin: 10px 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
}

.text-input,
.select-input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  outline: none;
  background: #fdfefe;
  color: var(--text);
}

.text-input:focus,
.select-input:focus {
  border-color: rgba(15, 91, 212, 0.45);
  box-shadow: 0 0 0 4px rgba(15, 91, 212, 0.08);
}

.selector-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}


.mini-button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(15, 91, 212, 0.08);
  color: var(--accent-dark);
  font-size: 0.86rem;
  font-weight: 700;
}

.selection-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.86rem;
}

.checkbox-list {
  max-height: 220px;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 4px;
}


.checkbox-item {
  display: flex;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fbfdff;
}

.checkbox-item input {
  margin-top: 2px;
}

.checkbox-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.checkbox-label strong {
  font-size: 0.93rem;
}

.checkbox-label span {
  font-size: 0.8rem;
  color: var(--muted);
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #eff3f9;
}

.segment {
  min-height: 40px;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment.is-active {
  background: #ffffff;
  color: var(--accent-dark);
  box-shadow: 0 6px 18px rgba(15, 35, 95, 0.08);
}

.source-status strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1rem;
}

.source-status p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 16px;
}

.kpi-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(245, 248, 253, 0.94));
  box-shadow: var(--shadow);
}

.kpi-label {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.kpi-value {
  font-size: clamp(1.4rem, 2vw, 2rem);
  line-height: 1.1;
}

.kpi-value.positive,
.metric-positive {
  color: var(--success);
}

.kpi-value.negative,
.metric-negative {
  color: var(--danger);
}

.rankings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.ranking-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
}

.ranking-card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.ranking-card p {
  margin: 0 0 14px;
  font-size: 0.82rem;
  color: var(--muted);
}

.ranking-list {
  display: grid;
  gap: 10px;
}

.ranking-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 12px;
  align-items: start;
  padding: 12px;
  border-radius: 14px;
  background: #f8fbff;
  border: 1px solid rgba(15, 23, 42, 0.06);
}

.ranking-position {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(15, 91, 212, 0.1);
  color: var(--accent-dark);
  font-size: 0.8rem;
  font-weight: 800;
}

.ranking-body {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.ranking-title {
  font-size: 0.92rem;
  font-weight: 800;
}

.ranking-metrics {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.79rem;
  color: var(--muted);
}

.ranking-value {
  font-size: 0.9rem;
  font-weight: 800;
}

.ranking-empty {
  padding: 14px;
  border-radius: 14px;
  background: #f8fbff;
  color: var(--muted);
  font-size: 0.86rem;
}

.dataset-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.dataset-stat {
  padding: 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: #fff;
}

.dataset-stat span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.dataset-stat strong {
  font-size: 1.2rem;
}

.dataset-note p {
  margin: 0;
  line-height: 1.5;
}

.legend-block {
  display: grid;
  gap: 10px;
}

.legend-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--muted);
}

.legend-scale {
  display: grid;
  grid-template-columns: auto minmax(180px, 240px) auto;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.84rem;
}

.legend-gradient {
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: linear-gradient(90deg, #b42318 0%, #f5cbc3 35%, #eff3f8 50%, #d3f0de 65%, #16733c 100%);
}

.heatmap-wrapper,
.table-wrapper {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #ffffff;
  overflow: auto;
}

.heatmap-table,
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 960px;
}

.heatmap-table thead th,
.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fbff;
}

.heatmap-table th,
.heatmap-table td,
.data-table th,
.data-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  border-right: 1px solid rgba(15, 23, 42, 0.05);
  text-align: left;
  vertical-align: top;
}

.heatmap-table th:first-child,
.heatmap-table td:first-child,
.data-table th:first-child,
.data-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #ffffff;
}

.heatmap-table thead th:first-child,
.data-table thead th:first-child {
  z-index: 4;
  background: #f8fbff;
}

.heatmap-row-header {
  min-width: 240px;
}

.family-header {
  min-width: 170px;
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--muted);
}

.cell-box {
  min-width: 170px;
  min-height: 90px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 16px;
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
  cursor: pointer;
}

.cell-box.is-empty {
  background: var(--neutral-cell);
  color: var(--muted);
}

.cell-box.is-new {
  outline: 2px dashed rgba(21, 128, 61, 0.35);
}

.cell-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: start;
  margin-bottom: 8px;
}

.cell-metric {
  font-size: 1rem;
  font-weight: 800;
}

.cell-tag {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.45);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.cell-subtext {
  display: grid;
  gap: 4px;
  font-size: 0.78rem;
  color: rgba(23, 32, 51, 0.82);
}

.row-meta {
  display: grid;
  gap: 4px;
}

.row-meta strong {
  font-size: 0.96rem;
}

.row-meta span {
  color: var(--muted);
  font-size: 0.8rem;
}

.empty-state {
  margin-bottom: 16px;
  padding: 16px 18px;
  border-radius: 16px;
  background: #fff7ed;
  border: 1px solid rgba(249, 115, 22, 0.18);
  color: #9a3412;
}

.hidden {
  display: none !important;
}

.data-table th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sort-button {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.sort-indicator {
  color: var(--accent);
  font-size: 0.72rem;
}

.mono {
  font-family: "IBM Plex Mono", monospace;
}

.tooltip {
  position: fixed;
  z-index: 20;
  width: min(320px, calc(100vw - 24px));
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(8, 18, 40, 0.94);
  color: #f8fbff;
  box-shadow: 0 18px 40px rgba(8, 18, 40, 0.25);
  pointer-events: none;
}

.tooltip h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.tooltip p {
  margin: 6px 0;
  font-size: 0.82rem;
  color: rgba(248, 251, 255, 0.8);
}

.tooltip strong {
  color: #ffffff;
}

.view-hidden {
  display: none;
}

@media (max-width: 1180px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    justify-content: flex-start;
  }

  .filter-card,
  .filter-card-wide {
    grid-column: span 6;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .rankings-grid,
  .dataset-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100% - 20px, 100%);
    padding-top: 16px;
  }

  .hero,
  .panel-filters,
  .panel-insights,
  .panel-visual,
  .panel-table {
    padding: 18px;
  }

  .panel-heading {
    flex-direction: column;
  }

  .filters-grid {
    grid-template-columns: 1fr;
  }

  .filter-card,
  .filter-card-wide {
    grid-column: span 1;
  }

  .kpi-grid,
  .rankings-grid,
  .dataset-grid {
    grid-template-columns: 1fr;
  }

  .legend-scale {
    grid-template-columns: 1fr;
  }

  .legend-gradient {
    min-width: 180px;
  }
}
