/* Harmonic calculator: inspector (properties panel) and form fields.
   Tokens only. Layout: 16px panel padding, 12px between fields, hairlines
   between sections. State is drawn from aria-* attributes where they exist. */

/* Author display rules would otherwise beat the UA [hidden] rule. */
.hc-insp [hidden] { display: none !important; }

.hc-insp {
  display: flex; flex-direction: column; min-height: 100%;
  background: var(--surface-card);
}
.hc-insp:focus { outline: none; box-shadow: none; }   /* a focus target for panel rebuilds, not a control */
.hc-insp--in { animation: ar-fade var(--dur-fast) var(--ease-out); }

/* ---- Header ------------------------------------------------------------------ */
.hc-insp__head {
  display: grid; gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--line-default);
  background: var(--surface-page);
}
.hc-insp__kindrow { display: flex; align-items: center; gap: var(--space-3); min-width: 0; min-height: 20px; }
.hc-insp__parentwrap {
  flex: 1 1 auto; min-width: 0;
  font: var(--type-caption); color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hc-insp__parent {
  padding: 0; border: 0; border-bottom: 1px solid var(--red-200); border-radius: 0;
  background: none; color: var(--text-link); font: inherit; cursor: pointer;
  transition: var(--transition-control);
}
.hc-insp__parent:hover { color: var(--text-link-hover); border-bottom-color: var(--red-500); }
.hc-insp__close { display: none; margin: -4px -8px -4px auto; }
@media (max-width: 1180px) and (min-width: 761px) {
  .hc-insp__close { display: inline-flex; }
}

.hc-fld.hc-insp__namefield { display: block; }
.hc-insp__name {
  display: block; width: calc(100% + 14px); margin: 0 -7px; padding: 2px 6px;
  font: var(--type-h3); letter-spacing: var(--tracking-tight); color: var(--text-primary);
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-1);
  transition: var(--transition-control);
}
.hc-insp__name:hover { border-color: var(--line-default); }
.hc-insp__name:focus { outline: 2px solid var(--red-500); outline-offset: -1px; border-color: var(--red-500); background: var(--surface-card); box-shadow: none; }
.hc-insp__name[aria-invalid="true"] { box-shadow: inset 0 -2px 0 var(--red-500); }
.hc-insp__namefield .hc-fld__err { margin-top: var(--space-2); }

.hc-insp__actions { display: flex; align-items: center; gap: var(--space-2); min-width: 0; margin: 0 -8px -4px 0; }
.hc-insp__inherited { font: var(--type-caption); color: var(--text-secondary); min-width: 0; }

/* ---- Result summary ------------------------------------------------------------- */
.hc-sum {
  display: grid; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line-default);
}
.hc-sum__head { display: flex; align-items: baseline; gap: var(--space-3); min-width: 0; }
.hc-sum__scenario { margin-left: auto; font: var(--type-caption); color: var(--text-secondary); white-space: nowrap; }
.hc-sum__body { display: grid; gap: var(--space-4); }
.hc-sum__hero { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); min-width: 0; }
.hc-sum__tile { display: grid; gap: 2px; min-width: 0; align-content: start; }
.hc-sum__tile--hero { flex: 1 1 0; }
.hc-sum__v {
  font: var(--type-mono); font-variant-numeric: tabular-nums; letter-spacing: var(--tracking-mono);
  color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hc-sum__v--hero { font-family: var(--font-mono); font-size: 22px; font-weight: 500; line-height: 1.15; }
/* Secondary figure under a tile value, e.g. 'Total ≈ 4.1 %' (THDv with background). */
.hc-sum__sub {
  font: 500 12px/1.3 var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: var(--tracking-mono);
  color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hc-sum__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3) var(--space-4); }
.hc-sum__msg { margin: 0; font: var(--type-body-sm); color: var(--text-secondary); }
.hc-sum__errors { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--space-2); }
.hc-sum__errors .hc-status { white-space: normal; align-items: baseline; font: var(--type-body-sm); }
.hc-sum__errors .hc-status::before { transform: translateY(-2px); }
.hc-sum__note { margin: 0; font: var(--type-caption); color: var(--text-secondary); }

