/* ============================================================================
   treemap.css — chart-view toggle (pie ↔ treemap), color-mode chips, treemap
   container, hover tooltip card, prominent zoom-out chip bar.
   Loaded by index.html. Theme-aware via body.dark-mode overrides at the end.
   Mobile overrides live in css/foliolytic-mobile-2026.css.
   2026-05-08: rewrote for ECharts treemap (replaced chartjs-chart-treemap).
============================================================================ */

/* --- Section header row that wraps title + toggle controls -------------- */
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.section-title-row > .section-title {
  margin: 0;
}

/* ------------------------------------------------------------------------
   Chart controls — owner's 2026-05-08 redesign request: previous transparent
   pill blended into chart backgrounds, controls were "barely visible" once
   chart colors got busy. NEW design: solid frosted pill, subtle drop-shadow
   to lift it above the chart, vibrant blue gradient on active state.
   Pattern is segmented-control like macOS/iOS Settings or Vercel/Linear UI.
   ------------------------------------------------------------------------ */
.chart-view-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- Pie/treemap segmented control -------------------------------------- */
.chart-view-toggle {
  display: inline-flex;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
  position: relative;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px -2px rgba(15, 23, 42, 0.06);
}
.chart-view-toggle .cv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  border-radius: 6px;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  padding: 0;
  position: relative;
}
.chart-view-toggle .cv-btn:hover {
  background: rgba(15, 23, 42, 0.05);
  color: #1e293b;
}
.chart-view-toggle .cv-btn.active {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.4), 0 0 0 0.5px rgba(176, 200, 244, 0.12) inset;
}
.chart-view-toggle .cv-btn.active:hover {
  background: linear-gradient(180deg, #4f8df8 0%, #2f6fe0 100%);
  color: #ffffff;
}
.chart-view-toggle .cv-btn:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}
.chart-view-toggle .cv-btn svg {
  display: block;
}

/* On-hover tooltip for the pie/treemap toggle — explains what each icon does. */
.cv-tooltip,
.cm-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #131d33;
  color: #ffffff;
  padding: 7px 11px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
  white-space: normal;
  width: max-content;
  max-width: 220px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease 0.15s, visibility 0.18s ease 0.15s;
  pointer-events: none;
  z-index: 9999;
}
.cv-tooltip::after,
.cm-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #131d33;
}
.chart-view-toggle .cv-btn:hover .cv-tooltip,
.cm-chip:hover .cm-tip {
  opacity: 1;
  visibility: visible;
}

/* --- Color-mode chips (Sector / Performance / Asset) -------------------- */
.chart-color-modes {
  display: inline-flex;
  gap: 0;
  padding: 3px;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 9px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px -2px rgba(15, 23, 42, 0.06);
}
.chart-color-modes[hidden] { display: none; }
.cm-chip {
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
  position: relative;
  letter-spacing: -0.005em;
}
.cm-chip:hover {
  background: rgba(15, 23, 42, 0.05);
  color: #1e293b;
}
.cm-chip.active {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.4), 0 0 0 0.5px rgba(176, 200, 244, 0.12) inset;
}
.cm-chip.active:hover {
  background: linear-gradient(180deg, #4f8df8 0%, #2f6fe0 100%);
  color: #ffffff;
}
.cm-chip:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; }

/* --- Treemap container -------------------------------------------------- */
.treemap-container {
  position: relative;
  width: 100%;
  /* Bumped from 480px → 520px to give the breadcrumb chip-row + zoom-out chip-bar
     enough vertical room without compressing the actual treemap. */
  min-height: 460px;
  height: 520px;
  max-height: 72vh;
  background: transparent;
}
.treemap-container[hidden] { display: none; }
/* ECharts injects its own canvas-stack; ensure it spans the container. */
.treemap-container > div[_echarts_instance_] {
  width: 100% !important;
  height: 100% !important;
}

/* Empty-state overlay if container is rendered with no holdings */
.treemap-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
}

/* ----------------------------------------------------------------------
   Prominent zoom-out chip bar — owner's bug #6 fix. When fully zoomed in,
   show a row of clear "step out" chips above the chart. The breadcrumb at
   the top of ECharts is already there but small; this bar is the "more
   prominent menu" the owner asked for.
   ---------------------------------------------------------------------- */
