/* 弹簧刚度与圈数计算器 —— 刚度卡 + 曲线
   与链条带、皮带图纸区分：右栏以「读数卡 + 载荷曲线」为主视觉。 */

.sp-desk {
    display: grid;
    grid-template-columns: minmax(0, .94fr) minmax(0, 1.06fr);
    gap: 18px;
    align-items: start;
    margin-top: 24px;
}

.sp-right { display: grid; gap: 14px; min-width: 0; }

/* 计算方向：胶囊式切换（与链条/皮带的下划线式区分） */
.sp-mode {
    display: flex;
    gap: 6px;
    padding: 3px;
    background: var(--d3-paper-2);
    border-radius: 9px;
    margin-bottom: 16px;
}
.sp-mode label {
    flex: 1 1 0;
    position: relative;
    cursor: pointer;
    text-align: center;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--d3-ink-3);
    padding: 8px 6px;
    border-radius: 7px;
    transition: background .16s ease, color .16s ease, box-shadow .16s ease;
    user-select: none;
}
.sp-mode input { position: absolute; opacity: 0; pointer-events: none; }
.sp-mode label:hover { color: var(--d3-ink); }
.sp-mode label:has(input:checked) {
    background: var(--d3-card);
    color: var(--d3-accent);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .08), inset 0 0 0 1px var(--d3-line);
}

.d3-io.sp-readonly { background: var(--d3-card-2); border-style: dashed; }
.d3-io.sp-readonly input { color: var(--d3-ink-2); cursor: default; }

/* 刚度卡 */
.sp-card {
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(520px 200px at 88% -30%, rgba(var(--d3-accent-rgb), .16), transparent 70%),
        var(--d3-card);
    border: 1px solid var(--d3-line);
    border-radius: var(--d3-radius);
    padding: 16px 18px 15px;
}

.sp-card-top {
    display: grid;
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 16px;
    align-items: center;
    padding-bottom: 14px;
    border-bottom: 1px dashed var(--d3-line);
}

.sp-coil { min-width: 0; }
.sp-coil-label {
    display: block;
    font-family: var(--d3-mono);
    font-size: 9.5px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--d3-ink-3);
    margin-bottom: 2px;
}
#spCoilSvg { display: block; width: 100%; height: auto; overflow: visible; }

.sp-headline { min-width: 0; }
.sp-hl-label {
    display: block;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--d3-ink-3);
    letter-spacing: .02em;
}
.sp-headline b {
    display: flex;
    align-items: baseline;
    gap: 5px;
    margin-top: 2px;
    font-family: var(--d3-mono);
    font-variant-numeric: tabular-nums;
    font-size: clamp(27px, 3.4vw, 34px);
    font-weight: 700;
    letter-spacing: -.03em;
    line-height: 1.12;
    color: var(--d3-accent);
}
.sp-headline b small {
    font-family: var(--d3-sans);
    font-size: 12px;
    font-weight: 600;
    color: var(--d3-ink-3);
}
.sp-headline em {
    display: block;
    margin-top: 2px;
    font-style: normal;
    font-size: 11.5px;
    color: var(--d3-ink-3);
}