/* Sparkline: bars scale from the baseline; tokens only, both themes. */
.hc-spark__wrap { display: grid; gap: var(--space-1); flex: none; }
.hc-spark { display: block; overflow: visible; }
.hc-spark__bar {
  fill: var(--text-secondary);
  transform-box: fill-box; transform-origin: 50% 100%;
  transition: transform var(--dur-base) var(--ease-out);
}
.hc-spark__bar.is-max { fill: var(--text-primary); }
.hc-spark__base { stroke: var(--line-strong); stroke-width: 1; }
.hc-spark__cap {
  display: flex; justify-content: space-between; gap: var(--space-3);
  font: 500 12px/1 var(--font-mono); font-variant-numeric: tabular-nums; color: var(--text-secondary);
}

/* ---- Sections --------------------------------------------------------------------- */
.hc-insp-sec { border-bottom: 1px solid var(--line-default); }
.hc-insp-sec__head.hc-panelhead { min-height: 44px; height: auto; padding: 0; background: var(--surface-page); }
.hc-insp-sec[data-open="false"] > .hc-insp-sec__head { border-bottom-color: transparent; }
.hc-insp-sec__title { flex: 1 1 auto; min-width: 0; height: 100%; margin: 0; font: inherit; }
.hc-insp-sec__toggle {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%; min-height: 44px; height: 100%; padding: 0 var(--space-5);
  border: 0; border-radius: 0; background: none; color: var(--text-secondary);
  text-align: left; cursor: pointer; transition: var(--transition-control);
}
.hc-insp-sec__toggle:hover { background: var(--surface-hover); color: var(--text-primary); }
.hc-insp-sec__toggle:hover .ar-label { color: var(--text-primary); }
.hc-insp-sec__toggle:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--red-500); }
.hc-insp-sec__toggle .hc-icon { transition: transform var(--dur-fast) var(--ease-out); }
.hc-insp-sec__toggle[aria-expanded="false"] .hc-icon { transform: rotate(-90deg); }
.hc-insp-sec__body {
  display: flex; flex-direction: column; gap: var(--space-4);
  padding: var(--space-5);
  animation: ar-fade var(--dur-fast) var(--ease-out);
}
.hc-insp-sec__toggle .ar-label { font-weight: var(--fw-semibold); color: var(--text-primary); }

/* Nested collapsible (generator lead cable). */
.hc-insp-sec--nested { border: 1px solid var(--line-default); border-radius: var(--radius-2); overflow: hidden; }
.hc-insp-sec--nested .hc-insp-sec__toggle { padding: 0 var(--space-4); }
.hc-insp-sec--nested .hc-insp-sec__body { padding: var(--space-4); }

/* Groups span the panel width so the highlight rule sits on the panel edge. */
.hc-insp-group {
  display: flex; flex-direction: column; gap: var(--space-4);
  margin: 0 calc(-1 * var(--space-5)); padding: 0 var(--space-5);
}
.hc-insp-group + .hc-insp-group { padding-top: var(--space-4); border-top: 1px solid var(--line-hairline); }
.hc-insp-group__head { margin-bottom: calc(-1 * var(--space-2)); }

.hc-insp__reveal { display: flex; flex-direction: column; gap: var(--space-4); animation: ar-fade var(--dur-fast) var(--ease-out); }
.hc-insp__btnrow { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.hc-insp__rule { width: 100%; height: 1px; margin: 0; border: 0; background: var(--line-hairline); }

/* Highlight ("hold, then fade"): inspector.js adds the class, holds it about
   1s, then adds --out, which fades the 2px red inline-start rule over
   --dur-slow. No keyframes; reduced motion makes the fade instant. */
.hc-flash {
  box-shadow: inset 2px 0 0 var(--red-500);
  transition: box-shadow var(--dur-slow) var(--ease-out);
}
.hc-flash.hc-flash--out { box-shadow: inset 2px 0 0 transparent; }
.hc-flash--field { position: relative; }
.hc-flash--field::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: calc(-1 * var(--space-5)); width: 2px;
  background: var(--red-500); pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease-out);
}
.hc-flash--field.hc-flash--out::before { opacity: 0; }

/* ---- Field rows --------------------------------------------------------------------- */
.hc-fld {
  display: grid; grid-template-columns: minmax(0, 1fr) 136px;
  align-items: center; column-gap: var(--space-4); row-gap: var(--space-2);
  min-width: 0;
}
.hc-fld > .hc-fld__hint,
.hc-fld > .hc-fld__err,
.hc-fld > .hc-slider { grid-column: 1 / -1; }
.hc-fld--stack { grid-template-columns: minmax(0, 1fr); }
.hc-fld--seg:not(.hc-fld--stack) { grid-template-columns: minmax(0, 1fr) auto; }
.hc-fld--check { row-gap: var(--space-1); }
.hc-fld__hint, .hc-fld__err { margin: 0; }
.hc-fld__note { margin: 0; font: var(--type-caption); color: var(--text-secondary); }

