:root {
  color-scheme: light;
  --ink: #102f3a;
  --muted: #60727a;
  --line: #cfdbde;
  --paper: #ffffff;
  --canvas: #eef3f4;
  --navy: #0d3b4d;
  --teal: #0ea68b;
  --teal-soft: #dff5f0;
  --orange: #e78432;
  --orange-soft: #fff0df;
  --danger: #b33b32;
  --shadow: 0 18px 50px rgba(16, 47, 58, 0.09);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

button, input, select { font: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(20px, 4vw, 56px);
  background: var(--navy);
  color: white;
  border-bottom: 4px solid var(--teal);
}

.topbar h1, .results-header h2, .section-heading h2, .card-heading h3 { margin: 0; }
.topbar h1 { font-size: clamp(1.35rem, 2.2vw, 2rem); letter-spacing: 0.02em; }

.eyebrow, .card-kicker {
  margin: 0 0 3px;
  color: #82e2d1;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.top-actions { display: flex; align-items: center; gap: 14px; }
.unit-note { color: #cce1e5; font-size: 0.9rem; }

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 390px) minmax(0, 1fr);
  gap: 22px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
}

.input-panel, .diagram-card, .detail-card, .alternatives-section {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.input-panel {
  align-self: start;
  position: sticky;
  top: 20px;
  padding: 22px;
}

.form-section { padding: 0 0 22px; margin: 0 0 22px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.section-heading h2 { font-size: 1.05rem; }
.step { color: var(--teal); font-size: 0.8rem; font-weight: 900; letter-spacing: 0.1em; }

.field-grid, .dimension-grid { display: grid; gap: 12px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.weight-fields { margin-top: 12px; }
.dimension-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; min-width: 0; }
.field.full { margin-top: 12px; }
.field > span { color: #415b64; font-size: 0.86rem; font-weight: 700; }

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #afc0c4;
  border-radius: 7px;
  background: #fbfdfd;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}
select { width: 100%; min-height: 44px; border: 1px solid #afc0c4; border-radius: 7px; background: #fbfdfd; color: var(--ink); padding: 9px 10px; }
.extra-item { margin: 12px 0; padding: 12px; border: 1px solid var(--line); background: #f7faf9; }
.extra-item header { display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; font-weight:800; }
.extra-item .button { min-height:32px; padding:5px 9px; }
.report-page { break-after: page; page-break-after: always; margin-bottom: 26px; }
.report-page:last-child { break-after:auto; page-break-after:auto; }
.tail-banner { margin:16px 0; padding:12px; border-left:5px solid var(--orange); background:var(--orange-soft); }

input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14, 166, 139, 0.15); }
.input-with-suffix { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.input-with-suffix input { border-radius: 7px 0 0 7px; }
.input-with-suffix b { display: grid; place-items: center; min-height: 44px; padding: 0 10px; border: 1px solid #afc0c4; border-left: 0; border-radius: 0 7px 7px 0; background: #e9eff0; color: var(--muted); font-size: 0.75rem; }
.hint, .muted { margin: 8px 0 0; color: var(--muted); font-size: 0.82rem; }

.toggle-field {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
  cursor: pointer;
}
.toggle-field input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { position: relative; width: 42px; height: 24px; border-radius: 99px; background: #9eafb4; transition: 0.2s ease; }
.toggle-track::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: white; transition: 0.2s ease; }
.toggle-field input:checked + .toggle-track { background: var(--teal); }
.toggle-field input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle-field input:focus-visible + .toggle-track { box-shadow: 0 0 0 3px rgba(14, 166, 139, 0.22); }
.toggle-field strong, .toggle-field small { display: block; }
.toggle-field strong { font-size: 0.9rem; }
.toggle-field small { margin-top: 2px; color: var(--muted); font-size: 0.76rem; line-height: 1.35; }

.button {
  min-height: 43px;
  border: 0;
  border-radius: 7px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 800;
}

.button.primary { width: 100%; background: var(--teal); color: #052c28; }
.button.primary:hover { background: #21bea1; }
.button.secondary { background: white; color: var(--navy); }
.button.secondary:hover { background: #e9f7f4; }
.form-error { display: none; margin: 0 0 12px; padding: 10px 12px; background: #fff0ee; color: var(--danger); border-left: 4px solid var(--danger); font-size: 0.9rem; }
.form-error.visible { display: block; }

.results { min-width: 0; }
.results-header { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 2px 2px 16px; }
.results-header .eyebrow { color: var(--teal); }
.results-header h2 { font-size: clamp(1.35rem, 2.4vw, 2rem); }
.status { display: inline-flex; align-items: center; gap: 8px; color: #126857; font-size: 0.88rem; font-weight: 800; }
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--teal); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { padding: 15px 16px; background: var(--navy); color: white; border-top: 4px solid var(--teal); }
.metric:nth-child(2n) { border-top-color: var(--orange); }
.metric small { display: block; color: #bcd3d8; font-size: 0.78rem; }
.metric strong { display: block; margin-top: 3px; font-size: clamp(1.25rem, 2.4vw, 1.9rem); line-height: 1.2; }

.diagram-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.8fr); gap: 16px; }
.diagram-card, .detail-card, .alternatives-section { padding: 18px; }
.card-heading { display: flex; justify-content: space-between; align-items: start; gap: 14px; margin-bottom: 12px; }
.card-heading h3 { font-size: 1.05rem; }
.card-kicker { color: var(--teal); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 0.75rem; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { display: block; width: 12px; height: 12px; }
.swatch.a { background: var(--teal-soft); border: 2px solid var(--teal); }
.swatch.b { background: var(--orange-soft); border: 2px solid var(--orange); }
.swatch.hidden { background: #ffe0f0; border: 2px solid #d52976; }
.svg-stage { width: 100%; min-height: 340px; display: grid; place-items: center; background: #f7faf9; border: 1px dashed #c3d2d5; overflow: hidden; }
.side-diagram .svg-stage { min-height: 340px; }
.svg-stage svg { display: block; width: 100%; max-height: 430px; }

.detail-card { margin-top: 16px; }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border: 1px solid var(--line); }
.summary-cell { padding: 13px 15px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.summary-cell:nth-child(3n) { border-right: 0; }
.summary-cell:nth-last-child(-n + 3) { border-bottom: 0; }
.summary-cell span { display: block; color: var(--muted); font-size: 0.78rem; }
.summary-cell strong { font-size: 1rem; }
.report-table-wrap { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.report-table th, .report-table td { padding: 10px 12px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.report-table th { width: 24%; background: #eaf2f3; color: #31505a; font-size: 0.78rem; letter-spacing: 0.02em; }
.report-table td { width: 26%; font-weight: 700; }
.report-caption { display: flex; justify-content: space-between; gap: 14px; margin: 0 0 10px; color: var(--muted); font-size: 0.78rem; }

.alternatives-section { margin-top: 16px; }
.alternatives { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.alternative { border: 1px solid var(--line); background: #f9fbfb; padding: 12px; }
.alternative.best { border-color: var(--teal); }
.alternative header { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.alternative h4 { margin: 0; font-size: 0.92rem; }
.alternative strong { color: var(--teal); white-space: nowrap; }
.mini-svg { width: 100%; aspect-ratio: 1.65; }
.mini-svg svg { width: 100%; height: 100%; }

.review-note { margin: 14px 2px 0; color: var(--muted); font-size: 0.78rem; }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .input-panel { position: static; }
  .diagram-grid { grid-template-columns: 1fr; }
  .side-diagram .svg-stage { min-height: 300px; }
}

@media (max-width: 680px) {
  .topbar { align-items: flex-start; padding: 16px; }
  .top-actions { align-items: flex-end; flex-direction: column; gap: 8px; }
  .unit-note { display: none; }
  .workspace { padding: 14px; }
  .input-panel, .diagram-card, .detail-card, .alternatives-section { padding: 15px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid.three { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-cell:nth-child(3n) { border-right: 1px solid var(--line); }
  .summary-cell:nth-child(2n) { border-right: 0; }
  .summary-cell:nth-last-child(-n + 3) { border-bottom: 1px solid var(--line); }
  .summary-cell:nth-last-child(-n + 2) { border-bottom: 0; }
  .alternatives { grid-template-columns: 1fr; }
  .results-header { align-items: flex-start; }
  .svg-stage { min-height: 280px; }
}

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: white; font-size: 12px; }
  .topbar { padding: 10px 0; background: white; color: var(--ink); border-bottom: 2px solid var(--ink); }
  .topbar .eyebrow, .top-actions, .input-panel, .alternatives-section, .review-note { display: none !important; }
  .workspace { display: block; max-width: none; padding: 12px 0; }
  .report-page { break-after: page; page-break-after: always; margin:0; }
  .extra-report-page { break-before: page; page-break-before: always; }
  .results-header { margin-bottom: 10px; }
  .metric-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .metric { print-color-adjust: exact; -webkit-print-color-adjust: exact; padding: 8px 10px; }
  .diagram-grid { grid-template-columns: 1.35fr 0.8fr; gap: 8px; }
  .diagram-card, .detail-card { box-shadow: none; break-inside: avoid; padding: 10px; }
  .svg-stage, .side-diagram .svg-stage { min-height: 260px; }
  .detail-card { margin-top: 8px; }
  .report-table { font-size: 10px; }
  .report-table th, .report-table td { padding: 6px 8px; }
}
