:root {
  color-scheme: light;
  font: 16px/1.5 "Segoe UI", system-ui, sans-serif;
  color: #172e34;
  background: #eff4f3;
  --muted: #506a70;
  --accent: #075c54;
  --line: #c9d9d7;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
a { color: var(--accent); text-underline-offset: 0.2em; }
:focus-visible { outline: 3px solid #178e81; outline-offset: 3px; }

.topbar {
  padding: 0.9rem max(1rem, calc((100% - 65rem) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: #183b3c;
}
.topbar a { color: #f2fffc; }
.brand { font-weight: 750; font-size: 1.25rem; text-decoration: none; letter-spacing: 0.08em; }
main { max-width: 67rem; margin: 0 auto; padding: 2.4rem 1rem 4rem; }
.page-title { margin-bottom: 1.6rem; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.85rem, 4.5vw, 2.9rem); line-height: 1.12; letter-spacing: -0.03em; }
h2 { font-size: 1.25rem; }
.page-title p { margin-top: 0.55rem; color: var(--muted); }
form { display: grid; gap: 0.9rem; }
.editor, .result-card {
  background: #fff;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
}
.section-head, .actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  column-gap: 1rem;
  row-gap: 0.65rem;
}
.section-head { margin-bottom: 0.9rem; }
.quick-pick { width: min(100%, 24rem); }
.fields, .group { display: grid; gap: 0.75rem; align-items: end; }
.fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.groups { display: grid; gap: 0.75rem; }
.group {
  padding: 0.75rem;
  border: 1px solid #dbe6e4;
  background: #f6faf9;
  border-radius: 0.55rem;
}
.terminal-group { grid-template-columns: 1.1fr 1fr minmax(0, 0.8fr) minmax(0, 0.7fr) auto; }
.gland-group { grid-template-columns: minmax(0, 0.5fr) 2fr minmax(0, 0.7fr) auto; }
label { display: grid; gap: 0.3rem; color: #334e53; font-size: 0.88rem; font-weight: 600; min-width: 0; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 2.6rem;
  padding: 0.38rem 0.55rem;
  background: #fff;
  border: 1px solid #a9c0bd;
  border-radius: 0.35rem;
  color: #172e34;
  font-size: 1rem;
  font-weight: 400;
}
details { margin-top: 0.9rem; }
summary { cursor: pointer; color: var(--accent); font-weight: 650; }
details .fields { margin-top: 0.75rem; }
.ex-field { margin-top: 0.9rem; max-width: 24rem; }
button { cursor: pointer; border-radius: 0.35rem; font-weight: 650; }
button:disabled { opacity: 0.5; cursor: default; }
.secondary { min-height: 2.6rem; padding: 0.35rem 0.65rem; border: 1px solid #a9c0bd; background: #fff; color: var(--accent); }
.primary { min-height: 3rem; padding: 0.5rem 1.05rem; border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.secondary:not(:disabled):hover { background: #e9f3f1; }
.primary:not(:disabled):hover { background: #064b45; }
.actions { justify-content: flex-start; }
.status { color: #39585a; }
#results { margin-top: 1.8rem; }
.result-card { margin-top: 0.65rem; overflow-wrap: anywhere; }
.result-card p { margin-top: 0.35rem; }
.order-form { margin-top: 0.9rem; }
.order-section { margin-top: 0.65rem; margin-bottom: 0; }
.order-position { grid-template-columns: minmax(0, 1fr) minmax(0, 2.25fr) minmax(0, 0.7fr) auto; }
.terminal-order-layout { display: grid; margin-top: 0.75rem; gap: 0.3rem; }
.order-actions { margin-top: 0.5rem; }
.designation { color: var(--muted); }
.result-links {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
}
.result-links span { grid-column: 1 / -1; font-size: 0.9rem; }
.result-links span:empty { display: none; }
.guide { max-width: 54rem; }
.guide > section { margin-top: 0.9rem; }
.guide section h2 { margin-bottom: 0.55rem; }
.guide section p + p { margin-top: 0.6rem; }
.guide pre { overflow-x: auto; padding: 0.85rem; border-radius: 0.4rem; background: #eff5f4; }
.guide code { overflow-wrap: anywhere; }
.guide ul { padding-inline-start: 1.45rem; margin: 0.5rem 0; }

form[data-mode="archive"] .catalog-only { display: none; }
.mode-bar {
  display: grid;
  grid-template-columns: minmax(15rem, 23rem) 1fr;
  align-items: end;
  gap: 1rem;
}
.mode-bar p, .field-help { color: var(--muted); font-size: 0.91rem; }
.component-help, .component-source { color: var(--muted); font-size: 0.88rem; }
.component-help { margin: -0.25rem 0 0.65rem; }
.component-choice, .component-source { grid-column: 1 / -1; }
.component-source { overflow-wrap: anywhere; }
.group input[readonly], .group select:disabled { background: #eff5f4; }
.mode-detail { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }
.order-fields, .mounting-fields { margin-top: 0.85rem; }
.order-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mounting-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sizing-help { padding-inline-start: 1.4rem; margin: 0.65rem 0; overflow-wrap: anywhere; }
.sizing-help li { margin-block: 0.2rem; }
form:is([data-mode="catalog"], [data-mode="two_motor"]) :is(.terminal-group, .gland-group) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
form:is([data-mode="catalog"], [data-mode="two_motor"]) .remove { justify-self: start; }
.motor-fields { margin-top: 0.75rem; }
.motor-edit { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: end; margin-top: 0.8rem; }
.motor-edit label { min-width: min(100%, 13rem); }
.enclosure-layout { margin: 1.25rem 0; }
.enclosure-layout > svg {
  display: block;
  width: min(100%, 34rem);
  margin-block: 0.6rem;
  background: #f5f9f8;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
}
.layout-shell { fill: white; stroke: #55726f; stroke-width: 2; }
.layout-zone { fill: #e2f2eb; stroke: #588170; stroke-dasharray: 4 3; }
.layout-branch[data-branch="M2"] .layout-zone { fill: #e7eff9; stroke: #6882a7; }
.layout-label, .layout-side { fill: #203e42; font-size: 13px; font-weight: 700; }
.layout-side { text-anchor: middle; }
.layout-rail { stroke: #54706e; stroke-dasharray: 6 2; }
.layout-terminal { fill: #54706e; }
.layout-terminal-pe { fill: #8b6c1a; }
.layout-rail-label, .layout-gland text {
  text-anchor: middle;
  dominant-baseline: central;
  font-size: 12px;
  font-weight: 700;
}
.layout-rail-label {
  fill: #203e42;
  stroke: #f5f9f8;
  stroke-width: 4;
  paint-order: stroke;
}
.layout-gland rect { fill: #28554c; }
.layout-branch[data-branch="M2"] .layout-gland rect { fill: #314d78; }
.layout-gland text { fill: white; }
.layout-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr)); gap: 0.6rem; }
.layout-legend section {
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-left: 3px solid #588170;
  border-radius: 0.45rem;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
}
.layout-legend section[data-branch="M2"] { border-left-color: #6882a7; }
.layout-legend h4, .layout-legend ul { margin: 0; }
.layout-legend ul { padding-inline-start: 1.2em; }
.layout-legend li { margin-top: 0.25rem; }
.layout-legend a { display: inline-block; margin-inline-start: 0.6em; }
.cable-record { grid-column: 1 / -1; min-width: 0; }
.cable-record > label { margin-block: 0.5rem; }
.cable-record > fieldset { padding: 0; border: 0; margin: 0.5rem 0; min-width: 0; }
.compound-option { align-self: end; }
.compound-option input { width: auto; }
.view-switch { margin-bottom: 0.65rem; }
.quick-selection fieldset { min-width: 0; border: 0; margin: 0; padding: 0; }
.quick-selection :is(h2, h3) { margin-bottom: 0.4rem; }
.quick-selection :is(.fields, .quick-journal-label, details) { margin-top: 0.75rem; }
.quick-journal-label { width: min(100%, 22rem); }
.quick-kvark { margin-top: 0.65rem; }
.quick-kvark input { width: auto; }
.quick-factory-profile { margin: 0.55rem 0; }
#quick-cables, #quick-matches, #quick-ex-lines { display: grid; gap: 0.75rem; margin-block: 0.85rem; }
.quick-cable, .quick-match { border: 1px solid var(--line); border-radius: 0.55rem; padding: 0.75rem; }
.quick-match label, .quick-match a { display: block; max-width: 32rem; margin-top: 0.55rem; }
.quick-actions { margin-top: 0.8rem; flex-wrap: wrap; }
.gland-picker { display: grid; gap: 0.45rem; justify-items: start; margin: 0.5rem 0; }
.gland-match-options { width: 100%; min-width: 0; }
.cable-journal { margin: 1rem 0; }
.cable-journal-scroll { overflow-x: auto; margin-block: 0.5rem; }
.cable-journal table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.cable-journal :is(th, td) {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
  overflow-wrap: anywhere;
}
.cable-journal th { background: #edf5f1; }
.order-attachments { display: grid; gap: 0.35rem; }
.clear-drawings { justify-self: start; }

.sizing-visual {
  display: grid;
  grid-template-columns: minmax(16rem, 1fr) minmax(15rem, 1.35fr);
  gap: 1.2rem;
  margin: 1rem 0;
}
.archive-visual { max-width: 24rem; margin-top: 0.85rem; }
.box-figure { margin: 0; align-self: start; }
.box-diagram {
  display: grid;
  grid-template-columns: auto minmax(6rem, 1fr) auto;
  grid-template-rows: auto minmax(7rem, 1fr) auto;
  gap: 0.35rem;
  padding: 0.65rem;
  align-items: center;
  justify-items: center;
  background: #eff5f4;
  border-radius: 0.55rem;
}
.box-face {
  grid-area: 2 / 2;
  display: grid;
  place-items: center;
  align-self: stretch;
  justify-self: stretch;
  border: 2px solid #567e7a;
  border-radius: 0.42rem;
  background: white;
  color: var(--muted);
  font-size: 0.9rem;
}
.box-face::before {
  content: "";
  grid-area: 1 / 1;
  width: 92%;
  height: 1.6rem;
  border-block: 1px dashed #a4c1ba;
}
.box-face span { grid-area: 1 / 1; padding-inline: 0.2rem; background: #fff; }
.side {
  padding: 0.16rem 0.4rem;
  border-radius: 0.25rem;
  background: #dcebe8;
  color: #184743;
  font-size: 0.88rem;
  font-weight: 650;
  white-space: nowrap;
}
.side-a { grid-area: 1 / 2; }
.side-b { grid-area: 3 / 2; }
.side-c { grid-area: 2 / 1; }
.side-d { grid-area: 2 / 3; }
.box-figure figcaption, .catalog-drawing figcaption, .enclosure-layout figcaption {
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.catalog-drawing { margin: 1rem 0; max-width: 44rem; }
.catalog-drawing img { display: block; max-width: 100%; height: auto; background: white; }
.dimension-comparison { display: grid; gap: 0.65rem; }
.dimension-line {
  padding: 0.5rem 0.75rem;
  border: 1px solid #dbe6e4;
  border-radius: 0.55rem;
}
.dimension-line p { color: var(--muted); font-size: 0.88rem; }
.dimension-bar { display: block; width: 100%; height: 0.65rem; margin-top: 0.3rem; accent-color: var(--accent); }
.catalog-designation { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.45rem; }
.catalog-designation span { grid-column: 1 / -1; font-size: 0.9rem; }
.catalog-designation span:empty { display: none; }

@media (max-width: 760px) {
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .terminal-group, .gland-group { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .order-position { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-links { grid-template-columns: minmax(0, 1fr) auto; }
  .result-links a { grid-column: 1 / -1; }
  .mode-bar, .sizing-visual { grid-template-columns: 1fr; }
  .mounting-fields, form:is([data-mode="catalog"], [data-mode="two_motor"]) :is(.terminal-group, .gland-group) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 390px) {
  main { padding-top: 1.5rem; }
  .editor, .result-card { padding: 0.8rem; }
  .result-links { grid-template-columns: 1fr; justify-items: start; }
  .catalog-designation, .order-fields { grid-template-columns: 1fr; }
}
