/* ==========================================================================
   Seizure Management course figures (components/seizure-figures.js)

   Built on the shared figure frame and tokens in teaching-figures.css
   (.brf, --viz-*): one frame per figure, solid hairline axes, series colors
   on marks only. Text keeps the ink colors; where a label sits on a colored
   segment the segment is a light tint of the series color with a solid edge,
   so the label stays readable in both themes. The charts are HTML, so their
   labels keep a legible size on a phone, and each one reflows to its own
   width (container queries), not the window's.
   ========================================================================== */

.sf { container-type: inline-size; }
.sf .sf-title { margin-bottom: 0.65rem; font-size: 0.9375rem; }
.sf .brf-note { max-width: none; }
.sf-small { margin: 0.4rem 0 0; font-size: 0.8125rem; line-height: 1.45; color: var(--text-secondary); max-width: none; }

/* series swatches and tints */
.sf-legend { margin-bottom: 0.85rem; }
.sf-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--viz-1); }
.sf-swatch.sf-c2, .sf-fill.sf-c2 { background: var(--viz-2); }
.sf-swatch.sf-c3, .sf-fill.sf-c3 { background: var(--viz-3); }
.sf-swatch.sf-ctl, .sf-fill.sf-ctl { background: var(--viz-ctl); }
.sf-swatch.sf-sw-mol { border-radius: 50%; background: var(--viz-1); }
.sf-swatch.sf-sw-free { border-radius: 50%; background: var(--viz-2); }

