:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --ink: #172126;
  --muted: #63717a;
  --line: #d9e0e4;
  --line-strong: #a9b6bd;
  --teal: #0f766e;
  --blue: #2563eb;
  --orange: #c2410c;
  --red: #b91c1c;
  --green-soft: #e6f4f1;
  --blue-soft: #e9f0ff;
  --orange-soft: #fff1e8;
  --shadow: 0 18px 55px rgba(23, 33, 38, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid transparent;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: #eef2f4;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--teal);
  color: white;
  font-size: 24px;
  font-weight: 800;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 23px;
  letter-spacing: 0;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.params-form {
  display: grid;
  gap: 16px;
}

fieldset {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

label:first-of-type {
  margin-top: 2px;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.45;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.input-row em {
  min-width: 30px;
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
}

input,
select {
  min-width: 0;
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0 10px;
  background: #fbfcfd;
  color: var(--ink);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.23);
  outline-offset: 1px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.actions,
.export-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.actions {
  margin-top: auto;
}

.actions button,
.export-actions button,
.tab-btn {
  height: 38px;
  border-radius: 7px;
  padding: 0 13px;
  font-size: 14px;
  font-weight: 800;
}

.ghost-btn {
  background: white;
  color: var(--ink);
  border-color: var(--line-strong);
}

.export-actions button {
  background: var(--ink);
  color: white;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.view-switch {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(58px, auto));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
}

.tab-btn.is-active {
  background: var(--blue);
  color: white;
}

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

.stat-card {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.stat-card b {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat-card span {
  display: block;
  margin-top: 7px;
  font-size: 19px;
  font-weight: 850;
}

.stat-card:nth-child(2n) {
  background: var(--blue-soft);
}

.stat-card:nth-child(3n) {
  background: var(--green-soft);
}

.stat-card:nth-child(5n) {
  background: var(--orange-soft);
}

.warning-panel {
  border: 1px solid #f3b39a;
  border-left: 5px solid var(--orange);
  border-radius: 8px;
  padding: 11px 13px;
  background: #fff7f1;
  color: #7c2d12;
  font-size: 14px;
  line-height: 1.55;
}

.formula-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: stretch;
  border: 1px solid #b9d7d3;
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  padding: 12px 14px;
  background: #f0fbf8;
}

.formula-panel div {
  display: grid;
  gap: 5px;
}

.formula-panel b {
  color: var(--muted);
  font-size: 12px;
}

.formula-panel div span {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.45;
}

.formula-panel ul {
  display: grid;
  grid-template-columns: repeat(4, minmax(92px, auto));
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.formula-panel li {
  display: grid;
  gap: 4px;
  min-width: 92px;
  padding: 8px;
  border: 1px solid #cfe5e1;
  border-radius: 7px;
  background: white;
}

.formula-panel li span {
  font-size: 14px;
  font-weight: 850;
}

.measurement-panel {
  display: grid;
  gap: 10px;
  border: 1px solid #d3dee5;
  border-left: 5px solid var(--orange);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fffaf5;
}

.measurement-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.measurement-head h2 {
  margin: 0;
  font-size: 17px;
}

.measurement-head span {
  color: #7c2d12;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.4;
  text-align: right;
}

.measurement-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: 8px;
}

.measurement-card {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #f1d4c2;
  border-radius: 7px;
  background: white;
}

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

.measurement-card span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 850;
  line-height: 1.35;
}

.line-diagram {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  border: 1px solid #bfd4ee;
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  padding: 12px;
  background: #f7fbff;
}

.line-diagram-visual {
  min-width: 0;
}

.line-diagram-visual svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 220px;
}

.diagram-bg {
  fill: white;
  stroke: #d8e5f5;
}

.sheet-fill {
  fill: rgba(15, 118, 110, 0.12);
  stroke: none;
}

.pipe-core {
  fill: #eef2f4;
  stroke: #8fa0a9;
  stroke-width: 1.2;
}

.expand-ring {
  fill: none;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.expand-ring.outer {
  stroke: var(--orange);
}

.expand-ring.neutral {
  stroke: var(--blue);
  stroke-dasharray: 6 4;
}

.expand-ring.inner {
  stroke: var(--teal);
}

.expand-ring.is-active {
  stroke-width: 4;
}

.diagram-callout,
.thickness-line {
  stroke: #64748b;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.diagram-callout.dashed {
  stroke-dasharray: 5 4;
}

.diagram-title {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 850;
}

.diagram-label {
  font-size: 12px;
  font-weight: 850;
}

.diagram-label.outer {
  fill: var(--orange);
}

.diagram-label.neutral {
  fill: var(--blue);
}

.diagram-label.inner {
  fill: var(--teal);
}

.diagram-note {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.line-diagram-info {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.line-diagram-info header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.line-diagram-info h2 {
  margin: 0;
  font-size: 17px;
}

.line-diagram-info header span {
  color: var(--blue);
  font-size: 14px;
  font-weight: 850;
  text-align: right;
}

.line-diagram-info p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.line-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.line-option {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 10px;
  border: 1px solid #dbe3e8;
  border-radius: 8px;
  background: white;
}

.line-option.is-active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.line-option strong {
  color: var(--ink);
  font-size: 15px;
}

.line-option span {
  color: var(--blue);
  font-size: 13px;
  font-weight: 850;
  line-height: 1.35;
}

.line-option em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
  line-height: 1.45;
}

.seam-diagram {
  display: grid;
  grid-template-columns: minmax(340px, 470px) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  border: 1px solid #d7dedf;
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  padding: 12px;
  background: #f6fbf9;
}

.seam-visual {
  min-width: 0;
}

.seam-visual svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 240px;
}

.seam-circle {
  fill: rgba(15, 118, 110, 0.07);
  stroke: var(--teal);
  stroke-width: 2;
}

.seam-axis {
  stroke: #b6c4ca;
  stroke-width: 1;
  stroke-dasharray: 5 5;
  vector-effect: non-scaling-stroke;
}

.seam-side-label,
.strip-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.seam-dot {
  fill: white;
  stroke: #64748b;
  stroke-width: 1.5;
}

.seam-dot.is-active {
  fill: var(--orange);
  stroke: #7c2d12;
  stroke-width: 2;
}

.seam-dot-label {
  fill: #64748b;
  font-size: 9px;
  font-weight: 800;
  paint-order: stroke;
  stroke: white;
  stroke-width: 3px;
  stroke-linejoin: round;
}

.seam-dot-label.is-active {
  fill: var(--orange);
}

.seam-selected-line {
  stroke: var(--orange);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.strip-body {
  fill: rgba(37, 99, 235, 0.08);
  stroke: #9db4d8;
  stroke-width: 1.4;
}

.strip-seam {
  fill: rgba(194, 65, 12, 0.16);
}

.strip-zero {
  stroke: var(--orange);
  stroke-width: 1.6;
  stroke-dasharray: 6 4;
  vector-effect: non-scaling-stroke;
}

.strip-label.strong {
  fill: var(--orange);
  font-weight: 900;
}

.strip-arrow {
  stroke: var(--teal);
  stroke-width: 1.5;
}

.strip-arrow-head {
  fill: var(--teal);
}

.seam-info {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.seam-info header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.seam-info h2 {
  margin: 0;
  font-size: 17px;
}

.seam-info header span {
  color: var(--teal);
  font-size: 14px;
  font-weight: 850;
  text-align: right;
}

.seam-info p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.5;
}

.seam-facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.seam-facts article {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 10px;
  border: 1px solid #d4e3df;
  border-radius: 8px;
  background: white;
}

.seam-facts b {
  color: var(--muted);
  font-size: 12px;
}

.seam-facts span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 850;
  line-height: 1.35;
}

.work-order {
  display: grid;
  gap: 12px;
  border: 1px solid #cbd5e1;
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  padding: 13px 14px;
  background: #f8fafc;
}

.work-order-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.work-order-head h2 {
  margin: 0;
  font-size: 17px;
}

.work-order-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.work-summary div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #dbe3e8;
  border-radius: 7px;
  background: white;
}

.work-summary b,
.work-step b {
  color: var(--muted);
  font-size: 12px;
}

.work-summary span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 850;
  line-height: 1.35;
}

.work-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

.work-step {
  min-width: 0;
  border: 1px solid #dbe3e8;
  border-radius: 8px;
  padding: 10px;
  background: white;
}

.work-step header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}

