:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  --bg: #f7f9fc;
  --card: #ffffff;
  --text: #1f2a44;
  --muted: #5f6b7a;
  --accent: #2f6fed;
  --grid: #dfe5ef;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.page {
  margin: 0;
  padding: 16px 16px 6px;
}

/* ========================================
   INTRO PAGE
   ======================================== */
.intro-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80vh;
}

.intro-page[hidden] {
  display: none;
}

.intro-card {
  max-width: 620px;
  background: var(--card);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  text-align: center;
}

.intro-card h1 {
  margin: 0 0 8px;
  font-size: 1.8rem;
}

.intro-subtitle {
  color: var(--muted);
  margin: 0 0 28px;
  font-size: 1.05rem;
}

.intro-body {
  text-align: left;
  margin-bottom: 32px;
}

.intro-body h2 {
  font-size: 1rem;
  margin: 20px 0 8px;
}

.intro-body p {
  margin: 0 0 12px;
  line-height: 1.6;
  color: var(--text);
}

.intro-body ul {
  margin: 0 0 12px;
  padding-left: 20px;
}

.intro-body li {
  margin: 6px 0;
  line-height: 1.5;
}

.intro-begin {
  padding: 14px 40px;
  font-size: 1.05rem;
}

.token-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--grid);
}

.token-section label {
  display: block;
  margin-bottom: 8px;
}

.token-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.token-input {
  font-family: monospace;
  font-size: 1.2rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  text-align: center;
  padding: 10px 16px;
  border: 2px solid var(--grid);
  border-radius: 8px;
  width: 160px;
  outline: none;
  transition: border-color .2s;
}

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

.token-input.token-valid {
  border-color: #16a34a;
}

.token-input.token-invalid {
  border-color: #dc2626;
}

.token-error {
  color: #dc2626;
  font-size: .85rem;
  margin-top: 6px;
  min-height: 1.2em;
}

footer {
  text-align: center;
  margin: 0;
  padding: 6px 16px;
  color: var(--muted);
  font-size: 0.65rem;
  line-height: 1;
}

footer p {
  margin: 0;
}

.page__header {
  margin-bottom: 28px;
}

.page__header h1 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.page__header p {
  margin: 0;
  color: var(--muted);
  max-width: 680px;
}

.page-content {
  display: grid;
  grid-template-columns: 4fr 1fr;
  gap: 16px;
  align-items: start;
}

.visualization-area {
  min-width: 0;
}

.viz-instructions {
  background: var(--card);
  border: 1px solid var(--grid);
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

.viz-instructions p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.questionnaire-area {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  margin-top: 0;
  height: auto;
  overflow-y: auto;
  font-size: 0.85rem;
}

/* Old styles - replaced by tab layout */
/* .charts {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.chart-card {
  flex: 1 1 320px;
  background: var(--card);
  border-radius: 16px;
  padding: 20px 20px 24px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  min-width: 280px;
}

.chart-card h2 {
  margin: 0 0 12px;
  font-size: 1.2rem;
} */

/* ========================================
   CHART LABEL (compact header above chart)
   ======================================== */
.chart-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.chart-label__title {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
}

.chart-label__hint {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ========================================
   CHART PANELS (auto-switched by questionnaire step)
   ======================================== */
.chart-panel {
  display: none;
  opacity: 0;
}

.chart-panel--active {
  display: block;
  opacity: 1;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* ========================================
   CHART LAYOUT (Main + Sidebar)
   ======================================== */
.chart-layout {
  display: flex;
  gap: 12px;
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.chart-main {
  flex: 1;
  min-width: 0;
}

.chart {
  width: 100%;
  position: relative;
}

.chart-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
}

.zoom-btn,
.reset-zoom-btn {
  padding: 8px 16px;
  background: var(--card);
  border: 1.5px solid var(--grid);
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.1);
}

.zoom-btn {
  min-width: 34px;
  padding: 8px 10px;
  font-weight: 700;
}

.zoom-btn:hover,
.reset-zoom-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(47, 111, 237, 0.3);
}

.zoom-btn:active,
.reset-zoom-btn:active {
  transform: scale(0.95);
}

svg {
  width: 100%;
  height: auto;
  display: block;
  cursor: grab;
}

svg:active {
  cursor: grabbing;
}

/* ========================================
   SIDEBAR
   ======================================== */
.chart-sidebar {
  width: 140px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--grid);
  padding-right: 12px;
}

.sidebar-header {
  margin-bottom: 16px;
}

.sidebar-header h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  color: var(--text);
  font-weight: 700;
}

.chart-sidebar .sidebar-header h3 {
  font-size: 0.72rem;
  font-weight: 600;
}

/* ========================================
   SEARCH INPUT
   ======================================== */
.search-input {
  width: 100%;
  padding: 6px 8px;
  border: 1.5px solid var(--grid);
  border-radius: 6px;
  font-size: 0.72rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.1);
}

.search-input::placeholder {
  color: var(--muted);
}

/* ========================================
   LEGEND CONTAINER
   ======================================== */
.legend-container {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
  /* max-height set dynamically via JS to match chart height */
}

.legend-container::-webkit-scrollbar {
  width: 6px;
}

.legend-container::-webkit-scrollbar-track {
  background: transparent;
}

.legend-container::-webkit-scrollbar-thumb {
  background: var(--grid);
  border-radius: 3px;
}

.legend-container::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.axis path,
.axis line {
  stroke: #9fb0c5;
}

.axis text {
  fill: var(--muted);
  font-size: 0.8rem;
}

.grid line {
  stroke: var(--grid);
  stroke-dasharray: 2 4;
}