.sf {
  --sf-acute: color-mix(in srgb, var(--viz-2) 26%, var(--surface-1));
  --sf-remote: color-mix(in srgb, var(--viz-1) 22%, var(--surface-1));
  --sf-wait: color-mix(in srgb, var(--viz-ctl) 45%, var(--surface-1));
  --sf-treat: color-mix(in srgb, var(--viz-2) 30%, var(--surface-1));
  --sf-harm: color-mix(in srgb, #d03b3b 52%, var(--surface-1));
  --sf-harm-edge: #c23434;
}

body.dark .sf { --sf-harm: color-mix(in srgb, #e66767 62%, var(--surface-1)); --sf-harm-edge: #f08a8a; }

.sf-swatch.sf-c-acute, .sf-tl-seg.sf-c-acute { background: var(--sf-acute); box-shadow: inset 0 0 0 1.5px var(--viz-2); }
.sf-swatch.sf-c-remote, .sf-tl-seg.sf-c-remote { background: var(--sf-remote); box-shadow: inset 0 0 0 1.5px var(--viz-1); }
.sf-tl-seg.sf-c-none { background: transparent; box-shadow: inset 0 0 0 1px var(--viz-grid); }
.sf-swatch.sf-c-wait, .sf-tl-seg.sf-c-wait { background: var(--sf-wait); box-shadow: inset 0 0 0 1.5px var(--viz-ctl); }
.sf-swatch.sf-c-treat, .sf-tl-seg.sf-c-treat { background: var(--sf-treat); box-shadow: inset 0 0 0 1.5px var(--viz-2); }
.sf-swatch.sf-c-harm, .sf-tl-seg.sf-c-harm { background: repeating-linear-gradient(135deg, transparent 0 5px, rgba(255, 255, 255, 0.22) 5px 7px), var(--sf-harm); box-shadow: inset 0 0 0 1.5px var(--sf-harm-edge); }
.sf-tl-seg.sf-c-fuzzy { background: linear-gradient(90deg, var(--sf-wait), var(--sf-treat)); }
.sf-tl-seg.sf-c-unknown { background: linear-gradient(90deg, var(--sf-treat) 40%, transparent); box-shadow: none; border-top: 1.5px solid var(--viz-2); border-bottom: 1.5px solid var(--viz-2); }

/* ---------------------------------------------------- horizontal bars */
.sf-bars { display: grid; gap: 0.4rem; }
.sf-row { display: grid; grid-template-columns: minmax(8rem, 15rem) minmax(0, 1fr) 4.2rem; gap: 0.75rem; align-items: center; }
.sf-label { display: grid; gap: 0.05rem; font-size: 0.875rem; font-weight: 600; line-height: 1.3; color: var(--text-color); }
.sf-label small { font-size: 0.75rem; font-weight: 400; color: var(--text-secondary); }
.sf-track { position: relative; height: 16px; border-radius: 4px; background: var(--viz-band); box-shadow: inset 1px 0 0 var(--viz-axis); }
.sf-fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 0 4px 4px 0; background: var(--viz-1); }
.sf-fill.sf-range { border-radius: 4px; }
.sf-fill.sf-ghost { background: color-mix(in srgb, var(--viz-1) 22%, transparent); border-radius: 0; }
.sf-val { font-size: 0.875rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-color); white-space: nowrap; }
.sf-ref { position: absolute; top: -5px; bottom: -5px; width: 0; border-left: 2px dashed var(--text-color); z-index: 1; }
.sf-ref-key { display: flex; align-items: center; gap: 0.5rem; margin: 0.55rem 0 0; font-size: 0.8125rem; line-height: 1.4; color: var(--text-secondary); max-width: none; }
.sf-ref-swatch { flex: none; width: 0; height: 16px; border-left: 2px dashed var(--text-color); }
.sf-bars-group { margin: 0.7rem 0 0.1rem; font-size: 0.8125rem; font-weight: 700; line-height: 1.35; color: var(--text-color); max-width: none; }
.sf-bars-group:first-child { margin-top: 0; }
.sf-bars-compact .sf-row { grid-template-columns: minmax(7rem, 12rem) minmax(0, 1fr) 4.2rem; }
.sf-bars-compact .sf-track { height: 13px; }

/* tick labels under a track, placed by percent */
.sf-axis { margin-top: 0.1rem; }
.sf-ticks { position: relative; height: 1.1rem; font-size: 0.75rem; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.sf-ticks span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.sf-ticks span:first-child { transform: none; }
.sf-ticks span[style="left:100%"] { transform: translateX(-100%); }

@container (max-width: 30rem) {
  .sf-row, .sf-bars-compact .sf-row { grid-template-columns: minmax(0, 1fr) 3.6rem; gap: 0.2rem 0.6rem; }
  .sf-label { grid-column: 1 / -1; }
  .sf-axis .sf-label { display: none; }
  /* short labels stay beside their bars */
  .sf-bars-inline .sf-row, .sf-bars-inline.sf-bars-compact .sf-row { grid-template-columns: 5.6rem minmax(0, 1fr) 3.6rem; gap: 0.5rem; }
  .sf-bars-inline .sf-label { grid-column: auto; }
  .sf-bars-inline .sf-axis .sf-label { display: block; }
  .sf-bars-inline .sf-ticks span:nth-child(even) { display: none; }
}

/* ---------------------------------------------------- timelines */
.sf-tl + .sf-tl { margin-top: 1.1rem; }
.sf-tl-title { margin: 0 0 0.35rem; font-size: 0.875rem; font-weight: 600; line-height: 1.35; color: var(--text-color); max-width: none; }
.sf-tl-track { position: relative; height: 2.6rem; }
.sf-tl-seg { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; justify-content: flex-start; overflow: hidden; border-radius: 6px; padding: 0 0.5rem; }
.sf-tl-seg > span { font-size: 0.75rem; font-weight: 600; line-height: 1.15; text-align: left; color: var(--text-color); }
.sf-tl-mark { position: absolute; top: -6px; bottom: -6px; width: 0; border-left: 2px dashed var(--text-color); }
.sf-tl-ticks { margin-top: 0.3rem; }
.sf-tl-callout { display: flex; align-items: flex-start; gap: 0.5rem; margin: 0.25rem 0 0; font-size: 0.8125rem; line-height: 1.4; color: var(--text-secondary); max-width: none; }
.sf-tl-callout-key { flex: none; width: 0; height: 1.1rem; border-left: 2px dashed var(--text-color); }

/* ---------------------------------------------------- status clocks */
.sf-clock-rows { display: grid; gap: 0.35rem; }
.sf-clock-row { padding-bottom: 0.25rem; }
.sf-clock-name { margin: 0 0 1.55rem; font-size: 0.875rem; font-weight: 700; line-height: 1.3; color: var(--text-color); max-width: none; }
.sf-clock-track { position: relative; height: 1.6rem; }
.sf-clock-t { position: absolute; bottom: calc(100% + 4px); transform: translateX(-50%); font-size: 0.75rem; font-weight: 700; white-space: nowrap; color: var(--text-color); }
.sf-clock-t::after { content: ""; position: absolute; left: 50%; top: 100%; height: calc(1.6rem + 8px); border-left: 2px solid var(--text-color); }
.sf-clock-t.sf-clock-unknown { font-weight: 600; color: var(--text-secondary); }
.sf-clock-t.sf-clock-unknown::after { display: none; }
.sf-clock-ticks { margin-top: 0.2rem; }

/* ---------------------------------------------------- first-line cards */
.sf-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
@container (max-width: 34rem) { .sf-cards { grid-template-columns: minmax(0, 1fr); } }
.sf-card { display: grid; align-content: start; gap: 0.45rem; padding: 0.8rem 0.85rem 0.85rem; border: 1px solid var(--border-color); border-radius: var(--radius-sm); background: var(--surface-2); }
.sf-card p { margin: 0; max-width: none; }
.sf-card-type { font-size: 0.9375rem; font-weight: 700; line-height: 1.3; color: var(--text-color); }
.sf-card-first { display: grid; gap: 0.1rem; font-size: 0.9375rem; font-weight: 600; line-height: 1.35; color: var(--text-color); }
.sf-card-first span, .sf-card-worse span { font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-secondary); }
.sf-card-then { font-size: 0.8125rem; line-height: 1.45; color: var(--text-secondary); }
.sf-card-worse { display: grid; gap: 0.1rem; padding-left: 0.6rem; border-left: 3px solid var(--viz-2); font-size: 0.8125rem; line-height: 1.45; color: var(--text-color); }

/* ---------------------------------------------------- free level */
.sf-two { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.25rem 1.5rem; align-items: start; }
.sf-two.sf-stack { grid-template-columns: minmax(0, 1fr); gap: 1.4rem; }
.sf-col-head { margin: 0 0 0.55rem; font-size: 0.875rem; font-weight: 700; line-height: 1.35; color: var(--text-color); max-width: none; }
.sf-jars { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.sf-jar { margin: 0; }
.sf-jar-title { margin: 0 0 0.3rem; font-size: 0.8125rem; font-weight: 600; line-height: 1.3; color: var(--text-color); max-width: none; }
@container (max-width: 30rem) { .sf-jar-title { min-height: 2.6em; } }
.sf-kinetics .brf-tick, .sf-kinetics .sf-pht-label { font-size: 12.5px; }
.sf-jar figcaption { margin-top: 0.3rem; font-size: 0.8125rem; line-height: 1.4; color: var(--text-secondary); }
.sf-jar-box { fill: var(--viz-band); stroke: var(--viz-axis); stroke-width: 1.5; }
.sf-alb { fill: color-mix(in srgb, var(--viz-ctl) 55%, var(--surface-1)); stroke: var(--viz-ctl); stroke-width: 1.5; }
.sf-mol { fill: var(--viz-1); stroke: var(--surface-1); stroke-width: 1.5; }
.sf-mol-free { fill: var(--viz-2); }
.sf-two .sf-legend { margin: 0.6rem 0 0; }
.sf-range-band { fill: var(--viz-band); }
.sf-line-ref { fill: none; stroke: var(--viz-axis); stroke-width: 2; stroke-dasharray: 5 4; }
.sf-line-pht { fill: none; stroke: var(--viz-2); stroke-width: 3; stroke-linecap: round; }
.sf-pht-label { font-size: 12px; font-weight: 700; fill: var(--text-color); }
.sf-step { fill: none; stroke: var(--text-color); stroke-width: 1.4; stroke-dasharray: 3 3; }

@container (max-width: 40rem) {
  .sf-two { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------------------------------------------- interactions */
.sf-inter-list { display: grid; gap: 0.6rem; }
.sf-inter-row { display: grid; grid-template-columns: minmax(10rem, 14rem) 4.5rem minmax(0, 1fr); gap: 0.75rem; align-items: center; padding: 0.7rem 0.8rem; border: 1px solid var(--border-color); border-radius: var(--radius-sm); background: var(--surface-2); }
.sf-inter-from { display: grid; gap: 0.15rem; font-size: 0.9375rem; line-height: 1.3; }
.sf-inter-from strong { color: var(--text-color); }
.sf-inter-from span { font-size: 0.8125rem; color: var(--text-secondary); }
.sf-inter-arrow { position: relative; height: 2rem; }
.sf-inter-arrow::before { content: ""; position: absolute; left: 0; right: 6px; top: 60%; border-top: 2px solid var(--text-secondary); }
.sf-inter-arrow::after { content: ""; position: absolute; right: 0; top: calc(60% - 5px); border: 6px solid transparent; border-left: 8px solid var(--text-secondary); border-right: 0; }
.sf-inter-arrow span { position: absolute; left: 0; right: 8px; top: 0; font-size: 0.75rem; font-weight: 700; text-align: center; color: var(--text-secondary); }
.sf-inter-to { display: grid; gap: 0.2rem; margin: 0; padding: 0; list-style: none; font-size: 0.875rem; line-height: 1.4; color: var(--text-color); }
.sf-inter-to li { display: flex; gap: 0.45rem; align-items: baseline; }
.sf-inter-to i { flex: none; font-size: 0.75rem; color: var(--text-secondary); }

@container (max-width: 34rem) {
  .sf-inter-row { grid-template-columns: minmax(0, 1fr) 3.5rem; }
  .sf-inter-to { grid-column: 1 / -1; }
}

/* ---------------------------------------------------- stages */
.sf-stages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; margin: 0; padding: 0; list-style: none; counter-reset: sf-stage; }
.sf-stages li { position: relative; display: grid; align-content: start; gap: 0.25rem; padding: 0.7rem 0.8rem; border: 1px solid var(--border-color); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 0.8125rem; line-height: 1.45; color: var(--text-secondary); counter-increment: sf-stage; }
.sf-stages li strong { font-size: 0.9375rem; color: var(--text-color); }
.sf-stages li strong::before { content: counter(sf-stage) ". "; color: var(--text-secondary); }
.sf-stages li + li::before { content: ""; position: absolute; left: -0.6rem; top: 50%; border: 5px solid transparent; border-left: 7px solid var(--viz-axis); border-right: 0; transform: translate(-1px, -50%); }

@container (max-width: 36rem) {
  .sf-stages { grid-template-columns: minmax(0, 1fr); }
  .sf-stages li + li::before { left: 1.2rem; top: -0.6rem; border: 5px solid transparent; border-top: 7px solid var(--viz-axis); border-bottom: 0; transform: translate(0, 0); }
}

/* ---------------------------------------------------- monitoring key */
.sf-monitor { display: grid; gap: 0.3rem; margin: 0.7rem 0 0; padding: 0; list-style: none; font-size: 0.8125rem; line-height: 1.4; color: var(--text-secondary); }
.sf-monitor li { padding-left: 0.55rem; border-left: 4px solid var(--viz-1); }
.sf-monitor li strong { margin-right: 0.3rem; color: var(--text-color); }
.sf-monitor .sf-c3-text { border-left-color: var(--viz-3); }
.sf-monitor .sf-c2-text { border-left-color: var(--viz-2); }

/* ---------------------------------------------------- lecture slides */
body.is-lecture .sf .sf-title { font-size: 1rem; }
