/* ═════════════════════════════════ CANVAS AREA ══ */

#workspace {
  display: grid;
  grid-template-columns: var(--media-lib-w) 1fr var(--props-w);
  overflow: hidden;
  background: var(--bg-base);
  min-height: 0;
}

/* ── Canvas Area ── */
#canvas-area {
  display: flex;
  flex-direction: column;
  background: var(--bg-deepest);
  overflow: hidden;
  position: relative;
  min-width: 0;
}

#canvas-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(45deg, #1a1a20 25%, transparent 25%) -10px 0,
    linear-gradient(-45deg, #1a1a20 25%, transparent 25%) -10px 0,
    linear-gradient(45deg, transparent 75%, #1a1a20 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a20 75%);
  background-size: 20px 20px;
  background-color: #141418;
}



/* ── Canvas ── */
#main-canvas {
  position: relative;
  display: block;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), var(--shadow-lg);
  cursor: default;
  transform-origin: center center;
  image-rendering: auto;
}

/* ── Selection Overlay ── */
#selection-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Transform handles */
.transform-box {
  position: absolute;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 20;
}
.transform-box.text-selected {
  border-color: var(--layer-text);
}

.resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: white;
  border: 1.5px solid var(--accent);
  border-radius: 1px;
  pointer-events: all;
  z-index: 21;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.resize-handle.nw { top: -4px;   left: -4px;   cursor: nw-resize; }
.resize-handle.n  { top: -4px;   left: 50%;    transform: translateX(-50%); cursor: n-resize; }
.resize-handle.ne { top: -4px;   right: -4px;  cursor: ne-resize; }
.resize-handle.e  { top: 50%;    right: -4px;  transform: translateY(-50%); cursor: e-resize; }
.resize-handle.se { bottom: -4px; right: -4px; cursor: se-resize; }
.resize-handle.s  { bottom: -4px; left: 50%;  transform: translateX(-50%); cursor: s-resize; }
.resize-handle.sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.resize-handle.w  { top: 50%;    left: -4px;  transform: translateY(-50%); cursor: w-resize; }

.rotate-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  cursor: grab;
  pointer-events: all;
  z-index: 21;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.rotate-handle::before {
  content: '';
  position: absolute;
  width: 1px;
  height: 16px;
  background: var(--accent);
  left: 50%;
  transform: translateX(-50%);
  top: 8px;
}
.rotate-handle:active { cursor: grabbing; }

/* ── Canvas Controls Bar ── */
#canvas-controls {
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle);
  height: 28px;
  gap: 6px;
  flex-shrink: 0;
}
.canvas-zoom {
  display: flex;
  align-items: center;
  gap: 4px;
}
#zoom-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  min-width: 36px;
  text-align: center;
}
#btn-zoom-fit {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
/* Thin vertical divider inside canvas-controls */
.canvas-controls-divider {
  width: 1px;
  height: 14px;
  background: var(--border-subtle);
  flex-shrink: 0;
  margin: 0 2px;
}
/* Duration input group */
.tl-duration-input {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10px;
}
.tl-duration-input input {
  width: 38px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 3px;
  color: var(--text-primary);
  font-size: 10px;
  padding: 2px 4px;
  text-align: center;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color var(--transition);
}
.tl-duration-input input:focus { border-color: var(--accent); }
.tl-dur-label {
  font-size: 9px;
  color: var(--text-muted);
}
/* Split button */
.tl-split-btn {
  width: auto !important;
  padding: 0 7px !important;
  font-size: 10px !important;
  gap: 4px;
  display: flex;
  align-items: center;
}
/* Push cursor-pos to far right */
.canvas-info {
  margin-left: auto;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ── Properties Panel ── */
#properties-panel {
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#props-content {
  flex: 1;
  overflow-y: auto;
}

/* Canvas cursor states */
#main-canvas.cursor-grab    { cursor: grab; }
#main-canvas.cursor-grabbing { cursor: grabbing; }
#main-canvas.cursor-crosshair { cursor: crosshair; }
#main-canvas.cursor-move    { cursor: move; }
#main-canvas.cursor-text    { cursor: text; }

/* ── Transform drag area (inside transform box, for drag) ── */
.transform-drag-area {
  position: absolute;
  inset: 12px;
  cursor: move;
  pointer-events: all;
  z-index: 19;
  border-radius: 2px;
}
.transform-drag-area:hover {
  background: rgba(124, 108, 255, 0.08);
}

/* ── Crop Overlay ── */
#crop-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  /* NO overflow:hidden — toolbar must be visible outside crop-border */
}

.crop-mask {
  position: absolute;
  background: rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

#crop-border {
  position: absolute;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
  cursor: move;
  z-index: 41;
}

/* Rule-of-thirds grid */
.crop-rule {
  position: absolute;
  background: rgba(255, 255, 255, 0.2);
  pointer-events: none;
}
.crop-rule-h { left: 0; right: 0; height: 1px; }
.crop-rule-v { top: 0; bottom: 0; width: 1px; }

/* Crop handles */
.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: white;
  border: 1.5px solid rgba(0,0,0,0.4);
  border-radius: 1px;
  z-index: 42;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.crop-handle[data-pos="nw"] { top: -6px;  left: -6px;  cursor: nw-resize; }
.crop-handle[data-pos="n"]  { top: -6px;  left: 50%;   transform: translateX(-50%); cursor: n-resize; }
.crop-handle[data-pos="ne"] { top: -6px;  right: -6px; cursor: ne-resize; }
.crop-handle[data-pos="e"]  { top: 50%;   right: -6px; transform: translateY(-50%); cursor: e-resize; }
.crop-handle[data-pos="se"] { bottom: -6px; right: -6px; cursor: se-resize; }
.crop-handle[data-pos="s"]  { bottom: -6px; left: 50%;  transform: translateX(-50%); cursor: s-resize; }
.crop-handle[data-pos="sw"] { bottom: -6px; left: -6px; cursor: sw-resize; }
.crop-handle[data-pos="w"]  { top: 50%;   left: -6px;  transform: translateY(-50%); cursor: w-resize; }

/* Crop toolbar — positioned directly in overlay by JS */
#crop-toolbar {
  position: absolute;
  display: flex;
  gap: 8px;
  white-space: nowrap;
  z-index: 50;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.6));
}

.crop-action-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}
.crop-action-btn.apply  { background: var(--accent); color: white; }
.crop-action-btn.apply:hover { background: var(--accent-hover); }
.crop-action-btn.reset  { background: var(--bg-surface); color: var(--text-secondary); border: 1px solid var(--border-default); }
.crop-action-btn.reset:hover { background: var(--bg-hover); }
.crop-action-btn.cancel { background: var(--bg-surface); color: var(--danger); border: 1px solid var(--danger); }
.crop-action-btn.cancel:hover { background: rgba(233,69,96,0.15); }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE DESIGN (Media Queries)
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  #properties-panel {
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    min-height: 250px;
    max-height: 400px;
  }
}
