/* ============================================
 * datavis.css
 * Styles for the Data Visualization page
 * ============================================ */

:root {
  /* Data visualization specific colors */
  --text: var(--grayscale-900);
  --muted: var(--grayscale-600);
  --bg: #fff;
  --pill-bg: var(--grayscale-50);
  --pill-hover: var(--grayscale-100);
  --pill-border: var(--grayscale-200);
  
  /* Primary Color RGB values for p5.js sketch */
  --color-primary-rgb-r: 249;
  --color-primary-rgb-g: 119;
  --color-primary-rgb-b: 26;
  
  /* Active/Highlight color for visualizations */
  --clr-active-r: var(--color-primary-rgb-r);
  --clr-active-g: var(--color-primary-rgb-g);
  --clr-active-b: var(--color-primary-rgb-b);
  
  /* Background and neutral colors */
  --clr-bg: 247, 247, 247; /* Same as grayscale-50 for panel background */
  --clr-dots: 180, 180, 180;
  --clr-plates: 210, 210, 210;
  --clr-tile: 190, 190, 190;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
}

/* ===== HEADER STYLES ===== */
.datavis-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}

.header-right {
  display: flex;
  gap: 16px;
  align-items: center;
}

/* ===== MAIN CONTENT LAYOUT ===== */
.main-content {
  height: calc(100vh - 88px);
  display: flex;
  flex-direction: column;
  gap: 16px; /* 16px gap between content and bottom controls */
}

.content-container {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 0 24px;
  overflow: hidden; /* Prevent overflow */
}

/* ===== DETAIL PANEL (3/7 width) ===== */
.panel {
  flex: 0 0 calc(3/7 * 100% - 8px); /* 3/7 of container width minus half the gap */
  background: var(--grayscale-50);
  border-radius: 20px;
  padding-left: 24px;
  padding-right: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.panelScroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 40px;
  -ms-overflow-style: none;
  scrollbar-width: none;
  padding: 24px 0;
}

.panelScroll::-webkit-scrollbar {
  display: none;
}

/* ===== CANVAS AREA (4/7 width) ===== */
.canvasWrap {
  flex: 0 0 calc(4/7 * 100% - 8px); /* 4/7 of container width minus half the gap */
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: var(--grayscale-50); /* Same background as panel */
  border-radius: 20px;
  padding-right: 24px; /* Right margin */
  height: 100%;
}

.canvasWrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* ===== BOTTOM CONTROLS ===== */
.bottom-controls {
  display: flex;
  gap: 16px;
  padding: 0 24px 16px;
  box-sizing: border-box;
}

.bottom-controls-left {
  flex: 0 0 calc(3/7 * 100% - 8px); /* Same width as Detail Panel */
  display: flex;
  justify-content: space-between; /* Space between help button and clear button */
  align-items: center;
}

.bottom-controls-right {
  flex: 0 0 calc(4/7 * 100% - 8px); /* Same width as Canvas */
  display: flex;
  justify-content: flex-end; /* Align content to right edge */
  align-items: center;
}

.clearBtn {
  background: var(--color-primary);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 12px 24px;
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.2s ease;
}

.clearBtn.visible {
  opacity: 1;
  visibility: visible;
}

.clearBtn:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

.clearBtn:active {
  transform: translateY(0);
  background: var(--color-primary);
}

/* Help Button */
.help-btn {
  background: var(--grayscale-50);
  color: var(--grayscale-300);
  border: 0;
  border-radius: 100px;
  width: 48px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-family: var(--font-family);
  font-weight: var(--weight-normal);
  font-size: var(--text-2xl);
  line-height: var(--leading-normal);
}

.help-btn:hover {
  background: var(--grayscale-100);
  color: var(--grayscale-500);
  transform: translateY(-1px);
}

.help-btn:active {
  transform: translateY(0);
  background: var(--grayscale-100);
}

