* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  background: #f4f2ee;
  color: #1a1a1a;
}

.hidden {
  display: none !important;
}

.app-header {
  padding: 16px 24px;
  background: #1a1a1a;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.part-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
}

.part-select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
}

.btn-icon:hover {
  background: #3a3a3a;
}

.app-main {
  display: flex;
  gap: 24px;
  padding: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.canvas-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.canvas-wrap {
  position: relative;
  display: inline-block;
  margin: 0 auto;
}

.canvas-container {
  background-color: #f5f5f5;
  background-image:
    linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
    linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  border: 1px solid #ddd;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  line-height: 0;
}

.canvas-container.autocolor-on {
  background-image: none;
  background-color: var(--auto-color, #f5f5f5);
}

.scale-indicator {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 3px 8px;
  background: rgba(26, 26, 26, 0.75);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 5px;
  pointer-events: none;
  z-index: 10;
}

.error {
  color: #b3261e;
  padding: 24px;
}

.view-switcher {
  display: flex;
  gap: 8px;
}

.view-btn {
  padding: 6px 14px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.view-btn.active {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

#autocolor-btn {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  margin-left: 0;
}

#autocolor-btn.active {
  background: #2196f3;
  color: #fff;
  border-color: #2196f3;
}

.autocolor-hint {
  font-size: 11px;
  color: #888;
  font-family: monospace;
}

.toolbar {
  width: 280px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tool-group h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #777;
}

.field-label {
  display: block;
  font-size: 12px;
  color: #555;
  margin: 10px 0 4px;
}

.field {
  width: 100%;
}

textarea.field {
  min-height: 70px;
  resize: vertical;
  font-family: inherit;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
}

.color-field {
  height: 32px;
  padding: 2px;
  border: 1px solid #ccc;
  border-radius: 6px;
}

.align-row {
  display: flex;
  gap: 6px;
}

.align-btn {
  flex: 1;
  padding: 6px 0;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
}

.align-btn:hover {
  background: #f0f0f0;
}

.align-btn.active {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

.btn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}

.btn:hover {
  background: #f0f0f0;
}

.btn-primary {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

.btn-primary:hover {
  background: #333;
}

.btn-danger {
  color: #b3261e;
  border-color: #e4b3ae;
}

.btn-danger:hover {
  background: #fdeceb;
}

.btn-success {
  background: #2e7d32;
  color: #fff;
  border-color: #2e7d32;
}

.btn-success:hover {
  background: #256428;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 10px;
  max-height: 260px;
  overflow-y: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #ddd;
  background: #fafafa;
  border-radius: 6px;
  cursor: pointer;
  padding: 6px;
}

.icon-btn:hover {
  background: #eee;
  border-color: #bbb;
}

.icon-btn img {
  width: 100%;
  height: 100%;
}

.no-selection-hint {
  margin: 0;
  padding: 10px 12px;
  font-size: 13px;
  color: #999;
  text-align: center;
  background: #f7f7f5;
  border: 1px dashed #ddd;
  border-radius: 6px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  z-index: 1000;
}

.preview-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  padding: 10px;
  z-index: 500;
}

.preview-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #777;
  margin-bottom: 6px;
}

.preview-wrapper {
  position: relative;
  line-height: 0;
  overflow: hidden;
}

.preview-bg {
  display: block;
  width: 300px;
  height: auto;
  position: relative;
  z-index: 1;
}

.preview-overlay {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  pointer-events: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  max-width: 720px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-content h2 {
  margin: 0 0 20px;
  font-size: 18px;
  text-align: center;
}

.part-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.part-card {
  border: 1px solid #ddd;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: #fafafa;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.part-card:hover {
  border-color: #1a1a1a;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.part-card-thumb {
  width: 100%;
  height: 130px;
  background-repeat: no-repeat;
  background-color: #eee;
}

.part-card-name {
  padding: 10px 12px;
  font-size: 13px;
  text-align: center;
  font-weight: 600;
}

.center-panel {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.center-btn {
  width: 38px;
  height: 38px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.center-btn:hover {
  background: #f0f0f0;
  border-color: #bbb;
}

/* ===== Panels Слоёв ===== */

.layers-panel {
  width: 240px;
  flex-shrink: 0;
  background: #fafafa;
  border: 1px solid #ddd;
  border-radius: 10px;
  overflow: hidden;
  align-self: flex-start;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
}

.layers-header {
  padding: 12px 10px;
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
  border-bottom: 1px solid #e0e0e0;
  background: #fafafa;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.layers-count {
  font-size: 11px;
  font-weight: 400;
  color: #999;
}

.layers-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: #ccc transparent;
}

.layers-list::-webkit-scrollbar {
  width: 6px;
}

.layers-list::-webkit-scrollbar-track {
  background: transparent;
}

.layers-list::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.layers-list::-webkit-scrollbar-thumb:hover {
  background: #999;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  user-select: none;
  position: relative;
  border-left: 4px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.layer-item:hover {
  background: #f5f5f5;
  border-color: #ccc;
}

.layer-item--active {
  background: #e3f2fd;
  border-color: #2196f3;
  border-left-color: #2196f3;
}

.layer-item--locked {
  opacity: 0.75;
}

.layer-item--dragging {
  opacity: 0.4;
  border-style: dashed;
}

.layer-item--dragover {
  border-top-color: #2196f3;
  box-shadow: 0 -2px 0 #2196f3;
}

/* Drag handle */
.layer-drag-handle {
  color: #ccc;
  font-size: 11px;
  cursor: grab;
  flex-shrink: 0;
  line-height: 1;
  letter-spacing: -1px;
  padding: 0 1px;
  transition: color 0.1s;
}

.layer-item:hover .layer-drag-handle {
  color: #999;
}

.layer-drag-handle:active {
  cursor: grabbing;
}

/* Иконка типа элемента */
.layer-type-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e0e0e0;
  color: #555;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}

.layer-type-icon.type-icon {
  background: #ede7f6;
  color: #6a3d9a;
  font-size: 12px;
}

.layer-type-icon.type-image {
  background: #e8f5e9;
  color: #2e7d32;
  font-size: 12px;
}

.layer-name {
  font-size: 12px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #333;
  min-width: 0;
}

.layer-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.layer-lock,
.layer-delete {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  line-height: 1;
  color: #888;
  opacity: 0.65;
  transition: background 0.1s, color 0.1s, opacity 0.1s;
}

.layer-lock:not(.locked),
.layer-delete {
  opacity: 0.65;
}

.layer-lock:hover,
.layer-delete:hover {
  opacity: 1;
}

.layer-lock:hover {
  background: #e3f2fd;
  color: #1a73e8;
}

.layer-delete:hover {
  background: #ffebee;
  color: #b3261e;
}

/* Замок в состоянии locked */
.layer-lock.locked {
  color: #ff9800;
  background: #fff3e0;
  border-radius: 4px;
  opacity: 1;
}

.layer-lock.locked:hover {
  background: #ffe0b2;
  color: #e65100;
}

/* ===== Конец панели слоёв ===== */

.arc-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #eee;
}

.arc-checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #555;
  cursor: pointer;
  user-select: none;
}

.arc-options {
  margin-top: 8px;
}

.tools-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tools-tab {
  flex: 1 1 0;
  min-width: 0;
  height: 44px;
  padding: 0 6px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  transition: 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
.tools-tab:hover { background: #f5f5f5; }
.tools-tab.active {
  background: #2196f3;
  color: #fff;
  border-color: #2196f3;
}
.tools-panel { display: none; }
.tools-panel.active { display: block; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 400px;
  overflow-y: auto;
}
.emoji-cell {
  font-size: 24px;
  text-align: center;
  padding: 6px 0;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.15s;
  user-select: none;
}
.emoji-cell:hover {
  background: #e3f2fd;
  transform: scale(1.1);
}

.part-type-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.part-type-badge.hidden {
  display: none;
}

.badge-laser {
  background: #3D2817;
  color: #f5deb3;
}

.badge-uv {
  background: linear-gradient(90deg, #f0f, #0ff);
  color: #111;
}

.badge-both {
  background: linear-gradient(90deg, #3D2817, #0ff);
  color: #fff;
}

#method-switcher {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}

.method-btn {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: 0.15s;
}

.method-btn:hover { background: #f5f5f5; }
.method-btn.active { background: #2196f3; color: #fff; border-color: #2196f3; font-weight: 600; }
