:root {
  color-scheme: light;
  --bg: #f4f2ed;
  --surface: #ffffff;
  --surface-muted: #f7f7f4;
  --ink: #1d2525;
  --muted: #67706d;
  --line: #d9ddd7;
  --accent: #0f766e;
  --accent-dark: #0b514d;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #166534;
  --shadow: 0 14px 34px rgba(33, 38, 36, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  min-height: 34px;
  padding: 0 12px;
}

button:hover {
  border-color: var(--accent);
}

button.primary,
#downloadButton {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

button.primary:hover,
#downloadButton:hover {
  background: var(--accent-dark);
}

button.is-picking {
  border-color: var(--warn);
  background: #fff7ed;
  color: #7c2d12;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

input {
  height: 34px;
  padding: 0 10px;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: middle;
}

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

td {
  font-size: 13px;
}

td input {
  height: 30px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

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

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.button-group,
.panel-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: #efeee8;
}

.content {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 14px;
  padding: 16px;
}

.content > *,
.split-grid > *,
.export-grid > * {
  min-width: 0;
}

.viewer-stage {
  position: relative;
  height: min(48vh, 520px);
  min-height: 360px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: #dfe5df;
}

#threeCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viewer-toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: flex;
  gap: 8px;
}

.viewer-toolbar button {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
}

.viewer-toolbar button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.viewer-status {
  position: absolute;
  z-index: 2;
  left: 12px;
  bottom: 12px;
  max-width: 420px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--muted);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.toolpath-legend {
  position: absolute;
  z-index: 2;
  top: 58px;
  right: 12px;
  display: grid;
  gap: 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  backdrop-filter: blur(8px);
}

.toolpath-legend[hidden] {
  display: none;
}

.idle-overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(223, 229, 223, 0.94);
  color: var(--text);
}

.idle-overlay[hidden] {
  display: none;
}

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

.idle-overlay button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.toolpath-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
}

.toolpath-swatch {
  width: 18px;
  height: 4px;
  border-radius: 2px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0;
  padding: 14px 14px 10px;
  font-size: 15px;
  letter-spacing: 0;
}

.panel-title-row {
  justify-content: space-between;
  padding: 0 14px;
}

.panel-title-row h2 {
  padding-left: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 0 14px 14px;
}

.file-input {
  margin: 0 14px 12px;
  display: grid;
  place-items: center;
  min-height: 74px;
  border: 1px dashed #aab3ad;
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--ink);
}

.file-input input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.file-input span {
  font-size: 14px;
  font-weight: 700;
}

.filter-input {
  margin: 0 14px 10px;
  width: calc(100% - 28px);
}

.object-list {
  max-height: 420px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.object-row {
  display: grid;
  grid-template-columns: 34px 1fr 76px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.object-row input {
  width: 18px;
  height: 18px;
  justify-self: center;
}

.object-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.object-row.is-hidden .object-name {
  color: var(--muted);
  text-decoration: line-through;
}

.object-row button {
  height: 30px;
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.setup-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(116px, 1fr));
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.setup-strip > button,
.setup-action button {
  height: 34px;
}

.setup-action {
  display: grid;
  gap: 6px;
}

.setup-action span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.rotation-control {
  display: grid;
  grid-template-columns: 48px minmax(64px, 1fr) 48px;
  gap: 4px;
}

.rotation-control button {
  min-width: 0;
  padding: 0 4px;
}

.coordinate-status {
  grid-column: 1 / -1;
  min-height: 32px;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: 8px 10px;
  font-size: 12px;
}

.coordinate-status.is-picking {
  border-color: var(--warn);
  color: var(--ink);
}

#threeCanvas.is-picking {
  cursor: crosshair;
}

.split-grid,
.export-grid {
  display: grid;
  grid-template-columns: minmax(420px, 0.9fr) minmax(420px, 1.1fr);
  gap: 14px;
}

.table-wrap {
  max-height: 280px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.operations-table {
  max-height: 360px;
}

.operations-table th:nth-child(1),
.operations-table td:nth-child(1) {
  width: 62px;
}

.operations-table th:nth-child(7),
.operations-table td:nth-child(7),
.operations-table th:nth-child(8),
.operations-table td:nth-child(8) {
  width: 62px;
}

.operations-table table {
  min-width: 860px;
}

.coordinate-output {
  color: var(--accent-dark);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.summary-list {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
  max-height: 280px;
  overflow: auto;
}

.summary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--surface-muted);
  font-size: 13px;
}

.summary-item strong {
  font-weight: 700;
}

.summary-item.is-active {
  border-color: var(--accent);
  background: #e8f4f2;
}

.summary-item:hover {
  border-color: var(--accent);
}

.tag {
  display: inline-grid;
  place-items: center;
  min-width: 48px;
  height: 24px;
  border-radius: 999px;
  background: #e8f4f2;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.validation-list {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.validation-item {
  border-left: 4px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  padding: 10px;
  font-size: 13px;
}

.validation-item.ok {
  border-color: var(--ok);
}

.validation-item.warn {
  border-color: var(--warn);
}

.validation-item.error {
  border-color: var(--danger);
}

textarea {
  display: block;
  min-height: 360px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  padding: 12px 14px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

.empty-state {
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
}

.danger-button {
  color: var(--danger);
}

@media (max-width: 960px) {
  .topbar {
    height: auto;
    min-height: 78px;
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions button {
    flex: 1;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

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

  .content {
    padding: 12px;
  }

  .viewer-stage {
    height: 360px;
    min-height: 320px;
  }

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

  .split-grid,
  .export-grid {
    grid-template-columns: 1fr;
  }

  .object-list {
    max-height: 260px;
  }
}

@media (max-width: 560px) {
  .setup-strip {
    grid-template-columns: 1fr;
  }

  .viewer-toolbar {
    top: 8px;
    right: 8px;
  }

  .viewer-status {
    left: 8px;
    right: 8px;
    max-width: none;
  }
}
