/* ──────────────────────────────────────────────────────────
   Planning Workbench — Four-panel data visualization
   Lives inside #vizDrawerContent (Analytics drawer)
   ────────────────────────────────────────────────────────── */

/* ── CSS Custom Properties ─────────────────────────────── */
:root {
  --wb-text: #231F20;
  --wb-secondary: #444441;
  --wb-muted: #5F5E5A;
  --wb-border: #D3D1C7;
  --wb-surface: #F7F5F0;
  --wb-surface-alt: #F1EFE8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --wb-text: #C2C0B6;
    --wb-secondary: #6E6C65;
    --wb-muted: #6E6C65;
    --wb-border: rgba(255,255,255,0.1);
    --wb-surface: #1C1C1A;
    --wb-surface-alt: #252523;
  }
}

/* Explicit default (light) theme — overrides prefers-color-scheme:dark
   when the user has chosen a light theme but their OS is in dark mode */
[data-theme="default"] {
  --wb-text: #231F20;
  --wb-secondary: #444441;
  --wb-muted: #5F5E5A;
  --wb-border: #D3D1C7;
  --wb-surface: #F7F5F0;
  --wb-surface-alt: #F1EFE8;
}

/* Dark mode via data-theme attribute (overrides prefers-color-scheme) */
[data-theme="dark"] {
  --wb-text: #C2C0B6;
  --wb-secondary: #6E6C65;
  --wb-muted: #6E6C65;
  --wb-border: rgba(255,255,255,0.1);
  --wb-surface: #1C1C1A;
  --wb-surface-alt: #252523;
}

/* Instrument Paper — stark monochrome, high contrast, no warmth */
[data-theme="instrument-paper"] {
  --wb-text: #000000;
  --wb-secondary: #404040;
  --wb-muted: #808080;
  --wb-border: #b3b3b3;
  --wb-surface: #ffffff;
  --wb-surface-alt: #f5f5f5;
}

/* Pastel Mondrian — soft blue-gray tones, warm muted palette */
[data-theme="pastel-mondrian"] {
  --wb-text: #304c61;
  --wb-secondary: #708299;
  --wb-muted: #95a8bb;
  --wb-border: #d4dfe6;
  --wb-surface: #ffffff;
  --wb-surface-alt: #f2f6f9;
}

/* ── Stats Row ─────────────────────────────────────────── */
.wb-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.wb-stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px;
  background: var(--wb-surface-alt);
  border-radius: 8px;
  border: 0.5px solid var(--wb-border);
}

.wb-stat-value {
  font-size: 20px;
  font-weight: 500;
  color: var(--wb-text);
  line-height: 1.2;
}

.wb-stat-label {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--wb-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

/* ── Two-column grid for half-width panels ─────────────── */
.wb-grid-half {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

/* ── Full-width panels ─────────────────────────────────── */
.wb-panel-full {
  width: 100%;
  margin-top: 8px;
}

.wb-panel-full:first-of-type {
  margin-top: 0;
}

/* ── Panel Chrome ──────────────────────────────────────── */
.wb-panel {
  border: 0.5px solid var(--wb-border);
  border-radius: 10px;
  background: var(--wb-surface);
  overflow: hidden;
  position: relative;
  transition: all 0.2s ease;
}

.wb-panel-header {
  display: flex;
  align-items: center;
  padding: 7px 12px;
  background: var(--wb-surface-alt);
  gap: 8px;
  border-bottom: 0.5px solid var(--wb-border);
  min-height: 28px;
}

.wb-panel-title {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--wb-muted);
}

.wb-panel-meta {
  font-size: 9px;
  color: var(--wb-muted);
  opacity: 0.7;
}

.wb-panel-controls {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.wb-toggle-btn,
.wb-expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--wb-muted);
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.wb-toggle-btn:hover,
.wb-expand-btn:hover {
  opacity: 1;
  background: var(--wb-surface);
}

.wb-panel-body {
  padding: 10px;
  overflow-x: auto;
}

/* ── Expanded (overlay) state ──────────────────────────── */
.wb-expanded {
  position: fixed !important;
  top: 60px;
  left: 20px;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  margin-top: 0 !important;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.wb-expanded .wb-panel-header {
  flex-shrink: 0;
}

.wb-expanded .wb-panel-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;  /* required for flex child overflow to work */
}

/* ── Mobile close button (injected by JS into .wb-panel-header when expanded) ── */
.wb-mobile-close {
  display: none;
}

.wb-expanded .wb-mobile-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--wb-surface);
  border: 1px solid var(--wb-border);
  color: var(--wb-text);
  font-size: 18px;
  cursor: pointer;
  margin-left: auto;
  transition: background 0.12s, transform 0.12s;
}

.wb-expanded .wb-mobile-close:active {
  background: var(--wb-border);
  transform: scale(0.92);
}

/* ── Empty state ───────────────────────────────────────── */
.wb-empty {
  text-align: center;
  color: var(--wb-muted);
  font-size: 11px;
  padding: 20px;
}

/* ── Sankey ─────────────────────────────────────────────── */
#wbSankeyBody {
  min-height: 250px;
  position: relative;
}

