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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #f5f5f5;
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
}

/* Component Palette */
.palette {
  width: 250px;
  background: white;
  border-right: 1px solid #ddd;
  padding: 20px;
  overflow-y: auto;
}

.palette h2 {
  font-size: 18px;
  margin-bottom: 20px;
  color: #333;
}

.palette-item {
  background: #4A90E2;
  color: white;
  padding: 15px;
  margin-bottom: 10px;
  border-radius: 4px;
  cursor: move;
  text-align: center;
  font-weight: 500;
  user-select: none;
  transition: transform 0.2s, box-shadow 0.2s;
}

.palette-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.palette-item.dragging-from-palette {
  opacity: 0.5;
}

/* History Controls */
.history-controls {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.history-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
}

.history-btn:hover:not(:disabled) {
  background: #f5f5f5;
  border-color: #4A90E2;
  color: #4A90E2;
}

.history-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Main Canvas */
.canvas {
  flex: 1;
  padding: 20px;
  overflow: auto;
  position: relative;
}

.canvas-header {
  background: white;
  padding: 15px 20px;
  margin-bottom: 20px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.canvas-header h1 {
  font-size: 24px;
  color: #333;
  margin-bottom: 5px;
}

.canvas-header p {
  color: #666;
  font-size: 14px;
}

.canvas-header .controls {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.viewport-toggle {
  display: flex;
  gap: 4px;
  background: #f5f5f5;
  padding: 4px;
  border-radius: 6px;
}

.viewport-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
  color: #666;
  font-weight: 500;
}

.viewport-btn:hover {
  background: rgba(74, 144, 226, 0.1);
  color: #4A90E2;
}

.viewport-btn.active {
  background: white;
  color: #4A90E2;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.canvas-header button {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.canvas-header button:hover {
  background: #f5f5f5;
  border-color: #4A90E2;
}

.canvas-header button.active {
  background: #4A90E2;
  color: white;
  border-color: #4A90E2;
}

/* Version Switcher */
.version-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  font-size: 12px;
}

.version-switcher-label {
  color: #666;
  font-weight: 500;
}

.version-switcher select {
  padding: 4px 8px;
  border: 1px solid #dee2e6;
  border-radius: 3px;
  background: white;
  color: #333;
  font-size: 12px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.version-switcher select:hover {
  border-color: #4A90E2;
}

.version-switcher select:focus {
  border-color: #4A90E2;
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}

/* Canvases Container */
.canvases-container {
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  overflow: hidden;
  transition: max-width 0.3s ease;
  margin: 0 auto;
}

.canvases-container.mobile-view {
  max-width: 480px;
}

.canvas-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  position: relative;
}

.canvas-item-header {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 12px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 1000;
  font-size: 12px;
  color: #666;
  opacity: 0.7;
  transition: opacity 0.2s;
  pointer-events: auto;
}

.canvas-item:hover .canvas-item-header {
  opacity: 1;
}

.canvas-item-header h3 {
  font-size: 11px;
  color: #999;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.canvas-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.canvas-controls label {
  font-size: 11px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 6px;
}

.canvas-bg-color {
  cursor: pointer;
  width: 32px;
  height: 24px;
  border: 1px solid #ddd;
  border-radius: 3px;
}

.clear-canvas-btn {
  padding: 4px 8px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.2s;
}

.clear-canvas-btn:hover {
  background: #f5f5f5;
  border-color: #ff4444;
  color: #ff4444;
}

/* Grid Builder */
.grid-builder {
  position: relative;
  flex: 1;
}

.grid-container {
  position: relative;
  width: 100%;
  min-height: 400px;
  background-image:
    linear-gradient(rgba(0,0,0,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.05) 1px, transparent 1px);
  background-size: 2% 20px;
  transition: background-color 0.2s;
}

.grid-container.hide-grid {
  background-image: none;
}

/* Grid Items */
.grid-item {
  position: absolute;
  background: white;
  border: 2px solid transparent;
  border-radius: 4px;
  padding: 20px 20px 20px 44px; /* Extra left padding for drag handle */
  cursor: default;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  min-width: 100px;
  min-height: 80px;
  user-select: none;
}

.grid-item:hover {
  border-color: #4A90E2;
}

