/* Layers Modal Styles */

/* Modal Overlay */
.layers-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.layers-modal-overlay.active {
  display: flex;
}

/* Disable canvas pointer events when modal is open */
body:has(.layers-modal-overlay.active) .canvas-container {
  pointer-events: none;
}

/* Modal Container */
.layers-modal {
  background: #2a2a3e;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

/* Modal Header */
.layers-modal-header {
  padding: 20px;
  border-bottom: 1px solid #3a3a4e;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.layers-modal-header h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.layers-close-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.layers-close-btn:hover {
  background: #3a3a4e;
  color: #fff;
}

.layers-close-btn:active {
  transform: scale(0.95);
}

/* Modal Body */
.layers-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  overscroll-behavior: contain;
}

/* Layer List */
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.layer-item {
  background: #1a1a2e;
  border: 2px solid #3a3a4e;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
  cursor: pointer;
}

.layer-item.active {
  border-color: #4a90e2;
  background: #252538;
}

.layer-item:hover {
  border-color: #5a5a6e;
}

/* Drag Handle */
.layer-drag-handle {
  cursor: grab;
  color: #666;
  font-size: 24px;
  user-select: none;
  touch-action: none;
  padding: 8px 12px;
  margin: -8px -4px -8px -8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}

.layer-drag-handle:active {
  cursor: grabbing;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* Dragging State */
.layer-item.dragging {
  opacity: 0.5;
  transform: scale(0.98);
}

.layer-item.drag-over {
  border-top: 3px solid #4a90e2;
  margin-top: 3px;
}

/* Visibility Toggle */
.layer-visibility-toggle {
  background: none;
  border: none;
  color: #aaa;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.layer-visibility-toggle:hover {
  color: #fff;
}

.layer-visibility-toggle:active {
  transform: scale(0.95);
}

.layer-visibility-toggle.hidden {
  color: #555;
}

/* Color Swatch */
.layer-color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 2px solid #3a3a4e;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.layer-color-swatch input[type="color"] {
  opacity: 0;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 10000;
  /* Ensure color picker popup appears above modal */
}

/* Layer Info */
.layer-info {
  flex: 1;
  min-width: 0;
}

.layer-name {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 4px;
}

.layer-params {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Delete Button */
.layer-delete-btn {
  background: none;
  border: none;
  color: #e74c3c;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.layer-delete-btn:hover {
  opacity: 1;
}

.layer-delete-btn:active {
  transform: scale(0.95);
  opacity: 1;
}

/* Add Layer Button */
.add-layer-btn {
  width: 100%;
  padding: 12px;
  background: #3a3a4e;
  border: 2px dashed #5a5a6e;
  border-radius: 8px;
  color: #aaa;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.add-layer-btn:hover {
  background: #4a4a5e;
  border-color: #6a6a7e;
  color: #fff;
}

.add-layer-btn:active {
  transform: scale(0.98);
}

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

.add-layer-btn:disabled:hover {
  background: #3a3a4e;
  border-color: #5a5a6e;
  color: #aaa;
}

/* Layer Limit */
.layer-limit {
  text-align: center;
  color: #888;
  font-size: 12px;
  margin-top: 10px;
}

/* Empty State */
.layer-empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #666;
}

.layer-empty-state-icon {
  font-size: 48px;
  margin-bottom: 10px;
}

/* Mobile Optimizations */
@media (max-width: 600px) {
  .layers-modal {
    max-width: 100%;
    max-height: 95vh;
  }

  .layers-modal-header {
    padding: 16px;
  }

  .layers-modal-header h2 {
    font-size: 18px;
  }

  .layers-modal-body {
    padding: 16px;
  }

  .layer-item {
    padding: 10px;
  }

  .layer-name {
    font-size: 13px;
  }

  .layer-params {
    font-size: 11px;
  }

  .layer-drag-handle {
    font-size: 28px;
    min-width: 48px;
    min-height: 48px;
    padding: 10px 14px;
  }

  .layer-item.drag-over {
    border-top-width: 4px;
    margin-top: 4px;
  }
}

/* Layers Button (in control panel) */
.layers-btn {
  width: 100%;
  margin-bottom: 10px;
}

