/* PCB Calculator (Calculator tab) — uses the playground's dark GitHub palette. */

.calc-view {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  background: var(--bg);
}

/* ── calculator list ─────────────────────────────────────────────────────── */
.calc-list {
  width: 186px;
  flex: none;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surf);
  padding: 8px 0 16px;
}

.calc-group {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--dim);
  padding: 12px 12px 5px;
}
.calc-group:first-child { padding-top: 4px; }

.calc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  border-left: 2px solid transparent;
}
.calc-item:hover { background: var(--surf2); }
.calc-item.active {
  background: var(--surf3);
  border-left-color: var(--blue);
  color: var(--bright);
}
.calc-item-ico { width: 15px; text-align: center; color: var(--blue); font-size: 12px; }
.calc-item.active .calc-item-ico { color: var(--teal); }
.calc-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── main panel ──────────────────────────────────────────────────────────── */
.calc-main { flex: 1; min-width: 0; overflow-y: auto; }
.calc-body { padding: 20px 24px 32px; max-width: 780px; }

.calc-head h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--bright);
  margin: 0 0 3px;
}
.calc-head p { font-size: 11.5px; color: var(--dim); margin: 0 0 18px; }

.calc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
/* Single column once side-by-side would squeeze the number fields. */
@media (max-width: 720px) { .calc-grid { grid-template-columns: minmax(0, 1fr); } }

/* ── inputs ──────────────────────────────────────────────────────────────── */
.calc-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}
/* Label column only. `.calc-in-wrap` is also a <span> child, so it must be
 * excluded — otherwise it inherits the fixed 96px and clips long values. */
.calc-field > span:not(.calc-in-wrap) {
  font-size: 11.5px;
  color: var(--text);
  flex: none;
  width: 96px;
}

/* Grow to fill the row: without a flex-basis of 0 the wrapper sizes to the
 * input's default ~20ch and long solved values (0.274678) get clipped. */
.calc-in-wrap {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
}
.calc-in-wrap i {
  position: absolute;
  right: 8px;
  font-style: normal;
  font-size: 10px;
  color: var(--dim);
  pointer-events: none;
}

.calc-input {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  color: var(--bright);
  font-size: 12px;
  font-family: inherit;
  padding: 6px 8px;
  outline: none;
}
.calc-in-wrap .calc-input { padding-right: 40px; }
.calc-input:focus { border-color: var(--blue); }
select.calc-input { cursor: pointer; padding-right: 6px; }

/* Number spinners add nothing here and steal width. */
.calc-input[type=number]::-webkit-inner-spin-button,
.calc-input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.calc-input[type=number] { -moz-appearance: textfield; appearance: textfield; }

.calc-actions { margin-top: 14px; }
.calc-reset {
  background: var(--surf3);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  padding: 5px 11px;
  cursor: pointer;
}
.calc-reset:hover { background: var(--surf2); color: var(--bright); border-color: var(--dim); }

/* ── results ─────────────────────────────────────────────────────────────── */
.calc-results {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 12px 14px;
  min-width: 0;
}

.calc-res-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 11.5px;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
}
.calc-res-row:last-child { border-bottom: none; }
.calc-res-row b {
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: right;
  word-break: break-word;
}
/* The headline answer — the number the user came for. */
.calc-res-row.hi { padding: 7px 0 9px; }
.calc-res-row.hi > span { color: var(--text); }
.calc-res-row.hi b {
  color: var(--teal);
  font-size: 17px;
  font-weight: 650;
}

.calc-sub {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 12px 0 2px;
  padding-top: 9px;
  border-top: 1px solid var(--border2);
}

.calc-warn {
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--yellow);
  background: rgba(227, 179, 65, .08);
  border: 1px solid rgba(227, 179, 65, .25);
  border-radius: var(--r);
  padding: 6px 8px;
  margin-top: 9px;
}

.calc-hint { font-size: 11.5px; color: var(--dim); padding: 6px 0; }

/* Tab icon colour, matching ws-icon-circuit / -sim / -layout in style.css */
.ws-icon-calc { color: var(--yellow); }

/* ── solve-for-an-input panel ─────────────────────────────────────────────── */
.calc-solve {
  margin-top: 14px;
  padding: 10px 11px;
  background: var(--surf);
  border: 1px solid var(--border2);
  border-radius: var(--r);
}
.calc-solve.on { border-color: rgba(57, 197, 207, .45); }

.calc-solve-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.calc-solve-toggle input { accent-color: var(--teal); cursor: pointer; margin: 0; }
.calc-solve.on .calc-solve-toggle span { color: var(--teal); font-weight: 600; }

.calc-solve-body { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.calc-solve-body .calc-field:last-child { margin-bottom: 0; }
.calc-solve-body .calc-field > span:not(.calc-in-wrap) { width: 74px; font-size: 11px; }

/* A field owned by the solver: visibly derived, not editable.
 * The label gets the "(solved)" marker; it must wrap inside the fixed-width
 * label column rather than pushing into the input, and the input keeps its
 * normal right padding so the value is never overlapped by the unit chip. */
.calc-field.solved .calc-input {
  background: rgba(57, 197, 207, .08);
  border-color: rgba(57, 197, 207, .4);
  color: var(--teal);
  font-weight: 600;
  cursor: default;
}
.calc-field.solved > span:not(.calc-in-wrap) {
  line-height: 1.25;
  color: var(--teal);
}
.calc-field.solved > span:not(.calc-in-wrap)::after {
  content: '(solved)';
  display: block;
  color: var(--teal);
  opacity: .8;
  font-size: 9.5px;
}

.calc-solved-note {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  background: rgba(57, 197, 207, .08);
  border: 1px solid rgba(57, 197, 207, .28);
  border-radius: var(--r);
  padding: 7px 9px;
  margin-bottom: 11px;
}
.calc-solved-note b { color: var(--teal); font-weight: 650; }

/* ── stackup editor ───────────────────────────────────────────────────────── */
.stk-top { max-width: 340px; margin-bottom: 14px; }

.stk-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) { .stk-wrap { grid-template-columns: minmax(0, 1fr); } }

