* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  background: #f8fafc;
  color: #0f172a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
button:disabled { cursor: not-allowed; opacity: .45; }
.page { max-width: 1280px; margin: 0 auto; padding: 16px; }
.topbar { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 16px; }
h1 { margin: 0; font-size: 26px; letter-spacing: 0; }
h2, h3 { margin: 0; }
p { margin: 0; }
.muted { color: #64748b; font-size: 14px; }
.small { color: #64748b; font-size: 12px; }
.panel {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgb(15 23 42 / .05);
}
.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; padding: 12px; }
.toolbar-kerf-input { width: 112px; }
.toolbar-unit-label { padding-bottom: 10px; }
.toolbar-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
}
.grid { display: grid; grid-template-columns: 330px 1fr; gap: 16px; }
.stack { display: grid; gap: 12px; }
.side-panel { display: flex; flex-direction: column; gap: 8px; }
.content { padding: 16px; }
.section-heading { font-size: 16px; }
.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
label { display: block; margin-bottom: 4px; color: #334155; font-size: 12px; font-weight: 700; }
input, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: white;
  padding: 9px 10px;
  outline: none;
}
input:focus, textarea:focus { border-color: #475569; box-shadow: 0 0 0 3px rgb(148 163 184 / .25); }
input.invalid { border-color: #dc2626; box-shadow: 0 0 0 3px rgb(220 38 38 / .15); }
textarea { min-height: 260px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.input-suggest-wrap {
  position: relative;
}
.input-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 45;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 20px rgb(15 23 42 / .12);
}
.input-suggestions li {
  padding: 8px 10px;
  font-size: 14px;
  color: #0f172a;
  cursor: pointer;
}
.input-suggestions li:hover {
  background: #f1f5f9;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-field-full { grid-column: span 2; }
.compact-action { align-self: end; justify-self: start; min-height: 36px; padding: 7px 11px; }
.modal-actions {
  display: flex;
  justify-content: end;
  gap: 8px;
  margin-top: 16px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 9px 13px;
  background: #0f172a;
  color: white;
}
.btn:hover { background: #1e293b; }
.btn.outline { background: white; color: #0f172a; border: 1px solid #cbd5e1; }
.btn.outline:hover, .icon-btn:hover, .menu button:hover { background: #f1f5f9; }
.icon-btn { width: 32px; height: 32px; background: transparent; color: #0f172a; }
.dropzone {
  display: grid;
  gap: 8px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
#unplaced { margin-top: 0; }
.dropzone.hot { border: 0; background: transparent; }
.piece-row {
  user-select: none;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: white;
  padding: 9px;
  box-shadow: 0 1px 2px rgb(15 23 42 / .05);
  cursor: grab;
}
.piece-row-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.piece-row-preview-wrap {
  width: 62px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px dashed #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
}
.piece-row-preview {
  max-width: 100%;
  max-height: 100%;
  min-width: 6px;
  min-height: 6px;
  border: 2px solid rgb(120 53 15 / .65);
  border-radius: 4px;
  background: #fffbeb;
  box-shadow: inset 0 0 8px rgb(120 53 15 / .1);
}
.piece-row-info {
  min-width: 0;
}
.piece-row-name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.piece-row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.piece-row:active, .piece:active { cursor: grabbing; }
.piece-row.locked { opacity: .6; }
.workspace-shell {
  overflow-y: auto;
  overflow-x: hidden;
  background: white;
  padding: 0;
}
#workspace { position: relative; min-width: 0; user-select: none; }
.board-wrap { position: absolute; left: 0; }
.board-wrap.dragging { opacity: .72; z-index: 2; }
.board-head {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid #cbd5e1;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #f1f5f9;
  cursor: grab;
  touch-action: none;
}
.board-head:active { cursor: grabbing; }
.board { position: relative; background: #fffbeb; box-shadow: inset 0 0 18px rgb(120 53 15 / .08); }
.board::after { content: ""; position: absolute; inset: 0; pointer-events: none; border: 2px solid rgb(120 53 15 / .65); }
.piece {
  position: absolute;
  display: flex;
  align-items: flex-start;
  min-width: 26px;
  min-height: 22px;
  overflow: hidden;
  border: 2px solid #1e293b;
  border-radius: 6px;
  background: white;
  padding: 4px;
  color: #0f172a;
  font-size: 12px;
  line-height: 1.15;
  box-shadow: 0 1px 2px rgb(15 23 42 / .12);
  cursor: grab;
}
.piece.invalid { border-color: #dc2626; background: #fee2e2; }
.piece.locked { border-color: #64748b; background: #e2e8f0; }
.piece.hatch-diagonal-1 {
  background-image: repeating-linear-gradient(45deg, rgb(15 23 42 / .24) 0 2px, transparent 2px 10px);
}
.piece.hatch-diagonal-2 {
  background-image: repeating-linear-gradient(-45deg, rgb(15 23 42 / .24) 0 2px, transparent 2px 10px);
}
.piece.hatch-both {
  background-image:
    repeating-linear-gradient(45deg, rgb(15 23 42 / .22) 0 2px, transparent 2px 10px),
    repeating-linear-gradient(-45deg, rgb(15 23 42 / .22) 0 2px, transparent 2px 10px);
}
.piece-content {
  white-space: nowrap;
}
.piece-lock-badge {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
}
.piece-drag-delete {
  position: fixed;
  z-index: 46;
  border-color: #dc2626;
  box-shadow: 0 0 0 1px rgb(220 38 38 / .2), 0 3px 10px rgb(15 23 42 / .18);
  pointer-events: none;
}
.piece-delete-badge {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
}
.menu, .tooltip {
  position: fixed;
  z-index: 50;
  border-radius: 8px;
  box-shadow: 0 20px 45px rgb(15 23 42 / .22);
}
.menu {
  width: 190px;
  border: 1px solid #e2e8f0;
  background: white;
  padding: 4px 0;
  overflow: visible;
}
.menu button { display: flex; width: 100%; align-items: center; gap: 8px; background: white; padding: 9px 12px; text-align: left; color: #0f172a; border-radius: 0; }
.menu button.danger { color: #dc2626; }
.menu-item { position: relative; }
.menu-submenu {
  position: absolute;
  left: 100%;
  top: -4px;
  min-width: 220px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: white;
  box-shadow: 0 20px 45px rgb(15 23 42 / .22);
  padding: 4px 0;
  display: none;
}
.menu-item.has-submenu:hover .menu-submenu,
.menu-item.has-submenu:focus-within .menu-submenu {
  display: block;
}
.tooltip {
  overflow: hidden;
  max-width: 300px;
  white-space: pre-line;
  background: #0f172a;
  color: white;
  padding: 9px 11px;
  font-size: 12px;
  pointer-events: none;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgb(0 0 0 / .42);
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal { width: min(100%, 680px); background: white; border-radius: 8px; padding: 16px; box-shadow: 0 22px 55px rgb(0 0 0 / .25); }
.modal.narrow { width: min(100%, 520px); }
.modal-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.file-label { position: relative; overflow: hidden; }
.file-label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.toolbar-file-action { margin: 0; }
@media (max-width: 900px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .grid { grid-template-columns: 1fr; }
}