.sp-kpi {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    background: var(--d3-line);
    border: 1px solid var(--d3-line);
    border-radius: var(--d3-radius-sm);
    overflow: hidden;
    margin-top: 14px;
}
.sp-kpi > div {
    background: var(--d3-card);
    padding: 8px 10px;
    min-width: 0;
}
.sp-kpi span {
    display: block;
    font-size: 11px;
    color: var(--d3-ink-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sp-kpi b {
    display: block;
    margin-top: 1px;
    font-family: var(--d3-mono);
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    font-weight: 650;
    color: var(--d3-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 应力利用率 */
.sp-gauge { margin-top: 14px; }
.sp-gauge-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 11.5px;
    color: var(--d3-ink-3);
    margin-bottom: 5px;
}
.sp-gauge-head span:last-child {
    font-family: var(--d3-mono);
    color: var(--d3-ink-2);
}
.sp-gauge-bar {
    position: relative;
    height: 8px;
    border-radius: 999px;
    background: var(--d3-paper-2);
    border: 1px solid var(--d3-line);
    overflow: hidden;
}
.sp-gauge-bar i {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #4a8a76, #c2a15a 62%, var(--d3-accent));
    transition: width .3s ease;
}
.sp-gauge-bar i.is-over { background: linear-gradient(90deg, var(--d3-accent), #8b1f2c); }
.sp-gauge-foot {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-family: var(--d3-mono);
    font-size: 9.5px;
    color: var(--d3-ink-3);
}

/* 曲线卡 */
.sp-plot {
    background: var(--d3-card);
    border: 1px solid var(--d3-line);
    border-radius: var(--d3-radius);
    padding: 0 0 10px;
    overflow: hidden;
}
.sp-plot-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--d3-line);
    background: var(--d3-card-2);
}
.sp-plot-head h2 { font-size: 13.5px; }
.sp-plot-head span {
    margin-left: auto;
    font-family: var(--d3-mono);
    font-size: 11px;
    color: var(--d3-ink-3);
}
#spChart { display: block; width: 100%; height: auto; padding: 4px 4px 0; }
.sp-plot-legend {
    display: flex;
    gap: 14px;
    padding: 2px 16px 4px;
    font-size: 11.5px;
    color: var(--d3-ink-3);
}
.sp-plot-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sp-plot-legend i { width: 12px; height: 3px; border-radius: 2px; }
.sp-plot-legend i[style*="50%"] { width: 8px; height: 8px; }

/* SVG 曲线元素 */
.sp-axis { stroke: var(--d3-line-2); stroke-width: 1; }
.sp-grid { stroke: var(--d3-line); stroke-width: 1; stroke-dasharray: 3 4; }
.sp-tick { font-family: var(--d3-mono); font-size: 10px; fill: var(--d3-ink-3); }
.sp-axis-label { font-family: var(--d3-mono); font-size: 10.5px; fill: var(--d3-ink-3); }
.sp-line { stroke: var(--d3-accent); stroke-width: 2.2; fill: none; }
.sp-area { fill: rgba(var(--d3-accent-rgb), .10); }
.sp-point { fill: var(--d3-accent); stroke: var(--d3-card); stroke-width: 2; }
.sp-allow { fill: #8a9099; stroke: var(--d3-card); stroke-width: 2; }
.sp-drop { stroke: var(--d3-accent); stroke-width: 1; stroke-dasharray: 3 3; opacity: .65; }
.sp-point-label { font-family: var(--d3-mono); font-size: 10px; fill: var(--d3-accent); font-weight: 700; }

/* 高度列表 */
.sp-tight { padding: 13px 18px 14px; }
.sp-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.sp-list li {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 5px 0;
    border-bottom: 1px dotted var(--d3-line);
    color: var(--d3-ink-2);
}
.sp-list li:last-child { border-bottom: 0; }
.sp-list li b {
    margin-left: auto;
    font-family: var(--d3-mono);
    font-variant-numeric: tabular-nums;
    font-size: 12.5px;
    color: var(--d3-ink);
    white-space: nowrap;
}

/* 操作 */
.sp-actions { display: flex; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--d3-line); }
.sp-btn {
    appearance: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 650;
    line-height: 1;
    padding: 10px 15px;
    border-radius: 7px;
    border: 1px solid var(--d3-accent);
    background: var(--d3-accent);
    color: #fff;
    transition: filter .15s ease, transform .1s ease;
}
.sp-btn:hover { filter: brightness(1.08); }
.sp-btn:active { transform: translateY(1px); }
.sp-btn-ghost { background: transparent; color: var(--d3-ink-2); border-color: var(--d3-line-2); }
.sp-btn-ghost:hover { color: var(--d3-ink); border-color: var(--d3-ink-3); filter: none; }

.sp-alerts { display: grid; gap: 8px; margin-top: 14px; }
.sp-alerts:empty { display: none; }
.sp-alerts .d3-alert { font-size: 12.5px; padding: 9px 11px; }

/* 表 */
.sp-table-wrap { margin-top: 14px; }
#spTable { min-width: 620px; }
#spTable tr.is-work td {
    background: rgba(var(--d3-accent-rgb), .085);
    font-weight: 700;
}
#spTable tr.is-work td:first-child::after {
    content: " · 工作点";
    font-size: 10.5px;
    font-weight: 600;
    color: var(--d3-accent);
}
#spTable td.is-over { color: var(--d3-bad); font-weight: 700; }

@media (max-width: 1020px) {
    .sp-desk { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .sp-card { padding: 14px 15px 13px; }
    .sp-card-top { grid-template-columns: 92px minmax(0, 1fr); gap: 12px; }
    .sp-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sp-actions { flex-wrap: wrap; }
    .sp-btn { flex: 1 1 auto; text-align: center; }
}

:root[data-theme="dark"] .sp-btn { color: #0c0e12; }
:root[data-theme="dark"] .sp-mode { background: #101319; }
:root[data-theme="dark"] .sp-mode label:has(input:checked) { background: var(--d3-card); }
