.pid-layout {
    grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.9fr);
    align-items: stretch;
}

.pid-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 560px;
    height: calc(100vh - 200px);
    padding: 12px 12px 10px;
    background: #0c0c10;
    overflow: hidden;
}

.pid-stage canvas {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    display: block;
    touch-action: pan-y;
}

.pid-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.pid-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.pid-legend .swatch {
    width: 14px;
    height: 3px;
    border-radius: 99px;
    display: inline-block;
}

.swatch-sp { background: #e4e4e7; }
.swatch-pv { background: #a5b4fc; }
.swatch-ghost { background: rgba(165, 180, 252, 0.55); }
.swatch-co { background: #fbbf24; }
.swatch-unsat {
    background: repeating-linear-gradient(90deg, #fbbf24 0 4px, transparent 4px 7px);
}
.swatch-err { background: #fb7185; }

.pid-cursor {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    min-height: 1.2em;
    margin-top: 6px;
}

.pid-panel {
    max-height: calc(100vh - 180px);
    overflow: auto;
    padding: 16px 16px 18px;
}

.pid-panel h2 {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 18px 0 10px;
}

.pid-panel h2:first-of-type {
    margin-top: 14px;
}

.pid-panel .readout-main {
    color: #c7d2fe;
    font-variant-numeric: tabular-nums;
    margin-bottom: 2px;
}

.pid-live,
.pid-law,
.pid-eq,
.pid-note,
.pid-form-note {
    color: var(--text-muted);
    font-size: 0.86rem;
    line-height: 1.45;
}

.pid-live,
.pid-law {
    font-variant-numeric: tabular-nums;
}

.pid-law {
    color: var(--text-main);
    margin: 6px 0 2px;
}

.pid-eq {
    margin: 10px 0 4px;
    font-variant-numeric: tabular-nums;
}

.pid-note {
    margin-top: 8px;
}

.pid-form-note {
    margin: 8px 0 2px;
}

#pid-status.alarm {
    color: #fb7185;
}

#pid-status.sat {
    color: #fbbf24;
}

.pid-actions,
.seg,
.pid-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pid-actions {
    margin-bottom: 4px;
}

.pid-actions button,
.seg button,
.pid-text-btn {
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-muted);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    font-size: 0.92rem;
}

.pid-actions button {
    flex: 1 1 8.5rem;
}

.seg button.active,
.pid-actions button:hover,
.seg button:hover,
.pid-text-btn:hover {
    color: var(--text-main);
    border-color: var(--accent);
    background: var(--accent-soft);
}

.pid-text-btn {
    margin-top: 8px;
}

.pid-text-btn:disabled {
    opacity: 0.4;
    cursor: default;
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-muted);
}

.pid-speed,
.pid-presets {
    margin-top: 10px;
}

.control {
    display: grid;
    gap: 4px;
    margin-top: 10px;
}

.control-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.control-head label,
.pid-limits label {
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
}

.control-head label span,
.pid-limits label {
    letter-spacing: 0.04em;
}

.control input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.pid-num {
    width: 5.6rem;
    flex: 0 0 auto;
    background: rgba(10, 10, 12, 0.9);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 5px 8px;
    font: inherit;
    font-size: 0.88rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.pid-limits {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
}

.pid-limits label {
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.88rem;
}

.check-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin-top: 12px;
}

.check-row label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    font-size: 0.92rem;
}

.pid-panel .result-list {
    grid-template-columns: 1fr 1fr;
    column-gap: 16px;
    row-gap: 0;
}

.pid-panel .result-list div {
    padding-bottom: 6px;
}

.pid-panel .result-list dt,
.pid-panel .result-list dd {
    font-size: 0.84rem;
}

.pid-panel .result-list dd {
    font-variant-numeric: tabular-nums;
}

.pid-panel .result-list dd.wound {
    color: #fb7185;
}

.pid-panel [hidden] {
    display: none !important;
}

@media (max-width: 900px) {
    .pid-layout {
        grid-template-columns: 1fr;
    }

    .pid-stage {
        height: 78vh;
        min-height: 520px;
    }

    .pid-panel {
        max-height: none;
    }
}

@media (max-width: 420px) {
    .pid-actions button {
        flex-basis: calc(50% - 8px);
    }

    .pid-panel .result-list {
        grid-template-columns: 1fr;
    }
}