.stk-list {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px;
}

.stk-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 2px 0;
}
.stk-row:hover .stk-del { opacity: 1; }

/* The cross-section bar: copper is solid, dielectric is tinted by type. */
.stk-bar {
  width: 76px;
  flex: none;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, .35);
}
.stk-copper  { background: linear-gradient(180deg, #d8952f, #b87333); }
.stk-core    { background: repeating-linear-gradient(45deg, #1d5b34, #1d5b34 4px, #205f38 4px, #205f38 8px); }
.stk-prepreg { background: repeating-linear-gradient(45deg, #2a6b45, #2a6b45 4px, #2f7049 4px, #2f7049 8px); }

.stk-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text);
  flex-wrap: wrap;
}
.stk-meta b { color: var(--bright); font-weight: 600; min-width: 20px; }
.stk-kind { color: var(--dim); font-size: 10px; }

.stk-in {
  width: 62px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  color: var(--bright);
  font-size: 11px;
  font-family: inherit;
  padding: 3px 5px;
  outline: none;
}
.stk-in:focus { border-color: var(--blue); }
.stk-in[type=number]::-webkit-inner-spin-button,
.stk-in[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stk-in[type=number] { -moz-appearance: textfield; appearance: textfield; }
.stk-meta i { font-style: normal; font-size: 9.5px; color: var(--dim); margin-left: -3px; }

.stk-plane {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--dim);
  cursor: pointer;
  user-select: none;
}
.stk-plane input { accent-color: var(--teal); margin: 0; cursor: pointer; }

.stk-note { font-size: 9.5px; color: var(--dim); width: 100%; }
.stk-note.stk-bad { color: var(--yellow); }

.stk-del {
  flex: none;
  width: 18px; height: 18px;
  background: none;
  border: none;
  color: var(--dim);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  border-radius: 3px;
}
.stk-del:hover { color: var(--red); background: var(--surf3); }

.stk-add { display: flex; gap: 6px; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border); }
.stk-add .calc-reset { font-size: 10.5px; padding: 4px 9px; }

/* ── net rules / design checks editor ─────────────────────────────────────── */
.nr-rules {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.nr-rules .calc-field { margin-bottom: 0; width: 240px; }
.nr-rules .calc-field > span:not(.calc-in-wrap) { width: 88px; }

/* Fab-house preset spec sheet */
.nr-fabspec { margin: 4px 0 10px; }
.nr-fabspec-title {
  font-size: 12px; font-weight: 600; color: var(--text);
  margin-bottom: 6px;
}
.nr-fabspec-grid {
  display: flex; flex-wrap: wrap; gap: 6px 10px; margin-bottom: 4px;
}
.nr-spec-cell {
  font-size: 11px; color: var(--text);
  background: var(--surf); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 9px;
}
.nr-spec-cell b { color: var(--dim); font-weight: 500; margin-right: 6px; }

.nr-table {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px;
  overflow-x: auto;
}

.nr-head, .nr-row { display: flex; align-items: center; gap: 6px; }
.nr-head {
  font-size: 9.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--dim);
  padding: 0 0 5px 1px;
}
.nr-head .nr-x { width: 18px; flex: none; }
.nr-row { padding: 2px 0; }
.nr-row:hover .nr-del { opacity: 1; }

.nr-in {
  flex: none;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  color: var(--bright);
  font-size: 11px;
  font-family: inherit;
  padding: 4px 6px;
  outline: none;
  min-width: 0;
}
.nr-in:focus { border-color: var(--blue); }
.nr-in::placeholder { color: #4a5058; }
.nr-in[type=number]::-webkit-inner-spin-button,
.nr-in[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.nr-in[type=number] { -moz-appearance: textfield; appearance: textfield; }

.nr-del {
  flex: none;
  width: 18px; height: 18px;
  background: none; border: none;
  color: var(--dim);
  font-size: 14px; line-height: 1;
  cursor: pointer; opacity: 0;
  border-radius: 3px;
}
.nr-del:hover { color: var(--red); background: var(--surf3); }
.nr-add { margin-top: 8px; font-size: 10.5px; padding: 4px 9px; }

.nr-findings { margin-top: 2px; }
.nr-find {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 11px;
  line-height: 1.5;
  padding: 7px 9px;
  border-radius: var(--r);
  margin-bottom: 6px;
  border: 1px solid transparent;
}
.nr-find.err { color: var(--text); background: rgba(248, 81, 73, .07); border-color: rgba(248, 81, 73, .28); }
.nr-find.wrn { color: var(--text); background: rgba(227, 179, 65, .07); border-color: rgba(227, 179, 65, .25); }
.nr-find .nr-sev { flex: none; }
.nr-find.err .nr-sev { color: var(--red); }
.nr-find.wrn .nr-sev { color: var(--yellow); }
.nr-msg { min-width: 0; }

.nr-open {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 10.5px;
  font-family: inherit;
  cursor: pointer;
  padding: 0 0 0 2px;
  white-space: nowrap;
}
.nr-open:hover { color: var(--teal); text-decoration: underline; }
