/* MakeFilter — workbench UX + unified chrome */

button.btn-primary,
a.btn-primary {
  background: var(--ink) !important;
  border-color: var(--ink) !important;
  color: #fff !important;
}
button.btn-primary:hover,
a.btn-primary:hover {
  background: #1a2229 !important;
  border-color: #1a2229 !important;
}

.app-header {
  padding: 0 1rem;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  min-height: var(--header-h);
  height: auto;
}

.header-actions { gap: 0.4rem; flex-wrap: wrap; }

.balance-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 0.82rem/1 var(--mono);
  text-decoration: none;
  border: 1px solid transparent;
}
.balance-chip:hover {
  text-decoration: none;
  border-color: rgba(15, 118, 110, 0.3);
}

.user-email {
  font-size: 0.8rem;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* —— Bench layout: channels | charts | results —— */
.page-app .workspace,
.tool-shell .workspace {
  height: calc(100vh - var(--header-h));
  min-height: 0;
  background: var(--bg);
}

.tool-shell .workspace {
  height: auto;
  min-height: 72vh;
}

.page-app .main-pane,
.tool-shell .main-pane {
  padding: 0;
  height: 100%;
  overflow: hidden;
}

.tool-shell .main-pane {
  height: auto;
  overflow: visible;
}

.bench {
  display: grid;
  grid-template-columns: minmax(300px, 340px) minmax(0, 1.35fr) minmax(280px, 380px);
  gap: 0;
  height: 100%;
  min-height: 0;
  align-items: stretch;
}

.tool-shell .bench {
  height: auto;
  min-height: 70vh;
}

.channels {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #f7f9fb;
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: 0.75rem 0.7rem 1rem;
}

.channels-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  padding: 0 0.15rem;
}

.channels-head strong {
  font-family: var(--display);
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

.channels-head .muted {
  font-size: 0.72rem;
}

.channel-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.channel-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.75rem 0.8rem;
  box-shadow: inset 3px 0 0 var(--band, var(--accent));
  display: grid;
  gap: 0.7rem;
}

.channel-card[data-band="lf"] { --band: var(--lf); }
.channel-card[data-band="mf"] { --band: var(--mf); }
.channel-card[data-band="hf"] { --band: var(--hf); }

.channel-card.is-off {
  opacity: 0.72;
}

.channel-head {
  display: grid;
  gap: 0.55rem;
}

.channel-name {
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--band, var(--ink));
}

.channel-selects {
  display: grid;
  grid-template-columns: 1.3fr 1fr 0.7fr;
  gap: 0.4rem;
}

.channel-card.is-off .channel-selects {
  grid-template-columns: 1fr 0.7fr;
}

.field-label {
  display: grid;
  gap: 0.2rem;
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.field-label select {
  width: 100%;
  min-width: 0;
  padding: 0.45rem 0.4rem;
  font-size: 0.82rem;
}

.cut-list {
  display: grid;
  gap: 0.45rem;
}

.cut {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr) 5.6rem;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.4rem;
}

.cut-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  cursor: pointer;
  user-select: none;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 700;
}

.cut-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.cut-toggle-ui {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1.5px solid var(--line-strong);
  background: #fff;
  flex: none;
  display: grid;
  place-items: center;
}

.cut-toggle-ui::after {
  content: "";
  width: 9px;
  height: 5px;
  border-left: 2px solid transparent;
  border-bottom: 2px solid transparent;
  transform: rotate(-45deg) translate(0.5px, -1px);
}

.cut-toggle input:checked + .cut-toggle-ui {
  background: var(--accent);
  border-color: var(--accent);
}

.cut-toggle input:checked + .cut-toggle-ui::after {
  border-color: #fff;
}

.cut-toggle input:focus-visible + .cut-toggle-ui {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cut-name {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.cut.is-off .cut-slider,
.cut.is-off .cut-hz {
  opacity: 0.4;
  pointer-events: none;
}

.cut-slider,
.z-field input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  accent-color: var(--ink);
}

.page-app input[type="range"],
.tool-shell input[type="range"] {
  appearance: none;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

.page-app input[type="range"]::-webkit-slider-runnable-track,
.tool-shell input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: #d5dde4;
}

.page-app input[type="range"]::-webkit-slider-thumb,
.tool-shell input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--ink);
  box-shadow: 0 1px 4px rgba(12, 16, 20, 0.25);
}

.page-app input[type="range"]::-moz-range-track,
.tool-shell input[type="range"]::-moz-range-track {
  height: 6px;
  border: none;
  border-radius: 999px;
  background: #d5dde4;
}

.page-app input[type="range"]::-moz-range-thumb,
.tool-shell input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 1px 4px rgba(12, 16, 20, 0.25);
}