.grid-item.selected {
  border-color: #4A90E2;
  box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
  z-index: 1000;
}

.grid-item.dragging {
  opacity: 0.7;
  cursor: move;
}

.grid-item.resizing {
  user-select: none;
}

.grid-item-header {
  font-weight: 600;
  color: #333;
  margin-bottom: 5px;
  font-size: 14px;
}

.grid-item-content {
  color: #666;
  font-size: 13px;
}

.grid-item-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.grid-item.selected .grid-item-controls,
.grid-item:hover .grid-item-controls {
  opacity: 1;
}

.grid-item-control-btn {
  width: 24px;
  height: 24px;
  background: #4A90E2;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  transition: background 0.2s;
}

.grid-item-control-btn:hover {
  background: #357ABD;
}

.grid-item-delete {
  width: 24px;
  height: 24px;
  background: #ff4444;
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  transition: background 0.2s;
}

.grid-item-delete:hover {
  background: #cc0000;
}

/* Resize Handles */
.resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #4A90E2;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 0 3px rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.2s;
}

.grid-item.selected .resize-handle,
.grid-item:hover .resize-handle {
  opacity: 1;
}

.resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }
.resize-handle.n { top: -5px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.resize-handle.s { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.resize-handle.e { top: 50%; right: -5px; transform: translateY(-50%); cursor: e-resize; }
.resize-handle.w { top: 50%; left: -5px; transform: translateY(-50%); cursor: w-resize; }

/* Drag Clone */
.dragging-clone {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  opacity: 0.9;
  background: white;
  color: #333;
  border: 2px solid #4A90E2;
  box-shadow: 0 8px 24px rgba(74, 144, 226, 0.4);
  border-radius: 4px;
}

/* Drop Zone Indicator */
.drop-zone-indicator {
  position: absolute;
  border: 2px dashed #4A90E2;
  background: rgba(74, 144, 226, 0.1);
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.drop-zone-indicator.active {
  opacity: 1;
}

/* Drag Handle */
.drag-handle {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  background: rgba(74, 144, 226, 0.1);
  border: 1px solid rgba(74, 144, 226, 0.3);
  border-radius: 4px;
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.3;
  transition: all 0.2s;
  z-index: 10;
}

.drag-handle::before {
  content: '⋮⋮';
  font-size: 14px;
  color: #4A90E2;
  font-weight: bold;
  letter-spacing: -2px;
}

.grid-item:hover .drag-handle {
  opacity: 1;
  background: rgba(74, 144, 226, 0.15);
}

.drag-handle:hover {
  background: rgba(74, 144, 226, 0.25);
  transform: scale(1.1);
}

/* Configuration Side Panel */
.config-panel {
  position: fixed;
  top: 0;
  right: -400px;
  width: 400px;
  height: 100vh;
  background: white;
  box-shadow: -2px 0 8px rgba(0,0,0,0.15);
  transition: right 0.3s ease;
  z-index: 10000;
  display: flex;
  flex-direction: column;
}

.config-panel.open {
  right: 0;
}

.config-panel-header {
  padding: 20px;
  border-bottom: 1px solid #ddd;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.config-panel-header h2 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

.config-panel-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 24px;
  color: #666;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.config-panel-close:hover {
  background: #f5f5f5;
  color: #333;
}

.config-panel-body {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.config-field {
  margin-bottom: 20px;
}

.config-field label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #333;
  font-size: 14px;
}

.config-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.config-field input:focus {
  outline: none;
  border-color: #4A90E2;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.z-index-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.z-index-btn {
  padding: 10px 12px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  text-align: center;
}

.z-index-btn:hover {
  background: #f5f5f5;
  border-color: #4A90E2;
  color: #4A90E2;
}

.z-index-btn:active {
  transform: translateY(1px);
}

.config-panel-footer {
  padding: 20px;
  border-top: 1px solid #ddd;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.config-panel-footer button {
  padding: 10px 20px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.config-panel-footer button:hover {
  background: #f5f5f5;
}

.config-panel-footer button.primary {
  background: #4A90E2;
  color: white;
  border-color: #4A90E2;
}

.config-panel-footer button.primary:hover {
  background: #357ABD;
  border-color: #357ABD;
}
