:root {
  --bg: #f2f2f2;
  --panel: #ffffff;
  --border: #e2e6ea;
  --accent: #2f6fed;
  --text: #1f2937;
  --grid: #e8edf3;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "PT Sans", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr 280px;
  gap: 16px;
  height: 100vh;
  padding: 16px;
}

.sidebar,
.inspector {
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
  overflow: hidden;
}

.aside-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.panel-fill {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.panel-bottom {
  flex: 0 0 auto;
  margin-top: auto;
}

.canvas {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  min-height: 0;
  box-shadow: var(--shadow);
}

.canvas-frame {
  position: relative;
  width: 100%;
  height: 100%;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: #f9fbff;
  overflow: hidden;
}

#mainCanvas,
#threeCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#threeCanvas {
  display: none;
  pointer-events: none;
}

.canvas-overlay {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.zoom-button {
  pointer-events: auto;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.zoom-button:active {
  transform: translateY(1px);
}

.catalog-section {
  margin-top: 12px;
}

.catalog-section h2 {
  margin-bottom: 10px;
}

.catalog-items {
  list-style: none;
  padding: 0;
  margin: 6px 0 0;
}

.catalog-items li {
  padding: 6px 8px;
  border-radius: 6px;
  background: #f4f6fb;
  margin-bottom: 6px;
  font-size: 14px;
  cursor: grab;
}

.catalog-items li:active {
  cursor: grabbing;
}

.catalog-items .muted {
  background: transparent;
  color: #9aa3af;
}

.file-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-actions button,
.file-actions .file-input {
  border: 1px solid var(--border);
  background: #ffffff;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-align: center;
}

.file-input input {
  display: none;
}

.file-actions .file-input {
  display: flex;
  align-items: center;
  justify-content: center;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 8px;
  font-family: "Rockwell", "Georgia", serif;
  font-weight: 700;
  font-size: 16px;
}

.inspector-section h3 {
  margin-bottom: 10px;
}

.inspector-section h3 + select,
.inspector-section h3 + .ring-list,
.inspector-section h3 + .checkbox-column {
  margin-top: 6px;
}

.sw-section .ring-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sw-layer {
  border: 1px solid #e6e9ef;
  background: #f8fafc;
  border-radius: 10px;
  padding: 10px;
}

.sw-layer-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.sw-layer-meta {
  font-size: 12px;
  color: #94a3b8;
  margin-left: auto;
}

.sw-layer-meta .warning {
  color: #dc2626;
  font-weight: 600;
}

.sw-toggle {
  border: none;
  background: transparent;
  font-size: 14px;
  color: #6b7280;
  cursor: pointer;
  padding: 2px 4px;
}

.sw-level-title {
  font-weight: 600;
  color: #1f2937;
  cursor: pointer;
}

.sw-item-index {
  font-size: 12px;
  color: #6b7280;
  width: 28px;
  display: inline-block;
}

.sw-item {
  border: none;
  border-radius: 0;
  padding: 0;
  background: transparent;
  margin-bottom: 6px;
}

.sw-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.sw-item select,
.sw-item input[type=number] {
  width: 100%;
}

.sw-item-row select {
  max-width: 190px;
  width: 100%;
}

.sw-item-row select:focus {
  max-width: 100%;
}

.sw-all-row select {
  max-width: 220px;
}

.sw-item input[type=number] {
  max-width: 90px;
}

.sw-item-meta {
  font-size: 12px;
  color: #94a3b8;
  flex: 1;
}

.sw-item-delete {
  border: 1px solid #e2e6ea;
  background: #f8fafc;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.sw-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.sw-actions button,
.sw-add-level {
  border: 1px solid #e2e6ea;
  background: #ffffff;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

.sw-add-level {
  margin-top: 10px;
}

h1 {
  font-size: 18px;
}

p {
  margin: 0;
  color: #4b5563;
}

.muted {
  color: #9aa3af;
}

.spacer {
  min-height: 14px;
}

.inspector-footer {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.checkbox-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.primary-button {
  border: 1px solid var(--border);
  background: var(--accent);
  color: #ffffff;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.primary-button:disabled {
  background: #a9b9df;
  cursor: not-allowed;
}

.bom-popup {
  position: fixed;
  right: 24px;
  bottom: 24px;
  pointer-events: none;
  z-index: 50;
}

.bom-popup[aria-hidden="true"] {
  display: none;
}

.bom-panel {
  width: min(520px, 90vw);
  max-height: 70vh;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.15);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
  overflow: hidden;
}

.bom-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.icon-button {
  border: 1px solid var(--border);
  background: #f8fafc;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.bom-tabs {
  display: flex;
  gap: 8px;
}

.tab-button {
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}

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

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

.bom-actions button {
  border: 1px solid var(--border);
  background: #ffffff;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}

.bom-content {
  overflow: auto;
  padding-right: 4px;
}

.bom-group {
  margin-bottom: 14px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-overlay[aria-hidden="false"] {
  display: flex;
}

.modal-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 16px;
  max-width: 520px;
  width: 100%;
  border: 1px solid var(--border);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.15);
}

.modal-card h4 {
  margin-top: 12px;
}

.bom-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.bom-table th,
.bom-table td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid #eef1f5;
}

.bom-table th.qty,
.bom-table td.qty {
  text-align: right;
  width: 60px;
}

.part-id {
  display: block;
  font-size: 11px;
  color: #94a3b8;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
  }

  .canvas {
    min-height: 50vh;
  }

  .aside-stack {
    height: auto;
  }
}