.work-step strong {
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--blue);
  color: white;
  font-size: 13px;
}

.work-step h2 {
  margin: 0;
  font-size: 15px;
}

.work-step div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid #edf1f3;
  font-size: 13px;
}

.work-step span {
  min-width: 0;
  text-align: right;
  overflow-wrap: anywhere;
  font-weight: 800;
  line-height: 1.35;
}

.cut-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.cut-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
}

.cut-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.cut-card h2 {
  margin: 0;
  font-size: 16px;
}

.cut-card strong {
  color: var(--teal);
  font-size: 14px;
}

.cut-card div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid #edf1f3;
  font-size: 13px;
}

.cut-card b {
  color: var(--muted);
}

.cut-card span {
  text-align: right;
  font-weight: 800;
}

.drawing-area {
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
  overflow: hidden;
}

#previewSvg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 520px;
}

.table-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.section-title h2 {
  margin: 0;
  font-size: 17px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  max-height: 360px;
  overflow: auto;
}

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

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

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

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2f4;
  color: var(--muted);
  font-size: 12px;
}

tbody tr:hover {
  background: #f7fbff;
}

.svg-bg {
  fill: #fbfcfd;
}

.grid-line {
  stroke: #dfe6ea;
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}

.axis-line {
  stroke: #8fa0a9;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.template-fill {
  fill: rgba(15, 118, 110, 0.1);
}

