* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.header {
  margin-bottom: 20px;
}
.header h1 {
  font-size: 24px;
  font-weight: 700;
}

/* Filters */
.filters {
  background: #fff;
  padding: 16px 20px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 16px;
}
.filter-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.filter-field {
  flex: 1;
  min-width: 150px;
}
.filter-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.filter-field input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}
.filter-field input:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74,144,217,0.2);
}
.filter-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: #4a90d9;
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: #357abd;
}
.btn-secondary {
  background: #e8e8e8;
  color: #333;
}
.btn-secondary:hover:not(:disabled) {
  background: #ddd;
}
.btn-small {
  padding: 4px 8px;
  font-size: 12px;
}
.btn-icon {
  padding: 6px 10px;
  font-size: 16px;
  line-height: 1;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover {
  background: #e0e0e0;
}
.btn-icon.active {
  background: #4a90d9;
  border-color: #4a90d9;
  color: #fff;
}

/* Toolbar (view toggle + select all) */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.select-all-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #666;
  cursor: pointer;
  user-select: none;
}
.select-all-label input {
  width: 18px;
  height: 18px;
  accent-color: #4a90d9;
  cursor: pointer;
}
.view-toggle {
  display: flex;
  gap: 4px;
}
.view-btn {
  font-size: 18px !important;
  padding: 6px 10px !important;
}
.view-btn.active {
  background: #4a90d9 !important;
  border-color: #4a90d9 !important;
  color: #fff !important;
}

/* Products Dropdown */
.filter-field-product {
  position: relative;
}
.dropdown-search {
  position: relative;
}
.dropdown-search input {
  width: 100%;
  padding: 8px 32px 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}
.dropdown-search input:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74,144,217,0.2);
}
.dropdown-search input.has-selection {
  background: #eef4fb;
  border-color: #4a90d9;
  font-weight: 600;
}
.dropdown-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 18px;
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
}
.dropdown-clear:hover {
  background: #e0e0e0;
  color: #333;
}
.dropdown-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
}
.dropdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f5f5f5;
}
.dropdown-item:hover {
  background: #f0f5ff;
}
.dropdown-item:last-child {
  border-bottom: none;
}
.dropdown-item-title {
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 8px;
}
.dropdown-item-sku {
  font-size: 11px;
  color: #999;
  flex-shrink: 0;
  font-family: 'SF Mono', 'Menlo', monospace;
}
.dropdown-empty {
  padding: 10px 12px;
  font-size: 12px;
  color: #999;
  text-align: center;
}

/* Status bar */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  font-size: 13px;
  color: #666;
  margin-bottom: 12px;
}

/* Record grid */
.record-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.record-card {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: box-shadow 0.2s;
  position: relative;
}
.record-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.record-card.selected {
  outline: 3px solid #4a90d9;
}

.card-checkbox {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: #4a90d9;
}

.card-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #f0f0f0;
}

.card-body {
  padding: 12px;
}

.card-info {
  margin-bottom: 10px;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-vendor {
  font-size: 12px;
  color: #888;
}
.card-sku {
  font-size: 11px;
  color: #aaa;
}

.swatch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.swatch-box {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 2px solid #e0e0e0;
  flex-shrink: 0;
}
.swatch-box.empty {
  background: repeating-conic-gradient(#ddd 0% 25%, #fff 0% 50%) 50% / 12px 12px;
}
.swatch-hex {
  font-size: 14px;
  font-weight: 600;
  font-family: 'SF Mono', 'Menlo', monospace;
  color: #333;
}
.swatch-hex.empty {
  color: #ccc;
  font-weight: 400;
}

.card-actions {
  display: flex;
  gap: 6px;
}
.card-actions .btn-icon {
  position: relative;
}
.btn-icon .tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  margin-bottom: 4px;
}
.btn-icon:hover .tooltip {
  display: block;
}

/* Color picker input (hidden, triggered by button) */
.color-picker-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Loading state */
.card-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  border-radius: 10px;
}
.spinner-small {
  width: 24px;
  height: 24px;
  border: 3px solid #e0e0e0;
  border-top-color: #4a90d9;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Load more */
.load-more-wrapper {
  text-align: center;
  padding: 20px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-content {
  background: #fff;
  border-radius: 12px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}
.modal-header h3 {
  font-size: 18px;
}
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
  padding: 0 4px;
}
.modal-close:hover { color: #333; }

/* Eyedropper modal */
.eyedropper-modal-content {
  width: 800px;
}
.eyedropper-body {
  display: flex;
  gap: 20px;
  padding: 20px;
}
.canvas-wrapper {
  flex: 1;
  position: relative;
  cursor: crosshair;
}
#eyedropper-canvas {
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid #eee;
}
.eyedropper-zoom {
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  pointer-events: none;
  display: none;
  image-rendering: pixelated;
  overflow: hidden;
}
.eyedropper-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 140px;
}
.swatch-large {
  width: 100px;
  height: 100px;
  border-radius: 12px;
  border: 2px solid #e0e0e0;
  background: #000;
}
.hex-display {
  font-size: 18px;
  font-weight: 700;
  font-family: 'SF Mono', 'Menlo', monospace;
}
.eyedropper-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.eyedropper-actions .btn {
  width: 100%;
}