.tm-zoomout-bar {
  position: absolute;
  top: 36px;       /* below the breadcrumb */
  right: 12px;
  display: inline-flex;
  gap: 8px;
  z-index: 5;
  flex-wrap: wrap;
  pointer-events: auto;
}
.tm-zoomout-bar[hidden] { display: none; }
.tm-chip {
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.96);
  color: #1e293b;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}
.tm-chip:hover {
  background: rgba(59, 130, 246, 0.06);
  border-color: rgba(59, 130, 246, 0.5);
  color: #2563eb;
}
.tm-chip:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}
.tm-chip-detail {
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.tm-chip-detail:hover {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  border-color: transparent;
}

/* ----------------------------------------------------------------------
   Tooltip card — wrapped inside ECharts tooltip <div> so we use a marker
   class .echarts-tip plus the existing .treemap-tooltip. ECharts already
   positions; we provide the visual.
   ---------------------------------------------------------------------- */
.treemap-tooltip {
  /* When inside ECharts, ECharts owns positioning — keep position:static */
  min-width: 240px;
  max-width: 340px;
  padding: 12px 14px;
  background: #ffffff;
  border: 1px solid #e8e6e1;
  border-radius: 10px;
  box-shadow: 0 12px 36px -8px rgba(15,23,42,0.18), 0 4px 8px -2px rgba(15,23,42,0.08);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 12px;
  color: #1e293b;
  -webkit-font-smoothing: antialiased;
  text-align: left;
}
.treemap-tooltip.echarts-tip {
  /* Inside ECharts tooltip wrapper — already opaque-bg cleared via formatter */
  position: static;
  pointer-events: none;
}
/* Keep the legacy non-ECharts tooltip behavior just in case it's reused */
.treemap-tooltip:not(.echarts-tip) {
  position: fixed;
  z-index: 99998;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.treemap-tooltip:not(.echarts-tip).visible { opacity: 1; }

.treemap-tooltip .tt-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.treemap-tooltip .tt-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}
.treemap-tooltip .tt-ticker {
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: -0.01em;
}
.treemap-tooltip .tt-name {
  font-size: 11.5px;
  font-weight: 500;
  color: #64748b;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.treemap-tooltip .tt-sector {
  font-size: 10.5px;
  font-weight: 500;
  color: #94a3b8;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.treemap-tooltip hr {
  border: none;
  height: 1px;
  background: #f1f5f9;
  margin: 8px 0;
}
.treemap-tooltip .tt-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 14px;
  font-size: 11.5px;
}
.treemap-tooltip .tt-grid > span:nth-child(odd) {
  color: #64748b;
}
.treemap-tooltip .tt-mono {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #0f172a;
  text-align: right;
}
.treemap-tooltip .tt-pos { color: #16a34a; }
.treemap-tooltip .tt-neg { color: #dc2626; }

/* Lifetime row (added 2026-05-25 per owner video walkthrough). Sits right
   under Gain/Loss + Annualized to surface realized P&L + dividends without
   bloating the tooltip. The label uses a downward-corner arrow (↳) so the
   eye reads it as a child continuation of the row above. Values still take
   the .tt-pos / .tt-neg colors so green/red parity is preserved, but at
   0.72 opacity + smaller size to feel like a secondary detail. */
.treemap-tooltip .tt-life-label {
  font-size: 10.5px;
  font-weight: 500;
  color: #94a3b8;
  font-style: italic;
  padding-left: 12px;
  position: relative;
}
.treemap-tooltip .tt-life-label::before {
  content: "↳";
  position: absolute;
  left: 0;
  top: 0;
  font-style: normal;
  opacity: 0.55;
}
.treemap-tooltip .tt-life-val {
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  opacity: 0.72;
  text-align: right;
}

.treemap-tooltip .tt-foot {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #f1f5f9;
  font-size: 10.5px;
  font-weight: 500;
  color: #94a3b8;
  text-align: center;
}

/* Sector-cell tooltip's "TOP HOLDINGS" mini-list (cardzgroup parity). */
.treemap-tooltip .tt-mini-title {
  font-size: 9.5px;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
  margin-top: 4px;
}
.treemap-tooltip .tt-mini-grid {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 3px 12px;
  font-size: 11px;
}
.treemap-tooltip .tt-mini-symbol {
  font-weight: 600;
  color: #1e293b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 130px;
}
.treemap-tooltip .tt-mini-val {
  color: #475569;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.treemap-tooltip .tt-mini-pct {
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 30px;
}

/* ============================================================================
   Dark mode overrides — hooks into existing body.dark-mode pattern.
============================================================================ */
/* Dark mode — frosted dark pill, vivid blue active state, strong shadow.
   Owner's 2026-05-08 redesign: previous styling was too transparent and
   blended into vibrant chart colors below. New design uses an opaque slate
   pill so it's always readable regardless of what's painted underneath. */
body.dark-mode .chart-view-toggle,
body.dark-mode .chart-color-modes {
  background: rgba(8, 13, 26, 0.96);
  border-color: rgba(176, 200, 244, 0.10);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45), 0 8px 24px -4px rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
body.dark-mode .chart-view-toggle .cv-btn { color: #cbd5e1; }
body.dark-mode .chart-view-toggle .cv-btn:hover {
  background: rgba(176, 200, 244, 0.08);
  color: #f1f5f9;
}
body.dark-mode .chart-view-toggle .cv-btn.active {
  background: linear-gradient(180deg, #4f8df8 0%, #2563eb 100%);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.16) inset;
}
body.dark-mode .chart-view-toggle .cv-btn.active:hover {
  background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%);
}

body.dark-mode .cm-chip {
  color: #cbd5e1;
  background: transparent;
  border: none;
}
body.dark-mode .cm-chip:hover {
  background: rgba(176, 200, 244, 0.08);
  color: #f1f5f9;
}
body.dark-mode .cm-chip.active {
  background: linear-gradient(180deg, #4f8df8 0%, #2563eb 100%);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.16) inset;
}
body.dark-mode .cm-chip.active:hover {
  background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%);
}

body.dark-mode .tm-chip {
  background: rgba(15, 23, 42, 0.92);
  border-color: rgba(176, 200, 244, 0.10);
  color: #e2e8f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
body.dark-mode .tm-chip:hover {
  background: rgba(96, 165, 250, 0.18);
  border-color: rgba(96, 165, 250, 0.5);
  color: #93c5fd;
}
body.dark-mode .tm-chip-detail {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
}
body.dark-mode .tm-chip-detail:hover {
  background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%);
  color: #ffffff;
}

body.dark-mode .treemap-empty { color: #64748b; }

body.dark-mode .treemap-tooltip {
  background: rgba(15, 23, 42, 0.97);
  border-color: rgba(176, 200, 244, 0.08);
  color: #f1f5f9;
  box-shadow: 0 16px 40px -8px rgba(0,0,0,0.6), 0 4px 8px -2px rgba(0,0,0,0.4);
}
body.dark-mode .treemap-tooltip .tt-ticker { color: #f8fafc; }
body.dark-mode .treemap-tooltip .tt-name { color: #94a3b8; }
body.dark-mode .treemap-tooltip .tt-sector { color: #64748b; }
body.dark-mode .treemap-tooltip hr { background: rgba(176, 200, 244, 0.06); }
body.dark-mode .treemap-tooltip .tt-grid > span:nth-child(odd) { color: #94a3b8; }
body.dark-mode .treemap-tooltip .tt-mono { color: #f8fafc; }
body.dark-mode .treemap-tooltip .tt-pos { color: #4ade80; }
body.dark-mode .treemap-tooltip .tt-neg { color: #f87171; }
body.dark-mode .treemap-tooltip .tt-life-label { color: #64748b; }
body.dark-mode .treemap-tooltip .tt-life-val { opacity: 0.78; }
body.dark-mode .treemap-tooltip .tt-foot {
  border-top-color: rgba(176, 200, 244, 0.06);
  color: #64748b;
}
body.dark-mode .treemap-tooltip .tt-mini-title { color: #64748b; }
body.dark-mode .treemap-tooltip .tt-mini-symbol { color: #f1f5f9; }
body.dark-mode .treemap-tooltip .tt-mini-val { color: #cbd5e1; }
body.dark-mode .treemap-tooltip .tt-mini-pct { color: #64748b; }
