:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f9fbfd;
  --border: #d9e1ec;
  --text: #1a2331;
  --text-muted: #5b6b80;
  --primary: #1f4e79;
  --primary-2: #2f5496;
  --primary-soft: #d9eaf7;
  --accent: #2e7d32;
  --warn: #c0392b;
  --shadow: 0 4px 14px rgba(20, 50, 90, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Calibri", "Inter", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: linear-gradient(90deg, #1f4e79 0%, #2f5496 100%);
  color: #fff;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 40px; height: 40px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.18);
  display: grid; place-items: center;
  font-weight: 700; font-size: 16px; letter-spacing: 0.5px;
  border: 1px solid rgba(255, 255, 255, 0.4);
}
.brand-title { font-size: 16px; font-weight: 600; }
.brand-sub { font-size: 12px; opacity: 0.85; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.badge {
  padding: 3px 10px; font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  background: rgba(255, 255, 255, 0.18); border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
}

.stepper {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 28px;
}
.stepper ol {
  display: flex; flex-wrap: wrap; gap: 8px;
  list-style: none; padding: 0; margin: 0;
}
.stepper li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 13px;
  user-select: none;
}
.stepper li .num {
  width: 22px; height: 22px; border-radius: 50%;
  background: #e3eaf3;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
}
.stepper li.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}
.stepper li.active .num { background: var(--primary); color: #fff; }
.stepper li.done { color: var(--accent); border-color: #b6dab8; background: #ebf6ec; }
.stepper li.done .num { background: var(--accent); color: #fff; }

main {
  max-width: 1200px;
  margin: 24px auto 60px;
  padding: 0 24px;
}

.step-header h1 {
  font-size: 22px;
  margin: 0 0 6px;
  color: var(--primary);
}
.step-header p {
  margin: 0 0 18px;
  color: var(--text-muted);
}

.grid2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}
.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}
@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--primary);
}
.card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--primary-2);
}
.card.auto { background: var(--surface-2); }

.form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.form.inline {
  grid-template-columns: repeat(3, 1fr);
}
@media (max-width: 700px) {
  .form.inline { grid-template-columns: 1fr; }
}
.form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}
.form label.row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(47, 84, 150, 0.15);
}

.btn {
  cursor: pointer;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  transition: background 0.15s, transform 0.05s, border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--primary-2); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn.ghost {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary-soft);
}
.btn.ghost:hover { background: var(--primary-soft); }
.btn.small {
  padding: 5px 10px;
  font-size: 12px;
}
.btn[disabled], .btn.primary[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--text-muted); font-size: 13px; }
.kv .v { font-weight: 600; color: var(--text); }
.kv .v.big { font-size: 22px; color: var(--primary); }
.auto-block { display: flex; flex-direction: column; }
.hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
  background: #fff7e0;
  border: 1px solid #f0d27a;
  border-radius: 6px;
  padding: 8px 10px;
}
.hint.compact {
  margin-top: 0;
  padding: 7px 9px;
}