.hc-fld__label {
  min-width: 0; font: var(--type-caption); color: var(--text-secondary);
  overflow-wrap: anywhere; user-select: none;
}
.hc-fld__label--scrub { cursor: ew-resize; touch-action: pan-y; transition: var(--transition-control); }
.hc-fld__label--scrub:hover { color: var(--text-primary); }
.hc-fld[data-disabled="true"] .hc-fld__label--scrub { cursor: default; color: var(--text-secondary); }
html.hc-scrubbing, html.hc-scrubbing * { cursor: ew-resize !important; user-select: none !important; }

/* Number input: a bordered box holding a right-aligned mono input and its unit. */
.hc-fld__box {
  display: flex; align-items: center; min-width: 0; height: 44px;
  background: var(--surface-card); border: 1px solid var(--line-default); border-radius: var(--radius-1);
  cursor: text; transition: var(--transition-control);
}
.hc-fld__box:hover { border-color: var(--line-strong); }
.hc-fld__box:focus-within { border-color: var(--red-500); outline: 2px solid var(--red-500); outline-offset: -1px; }
.hc-fld--invalid .hc-fld__box { box-shadow: inset 0 -2px 0 var(--red-500); }
.hc-fld[data-disabled="true"] .hc-fld__box { background: var(--surface-disabled); border-color: var(--line-default); cursor: not-allowed; }
.hc-fld__input {
  flex: 1 1 auto; min-width: 0; height: 100%; margin: 0; padding: 0 var(--space-3);
  border: 0; background: transparent; color: var(--text-primary);
  font: var(--type-mono); font-variant-numeric: tabular-nums; letter-spacing: var(--tracking-mono);
  text-align: right;
}
/* The box draws the focus ring for the input it holds. */
.hc-fld__input:focus, .hc-fld__input:focus-visible { outline: none; box-shadow: none; }
.hc-fld__input:disabled { color: var(--text-muted); cursor: not-allowed; }
.hc-fld__unit {
  flex: none; padding-right: var(--space-3); margin-left: calc(-1 * var(--space-2));
  font: 500 12px/1 var(--font-mono); color: var(--text-secondary); white-space: nowrap;
}

.hc-fld__text, .hc-fld__select { min-height: 44px; }
.hc-fld__text[aria-invalid="true"], .hc-fld__select[aria-invalid="true"], .hc-fld__area[aria-invalid="true"] { box-shadow: inset 0 -2px 0 var(--red-500); }
.hc-fld__select { cursor: pointer; }
.hc-fld__area { width: 100%; min-height: 88px; }

/* Slider under a number field: 2px track, ink fill, square 14px thumb.
   The fill is --line-strong (charcoal in light, light grey in dark) so it
   stands out from the --line-default track in both themes. */
