/* ============================================================
   RAR PHYSIOLOGY · Spirogram Engine styles
   Self-contained, bespoke to the Lung Volumes & Capacities module.
   Mirrors Arcanium component conventions (card surfaces, spacing,
   typography, palette) — no new visual language, no accent stripes,
   sentence case throughout. Scoped under .spg.
   ============================================================ */

.spg {
    display: block;
    margin: 10px 0 0;          /* fills the card width; height is kept short
                                  via the plot's wide aspect ratio (see JS viewBox) */
}

.spg-stage {
    display: grid;
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 12px;
    align-items: center;       /* center the lung against the graph */
}

/* ---- lung indicator (compact box that hugs the lung) ---- */
.spg-lung {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    align-self: center;
    padding: 8px 6px 6px;
    border: 1px solid var(--line, rgba(15, 23, 42, 0.08));
    border-radius: var(--radius-sm, 14px);
    background: var(--surface-soft, rgba(255, 255, 255, 0.58));
}
.spg-lung-svg { width: 100%; height: auto; max-height: 124px; display: block; }
/* Realistic lungs image (BioRender) — scaled via an SVG transform attribute
   (translate-pinned to the bottom); no CSS transform so pinning is exact.
   The PNG has an opaque WHITE background (not transparent); multiply blends
   that white into the (light) box so the lungs read as floating. */
.spg-lung-scalable { mix-blend-mode: multiply; }

/* Determinants (Mode B) — show only the morphing plot + lung */
.spg--determinants .spg-controls,
.spg--determinants .spg-caption,
.spg--determinants .spg-trace-layer { display: none; }

