/* =========================================================
   deeBoard v4.x — Floating Sketch Windows
   Mirrors flowchart.css window architecture (header/body/drag/resize),
   with a canvas-specific toolbar and a dedicated fullscreen mode.
========================================================= */

/* ---------- Header trigger (place next to flowchart-trigger-btn) ---------- */
.sketch-trigger-btn {
  width: auto !important;
  padding: 0 12px !important;
  gap: 6px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-md);
}
.sketch-trigger-btn .sketch-trigger-label {
  font-size: 13px;
  font-weight: 600;
}
@media (max-width: 640px) {
  .sketch-trigger-btn .sketch-trigger-label { display: none; }
  .sketch-trigger-btn { padding: 0 8px !important; }
}

/* ---------- Sketch window (same shell as flowchart-window) ---------- */
.sketch-window {
  position: absolute;
  pointer-events: all;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px var(--shadow-color);
  min-width: 300px;
  min-height: 260px;
  overflow: hidden;
  resize: none;
  animation: noteWindowIn 0.16s cubic-bezier(0.16, 1, 0.3, 1);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.sketch-window.dragging,
.sketch-window.resizing {
  transition: none;
}
.sketch-window.focused {
  border-color: var(--accent);
  box-shadow: 0 24px 60px var(--shadow-color), 0 0 0 1px var(--accent-soft);
}

/* Fullscreen mode: fills the viewport, header/resize handle stay in the
   DOM (drag/resize are guarded off in JS via el.classList.contains
   ('fullscreen') checks) but position becomes fixed+inset so it responds
   to browser resizes automatically. */
.sketch-window.fullscreen {
  position: fixed;
  inset: 0;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0;
  z-index: 1200 !important;
}

.sketch-window-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-soft);
  cursor: grab;
  flex-shrink: 0;
  user-select: none;
}
.sketch-window-header:active { cursor: grabbing; }
.sketch-window.fullscreen .sketch-window-header {
  cursor: default;
}

.sketch-window-title {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  padding: 4px 6px;
  border-radius: 6px;
}
.sketch-window-title:focus { background: var(--surface-hover); }

.sketch-window-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.sketch-window-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  font-size: 15px;
}
.sketch-window-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.sketch-window-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}
.sketch-window-btn.close:hover {
  background: var(--accent-rose-soft);
  color: var(--accent-rose);
}
.sketch-window-save-indicator {
  font-size: 10.5px;
  color: var(--text-tertiary);
  padding: 0 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Toolbar (color picker, pen/eraser tool, Mode Pen toggle) ---------- */
.sketch-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.sketch-color-input {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}
.sketch-color-input::-webkit-color-swatch-wrapper { padding: 2px; }
.sketch-color-input::-webkit-color-swatch { border: none; border-radius: 5px; }

.sketch-tool-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}
.sketch-tool-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}
.sketch-tool-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.sketch-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

.sketch-penmode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  height: 32px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.sketch-penmode-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
}
.sketch-penmode-toggle.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

/* ---------- Canvas body (white "paper", not theme-dependent) ---------- */
.sketch-window-body {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle, rgba(0, 0, 0, 0.06) 1px, transparent 1px);
  background-size: 22px 22px;
  background-color: #FFFFFF;
  cursor: grab;
}
.sketch-window-body.panning { cursor: grabbing; }

.sketch-canvas-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  backface-visibility: hidden;
}
.sketch-canvas-wrapper.animating {
  will-change: transform;
}

.sketch-canvas {
  position: absolute;
  display: block;
  pointer-events: none; /* pointer events are captured on the body, not the canvas itself */
}

/* ---------- Resize handle — identical mechanism to flowchart-window ---------- */
.sketch-window-resize-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 44px;
  height: 44px;
  touch-action: none;
  cursor: nwse-resize;
  z-index: 5;
}
.sketch-window.fullscreen .sketch-window-resize-handle {
  display: none;
}
.sketch-window-resize-handle::after {
  content: "";
  width: 16px;
  height: 16px;
  background:
    linear-gradient(135deg, transparent 0 50%, var(--accent) 50% 58%, transparent 58% 100%),
    linear-gradient(135deg, transparent 0 68%, var(--accent) 68% 76%, transparent 76% 100%);
  opacity: 0.85;
}

@media (max-width: 640px) {
  .sketch-window {
    min-width: 280px;
    min-height: 240px;
    touch-action: none;
  }
  .sketch-window-body {
    touch-action: none;
  }
  .sketch-window-header {
    touch-action: none;
  }
  .sketch-toolbar {
    padding: 6px 8px;
    gap: 5px;
  }
}