.cut-hz.with-unit input,
.z-read.with-unit input {
  width: 5.4rem;
  padding: 0.4rem 1.55rem 0.4rem 0.35rem;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.84rem;
  font-weight: 500;
}

.channel-params {
  display: grid;
  gap: 0.45rem;
}

.z-field {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr) 5.6rem;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  min-height: 2.4rem;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
}

.z-label { white-space: nowrap; }

/* —— Charts column —— */
.viz {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
  background: var(--bg);
}

.screen {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem 0.65rem;
}

.screen-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
  min-height: 1.5rem;
}

.screen-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.trace-toggles {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem 0.85rem;
  margin: 0;
}

.page-app .chart-wrap,
.tool-shell .chart-wrap {
  border: 0;
  background: #f7f9fb;
  border-radius: var(--radius-sm);
}

.page-app .chart-wrap-hero,
.tool-shell .chart-wrap-hero {
  height: clamp(220px, 32vh, 340px);
}

.page-app .chart-wrap-phase,
.tool-shell .chart-wrap-phase {
  height: clamp(140px, 18vh, 200px);
}

/* —— Results column —— */
.readout {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
  background: #f7f9fb;
  border-left: 1px solid var(--line);
  width: auto;
  position: static;
}

.page-app .parts-card,
.page-app .schematic-card,
.page-app .readout .schematic,
.page-app .readout .phase-hint,
.tool-shell .parts-card,
.tool-shell .readout .schematic,
.tool-shell .readout .phase-hint {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.parts-card { padding: 0.55rem 0.55rem 0.35rem; }

.parts-head {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.4rem 0.15rem;
}

.page-app .schematic { padding: 0.25rem; }

.page-app .schematic-scroll,
.tool-shell .schematic-scroll {
  height: 280px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
}

.page-app .schematic-svg,
.tool-shell .schematic-svg {
  width: 100%;
  height: 280px;
  min-width: 0;
  display: block;
}

.page-app .phase-hint,
.tool-shell .phase-hint {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin: 0;
  padding: 0.7rem 0.8rem;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.45;
}

.page-app .components-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.page-app .components-table th {
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  padding: 0.4rem 0.35rem;
  border-bottom: 1px solid var(--line);
  background: #f7f9fb;
}
.page-app .components-table td {
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid #e8eef2;
  vertical-align: middle;
}
.page-app .nominal-value { font-family: var(--mono); font-size: 0.84rem; }

.auth-gate-dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.35rem 1.4rem;
  max-width: 400px;
  background: #fff;
  box-shadow: var(--shadow-lg);
}
.auth-gate-dialog::backdrop { background: rgba(12, 16, 20, 0.45); }
.auth-gate-dialog h2 {
  margin: 0;
  font-family: var(--display);
  letter-spacing: -0.03em;
}
.auth-gate-dialog .lead { margin: 0.65rem 0 0; }

dialog {
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}

.tool-shell .page-app {
  min-height: 0;
  display: block;
  background: transparent;
}

.tool-shell .workspace {
  background: #f0f3f6;
}

[hidden] { display: none !important; }
.page-app.is-guest #user-balance { display: none !important; }

/* Kill old 2-col stage constraints when present */
.stage { display: contents; }
.controls-col { display: contents; }
.channel-row { display: contents; }

@media (max-width: 1200px) {
  .bench {
    grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
    grid-template-rows: auto auto;
  }
  .channels { grid-row: 1 / span 2; }
  .viz { grid-column: 2; }
  .readout {
    grid-column: 2;
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 50vh;
  }
}

@media (max-width: 860px) {
  .page-app .workspace,
  .tool-shell .workspace {
    height: auto;
  }
  .page-app .main-pane,
  .tool-shell .main-pane {
    overflow: visible;
    height: auto;
  }
  .bench {
    display: flex;
    flex-direction: column;
    height: auto;
  }
  .channels,
  .viz,
  .readout {
    border: 0;
    max-height: none;
    overflow: visible;
  }
  .channels {
    border-bottom: 1px solid var(--line);
    order: 1;
  }
  .viz { order: 2; }
  .readout {
    order: 3;
    border-top: 1px solid var(--line);
  }
  .page-app .chart-wrap-hero,
  .tool-shell .chart-wrap-hero { height: 240px; }
  .page-app .chart-wrap-phase,
  .tool-shell .chart-wrap-phase { height: 160px; }
  .cut {
    grid-template-columns: 4.2rem minmax(0, 1fr);
  }
  .cut-hz { grid-column: 2; justify-self: end; }
  .z-field {
    grid-template-columns: 4.2rem minmax(0, 1fr);
  }
  .z-read { grid-column: 2; justify-self: end; }
  .channel-selects {
    grid-template-columns: 1fr 1fr;
  }
}
