/* Scaling calculator. Loaded after sops.css and uses its tokens. */
:root { --good: #1d6b3a; --good-bg: #e6f4ea; --bad: #b42318; --bad-bg: #fdecea; }

.calc-head { padding-bottom: 4px; }
.calc-head .eyebrow { margin-top: 14px; }
.calc-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.calc-saved { font-size: 0.85rem; color: var(--muted); }
.calc-banner {
  margin: 14px 0 0; padding: 10px 14px; border-radius: 10px;
  background: #fff4d6; border: 1px solid #f3c77d; color: #6b3d00; font-weight: 700; font-size: 0.92rem;
}

.btn {
  font: 800 0.92rem var(--sans); color: #fff; background: var(--accent-dark);
  border: 1px solid var(--accent-dark); border-radius: 10px; padding: 9px 14px; cursor: pointer;
}
.btn:hover { background: var(--accent); border-color: var(--accent); }
.btn.ghost { color: var(--text); background: var(--surface); border-color: var(--border); }
.btn.ghost:hover { border-color: var(--muted); }
.btn.small { font-size: 0.85rem; padding: 6px 11px; }

.calc { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; margin-top: 24px; }
@media (min-width: 1000px) {
  .calc { grid-template-columns: 360px minmax(0, 1fr); align-items: start; }
  .calc-inputs { position: sticky; top: 70px; max-height: calc(100vh - 84px); overflow-y: auto; overscroll-behavior: contain; }
  .to-results { display: none; }
}

/* ---------- inputs ---------- */
.calc-inputs { min-width: 0; display: flex; flex-direction: column; gap: 14px; scrollbar-width: thin; }
.calc-inputs fieldset {
  margin: 0; min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.calc-inputs legend { float: left; width: 100%; padding: 0; margin: 0 0 4px; font-weight: 900; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.calc-inputs legend + * { clear: both; }
.sec-num {
  display: inline-grid; place-items: center; flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
  background: var(--gradient); color: #fff; font-size: 0.8rem; font-weight: 900;
}
.calc-inputs .help { margin: 0 0 12px; }
.help { font-size: 0.9rem; color: var(--muted); line-height: 1.5; margin: 0 0 14px; max-width: 70ch; }
.field { display: flex; flex-direction: column; gap: 5px; margin: 0 0 14px; }
.field:last-child { margin-bottom: 0; }
.lab { font-weight: 800; font-size: 0.92rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.opt { font-style: normal; font-weight: 700; font-size: 0.75rem; color: var(--muted); }
.assume {
  font-style: normal; font-weight: 800; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: #8a4f00; background: var(--google-bg); border: 1px solid var(--google-bd); border-radius: 100px; padding: 1px 8px;
}
.hint { display: block; font-size: 0.82rem; color: var(--muted); line-height: 1.45; font-weight: 400; }
.inp {
  display: flex; align-items: stretch; min-width: 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.inp:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--meta-bg); }
.inp input, .field select {
  flex: 1 1 auto; min-width: 0; width: 100%;
  font: 700 1rem var(--sans); color: var(--text); background: transparent; border: 0; padding: 9px 10px; outline: none;
}
.field select { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--meta-bg); }
.unit {
  display: flex; align-items: center; padding: 0 0 0 10px; color: var(--muted); font-weight: 800; font-size: 0.9rem; white-space: nowrap;
}
.unit.after { padding: 0 10px 0 0; font-size: 0.8rem; font-weight: 700; }
.pair { display: flex; align-items: center; gap: 8px; }
.pair .inp { flex: 1 1 0; }
.pair-to { color: var(--muted); font-weight: 700; font-size: 0.9rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.steps { display: flex; flex-direction: column; gap: 8px; }
.step-row { display: flex; gap: 8px; align-items: center; }
.step-row .inp { flex: 1 1 auto; }
.icon-btn {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
  font: 700 1.2rem/1 var(--sans); color: var(--muted); background: var(--surface); border: 1px solid var(--border);
}
.icon-btn:hover { color: var(--bad); border-color: var(--bad); }
[data-add-step] { align-self: flex-start; margin-top: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 700; font-size: 0.92rem; cursor: pointer; }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent-dark); flex-shrink: 0; }
.to-results { align-self: flex-start; font-weight: 800; }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- results ---------- */
.calc-results { min-width: 0; display: flex; flex-direction: column; gap: 16px; scroll-margin-top: 70px; }
.calc-panel { min-width: 0; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.calc-panel h2, .calc-notes h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; font-size: 1.3rem; font-weight: 900; letter-spacing: -0.01em; }
.calc-h3 { font-size: 1.05rem; font-weight: 900; margin: 22px 0 8px; padding-top: 16px; border-top: 1px solid var(--border); }
.calc-msg { margin: 0; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 0.95rem; }
.calc-msg.warn { margin-top: 12px; background: var(--bad-bg); color: var(--bad); }

.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
.tile { min-width: 0; display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.tile-label { font-size: 0.8rem; font-weight: 800; color: var(--muted); }
.tile-value { font-size: 1.55rem; font-weight: 900; letter-spacing: -0.01em; line-height: 1.2; overflow-wrap: anywhere; }
.tile-sub { font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
.tile.bad { background: var(--bad-bg); border-color: #f4b4ad; }
.tile.bad .tile-value { color: var(--bad); }

.calc-breakdown { margin-top: 12px; }
.calc-breakdown summary { cursor: pointer; font-weight: 800; font-size: 0.9rem; color: var(--accent-dark); }
.calc-breakdown .hint { margin-top: 8px; max-width: 70ch; }
.mini { border-collapse: collapse; margin-top: 8px; font-size: 0.92rem; min-width: min(100%, 320px); }
.mini th, .mini td { padding: 5px 0; border-bottom: 1px solid var(--border); }
.mini th { text-align: left; font-weight: 600; padding-right: 24px; }
.mini td { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.mini tr.total th, .mini tr.total td { font-weight: 900; border-bottom: 0; border-top: 2px solid var(--text); }

.calc-peak { margin: 0 0 14px; padding: 12px 14px; border-radius: 10px; border-left: 4px solid var(--orange); background: #fff8eb; }
.calc-peak.warn { border-left-color: var(--bad); background: var(--bad-bg); }
.peak-head { margin: 0; font-weight: 800; }
.calc-peak ul { margin: 6px 0 0; padding-left: 1.2em; font-size: 0.92rem; }
.calc-peak li { margin: 2px 0; }

.calc-table-wrap { margin: 12px 0 0; }
.calc-table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.calc-table th, .calc-table td { text-align: left; vertical-align: top; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.calc-table thead th { background: var(--surface-2); font-weight: 800; font-size: 0.82rem; line-height: 1.3; }
.calc-table .num { text-align: right; }
.calc-table td { font-variant-numeric: tabular-nums; }
.calc-table td.num { white-space: nowrap; }
.calc-table tbody th { font-weight: 900; white-space: nowrap; font-variant-numeric: tabular-nums; }
.calc-table tr:last-child > * { border-bottom: 0; }
.calc-table tr.base > * { background: #fcfaf7; }
.calc-table thead th { vertical-align: bottom; }
.calc-table thead th.group-h { text-align: center; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.th-sub { display: block; font-weight: 600; color: var(--muted); font-size: 0.75rem; }
.row-name { display: block; font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.cell-sub { display: block; font-size: 0.75rem; color: var(--muted); }
.neg { color: var(--bad); }
td.is-peak { background: #fff4d6; box-shadow: inset 0 -3px 0 var(--orange); font-weight: 900; }
.peak-tag {
  display: block; width: fit-content; margin: 0 0 3px auto;
  font-size: 0.66rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.06em;
  color: #fff; background: var(--accent-dark); border-radius: 100px; padding: 1px 7px;
}

/* chart */
.chart { margin: 4px 0 6px; }
.chart-title { margin: 0 0 4px; font-weight: 800; font-size: 0.9rem; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.8rem; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key-line { width: 16px; height: 2px; border-radius: 2px; background: var(--accent); }
.key-band { width: 14px; height: 10px; border-radius: 2px; background: rgba(229, 20, 131, 0.14); border: 1px solid rgba(229, 20, 131, 0.35); }
.key-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-dark); box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--accent-dark); }
.chart-box { position: relative; min-width: 0; }
.chart-box svg { display: block; overflow: visible; }
.chart-box .grid { stroke: var(--border); stroke-width: 1; }
.chart-box .zero { stroke: #b9aa9a; stroke-width: 1; }
.chart-box .tick { font: 600 11.5px var(--sans); fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-box .band { fill: rgba(229, 20, 131, 0.12); }
.chart-box .edge { fill: none; stroke: rgba(229, 20, 131, 0.38); stroke-width: 1; stroke-linejoin: round; }
.chart-box .mid { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-box .dot { fill: var(--accent); stroke: #fff; stroke-width: 2; }
.chart-box .peak { fill: var(--accent-dark); stroke: #fff; stroke-width: 2; }
.chart-box .peak-label { font: 900 12px var(--sans); fill: var(--text); }
.chart-box .cross { stroke: var(--muted); stroke-width: 1; }
.chart-box .hit { fill: transparent; cursor: crosshair; }
.chart-box .hit:focus { outline: none; }
.chart-box .hit:focus-visible { fill: rgba(245, 156, 6, 0.08); }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none; min-width: 140px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 8px 10px; font-size: 0.82rem; color: var(--muted);
}
.tip-h { display: block; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.tip-r { display: flex; align-items: center; gap: 6px; }
.tip-r b { color: var(--text); font-variant-numeric: tabular-nums; min-width: 68px; }
.tip-r i { width: 12px; height: 2px; border-radius: 2px; flex-shrink: 0; }
.k-mid { background: var(--accent); }
.k-best, .k-worst { background: rgba(229, 20, 131, 0.45); height: 1px !important; }

/* test */
.test-inputs { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); margin-bottom: 4px; }
.test-mult { margin: 0 0 12px; }
.verdict { display: inline-block; font-weight: 800; border-radius: 100px; padding: 1px 8px; font-size: 0.78rem; }
.verdict.good { color: var(--good); background: var(--good-bg); }
.verdict.bad { color: var(--bad); background: #fff; }
.test-advice { margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.92rem; }

.calc-notes { padding: 4px 2px; }
.calc-notes ul { margin: 6px 0 0; padding-left: 1.2em; color: var(--text); max-width: 72ch; }
.calc-notes li { margin: 4px 0; }

/* ---------- phones: tables become cards ---------- */
@media (max-width: 640px) {
  .calc-panel { padding: 14px; }
  .calc-inputs fieldset { padding: 14px; }
  .calc-table-wrap { border: 0; background: none; overflow: visible; }
  .calc-table thead { display: none; }
  .calc-table, .calc-table tbody { display: block; }
  .calc-table tr { display: block; margin: 0 0 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); overflow: hidden; }
  .calc-table tr.base > * { background: transparent; }
  .calc-table tr.base { background: #fcfaf7; }
  .calc-table tbody th { display: block; background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 8px 12px; }
  .calc-table tbody th .row-name { display: inline; margin-right: 8px; }
  .calc-table td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap;
    white-space: normal; text-align: right; padding: 7px 12px;
  }
  .calc-table td::before { content: attr(data-label); text-align: left; font-weight: 700; color: var(--muted); font-size: 0.82rem; }
  .calc-table td .cell-sub { flex-basis: 100%; }
  .calc-table tr > :last-child { border-bottom: 0; }
  .calc-table td.is-peak { box-shadow: inset 4px 0 0 var(--orange); }
  .tile-value { font-size: 1.35rem; }
}