/* Bulk modal */
.bulk-modal-content {
  width: 500px;
}
.bulk-body {
  padding: 20px;
}
.bulk-progress {
  margin-bottom: 16px;
}
.bulk-progress-bar {
  height: 8px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.bulk-progress-fill {
  height: 100%;
  background: #4a90d9;
  border-radius: 4px;
  transition: width 0.3s;
  width: 0%;
}
#bulk-progress-text {
  font-size: 13px;
  color: #666;
}
.bulk-results {
  max-height: 300px;
  overflow-y: auto;
}
.bulk-result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid #f0f0f0;
}
.bulk-result-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid #ddd;
  flex-shrink: 0;
}
.bulk-result-status {
  flex-shrink: 0;
}
.bulk-result-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Loading grid placeholder */
.loading-placeholder {
  text-align: center;
  padding: 60px 20px;
  color: #999;
  font-size: 16px;
}

/* ── Row View ──────────────────────────────────────────── */
.record-grid.view-rows {
  grid-template-columns: 1fr;
  gap: 2px;
}

.record-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #fff;
  border-radius: 6px;
  position: relative;
  transition: background 0.15s;
}
.record-row:hover {
  background: #fafafa;
}
.record-row.selected {
  outline: 2px solid #4a90d9;
}

.row-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #4a90d9;
  flex-shrink: 0;
}

.row-image {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: #f0f0f0;
}

.row-vendor {
  width: 130px;
  flex-shrink: 0;
  font-size: 12px;
  color: #888;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-title {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-color-name {
  width: 100px;
  flex-shrink: 0;
  font-size: 12px;
  color: #666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sku {
  width: 110px;
  flex-shrink: 0;
  font-size: 11px;
  color: #aaa;
  font-family: 'SF Mono', 'Menlo', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-swatch {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 110px;
  flex-shrink: 0;
}

.swatch-box-sm {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 2px solid #e0e0e0;
  flex-shrink: 0;
}
.swatch-box-sm.empty {
  background: repeating-conic-gradient(#ddd 0% 25%, #fff 0% 50%) 50% / 8px 8px;
}
.swatch-hex-sm {
  font-size: 11px;
  font-weight: 600;
  font-family: 'SF Mono', 'Menlo', monospace;
  color: #333;
}
.swatch-hex-sm.empty {
  color: #ccc;
  font-weight: 400;
}

.row-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.btn-icon-sm {
  padding: 4px 6px;
  font-size: 14px;
  line-height: 1;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon-sm:hover {
  background: #e0e0e0;
}

/* Row loading overlay */
.row-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  border-radius: 6px;
}

/* ── Square Placement Modal ──────────────────────────────── */
.square-modal-content {
  width: 920px;
}
.square-body {
  display: flex;
  gap: 20px;
  padding: 20px;
}
.square-canvas-wrapper {
  flex: 1;
  position: relative;
  min-width: 0;
  background: #f8f8f8;
  border-radius: 8px;
  border: 1px solid #eee;
}
#square-canvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: default;
}

/* Draggable / resizable square handle */
.square-handle {
  position: absolute;
  border: 2px dashed rgba(255, 0, 0, 0.8);
  background: rgba(255, 0, 0, 0.08);
  cursor: move;
  z-index: 10;
  touch-action: none;
}
.square-handle:hover {
  border-color: rgba(255, 0, 0, 1);
  background: rgba(255, 0, 0, 0.12);
}

/* Corner resize handles */
.sq-resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid rgba(255, 0, 0, 0.9);
  border-radius: 50%;
  z-index: 11;
}
.sq-resize-tl {
  top: -6px;
  left: -6px;
  cursor: nwse-resize;
}
.sq-resize-tr {
  top: -6px;
  right: -6px;
  cursor: nesw-resize;
}
.sq-resize-bl {
  bottom: -6px;
  left: -6px;
  cursor: nesw-resize;
}
.sq-resize-br {
  bottom: -6px;
  right: -6px;
  cursor: nwse-resize;
}
.sq-resize-handle:hover {
  background: rgba(255, 0, 0, 0.15);
  transform: scale(1.2);
}

/* Sidebar */
.square-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 160px;
  flex-shrink: 0;
}
.square-coords {
  background: #f8f8f8;
  border-radius: 8px;
  padding: 12px;
}
.sq-coord-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #999;
  margin-bottom: 8px;
}
.sq-coord-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: 13px;
  font-family: 'SF Mono', 'Menlo', monospace;
}
.sq-coord-key {
  font-weight: 600;
  color: #666;
}
#sq-x, #sq-y, #sq-w, #sq-h {
  color: #333;
}
.square-hint {
  font-size: 12px;
  color: #999;
  line-height: 1.4;
}
.square-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}
.square-actions .btn {
  width: 100%;
}

/* Auto-detect square button */
.btn-auto-square {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-auto-square:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.spinner-inline {
  width: 14px;
  height: 14px;
  border: 2px solid #ccc;
  border-top-color: #666;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

/* ── Square Overlay on Card/Row Images ─────────────────── */
.card-image-wrapper {
  position: relative;
  overflow: hidden;
}
.card-square-overlay {
  position: absolute;
  border: 2px dashed rgba(255, 0, 0, 0.7);
  background: rgba(255, 0, 0, 0.06);
  pointer-events: none;
  z-index: 1;
}

.row-image-wrapper {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 6px;
}
.row-square-overlay {
  position: absolute;
  border: 1.5px dashed rgba(255, 0, 0, 0.7);
  background: rgba(255, 0, 0, 0.06);
  pointer-events: none;
  z-index: 1;
}