.help-icon {
  font-family: var(--font-family);
  font-weight: var(--weight-normal);
  font-size: var(--text-2xl);
  line-height: var(--leading-normal);
}

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

.zoom-step {
  background: var(--primary-50);
  color: var(--color-primary);
  border: 0;
  border-radius: 100px;
  padding: 10px 12px;
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  cursor: pointer;
  height: 48px;
  min-width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.zoom-step.active {
  background: var(--color-primary);
  color: var(--grayscale-50);
}

.zoom-step:hover:not(.active) {
  background: var(--primary-100);
}

/* ===== TITLE HEADER ===== */
.titleTop {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 8px;
  row-gap: 4px;
  margin: 0;
}

.titleTop h1 {
  margin: 0;
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  color: var(--grayscale-950);
}

/* Votes Header Button */
.votesHeaderBtn {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;

  display: inline-flex;
  align-items: baseline;
  gap: 4px;

  font-size: var(--text-xl);
  color: var(--grayscale-950);
  font-family: var(--font-family);
  font-weight: var(--weight-regular);

  flex-shrink: 0;
  text-align: right;
}

.votesHeaderBtn.right {
  margin-left: auto;
}

.topVotesNumber {
  font-weight: var(--weight-regular);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-family);
  font-size: var(--text-xl);
}

/* hover hint for interactivity */
.votesHeaderBtn:hover {
  color: var(--color-primary);
}
.votesHeaderBtn:hover .topVotesNumber {
  color: var(--color-primary);
  opacity: 1;
}

/* ACTIVE STATE */
.votesHeaderBtn.active {
  color: var(--grayscale-950);
}
.votesHeaderBtn.active .topVotesNumber {
  color: var(--grayscale-950);
}

/* ===== SECTIONS IN SIDEBAR ===== */
.section {
  margin-bottom: 0;
  overflow-x: hidden !important;
  width: 100%;
  box-sizing: border-box;
}

.sectionHead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin: 0 0 16px;
  overflow-x: hidden !important;
  gap: 8px;
}

.leftHead {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.titleLine {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  column-gap: 4px;
}

.sectionHead h3 {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-medium);
  color: var(--grayscale-950);
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  flex-shrink: 0;
  line-height: var(--leading-normal);
}

.count {
  opacity: 0.6;
}

/* Show All Button - using GlobalStyles.css */
.btn-show-all {
  background-color: transparent;
  color: var(--color-primary);
  padding: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  min-height: 24px;
  gap: 12px;
  display: inline-flex;
  align-items: center;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  font-family: var(--font-family);
}

.btn-show-all:hover {
  color: var(--color-primary);
  text-decoration: none;
}

.btn-show-all:active {
  color: var(--color-primary);
}

/* Toggle arrow rotation */
.toggle-arrow {
  transition: transform 0.3s ease;
}

/* Rotate arrow when button is expanded */
.btn-show-all[aria-expanded="true"] .toggle-arrow {
  transform: rotate(180deg);
}

/* ===== INDICATOR LIST ===== */
.indList {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: hidden !important;
  width: 100%;
  box-sizing: border-box;
}

.indItem {
  position: relative;
  display: flex;
  gap: 10px;
  align-items: baseline;
  cursor: pointer;
  padding: 4px 8px 4px 16px;
  border: none;
  margin: 2px 0;
  background: transparent;
  transition: background-color 120ms ease, opacity 120ms ease;
  overflow-x: hidden !important;
  color: var(--text);
}

.indItem::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: var(--grayscale-200);
}

/* state classes for clicked/related indicators */
.ind--selected::before,
.ind--affected::before {
  background: var(--color-primary);
}

.indItem * {
  pointer-events: none;
}

.indLabel {
  line-height: var(--leading-normal);
  color: var(--grayscale-950);
  word-break: break-word;
  /* Default: regular-base text */
  font-family: var(--font-family);
  font-weight: var(--weight-normal);
  font-size: var(--text-sm);
}