.template-line {
  fill: none;
  stroke: var(--teal);
  stroke-width: 2.2;
  vector-effect: non-scaling-stroke;
}

.template-line.secondary {
  stroke: var(--blue);
}

.template-line.edge {
  stroke: var(--ink);
  stroke-width: 1.4;
}

.point-dot {
  fill: white;
  stroke: var(--orange);
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
}

.seam-fill {
  fill: rgba(194, 65, 12, 0.12);
}

.seam-line {
  stroke: var(--orange);
  stroke-dasharray: 6 4;
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
}

.svg-label {
  fill: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.svg-note {
  fill: var(--muted);
  font-size: 12px;
}

.dimension-line,
.dimension-tick {
  stroke: var(--orange);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.division-tick {
  stroke: #64748b;
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}

.dimension-label {
  fill: var(--orange);
  font-size: 11px;
  font-weight: 800;
}

.value-label {
  fill: #334155;
  font-size: 7.5px;
  font-weight: 700;
  paint-order: stroke;
  stroke: white;
  stroke-width: 3px;
  stroke-linejoin: round;
}

.value-label.end-detail {
  fill: #0f766e;
}

.value-label.low {
  fill: var(--blue);
}

.value-label.x-title {
  fill: var(--muted);
  font-size: 9px;
  font-weight: 850;
  text-anchor: start;
}

.value-label.x-axis {
  fill: #475569;
  font-size: 7px;
  stroke-width: 2.5px;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .actions {
    margin-top: 0;
  }

  .stats-grid,
  .formula-panel,
  .measurement-grid,
  .line-diagram,
  .seam-diagram,
  .seam-facts,
  .work-summary,
  .work-steps,
  .cut-list {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .line-diagram {
    grid-template-columns: 1fr;
  }

  .seam-diagram {
    grid-template-columns: 1fr;
  }

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

  .formula-panel ul {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 720px) {
  .workspace,
  .control-panel {
    padding: 14px;
  }

  .params-form,
  .stats-grid,
  .formula-panel,
  .measurement-grid,
  .line-diagram,
  .line-options,
  .seam-diagram,
  .seam-facts,
  .work-summary,
  .work-steps,
  .cut-list {
    grid-template-columns: 1fr;
  }

  .measurement-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .measurement-head span {
    text-align: left;
  }

  .line-diagram-info header {
    align-items: flex-start;
    flex-direction: column;
  }

  .line-diagram-info header span {
    text-align: left;
  }

  .seam-info header {
    align-items: flex-start;
    flex-direction: column;
  }

  .seam-info header span {
    text-align: left;
  }

  .work-order-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .formula-panel ul {
    grid-template-columns: 1fr;
  }

  .topbar,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .view-switch {
    width: 100%;
  }

  .export-actions button,
  .actions button {
    flex: 1;
  }

  .drawing-area,
  #previewSvg {
    min-height: 430px;
  }
}

@media print {
  body {
    background: white;
  }

  .control-panel,
  .topbar,
  .table-section {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .workspace {
    padding: 0;
  }

  .stats-grid,
  .formula-panel,
  .measurement-panel,
  .line-diagram,
  .seam-diagram,
  .work-order,
  .cut-list,
  .warning-panel {
    margin: 0 0 10px;
  }

  .drawing-area {
    border: 0;
    box-shadow: none;
  }
}
