:root { color-scheme: light; font-family: 'Microsoft YaHei UI', 'PingFang SC', system-ui, sans-serif; color: #182c27; background: #f3f5f0; --green: #146653; --line: #dce5de; --muted: #52645d; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
.wrap { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }
.masthead { background: #12382f; color: white; border-bottom: 4px solid #b7d398; }
.brand { min-height: 104px; display: flex; align-items: center; gap: 16px; }
.brand-symbol { display: block; flex: none; width: 64px; height: 64px; }
h1, h2, h3, p { margin: 0; }
.brand-title strong { display: block; font-size: 24px; line-height: 1.2; letter-spacing: .04em; }
.brand-title h1 { margin-top: 4px; color: #c5dacd; font-size: 14px; font-weight: 600; }
main.wrap { padding-block: 24px 40px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 22px; min-width: 0; }
.section-head, .form-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-head { margin-bottom: 16px; }
h2 { font-size: 19px; }
.section-head p, .form-foot span, .work-note, #copy-status { color: var(--muted); font-size: 13px; line-height: 1.55; }
.section-head p { margin-top: 5px; }
.workshop-head { flex-wrap: wrap; }
.workshop-title { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.workshop-print-logo { display: none; }
.workshop-title > div { min-width: 0; }
label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 7px; }
button, textarea, input, select { font: inherit; }
button { cursor: pointer; background: var(--green); color: #fff; border: 1px solid transparent; border-radius: 8px; padding: 9px 14px; font-size: 13px; font-weight: 700; white-space: nowrap; }
button.secondary { color: var(--green); background: #f4faf6; border-color: #cbded3; }
button:hover:not(:disabled) { filter: brightness(.94); }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 3px solid #7c9f37; outline-offset: 3px; }
textarea { width: 100%; padding: 12px 14px; border: 1px solid #bfcfc6; border-radius: 10px; background: #fafcf9; color: inherit; resize: vertical; line-height: 1.55; }
.order-row input, .order-row select, #order-number { display: block; width: 100%; min-width: 0; min-height: 37px; padding: 6px 9px; border: 1px solid #bfcfc6; border-radius: 7px; background: #fafcf9; color: inherit; }
.order-row select:disabled { opacity: 1; background: #eaf0eb; }
.order-rows { display: grid; gap: 9px; }
.order-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) auto; gap: 9px; align-items: end; min-width: 0; margin: 0; padding: 8px 11px 11px; border: 1px solid var(--line); border-radius: 9px; }
.order-row legend { padding-inline: 5px; font-size: 13px; color: var(--green); font-weight: 700; }
.order-row label { display: grid; gap: 4px; margin: 0; }
.remove-row { grid-column: -2; min-height: 37px; }
.form-foot { margin-top: 12px; }
#errors { margin-top: 12px; color: #963913; font-size: 14px; white-space: pre-line; }
.metrics { margin: 16px 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.metric { background: #e5efe6; padding: 12px 15px; border-radius: 10px; }
.metric span { display: block; font-size: 12px; color: var(--muted); }
.metric strong { display: block; margin-top: 3px; font-size: 19px; }
.outputs { display: grid; grid-template-columns: minmax(0, .93fr) minmax(0, 1.07fr); gap: 16px; align-items: start; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
th, td { border-bottom: 1px solid #e8eee9; padding: 10px 8px; }
th { background: #edf4ee; color: #39584a; }
td:nth-child(2), td:nth-child(3), th:nth-child(2), th:nth-child(3) { text-align: right; white-space: nowrap; }
td:nth-child(2) { font-weight: 750; font-variant-numeric: tabular-nums; }
#copy-status:not(:empty) { margin-top: 8px; }
.diagram-list { display: grid; gap: 9px; }
.diagram { border: 1px solid #dbe6df; border-radius: 10px; padding: 11px 13px; break-inside: avoid; }
.diagram-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.diagram h3 { font-size: 16px; font-variant-numeric: tabular-nums; }
.diagram-kind { color: #146653; font-weight: 700; font-size: 13px; }
.rails { display: grid; gap: 9px; margin-top: 9px; }
.rail-drawing { position: relative; padding: 18px 23px 17px; min-height: 45px; }
.rail-line { position: relative; height: 10px; border: 1px solid #749b89; border-radius: 4px; background: #e6f1e9; }
.rail-direction { position: absolute; inset: 0 0 auto; color: var(--green); text-align: center; font-size: 13px; font-weight: 800; line-height: 14px; }
.rail-carriage { width: 14px; height: 11px; background: #17644f; clip-path: polygon(0 0, 62% 0, 100% 50%, 62% 100%, 0 100%); }
.rail-carriage.facing-left { clip-path: polygon(100% 0, 38% 0, 0 50%, 38% 100%, 100% 100%); }
.rail-bead { width: 6px; height: 6px; border: 1px solid #24424a; border-radius: 50%; background: #c7dce0; }
.rail-line :is(.rail-carriage, .rail-bead) { position: absolute; top: 50%; transform: translate(-50%, -50%); }
.rail-center { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); padding-top: 3px; color: var(--muted); white-space: nowrap; font-size: 10px; line-height: 12px; }
.rail-center::before { content: ''; position: absolute; left: 50%; bottom: calc(100% - 2px); height: 8px; border-left: 1px dashed #35584b; }
.rail-joints, .rail-joint-key { color: #b82e29; }
.rail-joints {
  --joint-half-width: min(3px, calc(var(--joint-step) / 4));
  position: absolute;
  inset: -6px 0 auto;
  height: 11px;
  background: repeating-linear-gradient(to right, currentColor 0 var(--joint-half-width), transparent var(--joint-half-width) calc(var(--joint-step) - var(--joint-half-width)), currentColor calc(var(--joint-step) - var(--joint-half-width)) var(--joint-step));
  clip-path: inset(0 calc(var(--joint-step) / 2));
}
.motor-label { position: absolute; z-index: 1; top: 14px; padding: 1px 4px; border: 1px solid #688778; border-radius: 3px; color: #12382f; font-size: 10px; line-height: 15px; font-weight: 700; background: #f4faf6; }
.motor-left { left: 0; }
.motor-right { right: 0; }
.diagram p { font-size: 12px; color: var(--muted); }
.diagram .cut-size { margin-top: 4px; color: var(--green); font-size: 14px; font-weight: 750; }
.rail-legend { display: flex; flex-wrap: wrap; gap: 5px 12px; margin: 11px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: 11px; }
.rail-legend li { display: flex; align-items: center; gap: 5px; }
.rail-joint-key { width: 6px; height: 11px; background: currentColor; }
.work-note { margin-top: 12px; }
.motor-warning { margin-bottom: 12px; padding: 8px 10px; border-radius: 6px; background: #fff2d9; color: #744411; font-size: 13px; }
.print-required, .work-signoffs { display: none; }
#print-order-number { color: inherit; font-weight: 700; overflow-wrap: anywhere; }
#print-dialog { width: min(420px, calc(100% - 28px)); padding: 22px; border: 1px solid var(--line); border-radius: 12px; color: inherit; }
#print-dialog::backdrop { background: rgb(18 56 47 / 42%); }
#print-dialog h2 { margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (max-width: 840px) { .outputs { grid-template-columns: minmax(0, 1fr); } .order-row { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 520px) {
  .brand { min-height: 85px; gap: 10px; }
  .brand-symbol { width: 52px; height: 52px; }
  .brand-title strong { font-size: 21px; }
}
@media (max-width: 480px) { .wrap { width: calc(100% - 22px); } .card { padding: 14px; } .metric { padding: 8px; } .metric strong { font-size: 16px; } .order-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media print {
  @page { size: A4; margin: 13mm; }
  body { background: white; color: black; }
  .masthead, .entry, .metrics, .outputs > :not(.workshop), #print-dialog, button { display: none !important; }
  #results:not(.printable) .diagram-list, #results:not(.printable) .rail-legend, #results:not(.printable) .work-note { display: none !important; }
  #results:not(.printable) .print-required { display: block; }
  main.wrap, .workshop { width: 100%; padding: 0; margin: 0; border: 0; }
  .workshop-title { display: grid; width: 100%; grid-template-columns: 42px minmax(0, 1fr) minmax(0, 44%); gap: 3px 9px; align-items: start; }
  .workshop-details { display: contents; }
  .workshop-print-logo { display: block; width: 42px; height: 42px; grid-area: 1 / 1 / 3 / 2; }
  #work-title { grid-area: 1 / 2; }
  #work-summary { grid-area: 2 / 2; margin-top: 0; }
  #print-order-number { grid-area: 1 / 3 / 3 / 4; margin: 0; text-align: right; font-size: 20pt; line-height: 1.12; font-weight: 800; }
  .outputs, .diagram-list { display: block; }
  .diagram { margin-bottom: 8px; }
  .rail-drawing, .rail-legend { print-color-adjust: exact; }
  #results.printable .work-signoffs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8mm;
    margin-top: 6mm;
    break-inside: avoid;
    color: #000;
    font-size: 10pt;
  }
  .work-signoffs p::after { content: ''; display: block; height: 8mm; border-bottom: 1px solid currentColor; }
}

.history { margin-top: 16px; }
.history summary { cursor: pointer; font-weight: 700; }
.history-note, #history-count, .history-meta { color: var(--muted); font-size: 13px; }
.history-note:not(:empty) { margin-block: 8px; }
#history-search { display: block; width: min(100%, 350px); padding: 8px; border: 1px solid #bfcfc6; border-radius: 7px; }
#history-list { list-style: none; margin: 6px 0 0; padding: 0; }
.history-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.history-item strong { overflow-wrap: anywhere; }
.workshop-actions { display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 480px) { .entry .section-head { flex-wrap: wrap; } }
@media print { .history, #history-status { display: none !important; } }

.cut-settings { margin: 0 0 12px; padding: 9px 11px 11px; border: 1px solid var(--line); border-radius: 9px; min-width: 0; }
.cut-settings legend { padding-inline: 5px; color: var(--green); font-size: 13px; font-weight: 700; }
.cut-controls { display: flex; align-items: end; flex-wrap: wrap; gap: 10px 18px; }
.room-choice { position: relative; display: grid; grid-template-columns: 1fr 1fr; width: min(100%, 200px); border-radius: 999px; padding: 3px; background: #e4eee6; isolation: isolate; }
.room-choice::before { content: ''; position: absolute; inset: 3px auto 3px 3px; width: calc(50% - 3px); border-radius: inherit; background: var(--green); transition: transform .15s ease; z-index: -1; }
.room-choice:has(#room-rough:checked)::before { transform: translateX(100%); }
.room-choice label { margin: 0; cursor: pointer; }
.room-choice input { position: absolute; opacity: 0; }
.room-choice span { display: block; text-align: center; padding: 7px 10px; white-space: nowrap; }
.room-choice input:checked + span { color: #fff; }
.room-choice input:focus-visible + span { outline: 2px solid #587a27; outline-offset: 1px; border-radius: 999px; }
.kerf-control { display: flex; align-items: center; gap: 7px; margin: 0; }
.kerf-control input { width: 80px; min-height: 34px; padding: 4px 7px; border: 1px solid #bfcfc6; border-radius: 7px; color: inherit; background: #fafcf9; }
.cut-settings p { margin-block: 8px 0; }
.metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.rail-real-joint { position: absolute; z-index: 1; top: -6px; width: 6px; height: 11px; border-radius: 1px; background: #b82e29; transform: translateX(-50%); }
.rail-pieces { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0 0 7px; padding: 0; list-style: none; }
.rail-pieces li { display: flex; align-items: center; gap: 4px; font-size: 11px; }
.rail-pieces li + li::before { content: '→'; color: #b82e29; font-weight: 700; }
.piece-label { display: inline-block; border: 1px solid #cadae0; border-radius: 3px; padding: 2px 4px; color: #28423c; }
.cutting-section { margin-top: 14px; }
.cutting-section h3 { font-size: 16px; }
#cut-summary { margin: 5px 0 8px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.cut-bar { padding: 6px 8px; margin-top: 6px; border: 1px solid var(--line); border-radius: 6px; break-inside: avoid; }
.cut-bar-heading { margin-bottom: 4px; font-size: 12px; font-weight: 700; }
.stock-strip { display: flex; align-items: stretch; height: 8px; background: #edf0ee; border: 1px solid #bfcfc6; overflow: hidden; }
.stock-strip span { flex: none; border-inline-end: 1px solid #fff; background: #237b63; }
.stock-strip span:nth-child(even) { background: #81b19b; }
.stock-pieces { margin: 5px 0 0; font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) { .room-choice::before { transition: none; } }
@media print {
  #results:not(.printable) .cutting-section { display: none; }
  .cutting-section h3 { break-after: avoid; }
  .stock-strip, .rail-real-joint { print-color-adjust: exact; }
}