.hc-slider {
  --hc-thumb: 14px;
  position: relative; height: 20px; margin-top: calc(-1 * var(--space-1));
}
.hc-slider::before {
  content: ''; position: absolute; top: 50%; left: calc(var(--hc-thumb) / 2); right: calc(var(--hc-thumb) / 2);
  height: 2px; margin-top: -1px; background: var(--line-default); pointer-events: none;
}
.hc-slider__fill {
  position: absolute; top: 50%; left: calc(var(--hc-thumb) / 2); height: 2px; margin-top: -1px;
  width: calc((100% - var(--hc-thumb)) * var(--hc-p, 0)); background: var(--line-strong); pointer-events: none;
}
.hc-slider__input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0;
  background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer;
}
.hc-slider__input:focus, .hc-slider__input:focus-visible { outline: none; box-shadow: none; }
.hc-slider__input::-webkit-slider-runnable-track { height: 100%; background: transparent; border: 0; }
.hc-slider__input::-moz-range-track { height: 2px; background: transparent; border: 0; }
.hc-slider__input::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: var(--hc-thumb); height: var(--hc-thumb); margin-top: calc((20px - var(--hc-thumb)) / 2);
  background: var(--surface-card); border: 1px solid var(--line-strong); border-radius: var(--radius-1);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.hc-slider__input::-moz-range-thumb {
  box-sizing: border-box; width: var(--hc-thumb); height: var(--hc-thumb);
  background: var(--surface-card); border: 1px solid var(--line-strong); border-radius: var(--radius-1);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.hc-slider__input:hover::-webkit-slider-thumb { border-color: var(--text-primary); }
.hc-slider__input:hover::-moz-range-thumb { border-color: var(--text-primary); }
.hc-slider__input:focus-visible::-webkit-slider-thumb { box-shadow: var(--focus-ring); }
.hc-slider__input:focus-visible::-moz-range-thumb { box-shadow: var(--focus-ring); }
.hc-slider__input:disabled { cursor: not-allowed; }
.hc-slider__input:disabled::-webkit-slider-thumb { background: var(--surface-disabled); border-color: var(--line-default); }
.hc-slider__input:disabled::-moz-range-thumb { background: var(--surface-disabled); border-color: var(--line-default); }
.hc-fld[data-disabled="true"] .hc-slider__fill { background: var(--line-default); }

/* Segmented controls inside fields keep app.css styling. */
.hc-fld .hc-seg { min-width: 0; }
.hc-fld--seg .hc-seg:not(.hc-seg--full) { justify-self: end; }
.hc-seg > button:focus-visible { position: relative; z-index: 1; }

/* Stepper: − value + in one bordered group. */
.hc-stepper {
  display: flex; align-items: stretch; height: 44px; min-width: 0;
  background: var(--surface-card); border: 1px solid var(--line-default); border-radius: var(--radius-1);
  transition: var(--transition-control);
}
.hc-stepper:hover { border-color: var(--line-strong); }
.hc-stepper__btn {
  flex: none; display: grid; place-items: center; width: 44px; padding: 0;
  border: 0; border-radius: 0; background: transparent; color: var(--text-primary); cursor: pointer;
  transition: var(--transition-control);
}
.hc-stepper__btn:hover:not(:disabled) { background: var(--surface-hover); }
.hc-stepper__btn:active:not(:disabled) { background: var(--surface-active); }
.hc-stepper__btn:active:not(:disabled) .hc-icon { transform: translateY(1px); }
.hc-stepper__btn:disabled { color: var(--text-muted); cursor: not-allowed; }
.hc-stepper__btn:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--red-500); }
.hc-stepper__input {
  flex: 1 1 auto; min-width: 0; width: 100%; padding: 0 var(--space-2);
  border: 0; border-left: 1px solid var(--line-hairline); border-right: 1px solid var(--line-hairline);
  background: transparent; color: var(--text-primary); text-align: center;
  font: var(--type-mono); font-variant-numeric: tabular-nums;
}
.hc-stepper__input:focus, .hc-stepper__input:focus-visible { outline: 2px solid var(--red-500); outline-offset: -2px; box-shadow: none; }
.hc-stepper__input[aria-invalid="true"] { box-shadow: inset 0 -2px 0 var(--red-500); }
.hc-fld[data-disabled="true"] .hc-stepper { background: var(--surface-disabled); }

