/* Base reset */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Base variables */
  --primary-color: #333333;
  --border-color: #666666;
  --border-width: 1px;
  --border-radius: 6px;
  --grid-gap: 0.75rem;
  --spot-padding: 0.75rem;
  
  /* Base grid properties - will be overridden by media queries */
  --grid-cols: 2;
  --grid-rows: 3;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  padding: 0.625rem;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* The unified layout grid */
.layout-grid {
  position: relative;
  width: 100%;
  height: 95vh;
  min-height: 95vh;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0.625rem;
  border: 2px solid var(--primary-color);
}

/* Your existing resize handle styles */
.resize-handle {
  position: absolute;
  background-color: rgba(0, 0, 0, 0.1);
  transition: background-color 0.2s;
  z-index: 10;
  
  /* New additions to ensure resize handles capture clicks before drag starts */
  pointer-events: auto;
  z-index: 30; /* Increase z-index to ensure handles are on top */
}

.resize-handle:hover {
  background-color: rgba(0, 0, 0, 0.3);
}

/* Resize handle positioning */
.resize-right {
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: e-resize;
}

.resize-bottom {
  bottom: 0;
  left: 0;
  height: 8px;
  width: 100%;
  cursor: s-resize;
}

.resize-corner {
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  cursor: se-resize;
}

/* Update the spot styles for absolute positioning */
.spot {
  position: absolute; /* Changed from relative to absolute */
  padding: var(--spot-padding);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
  transition: all 0.2s ease;
  cursor: grab;
  overflow: hidden;
  
  /* Remove grid-column and grid-row properties */
  /* Internal layout */
  display: flex;
  flex-direction: column;
  
  /* Transition for smooth movement */
  transition: left 0.2s ease, top 0.2s ease, width 0.2s ease, height 0.2s ease;

  width: calc(100% / var(--grid-cols) - var(--grid-gap));
  height: calc(100% / var(--grid-rows) - var(--grid-gap));
}

.spot .component-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.spot header {
  font-weight: bold;
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border-color);
}

/* Style applied during active resizing */
.spot.resizing {
  opacity: 0.8;
  outline: 2px dashed #007bff;
  z-index: 20;
  transition: none; /* Disable transitions during active resizing */
}

/* Spot sizing utility classes */
.spot-col-2, .spot-col-3, .spot-col-4, .spot-col-5, 
.spot-col-6, .spot-col-7, .spot-col-8,

.spot-row-2, .spot-row-3, .spot-row-4, .spot-row-5, 
.spot-row-6, .spot-row-7 {
  /* These don't affect visual sizing directly */
}

/* Drag and drop visual feedback */
.dragging {
  opacity: 0.6;
  transform: scale(0.95);
  border: 2px dashed #666 !important;
}

.drop-target {
  border: 2px dashed #007bff !important;
  background-color: rgba(0, 123, 255, 0.1);
}

.drop-indicator {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  opacity: 0.6;
  transition: all 0.1s ease;
}

.drop-indicator-valid {
  border: 2px dashed #007bff;
  background-color: rgba(0, 123, 255, 0.1);
}

.drop-indicator-invalid {
  border: 2px dashed #ff0000;
  background-color: rgba(255, 0, 0, 0.1);
}

/* Background colors */
.bg-red-100 { background-color: #fee2e2; }
.bg-red-200 { background-color: #fecaca; }
.bg-red-300 { background-color: #fca5a5; }

.bg-blue-100 { background-color: #dbeafe; }
.bg-blue-200 { background-color: #bfdbfe; }
.bg-blue-300 { background-color: #93c5fd; }

.bg-green-100 { background-color: #d1fae5; }
.bg-green-200 { background-color: #a7f3d0; }
.bg-green-300 { background-color: #6ee7b7; }

.bg-yellow-100 { background-color: #fef3c7; }
.bg-yellow-200 { background-color: #fde68a; }
.bg-yellow-300 { background-color: #fcd34d; }

.bg-purple-100 { background-color: #ede9fe; }
.bg-purple-200 { background-color: #ddd6fe; }
.bg-purple-300 { background-color: #c4b5fd; }

/* Container background colors */
.bg-slate-50 { background-color: #f8fafc; }
.bg-slate-100 { background-color: #f1f5f9; }
.bg-slate-200 { background-color: #e2e8f0; }

/* Mobile Portrait (up to 480px) */
@media only screen and (max-width: 480px) and (orientation: portrait) {
  :root {
    --grid-cols: 2;  /* 2 columns */
    --grid-rows: 3;  /* 3 rows */
    --grid-gap: 0.5rem;
    --border-radius: 4px;
    --spot-padding: 0.5rem;
  }
  
  /* Force single column for multi-cell spans to ensure they fit */
  .spot[class*="spot-col-"] {
    grid-column: 1 / -1;
  }
}

/* Mobile Landscape */
@media only screen and (max-width: 768px) and (orientation: landscape) {
  :root {
    --grid-cols: 3;  /* 3 columns */
    --grid-rows: 2;  /* 2 rows */
    --grid-gap: 0.5rem;
  }
  
  /* Limit column spans */
  .spot-col-3, .spot-col-4, .spot-col-5, .spot-col-6, .spot-col-7, .spot-col-8 {
    grid-column: span 3;
  }
}

/* Tablet (481px-768px) */
@media only screen and (min-width: 481px) and (max-width: 768px) and (orientation: portrait) {
  :root {
    --grid-cols: 4;  /* 4 columns */
    --grid-rows: 4;  /* 4 rows */
    --grid-gap: 0.75rem;
    --border-radius: 6px;
  }
  
  /* Limit column spans */
  .spot-col-5, .spot-col-6, .spot-col-7, .spot-col-8 {
    grid-column: span 4;
  }
}

/* Small Laptop (769px-1024px) */
@media only screen and (min-width: 769px) and (max-width: 1024px) {
  :root {
    --grid-cols: 5;  /* 5 columns */
    --grid-rows: 6;  /* 6 rows */
    --grid-gap: 0.75rem;
  }
  
  /* Limit column spans */
  .spot-col-6, .spot-col-7, .spot-col-8 {
    grid-column: span 5;
  }
}

/* Desktop (1025px-1440px) */
@media only screen and (min-width: 1025px) and (max-width: 1440px) {
  :root {
    --grid-cols: 6;  /* 6 columns */
    --grid-rows: 7;  /* 7 rows */
    --grid-gap: 1rem;
    --border-radius: 8px;
    --spot-padding: 1rem;
  }
  
  /* Limit column spans */
  .spot-col-7, .spot-col-8 {
    grid-column: span 6;
  }
}

/* Large screens (1441px+) */
@media only screen and (min-width: 1441px) {
  :root {
    --grid-cols: 8;  /* 8 columns */
    --grid-rows: 6;  /* 6 rows as requested */
    --grid-gap: 1.25rem;
    --border-radius: 10px;
    --spot-padding: 1.25rem;
  }
}