.grid path {
  stroke: none;
}

.dot {
  opacity: 0.7;
  transition: opacity 0.2s ease, stroke 0.2s ease;
}

.dot--highlight {
  opacity: 1;
  stroke: #0f1f3d;
  stroke-width: 1.5px;
}

.tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.4;
  opacity: 0;
  transform: translate3d(0, 0, 0);
  transition: opacity 0.2s ease;
  z-index: 5;
}

.tooltip.is-visible {
  opacity: 1;
}

.legend text {
  fill: var(--muted);
  font-size: 0.75rem;
}

.legend rect {
  rx: 4px;
  ry: 4px;
}

/* ========================================
   LEGEND ITEMS (Vertical List)
   ======================================== */
.legend-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: var(--text);
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.legend-item:hover {
  background: rgba(47, 111, 237, 0.08);
}

.legend-item--selected {
  background: rgba(47, 111, 237, 0.15);
  font-weight: 600;
}

.legend-item--hidden {
  display: none;
}

.legend-item--dimmed {
  opacity: 0.3;
}

.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ========================================
   DOT FILTERING STATES
   ======================================== */
.dot--dimmed {
  opacity: 0.15;
  pointer-events: none;
}

.dot--highlighted {
  opacity: 1 !important;
  stroke: #0f1f3d;
  stroke-width: 2px;
}

/* ========================================
  QUESTIONNAIRE
  ======================================== */
.questionnaire {
  display: grid;
  gap: 16px;
}

.q-section {
  background: var(--card);
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 12px;
}

.q-section h2 {
  margin: 0 0 6px;
  font-size: 0.9rem;
}

/* Progress bar */
.q-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.q-progress[hidden] {
  display: none;
}

.q-progress__bar {
  flex: 1;
  height: 6px;
  background: var(--grid);
  border-radius: 3px;
  overflow: hidden;
}

.q-progress__fill {
  height: 100%;
  width: 20%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.q-progress__label {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

/* Questionnaire step navigation */
.q-step {
  display: none;
}

.q-step--active {
  display: block;
  animation: fadeIn 0.3s ease;
}

.q-block--incomplete {
  border-color: #e04848;
  background: #fef5f5;
}

.q-incomplete-msg {
  color: #d32f2f;
  font-size: 0.78rem;
  font-weight: 600;
  margin: 6px 0 0;
}

.q-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--grid);
}

.q-nav .btn-primary {
  margin-left: auto;
}

.instruction {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.q-block {
  margin: 6px 0;
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 10px;
  background: #fcfdff;
}

.q-block legend {
  padding: 0 2px;
  font-weight: 600;
  font-size: 0.84rem;
}

.q-block label {
  display: block;
  margin: 4px 0;
  line-height: 1.35;
  font-size: 0.82rem;
}

.helper-text {
  margin: 2px 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.3;
}

.required {
  color: #9b1f1f;
}

.text-input,
.text-area {
  width: 100%;
  margin-top: 4px;
  border: 1px solid #c9d2e0;
  border-radius: 6px;
  padding: 7px 10px;
  font: inherit;
  font-size: 0.84rem;
  color: var(--text);
  background: #fff;
}

.text-input:focus,
.text-area:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.14);
}

.likert-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(36px, 1fr));
  gap: 4px;
}

.actions-row,
.submit-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:disabled {
  background: #9db5e9;
  cursor: not-allowed;
}

.btn-secondary {
  background: #e8eefb;
  color: #1f2a44;
}

.status-message {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.thank-you {
  background: var(--card);
  border: 1px solid var(--grid);
  border-radius: 12px;
  padding: 20px;
}

.thank-you h2 {
  margin-top: 0;
}

/* ========================================
   TUTORIAL OVERLAY
   ======================================== */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tutorial-overlay[hidden] {
  display: none;
}

.tutorial-overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.tutorial-callout {
  position: absolute;
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  max-width: 260px;
  font-size: 0.82rem;
  line-height: 1.45;
  z-index: 1001;
}

.tutorial-callout p {
  margin: 0;
}

.tutorial-callout__badge {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.tutorial-callout--chart {
  top: 50%;
  left: 35%;
  transform: translate(-50%, -50%);
}

.tutorial-callout--legend {
  top: 30%;
  left: 8%;
}

.tutorial-callout--questionnaire {
  top: 40%;
  right: 4%;
}

.tutorial-confirm {
  position: absolute;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1002;
  padding: 12px 40px;
  font-size: 1rem;
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */
@media (max-width: 1024px) {
  .page-content {
    grid-template-columns: 1fr;
  }

  .questionnaire-area {
    margin-top: 0;
    height: auto;
    max-height: none;
    overflow-y: visible;
  }

  .chart-layout {
    flex-direction: column;
  }

  .chart-sidebar {
    width: 100%;
    border-right: none;
    border-top: 1px solid var(--grid);
    padding-right: 0;
    padding-top: 24px;
    max-height: 400px;
  }

  .legend-container {
    max-height: 300px;
  }

  .chart {
    min-height: 500px;
  }
}

@media (max-width: 640px) {
  .chart-layout {
    padding: 16px;
  }

  .chart {
    min-height: 400px;
  }

  .legend-container {
    max-height: 250px;
  }

  .chart-controls {
    top: 8px;
    right: 8px;
    gap: 6px;
  }

  .zoom-btn,
  .reset-zoom-btn {
    padding: 6px 12px;
    font-size: 0.75rem;
  }

  .zoom-btn {
    min-width: 30px;
    padding: 6px 8px;
  }

  .q-section,
  .q-block {
    padding: 12px;
  }

  .likert-row {
    gap: 4px;
  }
}
