:root {
  color-scheme: dark;
  --bg: #060713;
  --panel: #10111c;
  --panel-soft: #171827;
  --panel-deep: #0b0c16;
  --text: #f5f7ff;
  --muted: #a7adbe;
  --line: rgba(255, 255, 255, 0.11);
  --strong: #22d3ee;
  --strong-dark: #06b6d4;
  --violet: #8b5cf6;
  --accent: #fb7185;
  --ok: #34d399;
  --cut: #f59e0b;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
  font-size: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 66% 18%, rgba(91, 33, 182, 0.22), transparent 32%),
    radial-gradient(circle at 20% 8%, rgba(34, 211, 238, 0.12), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter,
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(236px, 278px) minmax(0, 1fr);
  gap: 10px;
  max-width: 1720px;
  margin: 0 auto;
}

.panel,
.controls-panel,
.preview-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.controls-panel {
  padding: 12px;
  height: fit-content;
  position: sticky;
  top: 10px;
  background: linear-gradient(180deg, #11131f 0%, #0b0c15 100%);
}

.brand-row,
.section-head,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 14px;
  line-height: 1.3;
}

p,
small,
label span,
.metric span,
td,
th,
li {
  font-size: 12px;
}

button,
input,
select {
  font-size: 12px;
}

p,
small,
label span,
.metric span {
  color: var(--muted);
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.04);
}

.status-pill.ok {
  border-color: rgba(52, 211, 153, 0.35);
  color: var(--ok);
  background: rgba(52, 211, 153, 0.1);
}

.status-pill.error {
  border-color: rgba(214, 69, 69, 0.28);
  color: var(--accent);
  background: rgba(214, 69, 69, 0.08);
}

.form-stack {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.calc-mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.mode-button {
  min-height: 52px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.mode-button.active {
  background: rgba(34, 211, 238, 0.14);
  color: var(--strong);
  box-shadow: inset 0 0 0 1px rgba(34, 211, 238, 0.3);
}

.mode-upload-panel {
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 1px solid rgba(34, 211, 238, 0.16);
  border-radius: 12px;
  background: rgba(12, 16, 28, 0.74);
}

.mode-upload-panel.unlaid {
  border-color: rgba(167, 139, 250, 0.24);
  background: rgba(20, 16, 36, 0.72);
}

.mode-hint {
  padding: 7px 9px;
  border: 1px solid rgba(34, 211, 238, 0.18);
  border-radius: 8px;
  background: rgba(34, 211, 238, 0.055);
  color: #c7d2fe;
  font-size: 12px;
  line-height: 1.45;
}

label {
  display: grid;
  gap: 5px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  padding: 6px 8px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--strong);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.14);
}

.file-drop {
  position: relative;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  border: 1px dashed rgba(34, 211, 238, 0.34);
  background: rgba(34, 211, 238, 0.06);
  border-radius: 10px;
  min-height: 112px;
  padding: 18px 42px 18px 16px;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.file-drop:hover {
  border-color: rgba(34, 211, 238, 0.58);
  background: rgba(34, 211, 238, 0.1);
}

.file-drop.drag-over {
  border-color: rgba(34, 211, 238, 0.78);
  background: rgba(34, 211, 238, 0.16);
}

.file-drop.has-file {
  border-style: solid;
  border-color: rgba(52, 211, 153, 0.42);
  background: rgba(52, 211, 153, 0.08);
}

.file-drop strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.file-drop small {
  display: block;
  margin-top: 4px;
  line-height: 1.45;
}

.file-drop input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--strong), var(--violet));
  color: #fff;
  font-size: 42px;
  font-weight: 500;
  line-height: 1;
}

.file-drop.has-file .file-icon {
  background: rgba(52, 211, 153, 0.16);
  border: 1px solid rgba(52, 211, 153, 0.36);
  color: var(--ok);
  font-size: 15px;
  font-weight: 800;
}

.file-drop.has-file strong {
  color: #d1fae5;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.file-clear-button {
  position: absolute;
  top: 9px;
  right: 9px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(248, 250, 252, 0.16);
  border-radius: 999px;
  background: rgba(8, 10, 20, 0.72);
  color: #f8fafc;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.file-clear-button:hover {
  border-color: rgba(251, 113, 133, 0.55);
  color: #fb7185;
  background: rgba(251, 113, 133, 0.12);
}

.tile-spec-panel {
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
}