/* Floating Action Button */
.layers-fab {
  display: flex;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #4a90e2;
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 1000;
  font-size: 24px;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.layers-fab svg {
  flex-shrink: 0;
}

.layers-fab:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.layers-fab:hover {
  background: #357abd;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* FAB Badge (layer count) */
.layers-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #e74c3c;
  color: white;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Undo FAB */
.undo-fab {
  display: flex;
  position: fixed;
  bottom: 90px;
  /* Above layers FAB */
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #2ecc71;
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 1000;
  font-size: 24px;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Redo FAB */
.redo-fab {
  display: flex;
  position: fixed;
  bottom: 160px;
  /* Above undo FAB */
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #2ecc71;
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 1000;
  font-size: 24px;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Hide UI FAB */
.hide-ui-fab {
  display: flex;
  position: fixed;
  bottom: 230px;
  /* Above redo FAB */
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #9b59b6;
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 1000;
  font-size: 24px;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Debug FAB */
.debug-fab {
  display: flex;
  position: fixed;
  bottom: 300px;
  /* Above hide UI FAB */
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #e67e22;
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 1000;
  font-size: 24px;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.undo-fab:active,
.redo-fab:active,
.hide-ui-fab:active,
.debug-fab:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.undo-fab:hover:not(:disabled),
.redo-fab:hover:not(:disabled) {
  background: #27ae60;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.hide-ui-fab:hover {
  background: #8e44ad;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.debug-fab:hover {
  background: #d35400;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* Disabled state for undo/redo */
.undo-fab:disabled,
.redo-fab:disabled {
  background: #555;
  cursor: not-allowed;
  opacity: 0.5;
}

.hide-ui-fab.ui-hidden {
  bottom: 20px;
  /* Move down when UI is hidden */
}

/* Mobile FAB positioning adjustments */
@media (max-width: 768px) {

  /* Use IDs for higher specificity + !important to override any other styles */
  #layersFab {
    position: fixed !important;
    top: calc(10px + env(safe-area-inset-top)) !important;
    right: 10px !important;
    bottom: auto !important;
    left: auto !important;
    z-index: 2000 !important;
  }

  /* Move Undo/Redo to Top-Left */
  #undoFab {
    position: fixed !important;
    top: calc(10px + env(safe-area-inset-top)) !important;
    left: 10px !important;
    bottom: auto !important;
    right: auto !important;
    z-index: 2000 !important;
  }

  #redoFab {
    position: fixed !important;
    top: calc(10px + env(safe-area-inset-top)) !important;
    left: 76px !important;
    /* 10px + 56px + 10px gap */
    bottom: auto !important;
    right: auto !important;
    z-index: 2000 !important;
  }

  /* Top-Right Stack: Layers -> Share -> Hide UI -> Debug */

  #fabShare {
    display: flex !important;
    position: fixed !important;
    top: calc(76px + env(safe-area-inset-top)) !important;
    /* Below layers */
    right: 10px !important;
    bottom: auto !important;
    left: auto !important;
    z-index: 2000 !important;
  }

  #hideUiFab {
    position: fixed !important;
    top: calc(142px + env(safe-area-inset-top)) !important;
    /* Below Share */
    right: 10px !important;
    bottom: auto !important;
    left: auto !important;
    z-index: 2000 !important;
  }

  /* Debug can stay bottom or stack under Hide UI */
  #debugFab {
    display: flex !important;
    /* Force visible on mobile */
    position: fixed !important;
    top: calc(76px + env(safe-area-inset-top)) !important;
    /* Below Undo/Redo */
    left: 10px !important;
    /* Move to Left side */
    right: auto !important;
    bottom: auto !important;
    z-index: 2000 !important;
  }

  /* Fallback class selector if ID fails for some reason */
  .debug-fab {
    display: flex !important;
    position: fixed !important;
    top: calc(76px + env(safe-area-inset-top)) !important;
    left: 10px !important;
    right: auto !important;
    bottom: auto !important;
    z-index: 2000 !important;
  }
}

/* Hide UI state - Desktop */
.ui-hidden .control-panel {
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

.ui-hidden .fab-cluster {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.control-panel {
  transition: transform 0.3s ease;
}

.fab-cluster {
  transition: opacity 0.3s ease;
}

/* Hide UI state - Mobile */
@media (max-width: 768px) {

  .mobile-tab-bar,
  .mobile-panels {
    transition: transform 0.3s ease;
  }

  .ui-hidden .mobile-tab-bar {
    transform: translateY(100%) !important;
  }

  .ui-hidden .mobile-panels {
    transform: translateY(100%) !important;
  }
}