/* ═══════════════════════════════════════════════════════════
   Spec Limits & Process Capability (Cpk)
   Obsidian & Copper — status layer for Monte Carlo histograms
   ═══════════════════════════════════════════════════════════

   Colour rationale (validated, not eyeballed):
   The three capability colours were checked with the data-viz validator
   against this app's real surfaces — #0B0E14 dark, #F9FAFB light.

     dark   #FF6B6B / #FFD24D / #34D399
            CVD separation ΔE 10.5 (protan) · normal-vision ΔE 21.2 · all ≥3:1
     light  #B91C1C / #CA8A04 / #047857
            CVD separation ΔE 14.1 (protan) · normal-vision ΔE 22.6

   Light-mode amber sits at 2.81:1 against the surface. Darkening it to clear
   3:1 collapses its separation from the red (ΔE drops to ~9, a hard fail), so
   the contrast WARN is accepted and relieved the way the method requires: every
   capability state ships an ICON AND A TEXT LABEL, never colour alone.

   These are status colours and are reserved — they never double as series hues.
   ═══════════════════════════════════════════════════════════ */

:root {
    --cpk-critical: #FF6B6B;
    --cpk-warning: #FFD24D;
    --cpk-good: #34D399;

    /* Washes for out-of-spec regions — a tint, never a saturated block */
    --cpk-critical-wash: rgba(255, 107, 107, 0.10);
    --cpk-critical-edge: rgba(255, 107, 107, 0.55);

    --cpk-critical-surface: rgba(255, 107, 107, 0.12);
    --cpk-warning-surface: rgba(255, 210, 77, 0.12);
    --cpk-good-surface: rgba(52, 211, 153, 0.12);
}

[data-theme="light"] {
    --cpk-critical: #B91C1C;
    --cpk-warning: #CA8A04;
    --cpk-good: #047857;

    --cpk-critical-wash: rgba(185, 28, 28, 0.08);
    --cpk-critical-edge: rgba(185, 28, 28, 0.5);

    --cpk-critical-surface: rgba(185, 28, 28, 0.08);
    --cpk-warning-surface: rgba(202, 138, 4, 0.10);
    --cpk-good-surface: rgba(4, 120, 87, 0.10);
}

/* ───────────────────────────────────────────────
   Chart header — title left, capability badge right
   ─────────────────────────────────────────────── */

.mc-chart-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.mc-chart-head h4 {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    text-align: left;
}

/* ───────────────────────────────────────────────
   Capability badge — icon + label + value.
   Never colour alone: the icon and the word carry the state.
   ─────────────────────────────────────────────── */

.cpk-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px 3px 7px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    cursor: help;
}

.cpk-badge .material-symbols-outlined {
    font-size: 15px;
    line-height: 1;
}

.cpk-badge .cpk-value {
    font-family: var(--font-family-mono);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.cpk-badge .cpk-label {
    color: var(--color-text-secondary);
    font-weight: 500;
}

.cpk-badge--critical {
    color: var(--cpk-critical);
    background: var(--cpk-critical-surface);
    border-color: color-mix(in srgb, var(--cpk-critical) 35%, transparent);
}

.cpk-badge--warning {
    color: var(--cpk-warning);
    background: var(--cpk-warning-surface);
    border-color: color-mix(in srgb, var(--cpk-warning) 35%, transparent);
}

.cpk-badge--good {
    color: var(--cpk-good);
    background: var(--cpk-good-surface);
    border-color: color-mix(in srgb, var(--cpk-good) 35%, transparent);
}

/* No spec declared — stays neutral so an absent spec never reads as a verdict */
.cpk-badge--none {
    color: var(--color-text-tertiary);
    background: var(--color-bg-tertiary);
    border-color: var(--color-border);
    font-weight: 500;
    cursor: default;
}

/* ───────────────────────────────────────────────
   Histogram spec overlay
   ─────────────────────────────────────────────── */

.mc-histogram {
    position: relative;
}

/* Out-of-spec region: a wash, with the limit itself as the hard edge.
   Both tails share one hue — crossing either limit is the same failure. */
.mc-spec-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    background: var(--cpk-critical-wash);
    pointer-events: none;
    z-index: 0;
}

.mc-spec-zone--low { border-right: 2px solid var(--cpk-critical-edge); }
.mc-spec-zone--high { border-left: 2px solid var(--cpk-critical-edge); }

/* Limit label rides just above the boundary, in mono so it reads as a value */
.mc-spec-label {
    position: absolute;
    top: -2px;
    font-family: var(--font-family-mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--cpk-critical);
    pointer-events: none;
    white-space: nowrap; /* Never wrap "USL 3.465V" onto two lines */
    z-index: 2;
}

.mc-spec-label--low { transform: translateX(calc(-100% - 3px)); }
.mc-spec-label--high { transform: translateX(3px); }

/* Bars keep their series colour in spec; failures take the status hue.
   This is the whole point of the view — the failing tail is visible at a glance. */
.mc-bar {
    position: relative;
    z-index: 1;
}

.mc-bar.out-of-spec {
    background: var(--cpk-critical);
}

.mc-bar.out-of-spec:hover {
    background: var(--cpk-critical);
    filter: brightness(1.15);
}

/* ───────────────────────────────────────────────
   Yield line under each chart
   ─────────────────────────────────────────────── */

.mc-yield-line {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--color-text-tertiary);
    margin: 2px 0 var(--space-2);
    min-height: 16px;
}

.mc-yield-line .material-symbols-outlined { font-size: 13px; }
.mc-yield-line.has-fails { color: var(--cpk-critical); }
.mc-yield-line .mc-yield-source {
    margin-left: auto;
    font-family: var(--font-family-mono);
    font-size: 10px;
    color: var(--color-text-tertiary);
    opacity: 0.75;
}

/* Shown only when the observed rate and the normal model disagree materially */
.mc-normality-flag {
    color: var(--cpk-warning);
    cursor: help;
}

/* ───────────────────────────────────────────────
   Export Studio — spec limit editor
   ─────────────────────────────────────────────── */

.spec-limit-row {
    display: grid;
    grid-template-columns: 1fr 84px 84px;
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
}

.spec-limit-row .spec-metric {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.spec-limit-row .spec-metric-name {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.spec-limit-row .spec-metric-source {
    font-family: var(--font-family-mono);
    font-size: 9px;
    color: var(--color-text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.spec-limit-row input {
    width: 100%;
    padding: 4px 6px;
    font-family: var(--font-family-mono);
    font-size: 11px;
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    text-align: right;
}

.spec-limit-row input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* An edited value is visibly no longer the auto-derived one */
.spec-limit-row input.overridden {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.spec-limit-header {
    display: grid;
    grid-template-columns: 1fr 84px 84px;
    gap: 6px;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-tertiary);
    margin-bottom: 4px;
}

.spec-limit-header span:not(:first-child) { text-align: right; }

.spec-limit-hint {
    font-size: 10px;
    color: var(--color-text-tertiary);
    line-height: 1.5;
    margin: 8px 0 6px;
}

.spec-limit-reset {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    padding: 2px 0;
    font-size: 10px;
    color: var(--color-primary);
    cursor: pointer;
}

.spec-limit-reset:hover { text-decoration: underline; }
.spec-limit-reset .material-symbols-outlined { font-size: 13px; }

/* ───────────────────────────────────────────────
   Print — keep the status fills in exported/printed reports
   ─────────────────────────────────────────────── */

@media print {
    .mc-bar.out-of-spec,
    .mc-spec-zone,
    .cpk-badge {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}