/* Switch: square track, knob snaps across. */
.hc-switch {
  display: inline-flex; align-items: center; gap: var(--space-3);
  min-height: 44px; padding: 0 var(--space-2) 0 0;
  border: 0; border-radius: var(--radius-1); background: none;
  color: var(--text-primary); font: 500 13px/1 var(--font-sans); cursor: pointer;
}
.hc-switch__track {
  position: relative; flex: none; width: 28px; height: 16px;
  background: var(--surface-sunken); border: 1px solid var(--line-strong); border-radius: var(--radius-1);
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.hc-switch__knob {
  position: absolute; top: 2px; left: 2px; width: 10px; height: 10px;
  background: var(--text-secondary); border-radius: var(--radius-1);
  transition: transform var(--dur-fast) var(--ease-snap), background-color var(--dur-fast) var(--ease-out);
}
.hc-switch:hover .hc-switch__track { border-color: var(--text-primary); }
.hc-switch[aria-checked="true"] .hc-switch__track { background: var(--text-primary); border-color: var(--text-primary); }
.hc-switch[aria-checked="true"] .hc-switch__knob { transform: translateX(12px); background: var(--surface-card); }
.hc-switch:disabled { color: var(--text-muted); cursor: not-allowed; }
.hc-switch:disabled .hc-switch__track { background: var(--surface-disabled); border-color: var(--line-default); }

/* Checkbox row. */
.hc-check {
  display: flex; align-items: center; gap: var(--space-3); min-height: 44px;
  font: var(--type-body-sm); color: var(--text-primary); cursor: pointer;
}
.hc-fld[data-disabled="true"] .hc-check { color: var(--text-muted); cursor: not-allowed; }

/* Quick picks (standard VSD ratings). Not .hc-chip: that is the diagram's bus chip. */
.hc-picks { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: calc(-1 * var(--space-2)); }
.hc-pick {
  height: 24px; min-width: 36px; padding: 0 6px;
  border: 1px solid var(--line-default); border-radius: var(--radius-1);
  background: var(--surface-card); color: var(--text-body); cursor: pointer;
  font: 500 12px/1 var(--font-mono); font-variant-numeric: tabular-nums;
  transition: var(--transition-control);
}
.hc-pick:hover { background: var(--surface-hover); border-color: var(--line-strong); color: var(--text-primary); }
.hc-pick:active { transform: translateY(1px); }
.hc-pick[aria-pressed="true"] {
  background: var(--surface-brand-subtle); border-color: var(--red-200); color: var(--text-primary);
  box-shadow: inset 0 -2px 0 var(--red-500);
}

/* Readout sentences with mono figures. */
.hc-readout {
  margin: 0; padding: var(--space-3);
  background: var(--surface-sunken); border: 1px solid var(--line-hairline); border-radius: var(--radius-1);
  font: var(--type-caption); color: var(--text-body);
}
.hc-readout__n { font: 500 12px/1.45 var(--font-mono); font-variant-numeric: tabular-nums; color: var(--text-primary); white-space: nowrap; }

/* ---- Cable editor ------------------------------------------------------------------ */
.hc-cable { display: flex; flex-direction: column; gap: var(--space-4); }
.hc-cable__readout { display: grid; gap: var(--space-1); }
.hc-cable__rx { font: var(--type-mono); font-variant-numeric: tabular-nums; letter-spacing: var(--tracking-mono); color: var(--text-primary); }
.hc-cable__desc { color: var(--text-body); }
.hc-cable__src { color: var(--text-secondary); }

/* ---- Connected list (bus) ------------------------------------------------------------ */
.hc-conn {
  display: flex; flex-direction: column;
  border: 1px solid var(--line-default); border-radius: var(--radius-2); overflow: hidden;
}
.hc-conn__row {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; align-items: center; gap: var(--space-3);
  width: 100%; min-height: 44px; padding: 0 var(--space-3);
  border: 0; border-bottom: 1px solid var(--line-hairline); border-radius: 0;
  background: var(--surface-card); color: var(--text-primary); text-align: left; cursor: pointer;
  font: var(--type-body-sm); transition: var(--transition-control);
}
.hc-conn > [role="listitem"]:last-child .hc-conn__row { border-bottom: 0; }
.hc-conn__row:hover { background: var(--surface-hover); }
.hc-conn__row:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--red-500); }
.hc-conn__tag { font: var(--type-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-secondary); }
.hc-conn__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-conn__row[data-off="true"] .hc-conn__name { color: var(--text-secondary); }
.hc-conn__off { font: var(--type-caption); color: var(--text-secondary); }
.hc-conn__fig { font: var(--type-mono); font-variant-numeric: tabular-nums; color: var(--text-body); white-space: nowrap; }

/* ---- Touch: 44px hit targets ----------------------------------------------------------- */
@media (pointer: coarse) {
  .hc-insp-sec__head.hc-panelhead { height: 44px; }
  .hc-fld__box, .hc-stepper, .hc-fld__text { height: 44px; }
  .hc-fld__input, .hc-stepper__input { font-size: 16px; }
  .hc-stepper__btn { width: 44px; }
  .hc-fld:not(.hc-fld--stack):not(.hc-fld--seg) { grid-template-columns: minmax(0, 1fr) 152px; }
  .hc-slider { --hc-thumb: 22px; height: 36px; }
  .hc-slider__input::-webkit-slider-thumb { margin-top: calc((36px - var(--hc-thumb)) / 2); }
  .hc-switch, .hc-check, .hc-conn__row, .hc-pick { min-height: 44px; }
  .hc-insp__name { min-height: 44px; }
  .hc-insp__parent { min-height: 44px; }
}