#wbSankeyChart svg {
  display: block;
}

.wb-sankey-tooltip {
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  white-space: nowrap;
}

/* ── Bubble Matrix ──────────────────────────────────────── */
.wb-bubble-matrix {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.wb-bubble-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.wb-bubble-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
  flex: 1;
}

.wb-bubble-corner {
  min-width: 80px;
  flex: 0 0 80px;
}

.wb-bubble-stage {
  min-width: 80px;
  flex: 0 0 80px;
  justify-content: flex-end;
  padding-right: 8px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.wb-bubble-ch {
  font-size: 9px;
  font-weight: 500;
  color: var(--wb-muted);
  writing-mode: horizontal-tb;
  text-align: center;
  word-break: break-word;
  padding: 0 2px;
  line-height: 1.15;
}

.wb-bubble-data {
  position: relative;
}

.wb-bubble {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.wb-bubble:hover {
  transform: scale(1.15);
}

.wb-bubble-label {
  font-size: 9px;
  font-weight: 500;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* ── Donut Array ────────────────────────────────────────── */
.wb-donut-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.wb-donut-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.wb-donut-canvas {
  display: block;
}

.wb-donut-center {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.wb-donut-total {
  font-size: 16px;
  font-weight: 500;
  color: var(--wb-text);
}

.wb-donut-stage {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
  margin-top: 4px;
  text-transform: uppercase;
}

.wb-donut-legend {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}

.wb-donut-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  color: var(--wb-secondary);
}

.wb-legend-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

.wb-legend-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Stacked Bar ────────────────────────────────────────── */
.wb-stacked-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wb-stacked-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 24px;
}

.wb-stacked-label {
  width: 90px;
  flex-shrink: 0;
  text-align: right;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.wb-stacked-bar-container {
  flex: 1;
  height: 20px;
  display: flex;
  border-radius: 4px;
  overflow: hidden;
  background: var(--wb-surface-alt);
}

.wb-stacked-segment {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8.5px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 4px;
  transition: opacity 0.15s;
}

.wb-stacked-segment:hover {
  opacity: 0.85;
}

.wb-stacked-count {
  width: 30px;
  flex-shrink: 0;
  text-align: right;
  font-size: 10px;
  font-weight: 500;
  color: var(--wb-muted);
}

.wb-stacked-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 0.5px solid var(--wb-border);
}

.wb-stacked-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  color: var(--wb-secondary);
}

/* ── RESPONSIVE BREAKPOINTS ────────────────────────────── */

/* Narrow desktop (user tests at 687px) */
@media (max-width: 768px) {
  .wb-grid-half {
    grid-template-columns: 1fr;
  }
  .wb-donut-grid {
    grid-template-columns: 1fr 1fr;
  }
  .wb-stats-row {
    gap: 6px;
  }
  .wb-stat-value {
    font-size: 17px;
  }
  .wb-bubble-corner,
  .wb-bubble-stage {
    min-width: 64px;
    flex: 0 0 64px;
  }
  .wb-stacked-label {
    width: 72px;
  }

  /* ── Mobile expanded: full-viewport takeover ── */
  .wb-expanded {
    position: fixed !important;
    inset: 0;
    z-index: 1000;
    border-radius: 0;
    box-shadow: none;
    background: var(--wb-surface);
    padding: 0;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;  /* panel itself doesn't scroll — body does */
  }

  .wb-expanded .wb-panel-header {
    flex-shrink: 0;
    z-index: 5;
    background: var(--wb-surface-alt);
    padding: 10px 12px;
    min-height: 44px;
  }

  .wb-expanded .wb-panel-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    min-height: 0;  /* required for flex child overflow to work */
  }

  /* When any panel is expanded, hide siblings via JS-toggled class */
  .wb-panel.wb-hidden-by-expand,
  .wb-panel-full.wb-hidden-by-expand,
  .wb-grid-half.wb-hidden-by-expand,
  .wb-stats-row.wb-hidden-by-expand {
    display: none !important;
  }
}

/* Mobile: everything stacks, donuts go 1-column */
@media (max-width: 480px) {
  .wb-grid-half {
    grid-template-columns: 1fr;
  }
  .wb-donut-grid {
    grid-template-columns: 1fr;
  }
  .wb-stats-row {
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }
  .wb-stat-card {
    padding: 6px 4px;
  }
  .wb-stat-value {
    font-size: 15px;
  }
  .wb-stat-label {
    font-size: 8px;
  }
  .wb-panel-body {
    padding: 6px;
  }
  #wbSankeyBody {
    min-height: 140px;
  }
  .wb-bubble-cell {
    min-width: 32px;
    min-height: 32px;
  }
  .wb-bubble-corner,
  .wb-bubble-stage {
    min-width: 48px;
    flex: 0 0 48px;
    font-size: 8px;
  }
  .wb-stacked-label {
    width: 52px;
    font-size: 8px;
  }
  .wb-stacked-row {
    height: 18px;
  }
  .wb-stacked-bar-container {
    height: 14px;
  }
}
