:root {
  color-scheme: dark;
  --bg: #121920;
  --surface: #1a242d;
  --surface-2: #22303a;
  --line: #3d4d58;
  --muted: #9eb0ba;
  --text: #eef6f7;
  --green: #2fff4c;
  --cyan: #35d8ff;
  --magenta: #ff23df;
  --red: #ff4242;
  --yellow: #ffd44d;
  --blue: #2184ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: rgba(18, 25, 32, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

button,
.file-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: var(--cyan);
}

.ghost {
  background: transparent;
}

.file-button {
  display: inline-flex;
  align-items: center;
}

.file-button input {
  display: none;
}

.icon-btn {
  width: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.print-title {
  display: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(380px, 460px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.controls,
.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.controls {
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 102px);
  overflow: auto;
  padding-right: 4px;
}

.panel,
.view-card,
.metric-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.panel {
  padding: 14px;
}

.panel-head,
.view-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head span,
.view-title span,
.note {
  color: var(--muted);
  font-size: 12px;
}

.grid {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text);
  background: #101820;
}

textarea {
  resize: vertical;
  line-height: 1.35;
}

input[type="color"] {
  height: 34px;
  padding: 3px;
}

select {
  margin-top: 6px;
}

.full {
  margin-top: 10px;
}

.unit-row {
  max-width: 220px;
}

.unit-row select {
  font-weight: 800;
}

.quick-limit {
  max-width: 220px;
}

.group-editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.group-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #15202a;
}

.group-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
}

.group-summary {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 7px;
  min-height: 48px;
  padding: 7px 8px;
  background: #101820;
  text-align: left;
}

.group-summary .mini-dot {
  grid-row: 1 / 3;
}

.group-summary strong,
.group-summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-summary span {
  color: var(--muted);
  font-size: 11px;
}

.group-summary.active {
  border-color: var(--cyan);
  background: #21313d;
}

.selected-group {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px rgba(53, 216, 255, 0.25) inset;
}

.group-row-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.group-row-head input {
  min-width: 0;
}

.color-dot {
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.remove {
  width: 34px;
  padding: 0;
  color: var(--red);
}

.assignment-toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segmented button,
.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #101820;
}

.segmented button.active {
  border-color: var(--cyan);
  background: #21313d;
}

.mini-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.checkbox-line {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.checkbox-line input {
  width: 16px;
  min-height: 16px;
}

.group-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.group-actions.tight {
  margin-top: 8px;
}

.selector-box {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
}

.axle-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.axle-check {
  display: grid;
  grid-template-columns: 16px 10px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #15202a;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.axle-check.checked {
  border-color: var(--cyan);
  background: #20323e;
}

.axle-check input {
  width: 14px;
  min-height: 14px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.metric-card {
  padding: 14px;
}

.metric-card .label {
  color: var(--muted);
  font-size: 12px;
}

.metric-card .value {
  margin-top: 8px;
  font-size: 24px;
  font-weight: 800;
}

.metric-card.safe .value {
  color: var(--green);
}

.metric-card.warn .value {
  color: var(--yellow);
}

.metric-card.fail .value {
  color: var(--red);
}

.template-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.template-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 118px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151f28;
  text-align: left;
}

.template-card strong {
  font-size: 13px;
}

.template-card span {
  color: var(--muted);
  font-size: 12px;
}

.template-card svg {
  width: 100%;
  height: 58px;
}

.views {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.view-card {
  min-width: 0;
  padding: 12px;
}

.view-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.small-select {
  min-height: 30px;
  max-width: 116px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  color: var(--text);
  background: var(--surface-2);
}

.top-view {
  grid-column: 1 / -1;
}

svg {
  width: 100%;
  height: auto;
  display: block;
  background: #17212a;
  border-radius: 6px;
}

#topSvg {
  cursor: pointer;
  height: 620px;
}

.top-view.active #topSvg {
  cursor: grab;
}

.top-view.active #topSvg:active {
  cursor: grabbing;
}

.top-view.active {
  border-color: rgba(53, 216, 255, .75);
  box-shadow: inset 0 0 0 1px rgba(53, 216, 255, .22);
}

.axle-glyph {
  cursor: pointer;
}

.axle-glyph:hover rect {
  stroke: #fff;
  stroke-width: 2;
}

.axle-label {
  fill: #dce6ea;
  font-size: 9px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 3.5px;
  pointer-events: none;
}