/* ghost baseline (faded "normal" reference behind the current state) */
.spg-ghost-line { stroke: rgba(15, 23, 42, 0.28); stroke-width: 1; stroke-dasharray: 4 4; }
.spg-ghost-label { fill: #64748b; font-size: 8.5px; font-weight: 700; letter-spacing: 0.02em; }
.spg-lung-label {
    margin-top: 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted-strong, #475467);
    letter-spacing: 0.01em;
}

/* ---- plot ---- */
.spg-plot {
    border: 1px solid var(--line, rgba(15, 23, 42, 0.08));
    border-radius: var(--radius-sm, 14px);
    background: var(--surface-strong, rgba(255, 255, 255, 0.92));
    padding: 8px 10px;
}
.spg-svg { width: 100%; height: auto; display: block; }

.spg-frame { fill: none; stroke: var(--line, rgba(15, 23, 42, 0.12)); stroke-width: 1; }
.spg-grid { stroke: rgba(15, 23, 42, 0.07); stroke-width: 1; }
.spg-axis-num { fill: var(--muted, #667085); font-size: 10px; font-weight: 600; }
.spg-axis-unit { fill: var(--muted-strong, #475467); font-size: 10.5px; font-weight: 700; letter-spacing: 0.02em; }

.spg-band { transition: fill-opacity 0.15s ease; }
/* white halo so the label stays readable even when the trace crosses it */
.spg-band-label {
    fill: var(--text, #111318);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.02em;
    paint-order: stroke;
    stroke: #fff;
    stroke-width: 3.5px;
    stroke-linejoin: round;
}
.spg-band-hit { fill: transparent; cursor: pointer; }

.spg-trace { fill: none; stroke: #1d2433; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.spg-pen { fill: var(--accent-strong, #0066cc); stroke: #fff; stroke-width: 1.5; }

.spg-bracket-line { stroke-width: 1.6; }
.spg-bracket-label { font-size: 11px; font-weight: 800; letter-spacing: 0.02em; }
.spg-bracket-lock { font-size: 8.5px; }

/* ---- controls ---- */
.spg-controls { margin-top: 14px; display: flex; flex-direction: column; gap: 11px; }
.spg-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spg-modes { justify-content: space-between; }

.spg-btn {
    appearance: none;
    border: 1px solid var(--line, rgba(15, 23, 42, 0.12));
    background: var(--surface-strong, #fff);
    color: var(--text, #111318);
    font-size: 12.5px;
    font-weight: 650;
    padding: 7px 13px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}
.spg-btn:hover { border-color: var(--accent, #0a84ff); color: var(--accent-strong, #0066cc); }
.spg-btn--reset { color: var(--muted-strong, #475467); }
.spg-btn--toggle.is-on,
.spg-btn.is-on {
    background: var(--accent, #0a84ff);
    border-color: var(--accent, #0a84ff);
    color: #fff;
}

/* sex segmented toggle */
.spg-sex {
    display: inline-flex;
    border: 1px solid var(--line, rgba(15, 23, 42, 0.12));
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface-soft, rgba(255, 255, 255, 0.58));
}
.spg-sex-btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--muted-strong, #475467);
    font-size: 12.5px;
    font-weight: 700;
    padding: 7px 16px;
    cursor: pointer;
    transition: background 0.14s ease, color 0.14s ease;
}
.spg-sex-btn.is-on { background: var(--accent, #0a84ff); color: #fff; }

.spg-label-all {
    appearance: none;
    border: 1px solid var(--line, rgba(15, 23, 42, 0.12));
    background: var(--surface-strong, #fff);
    color: var(--text, #111318);
    font-size: 12.5px;
    font-weight: 650;
    padding: 7px 13px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}
.spg-label-all.is-on { background: var(--text, #111318); border-color: var(--text, #111318); color: #fff; }

/* chips */
.spg-chipset { display: flex; flex-direction: column; gap: 8px; }
.spg-chiprow { display: flex; align-items: center; gap: 10px; }
.spg-chiprow-tag {
    width: 78px;
    flex-shrink: 0;
    font-size: 10.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted, #667085);
}
.spg-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.spg-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    appearance: none;
    border: 1px solid var(--line, rgba(15, 23, 42, 0.14));
    background: var(--surface-strong, #fff);
    color: var(--text, #111318);
    font-size: 12px;
    font-weight: 700;
    padding: 5px 11px;
    border-radius: 999px;
    cursor: pointer;
    transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}
.spg-chip:hover { border-color: var(--accent, #0a84ff); }
.spg-chip.is-pinned { border-color: var(--accent, #0a84ff); box-shadow: inset 0 0 0 1px var(--accent, #0a84ff); }
.spg-chip-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.spg-chip.is-locked { color: var(--muted-strong, #475467); }

/* readout */
.spg-readout {
    margin-top: 1px;
    padding: 10px 13px;
    border: 1px solid var(--line, rgba(15, 23, 42, 0.1));
    border-radius: var(--radius-sm, 14px);
    background: var(--surface-soft, rgba(255, 255, 255, 0.58));
    font-size: 13px;
    line-height: 1.5;
    color: var(--text, #111318);
    min-height: 38px;
}
.spg-readout strong { font-weight: 800; }
.spg-readout-hint { color: var(--text, #111318); }
.spg-ok { color: #1f8f43; font-weight: 700; }
.spg-no { color: var(--danger, #ff453a); font-weight: 700; white-space: nowrap; }

/* lock icon */
.spg-lock { width: 13px; height: 13px; vertical-align: -2px; }
.spg-lock--inline { width: 12px; height: 12px; margin-right: 1px; }
.spg-lock--chip { width: 12px; height: 12px; opacity: 0.6; }
.spg-lock--cap { width: 16px; height: 16px; flex-shrink: 0; color: var(--muted-strong, #475467); }

/* high-yield clinical-pearl alert (the RV / FRC / TLC lock rule) */
.spg-caption {
    margin: 12px 0 0;
    padding: 11px 14px;
    border: 1px solid rgba(255, 159, 10, 0.5);
    border-radius: var(--radius-sm, 14px);
    background: rgba(255, 159, 10, 0.13);
}
.spg-caption-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 7px;
    padding: 3px 10px;
    border-radius: 999px;
    background: #ff9f0a;
    color: #3d2a00;
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.spg-caption-tag .spg-lock { width: 12px; height: 12px; color: #3d2a00; }
.spg-caption-body {
    margin: 0;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text, #111318);
}
.spg-caption-body strong { color: var(--text, #111318); font-weight: 800; }

/* tooltip — body-anchored, fixed, never clipped */
.spg-tip {
    position: fixed;
    left: 0; top: 0;
    z-index: 9999;
    max-width: min(304px, 86vw);
    padding: 10px 13px;
    border-radius: 10px;
    background: #111318;
    color: #f4f6fb;
    font-size: 12.5px;
    line-height: 1.5;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.spg-tip.is-on { opacity: 1; }
.spg-tip strong { display: block; color: #fff; font-weight: 800; font-size: 13px; }
.spg-tip b { color: #fff; font-weight: 800; }
.spg-tip__tag {
    display: block;
    margin-bottom: 3px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #7fb4ff;
}
.spg-tip__def { display: block; margin-top: 5px; color: #d4dcea; }
.spg-tip__val { display: block; margin-top: 6px; font-weight: 700; color: #fff; }
.spg-tip__ok { display: block; margin-top: 6px; font-size: 11.5px; font-weight: 700; color: #7ee0a0; }
.spg-tip__no { display: block; margin-top: 6px; font-size: 11.5px; font-weight: 700; color: #ffb3ad; }
.spg-tip .spg-lock { color: #ffb3ad; }

@media (max-width: 640px) {
    .spg-stage { grid-template-columns: 1fr; }
    .spg-lung { flex-direction: row; justify-content: center; gap: 12px; max-height: 160px; }
    .spg-lung-svg { max-height: 140px; width: auto; }
    .spg-chiprow { align-items: flex-start; flex-direction: column; gap: 4px; }
}