.examples { margin-top: 14px; }
.muted { color: var(--text-muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  cursor: pointer;
  padding: 4px 10px;
  font-size: 12px;
  background: var(--primary-soft);
  border: 1px solid #b8d4ec;
  border-radius: 999px;
  color: var(--primary);
  user-select: none;
}
.chip:hover { background: #c5dff3; }

.schema-controls {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}
.schema-wrap {
  position: relative;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #f7faff 0%, #eef2f8 100%);
  border-radius: 12px;
  padding: 10px;
  border: 1px solid var(--border);
}
#schema, #ndtSchema { width: 100%; max-width: 540px; height: auto; display: block; }
.schema-card { min-width: 0; }

.legend { display: flex; gap: 14px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.legend-item { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.reper { background: #c0392b; }
.dot.sector { background: #b8d4ec; border: 1px solid #6ea4d6; }
.dot.filled { background: #6ea4d6; }

.sector-list { display: flex; flex-direction: column; gap: 8px; }
.sector-row {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.sector-row.filled { background: #ebf6ec; border-color: #b6dab8; }
.sector-num {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
  font-weight: 600;
}
.sector-info { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.sector-info .who { font-weight: 600; }
.sector-info .meta { color: var(--text-muted); font-size: 12px; }

.root-block { margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--border); }

.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; }
.modal[hidden] { display: none !important; }
.modal-bg { position: absolute; inset: 0; background: rgba(20, 30, 50, 0.45); }
.modal-card {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  width: min(440px, 92vw);
  box-shadow: 0 20px 60px rgba(20, 30, 50, 0.3);
}
.modal-card h2 { margin: 0 0 14px; color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

.kv-list { display: flex; flex-direction: column; }
.kv-list .kv { padding: 6px 0; }

.placement-summary { display: flex; flex-direction: column; gap: 6px; }
.placement-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.placement-row .num {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 600;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  box-shadow: var(--shadow);
}
.kpi-label { color: var(--text-muted); font-size: 13px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--primary); margin-top: 4px; }

.report, .defect-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.report th, .report td,
.defect-table th, .defect-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.report thead th, .defect-table thead th {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.status-pill.ok { background: #ebf6ec; color: var(--accent); border: 1px solid #b6dab8; }
.status-pill.bad { background: #fdecea; color: var(--warn); border: 1px solid #f5b7af; }

.auto-attach {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
.auto-attach .k { white-space: nowrap; }
.auto-attach .v { font-weight: 600; color: var(--primary); }

.center { text-align: center; }
.mt { margin-top: 16px; }

.foot {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 14px 0 24px;
}

/* ====== Схема в стиле чертежа ====== */

.schema-card { background: #ffffff; }
.schema-title {
  text-align: center;
  font-style: italic;
  font-size: 14px;
  font-weight: 600;
  color: #1f4e79;
  margin-bottom: 8px;
}
.schema-note {
  margin-top: 8px;
  font-size: 11px;
  color: #5b6b80;
  background: #fafbfd;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  line-height: 1.4;
}

.schema-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
  padding: 12px 14px;
}
.toolbar-label { font-size: 12px; color: var(--text-muted); margin-right: 6px; }
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.toolbar-group.push-right { margin-left: auto; }
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.seg-btn {
  border: none;
  background: transparent;
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn:hover { background: var(--surface-2); color: var(--primary); }
.seg-btn.active {
  background: var(--primary);
  color: #fff;
}
.num-input {
  width: 64px;
  padding: 4px 8px;
  font-size: 13px;
}

/* Окружности стыка */
.ring-outer        { fill: none; stroke: #2a6fb3; stroke-width: 1.4; }
.ring-control      { fill: none; stroke: #2a6fb3; stroke-width: 1.0; }
.ring-layers       { fill: none; stroke: #1a2331; stroke-width: 0.8; }
.ring-root         { fill: none; stroke: #1a4d80; stroke-width: 2.4; }
.ring-inner        { fill: none; stroke: #2a6fb3; stroke-width: 1.0; }

/* Радиальные пунктирные оси */
.axis-line {
  stroke: #d97a2c;
  stroke-width: 1;
  stroke-dasharray: 6 4;
  opacity: 0.85;
}

/* Сектора (кликабельная зона между внешним и корневым контурами) */
.sector-arc {
  fill: rgba(31, 78, 121, 0.0);
  stroke: none;
  cursor: pointer;
  transition: fill 0.15s;
}
.sector-arc:hover { fill: rgba(110, 164, 214, 0.18); }
.sector-arc.filled { fill: rgba(110, 164, 214, 0.18); }
.sector-arc.active { fill: rgba(31, 78, 121, 0.22); }

/* Римские цифры */
.sector-roman {
  font-size: 14px;
  font-weight: 600;
  fill: #1a2331;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  font-style: italic;
  font-family: "Cambria", "Georgia", serif;
}

/* Засечки и подписи долей П */
.scale-tick { stroke: #1a2331; stroke-width: 1; }
.scale-text {
  font-size: 11px;
  fill: #1a2331;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

/* Реперная стрелка */
.reper-arrow { stroke: #1a2331; stroke-width: 1.2; fill: none; }
.reper-arrow-head { fill: #1a2331; }
.reper-text {
  font-size: 10px;
  fill: #1a2331;
  text-anchor: middle;
}

/* Выноски «КЛЕЙМО (факт)» */
.callout-line {
  stroke: #1a2331;
  stroke-width: 0.8;
  fill: none;
}
.callout-box {
  fill: #ffffff;
  stroke: #1a2331;
  stroke-width: 0.8;
  cursor: pointer;
}
.callout-box:hover { fill: #f0f4fa; }
.callout-box.filled { fill: #ebf6ec; stroke: #2e7d32; }
.callout-text {
  font-size: 10px;
  fill: #1a2331;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  font-family: "Cambria", "Georgia", serif;
  font-style: italic;
}
.callout-stamp {
  font-size: 10px;
  font-weight: 700;
  fill: #1f4e79;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

/* Перимиметр кликабельный (для дефектов) */
.perimeter-hit { fill: none; stroke: transparent; stroke-width: 18; cursor: crosshair; }

.defect-marker { fill: #c0392b; stroke: #fff; stroke-width: 1.4; }
.defect-label { font-size: 10px; fill: #c0392b; text-anchor: middle; }

.legend { display: flex; gap: 14px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.legend-item { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.reper { background: #c0392b; }
.dot.sector { background: #b8d4ec; border: 1px solid #6ea4d6; }
.dot.filled { background: #6ea4d6; }

/* ====== Таблица расстановки ====== */
.table-wrap { overflow-x: auto; }
.placement-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  border: 1px solid #1a2331;
}
.placement-table th, .placement-table td {
  border: 1px solid #1a2331;
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
}
.placement-table thead th {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  text-align: center;
}
.placement-table th.subhead, .placement-table td.center {
  text-align: center;
}
.placement-table .roman {
  font-style: italic;
  font-weight: 600;
  text-align: center;
  font-family: "Cambria", "Georgia", serif;
  width: 60px;
}
.placement-table input, .placement-table select {
  width: 100%;
  padding: 4px 6px;
  font-size: 12px;
  border-radius: 4px;
}
.table-foot {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
}
.placement-table .root-row td {
  background: #fff7e0;
}
.placement-table input[data-bind="layerThickness"] {
  max-width: 90px;
  text-align: right;
}

/* Слои в модалке сектора */
.layers-list {
  display: grid;
  grid-template-columns: 90px 1fr 1fr;
  row-gap: 6px;
  column-gap: 8px;
  align-items: center;
}
.layers-list .layer-name {
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  font-style: italic;
}

/* Модалка чертежа */
.modal-card.wide { width: min(820px, 95vw); }
.canon-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.canon-tab {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  padding: 8px 10px;
  font: inherit;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
}
.canon-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.canon-image-wrap {
  border: 1px solid var(--border);
  background: #fafbfd;
  border-radius: 8px;
  padding: 10px;
  display: grid;
  place-items: center;
  max-height: 60vh;
  overflow: auto;
}
.canon-image-wrap img {
  max-width: 100%;
  height: auto;
  display: block;
}