.tile-spec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.tile-spec-head span {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.tile-spec-head small {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.spec-conflict-panel {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid rgba(251, 113, 133, 0.55);
  border-radius: 8px;
  background: rgba(127, 29, 29, 0.18);
}

.spec-conflict-panel[hidden] {
  display: none;
}

.spec-conflict-panel strong {
  color: #fecdd3;
  font-size: 13px;
}

.spec-conflict-panel p {
  margin: 0;
  color: #fda4af;
  font-size: 12px;
  line-height: 1.45;
}

.spec-conflict-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.quick-specs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.quick-spec-button {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.quick-spec-button.active {
  border-color: rgba(34, 211, 238, 0.42);
  background: rgba(34, 211, 238, 0.13);
  color: var(--strong);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.reuse-mode-field {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
}

.reuse-mode-field > span {
  color: var(--text);
  font-size: 15px;
  font-weight: 900;
}

.reuse-mode-field small {
  line-height: 1.45;
}

.reuse-mode-options {
  display: grid;
  gap: 6px;
}

.reuse-mode-button {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 8px 9px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  text-align: left;
}

.reuse-mode-button strong {
  color: var(--text);
  font-size: 12px;
}

.reuse-mode-button small {
  color: var(--muted);
  font-size: 11px;
}

.reuse-mode-button.active {
  border-color: rgba(34, 211, 238, 0.78);
  background: rgba(34, 211, 238, 0.12);
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.1);
}

.reuse-mode-button.active strong {
  color: #e0faff;
}

.advanced-settings {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
  overflow: hidden;
}

.advanced-settings summary {
  min-height: 32px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.advanced-settings summary::-webkit-details-marker {
  display: none;
}

.advanced-settings summary::after {
  content: "+";
  color: var(--strong);
  font-size: 16px;
}

.advanced-settings[open] summary {
  border-bottom: 1px solid var(--line);
}

.advanced-settings[open] summary::after {
  content: "-";
}

.advanced-settings label,
.advanced-settings .check-row {
  margin: 8px 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: 15px;
  height: 15px;
}

.primary-button,
.secondary-button,
.report-link {
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-grid;
  place-items: center;
  white-space: nowrap;
}

.preview-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.mode-hidden {
  display: none !important;
}

.preview-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  color: var(--muted);
  white-space: nowrap;
}

.preview-toggle input {
  width: 14px;
  height: 14px;
}

.icon-button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
}

.icon-button:hover,
.secondary-button:hover,
.report-link:hover {
  border-color: rgba(34, 211, 238, 0.45);
}

.compact-button {
  min-height: 28px;
  padding-inline: 9px;
}

.zoom-label {
  min-width: 46px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.measure-label {
  min-width: 72px;
  color: #e0faff;
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.measure-label.calibration-success {
  color: #6ee7b7;
  font-weight: 800;
}

.measure-label.calibration-error {
  color: #fda4af;
  font-weight: 800;
}

.measure-label.correction-active {
  color: #fcd34d;
  font-weight: 800;
}

.measure-label.correction-success {
  color: #6ee7b7;
  font-weight: 800;
}

.correction-panel {
  min-height: 44px;
  margin: 0 0 8px;
  padding: 7px 9px;
  border-block: 1px solid rgba(245, 158, 11, 0.28);
  background: rgba(245, 158, 11, 0.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.correction-panel[hidden] {
  display: none;
}

.correction-panel > div:first-child {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.correction-panel strong,
.correction-panel span {
  overflow-wrap: anywhere;
}

.correction-panel strong {
  color: #fef3c7;
  font-size: 13px;
}

.correction-panel span {
  color: var(--muted);
  font-size: 12px;
}

.correction-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.correction-include.recommended-action {
  border-color: rgba(52, 211, 153, 0.7);
  background: rgba(52, 211, 153, 0.14);
  color: #d1fae5;
}

.correction-exclude.recommended-action {
  border-color: rgba(251, 113, 133, 0.7);
  background: rgba(251, 113, 133, 0.12);
  color: #ffe4e6;
}

.icon-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.primary-button {
  flex: 1;
  background: linear-gradient(135deg, #06b6d4, #8b5cf6);
  color: #fff;
}

.primary-button:hover {
  filter: brightness(1.08);
}

.secondary-button,
.report-link {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
  color: var(--text);
}

.secondary-button.active {
  border-color: rgba(34, 211, 238, 0.65);
  background: rgba(34, 211, 238, 0.14);
  color: #e0faff;
}

.secondary-button.attention {
  border-color: rgba(245, 158, 11, 0.7);
  color: #fde68a;
}

.report-link.disabled {
  pointer-events: none;
  color: var(--muted);
  background: var(--panel-soft);
}

.main-panel {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 8px;
}

.summary-note {
  margin: -2px 0 0;
  padding: 7px 10px;
  border: 1px solid rgba(34, 211, 238, 0.24);
  border-radius: 10px;
  background: rgba(34, 211, 238, 0.07);
  color: #c7d2fe;
  font-size: 12px;
  line-height: 1.4;
}

.side-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 0;
}

.side-summary-grid .metric {
  padding: 7px 8px;
  box-shadow: none;
}

.side-summary-grid .metric strong {
  font-size: 19px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  line-height: 1;
  color: #ffffff;
}

.input-metric {
  display: grid;
  gap: 5px;
}

.input-metric input {
  margin-top: 0;
  padding: 5px 7px;
  font-size: 13px;
}

.reliability-metric strong {
  font-size: 16px;
}

.reliability-metric small {
  display: block;
  margin-top: 5px;
  line-height: 1.45;
}

.reliability-metric.ok {
  border-color: rgba(52, 211, 153, 0.32);
}

.reliability-metric.review {
  border-color: rgba(245, 158, 11, 0.35);
}

.reliability-metric.needs_calibration {
  border-color: rgba(251, 113, 133, 0.35);
}

.side-status {
  margin-top: 10px;
  padding: 9px;
  box-shadow: none;
}

.side-status strong {
  font-size: 15px;
}

.side-status small {
  font-size: 12px;
}

.preview-wrap {
  padding: 10px;
  background: #0d0e19;
}

.section-head {
  margin-bottom: 8px;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #080a14;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

canvas.dragging {
  cursor: grabbing;
}

canvas.measuring {
  cursor: crosshair;
}

canvas.setting-origin {
  cursor: crosshair;
}

canvas.selecting-area {
  cursor: crosshair;
}

canvas.calibrating-tile {
  cursor: crosshair;
}

canvas.correcting-result {
  cursor: crosshair;
}

.details-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(0, 1.6fr);
  gap: 20px;
}

.review-details {
  padding: 0;
  overflow: hidden;
}

.review-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
  list-style: none;
}

.review-details summary::-webkit-details-marker {
  display: none;
}

.review-details summary span {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.review-details summary small {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.review-details summary::after {
  content: "+";
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--strong);
  font-size: 17px;
  line-height: 1;
}

.review-details[open] summary {
  border-bottom: 1px solid var(--line);
}

.review-details[open] summary::after {
  content: "-";
}

.review-details .details-grid {
  padding: 12px;
}

.ignored-panel {
  grid-column: 1 / -1;
}

.spec-panel .table-scroll {
  max-height: 220px;
}

.prominent-spec {
  padding: 10px;
  border-color: rgba(34, 211, 238, 0.26);
  background: linear-gradient(180deg, rgba(34, 211, 238, 0.08), rgba(16, 17, 28, 0.96));
}

.prominent-spec .section-head {
  margin-bottom: 8px;
}

.prominent-spec h2 {
  font-size: 15px;
}

.prominent-spec p {
  margin-top: 3px;
  font-size: 12px;
}

.prominent-spec .table-scroll {
  max-height: none;
  margin-top: 0;
  border-radius: 8px;
}

.prominent-spec table {
  min-width: 760px;
}

.reuse-panel {
  padding: 0;
  overflow: hidden;
  border-color: rgba(139, 92, 246, 0.24);
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.08), rgba(16, 17, 28, 0.96));
}

.reuse-panel summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  cursor: pointer;
  list-style: none;
}

.reuse-panel summary::-webkit-details-marker {
  display: none;
}

.reuse-panel summary span {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.reuse-panel summary small {
  color: #c7d2fe;
  font-size: 12px;
  line-height: 1.45;
  text-align: right;
}

.reuse-panel summary::after {
  content: "+";
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(139, 92, 246, 0.34);
  border-radius: 999px;
  color: #c4b5fd;
  font-size: 17px;
  line-height: 1;
}

.reuse-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.reuse-panel[open] summary::after {
  content: "-";
}

.reuse-table-scroll {
  margin: 10px;
  max-height: 220px;
}

.reuse-table-scroll table {
  min-width: 760px;
}

.piece-chip {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 3px 6px;
  margin: 2px 4px 2px 0;
  padding: 4px 7px;
  border: 1px solid rgba(245, 158, 11, 0.28);
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.1);
  color: #fbbf24;
  cursor: pointer;
}

.piece-chip:hover {
  border-color: rgba(245, 158, 11, 0.62);
  background: rgba(245, 158, 11, 0.16);
}

.piece-chip small {
  color: var(--muted);
  font-size: 11px;
}

.reuse-warning {
  grid-column: 1 / -1;
  color: var(--accent);
  font-size: 11px;
}

.muted-text {
  color: var(--muted);
}

.prominent-spec th {
  padding: 7px 9px;
  font-size: 12px;
}

.prominent-spec td {
  padding: 8px 9px;
  font-size: 12px;
  vertical-align: middle;
}

.prominent-spec td:first-child {
  color: var(--strong-dark);
  font-size: 14px;
  font-weight: 800;
}

.prominent-spec td:nth-child(n + 2) {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.prominent-spec td:nth-child(5),
.prominent-spec td:nth-child(6) {
  color: var(--accent);
}

.compact-table table {
  min-width: 520px;
}

.details-grid .panel {
  padding: 10px;
  min-width: 0;
}

.message-list {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.message-list li + li {
  margin-top: 8px;
}

.table-scroll {
  margin-top: 10px;
  overflow: auto;
  max-height: 320px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #171827;
  color: var(--muted);
  font-weight: 600;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td,
.selected-row td {
  background: rgba(34, 211, 238, 0.09);
}

.ignored-row td {
  color: var(--muted);
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  border: 1px solid var(--line);
}

.tag.whole {
  color: var(--ok);
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.25);
}

.tag.cut {
  color: var(--cut);
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.24);
}

@media (max-width: 960px) {
  .app-shell {
    padding: 12px;
  }

  .workspace,
  .details-grid {
    grid-template-columns: 1fr;
  }

  .controls-panel {
    position: static;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .field-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .brand-row,
  .section-head,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .secondary-button,
  .report-link {
    width: 100%;
  }
}