/* selected: Medium-base text, grayscale 950 */
.ind--selected .indLabel {
  font-weight: var(--weight-medium);
  color: var(--grayscale-950);
}

/* affected: Medium-base text, grayscale 950 */
.ind--affected .indLabel {
  font-weight: var(--weight-medium);
  color: var(--grayscale-950);
}

/* dimmed: regular-base text, grayscale 800 */
.ind--dimmed .indLabel {
  font-weight: var(--weight-normal);
  color: var(--grayscale-800);
}

/* hover: medium-base text, grayscale 950, background primary 100 */
.indItem:hover .indLabel {
  font-weight: var(--weight-medium);
  color: var(--grayscale-950);
}

.indItem:hover {
  background: var(--primary-100);
}

.indVotes {
  margin-left: auto;
  min-width: 26px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  /* Always regular-sm text */
  font-family: var(--font-family);
  font-weight: var(--weight-normal);
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  /* Default color: grayscale 950 */
  color: var(--grayscale-950);
}

/* selected: grayscale 950 */
.ind--selected .indVotes {
  color: var(--grayscale-950);
}

/* affected: grayscale 950 */
.ind--affected .indVotes {
  color: var(--grayscale-950);
}

/* dimmed: grayscale 800 */
.ind--dimmed .indVotes {
  color: var(--grayscale-800);
  opacity: 1;
}

/* hover: grayscale 950 */
.indItem:hover .indVotes {
  color: var(--grayscale-950);
}

.indItem * {
  pointer-events: none;
}

/* ===== PILLS ===== */
.pill {
  display: inline-block;
  padding: 4px 12px;
  margin: 6px 6px 0 0;
  border-radius: 999px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  color: var(--text);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease,
    color 120ms ease;
  max-width: 100%;
  /* text-medium-sm styling */
  font-family: var(--font-family);
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
}

/* Remove whitespace between inline-block pills */
#subPills, #catPills, #dimPills {
  font-size: 0;
  width: 100%;
  box-sizing: border-box;
}

#subPills .pill, #catPills .pill, #dimPills .pill {
  font-size: var(--text-sm);
}

  .pill:hover {
    background: var(--primary-50);
    border: 1px solid var(--primary-500) !important;
    color: var(--primary-500);
  }
.pill.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.pill.dim {
  opacity: 0.5;
}

.pill .pillCount {
  margin-left: 6px;
  opacity: 0.75;
  /* text-xs styling */
  font-size: var(--text-xs);
  font-weight: var(--weight-normal);
  line-height: var(--leading-tight);
  font-variant-numeric: tabular-nums;
}

/* highlight tint block behind whichever layer is selected */
.hl {
  position: relative;
  z-index: 0;
}

.hl::before {
  content: "";
  position: absolute;
  left: -16px;
  right: -16px;
  top: -12px;
  bottom: -12px;

  background: transparent; /* no fill */
  border: none; /* border removed */
  border-radius: 6px; /* tiny rounding so it feels intentional */

  pointer-events: none;
  z-index: -1;
}

/* Selected Layer badge in the canvas area */
.layerBadge {
  position: absolute;
  left: 16px;
  top: 32px;
  z-index: 30;
  color: var(--grayscale-600); /* same grey as sidebar titles */
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--font-family);
  background: none;
  padding: 0;
  margin: 0;
}

.layerBadge span {
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
}

.layerBadgeLabel {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--grayscale-600);
}

.layerBadgeValue {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--text);
  line-height: var(--leading-tight);
  word-break: break-word;
}

/* ==== Prevent nested scrollbars inside layer sections ==== */
#indicatorList,
#indWrap,
#subsWrap,
#catsWrap,
#dimsWrap,
#subPills,
#catPills,
#dimPills {
  overflow: visible !important;
  max-height: none !important;
}

.section {
  overflow: visible !important;
}

