/* Sell-business Monte Carlo widget styles.
 *
 * Loaded by the embed snippet at
 * priv/content/posts/should-you-sell-your-business.widget-embed.html.
 * Mirrors the search-fund sandbox styling, but applied to the
 * full four-chart widget (NPV histograms, persona/path matrix,
 * leverage heatmap, friction waterfall) plus its slider stack.
 *
 * All colours come from the design tokens defined in
 * assets/css/app.css :root (--ink, --ink-soft, --ink-faint,
 * --rule, --sky-*, --paper). No hardcoded hex outside the
 * heatmap / matrix continuous scales, which are declared as
 * CSS variables for portability. */

article.post .post-body .sb-widget {
  margin: 22px 0 36px;
}

/* Header strip — title + summary line for the loaded grid point. */
article.post .post-body .sb-widget .sb-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}

article.post .post-body .sb-widget .sb-head h3 {
  margin: 0;
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
}

article.post .post-body .sb-widget .sb-status {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-soft);
}

/* Slider stack — five controls in a row of compact pills. */
article.post .post-body .sb-widget .sb-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px 18px;
  margin-bottom: 22px;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
}

article.post .post-body .sb-widget .sb-control {
  display: grid;
  gap: 6px;
}

article.post .post-body .sb-widget .sb-control select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}

article.post .post-body .sb-widget .sb-control.sb-control--compact {
  max-width: 170px;
  justify-self: start;
}

article.post .post-body .sb-widget .sb-control label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
}

article.post .post-body .sb-widget .sb-control output {
  font-family: 'JetBrains Mono', monospace;
  color: var(--sky-700);
  white-space: nowrap;
}

article.post .post-body .sb-widget .sb-control input[type="range"] {
  width: 100%;
  accent-color: var(--sky-700);
}

/* "Not modeled" empty state for invalid grid combinations. */
article.post .post-body .sb-widget .sb-empty {
  margin: 12px 0 22px;
  padding: 14px 16px;
  border: 1px dashed var(--rule);
  border-radius: 8px;
  background: var(--paper);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}

article.post .post-body .sb-widget .sb-empty.is-hidden {
  display: none;
}

/* Chart blocks — one figure per chart, four total. */
article.post .post-body .sb-widget .sb-chart {
  margin: 0 0 28px;
}

article.post .post-body .sb-widget .sb-chart h4 {
  margin: 0 0 4px;
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

article.post .post-body .sb-widget .sb-chart .sb-chart-sub {
  margin: 0 0 12px;
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-soft);
}

article.post .post-body .sb-widget .sb-chart-body {
  width: 100%;
  min-height: 220px;
}

/* Per-chart minimum heights — reserve layout space so the page
 * doesn't jump as data loads in. The numbers match each chart's
 * SVG default height in mc-sell-business-charts.js. */
article.post .post-body .sb-widget .sb-chart-body.sb-fourup {
  min-height: 380px;
}
article.post .post-body .sb-widget .sb-chart-body.sb-matrix-grid {
  min-height: 220px;
}
article.post .post-body .sb-widget .sb-chart-body.sb-heatmap {
  min-height: 320px;
}
article.post .post-body .sb-widget .sb-chart-body.sb-waterfall-grid {
  min-height: 280px;
}

article.post .post-body .sb-widget .sb-chart-body svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Skeleton placeholder for chart bodies that haven't painted yet.
 * Subtle pulsing text — visible enough to read on mobile, quiet
 * enough to disappear once the real chart lands on top of it.
 * `grid-column: 1 / -1` makes it span the full width of any CSS Grid
 * parent (the matrix-grid and fourup chart bodies use grids); on
 * non-grid parents the property is harmlessly ignored. */
article.post .post-body .sb-widget .sb-skel {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: inherit;
  grid-column: 1 / -1;
  padding: 60px 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  background: var(--paper);
  border: 1px dashed var(--rule);
  border-radius: 6px;
  animation: sb-skel-pulse 1.6s ease-in-out infinite;
}

@keyframes sb-skel-pulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
  article.post .post-body .sb-widget .sb-skel {
    animation: none;
    opacity: 0.7;
  }
}

/* Visible per-chart error state — replaces blank space when a render
 * fails or its data file 404s / network-drops. The retry button calls
 * back into renderAll() so the user can recover without a full reload. */
article.post .post-body .sb-widget .sb-render-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 180px;
  grid-column: 1 / -1;
  padding: 24px 18px;
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-soft);
  text-align: center;
  background: var(--paper);
  border: 1px dashed var(--rule);
  border-radius: 6px;
}

article.post .post-body .sb-widget .sb-render-error__retry {
  appearance: none;
  -webkit-appearance: none;
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--sky-700);
  background: #fff;
  border: 1px solid var(--sky-700);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
}

article.post .post-body .sb-widget .sb-render-error__retry:hover,
article.post .post-body .sb-widget .sb-render-error__retry:focus-visible {
  background: var(--sky-700);
  color: #fff;
}