.svg-label {
  fill: #dce6ea;
  font-size: 13px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.group-cog-label {
  fill: #eef6f7;
  font-size: 11px;
}

.svg-dim {
  fill: var(--muted);
  font-size: 12px;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.cad-model-grid {
  opacity: 1;
}

.cad-grid-minor {
  stroke: rgba(82, 107, 120, .28);
  stroke-width: .8;
}

.cad-grid-major {
  stroke: rgba(99, 128, 142, .46);
  stroke-width: 1.1;
}

.axis-line {
  stroke-width: 2.4;
  stroke-dasharray: none;
}

.axis-x {
  stroke: rgba(255, 66, 66, .95);
}

.axis-y {
  stroke: rgba(47, 255, 76, .92);
}

.axis-tick {
  stroke: rgba(214, 233, 239, .82);
  stroke-width: 1.5;
}

.axis-arrow {
  fill: rgba(214, 233, 239, .86);
}

.axis-x-fill {
  fill: rgba(255, 66, 66, .96);
}

.axis-y-fill {
  fill: rgba(47, 255, 76, .94);
}

.axis-label,
.axis-name,
.origin-label {
  fill: #d7e8ee;
  font-size: 12px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.axis-name,
.origin-label {
  font-size: 14px;
}

.axis-x-label {
  fill: #ff6868;
}

.axis-y-label {
  fill: #5aff6c;
}

.origin-label {
  fill: #35d8ff;
}

.svg-angle {
  fill: #ffd62a;
  font-size: 13px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.angle-arc path {
  fill: none;
  stroke: #ffd62a;
  stroke-width: 2;
}

.spmt-anchor circle {
  fill: rgba(255, 214, 42, .16);
  stroke: #ffd62a;
  stroke-width: 2;
}

.spmt-anchor line {
  stroke: #ffd62a;
  stroke-width: 1.6;
}

.anchor-label {
  fill: #ffd62a;
  font-size: 11px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.spmt-row-name text {
  fill: #eef6f7;
  font-size: 15px;
  font-weight: 900;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 5px;
  letter-spacing: 0;
}

.anchor-dim-x {
  stroke: rgba(255, 66, 66, .88);
  stroke-width: 1.2;
  stroke-dasharray: 8 5;
}

.anchor-dim-y {
  stroke: rgba(47, 255, 76, .86);
  stroke-width: 1.2;
  stroke-dasharray: 8 5;
}

.anchor-dim-ext {
  stroke: rgba(214, 233, 239, .40);
  stroke-width: 1;
  stroke-dasharray: 4 5;
}

.anchor-dim-label {
  font-size: 10px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.anchor-dim-x-label {
  fill: #ff6868;
}

.anchor-dim-y-label {
  fill: #5aff6c;
}

.view-dim-line {
  stroke: #ffd62a;
  stroke-width: 1.3;
}

.view-dim-fill {
  fill: #ffd62a;
}

.view-dim-text {
  fill: #ffd62a;
  font-size: 12px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.svg-car-dim {
  fill: #ffd62a;
  font-size: 12px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.svg-spacing-dim {
  fill: #2fff4c;
  font-size: 10px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 3px;
  pointer-events: none;
}

.svg-gap-dim {
  fill: #2fff4c;
  font-size: 12px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.editable-dim {
  cursor: pointer;
  pointer-events: all;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.editable-dim:hover {
  filter: drop-shadow(0 0 5px rgba(255, 214, 42, .55));
}

.editable-dim-hit {
  fill: rgba(255, 214, 42, .04);
  pointer-events: all;
  cursor: pointer;
}

.dim-label-leader,
.cog-leader {
  stroke: rgba(238, 246, 247, .62);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  pointer-events: none;
}

.top-cog-label {
  font-size: 12px;
}

.dimension-inline-editor {
  position: fixed;
  z-index: 50;
  width: 140px;
  height: 34px;
  border: 1px solid #ffd62a;
  border-radius: 6px;
  padding: 0 10px;
  background: #091017;
  color: #f6fbfd;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .42), 0 0 0 3px rgba(255, 214, 42, .16);
  font: 800 14px/34px inherit;
  outline: none;
}

.editable-dim-hit:hover + .editable-dim {
  filter: drop-shadow(0 0 5px rgba(255, 214, 42, .55));
}

.svg-title {
  fill: #2fff4c;
  font-size: 14px;
  font-weight: 800;
  pointer-events: none;
}

.svg-caption {
  fill: #2fff4c;
  font-size: 13px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
  pointer-events: none;
}

.dim-line {
  stroke: #2fff4c;
  stroke-width: 1.4;
  fill: none;
}

.ghost-dim {
  opacity: .55;
  stroke-dasharray: 6 5;
}

.car-dim-line {
  stroke: #ffd62a;
  stroke-width: 1.3;
  fill: none;
}

.spmt-gap-line {
  stroke: #ff4242;
  stroke-width: 1.4;
  fill: none;
}

.group-area {
  mix-blend-mode: screen;
}

.group-hatch {
  stroke-width: 1.2;
  stroke-opacity: .36;
}

.group-area-label {
  font-size: 15px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #17212a;
  stroke-width: 4px;
}

.cad-body {
  fill: rgba(33, 132, 255, 0.05);
  stroke: #0062ff;
  stroke-width: 1.8;
}

.cad-thin {
  fill: none;
  stroke: #0062ff;
  stroke-width: 0.9;
}

.cad-center {
  fill: none;
  stroke: #0062ff;
  stroke-width: 0.9;
  stroke-dasharray: 7 6;
}

.cad-joint {
  fill: none;
  stroke: #0062ff;
  stroke-width: 1.4;
}

.cad-bogie {
  fill: rgba(33, 132, 255, 0.06);
  stroke: #0062ff;
  stroke-width: 1;
}

.cad-wheel {
  fill: none;
  stroke: #0062ff;
  stroke-width: 1.2;
}

.cad-tire {
  fill: rgba(33, 132, 255, 0.05);
  stroke: #0062ff;
  stroke-width: 1;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}

th:first-child,
td:first-child,
th:last-child,
td:last-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

.pill.safe {
  color: #071a09;
  background: var(--green);
}

.pill.fail {
  color: #230708;
  background: var(--red);
}

.pill.warn {
  color: #241a00;
  background: var(--yellow);
}

.method-notes {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.method-notes strong {
  color: var(--text);
}

@media (max-width: 1180px) {
  .layout,
  .views {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .summary-grid,
  .template-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-header,
  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    padding: 10px;
  }

  .grid.two,
  .summary-grid,
  .template-options {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 6mm;
  }

  * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  :root,
  body {
    background: #ffffff !important;
    color: #14211b;
  }

  body {
    min-height: auto;
  }

  .app-header,
  .header-actions,
  .controls,
  .options-panel,
  .view-tools {
    display: none !important;
  }

  .eyebrow {
    color: #20312b;
    font-size: 9pt;
  }

  h1 {
    font-size: 18pt;
  }

  h2 {
    font-size: 10pt;
  }

  .print-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8mm;
    margin: 0 0 2.2mm;
    padding: 3.2mm 4.2mm;
    border: 0;
    border-left: 5px solid #49b86f;
    border-radius: 3px;
    background: #17212a;
    color: #eef6f7;
    break-inside: avoid;
  }

  .print-title div {
    display: grid;
    gap: 1.2mm;
  }

  .print-title div:last-child {
    align-content: center;
    justify-items: end;
    text-align: right;
  }

  .print-title strong {
    font-size: 15pt;
  }

  .print-title span {
    color: #b8c8d0;
    font-size: 7.2pt;
    font-weight: 700;
  }

  .print-title em {
    color: #7ddc93;
    font-size: 8pt;
    font-style: normal;
    font-weight: 800;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .workspace {
    display: grid;
    gap: 2.2mm;
  }

  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 2.2mm;
    break-inside: avoid;
  }

  .metric-card {
    padding: 1.8mm 2.3mm;
    border-color: #cfdad3;
    background: #fbfdfb;
    color: #14211b;
    box-shadow: none;
  }

  .metric-card .label {
    color: #516058;
    font-size: 6.8pt;
  }

  .metric-card .value {
    margin-top: .4mm;
    font-size: 12.5pt;
  }

  .metric-card.safe .value {
    color: #16803a;
  }

  .metric-card.warn .value {
    color: #9a6a00;
  }

  .metric-card.fail .value {
    color: #b4232a;
  }

  .views {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2.5mm;
  }

  .view-card,
  .panel {
    border-color: #b9c7be;
    border-radius: 4px;
    background: #ffffff;
    box-shadow: none;
    break-inside: avoid;
  }

  .view-card {
    padding: 1.8mm;
  }

  .view-title {
    position: relative;
    justify-content: center;
    margin-bottom: 1.4mm;
    color: #14211b;
    text-align: center;
  }

  .view-title h2 {
    width: 100%;
  }

  .view-title span,
  .panel-head span {
    color: #516058;
    font-size: 7pt;
  }

  .view-title span {
    position: absolute;
    right: 0;
  }

  .top-view {
    grid-column: 1 / -1;
    break-after: page;
  }

  #topSvg {
    width: 100%;
    height: auto;
    max-height: 136mm;
    aspect-ratio: 980 / 560;
  }

  #frontSvg,
  #sideSvg {
    width: 100%;
    height: auto;
    max-height: 92mm;
  }

  svg {
    border-radius: 3px;
    page-break-inside: avoid;
  }

  .panel {
    padding: 2.2mm;
  }

  .panel-head {
    margin-bottom: 2mm;
  }

  table {
    min-width: 0;
    font-size: 7.2pt;
  }

  th,
  td {
    padding: 1.35mm 1.7mm;
    border-bottom-color: #c8d4cc;
  }

  th {
    color: #516058;
  }

  .pill {
    min-height: 16px;
    padding: 0 6px;
    font-size: 7pt;
  }

  .pill.safe {
    color: #ffffff;
    background: #16803a;
  }

  .pill.fail {
    color: #ffffff;
    background: #b4232a;
  }

  .pill.warn {
    color: #161006;
    background: #d39b16;
  }

  .method-notes {
    gap: 1.5mm;
    color: #31413a;
    font-size: 7.4pt;
    line-height: 1.28;
  }

  .method-notes strong {
    color: #111c17;
  }
}