.panelScroll {
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

/* Hide all WebKit scrollbars inside children just in case */
#indicatorList::-webkit-scrollbar,
#indWrap::-webkit-scrollbar,
#subsWrap::-webkit-scrollbar,
#catsWrap::-webkit-scrollbar,
#dimsWrap::-webkit-scrollbar {
  display: none !important;
}

/* Add top margin to lists/pills for clarity */
#indicatorList,
#subPills,
#catPills,
#dimPills {
  margin-top: 4px;
}

/* === Cross-highlight from viz hover to sidebar === */
.indItem.hoverSync {
  background: rgba(249, 119, 26, 0.1);
  color: var(--color-primary) !important;

  /* border removed */
  border-radius: 6px;
}

/* make the little left bar also orange on hoverSync */
.indItem.hoverSync::before {
  background: var(--color-primary);
}

/* numbers on the right also go orange */
.indItem.hoverSync .indVotes {
  color: var(--color-primary) !important;
  opacity: 1;
}

/* pill hoverSync matches normal hover styling */
.pill.hoverSync {
  background: var(--primary-50);
  border: 1px solid var(--primary-500) !important;
  color: var(--primary-500);
}
.pill.hoverSync .pillCount {
  color: var(--primary-500);
  opacity: 0.75;
}

/* Orange outline around the "Votes" header when active */
.votesHeaderWrap {
  position: relative;
  display: inline-flex;
  border-radius: 6px;
  /* no border by default */
}

.votesHeaderWrap.hlHeader::before {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  top: -4px;
  bottom: -4px;

  background: transparent;
  border: none; /* border removed */
  border-radius: 6px;

  pointer-events: none;
  z-index: 0;
}

/* === HOVER SYNC STATE FOR THE "Votes 727" HEADER === */
.votesHeaderWrap.hoverSync::before {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  top: -4px;
  bottom: -4px;

  /* light orange fill like pills/rows on hover */
  background: rgba(249, 119, 26, 0.1);
  border: none; /* border removed */
  border-radius: 6px;

  pointer-events: none;
  z-index: 0;
}

/* also tint the text "Votes 727" itself orange when synced */
.votesHeaderWrap.hoverSync .votesHeaderBtn {
  color: var(--color-primary) !important;
}

.votesHeaderWrap.hoverSync .topVotesNumber {
  color: var(--color-primary) !important;
  opacity: 1 !important;
}

/* Remove old zoom button styles since it's now in bottom controls */
.zoomBtn {
  display: none;
}

/* ===== TOOLTIP ===== */
.tooltip {
  position: absolute;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(8px);
  color: var(--grayscale-900);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: var(--font-family);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  pointer-events: none;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  max-width: 300px;
  word-wrap: break-word;
}

.tooltip.show {
  opacity: 1;
  visibility: visible;
}

.tooltip.fade-out {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.tooltip-layer {
  font-weight: var(--weight-semibold);
  color: var(--primary-500);
}

.tooltip-content {
  color: var(--grayscale-900);
  font-weight: var(--weight-normal);
}

/* ===== HELP OVERLAY ===== */
.help-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.help-overlay.show {
  opacity: 1;
  visibility: visible;
}

.help-overlay-content {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: white;
  padding: 80px 24px 24px 24px;
  box-sizing: border-box;
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

.help-overlay.show .help-overlay-content {
  transform: scale(1);
}

.close-help-btn {
  position: absolute;
  top: 24px;
  right: 24px;
  background: transparent;
  border: none;
  color: var(--color-primary);
  font-family: var(--font-family);
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.close-help-btn:hover {
  transform: translateY(-1px);
}

.close-help-btn:active {
  transform: translateY(0);
}

.close-icon {
  width: 18px;
  height: 18px;
}

.help-image-container {
  width: 100%;
  height: 100%;
  background: var(--grayscale-50);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.help-image {
  height: 100%;
  width: auto;
  object-fit: contain;
  object-position: center;
}