/* Chart 1: 2x2 grid of NPV histograms. */
article.post .post-body .sb-widget .sb-fourup {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

article.post .post-body .sb-widget .sb-fourup .sb-fourup-cell {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px 12px;
  background: var(--paper);
}

article.post .post-body .sb-widget .sb-fourup .sb-fourup-cell h5 {
  margin: 0 0 2px;
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

article.post .post-body .sb-widget .sb-fourup .sb-fourup-stats {
  margin: 0 0 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

/* Chart 2: persona x path matrix. */
article.post .post-body .sb-widget .sb-matrix-grid {
  display: grid;
  grid-template-columns: 92px repeat(4, minmax(0, 1fr));
  gap: 4px;
}

article.post .post-body .sb-widget .sb-matrix-grid .sb-matrix-h {
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
  padding: 6px 4px;
}

article.post .post-body .sb-widget .sb-matrix-grid .sb-matrix-row-label {
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 11.5px;
  color: var(--ink);
  font-weight: 600;
  display: flex;
  align-items: center;
  padding: 0 8px 0 0;
}

article.post .post-body .sb-widget .sb-matrix-grid .sb-matrix-cell {
  /* Use flex column instead of grid place-items: center. iOS Safari has
   * been observed to leave grid items inside another grid invisible —
   * the cell takes its grid track size but the inline-styled spans
   * inside paint at zero size. Flex centering is the lowest-common-
   * denominator path that all WebKit versions handle reliably. */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  padding: 6px 4px;
  line-height: 1.25;
  /* Force a new stacking context so the cell paints above any
   * sibling row that ended up at a higher z-index by accident. */
  position: relative;
  z-index: 1;
}

article.post .post-body .sb-widget .sb-matrix-grid .sb-matrix-cell.is-active-row {
  outline: 2px solid var(--sky-700);
  outline-offset: -2px;
}

article.post .post-body .sb-widget .sb-matrix-grid .sb-matrix-row-label.is-active {
  color: var(--sky-700);
}

article.post .post-body .sb-widget .sb-matrix-grid .sb-matrix-cell.is-missing {
  background: var(--paper);
  border: 1px dashed var(--rule);
  color: var(--ink-faint);
  font-weight: 400;
}

/* Chart 4: friction waterfall — three columns side-by-side. */
article.post .post-body .sb-widget .sb-waterfall-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

article.post .post-body .sb-widget .sb-waterfall-grid .sb-waterfall-col {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px 12px;
  background: var(--paper);
}

article.post .post-body .sb-widget .sb-waterfall-grid .sb-waterfall-col h5 {
  margin: 0 0 8px;
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
}

/* Friction-term controls — second row of toggles below the main slider stack. */
article.post .post-body .sb-widget .sb-friction-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 16px;
  margin: 18px 0 22px;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
}

article.post .post-body .sb-widget .sb-friction-control {
  display: grid;
  gap: 5px;
}

article.post .post-body .sb-widget .sb-friction-control label {
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
}

article.post .post-body .sb-widget .sb-friction-control select,
article.post .post-body .sb-widget .sb-friction-control input[type="checkbox"] {
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 12px;
}

article.post .post-body .sb-widget .sb-friction-control select {
  padding: 4px 6px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}

/* Friction toggle gets its own thinner heading. */
article.post .post-body .sb-widget .sb-section-eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 22px 0 6px;
}

/* Heatmap legend strip. */
article.post .post-body .sb-widget .sb-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--ink-soft);
}

article.post .post-body .sb-widget .sb-legend .sb-legend-bar {
  flex: 1;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    #a23934 0%,
    #d4a85a 35%,
    #e6d8a8 50%,
    #b6c987 65%,
    #4d7a36 100%
  );
  border: 1px solid var(--rule);
}

@media (max-width: 720px) {
  article.post .post-body .sb-widget {
    margin: 18px 0 30px;
  }
  article.post .post-body .sb-widget .sb-fourup {
    grid-template-columns: 1fr;
    /* Single-column on mobile means each cell renders ~full width;
     * the JS is designed for ~360px cells, so let the cells size
     * naturally without our 2-up grid math. */
  }
  article.post .post-body .sb-widget .sb-waterfall-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  article.post .post-body .sb-widget .sb-matrix-grid {
    grid-template-columns: 64px repeat(4, minmax(0, 1fr));
    gap: 3px;
    font-size: 10px;
  }
  article.post .post-body .sb-widget .sb-matrix-grid .sb-matrix-cell {
    min-height: 50px;
    padding: 4px 2px;
    font-size: 10px;
  }
  article.post .post-body .sb-widget .sb-matrix-grid .sb-matrix-h {
    font-size: 10px;
    padding: 4px 2px;
  }
  article.post .post-body .sb-widget .sb-matrix-grid .sb-matrix-row-label {
    font-size: 10.5px;
    padding-right: 4px;
  }
  article.post .post-body .sb-widget .sb-controls,
  article.post .post-body .sb-widget .sb-friction-controls {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    padding: 12px 14px;
  }
  /* Native select pickers on iOS render 16px+ to avoid auto-zoom on
   * focus. Lock to 16px so tapping a control doesn't pan the post. */
  article.post .post-body .sb-widget select {
    font-size: 16px;
  }
  /* Reserve a touch larger min-height for charts on mobile so the
   * page settles in one pass instead of jumping when each chart
   * paints. */
  article.post .post-body .sb-widget .sb-chart-body.sb-fourup {
    min-height: 720px; /* four cells stacked, 180px chart + ~50px stats each */
  }
  article.post .post-body .sb-widget .sb-chart-body.sb-heatmap {
    min-height: 260px;
  }
  article.post .post-body .sb-widget .sb-chart-body.sb-waterfall-grid {
    min-height: 840px; /* three columns stacked at 280px each */
  }
}
