.draw-overlay-parent {
  position: relative;
}

.draw-overlay-host {
  position: absolute;
  z-index: 40;
  pointer-events: none;
}

.draw-overlay {
  position: absolute;
  inset: 0;
  display: block;
  overflow: visible;
  pointer-events: none;
}

.draw-overlay.draw-active {
  pointer-events: auto;
  touch-action: none;
  cursor: crosshair;
}

.draw-toggle {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  border: 1px solid var(--border, var(--line));
  border-radius: var(--radius, 6px);
  color: var(--text, var(--ink));
  background: var(--card-bg, var(--surface));
  cursor: pointer;
  line-height: 1;
}

.draw-toggle:hover,
.draw-toggle.active {
  border-color: var(--accent, var(--teal));
  background: var(--accent-light, color-mix(in srgb, var(--surface) 84%, var(--teal)));
}

.draw-toggle:hover::after {
  content: attr(data-draw-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: max-content;
  max-width: 240px;
  padding: 6px 9px;
  border: 1px solid var(--border, var(--line));
  border-radius: 6px;
  color: var(--text, var(--ink));
  background: var(--card-bg, var(--surface));
  box-shadow: 0 4px 16px rgba(0, 0, 0, .14);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  white-space: normal;
  z-index: 1100;
}

.draw-toggle-fallback {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}

.draw-toolbar {
  position: fixed;
  top: 72px;
  left: 50%;
  z-index: 1000;
  display: none;
  align-items: center;
  gap: 5px;
  max-width: calc(100vw - 24px);
  padding: 7px;
  overflow-x: auto;
  border: 1px solid var(--border, var(--line));
  border-radius: var(--radius, 8px);
  color: var(--text, var(--ink));
  background: var(--card-bg, var(--surface));
  box-shadow: 0 8px 28px rgba(0, 0, 0, .18);
  font-family: var(--font, Inter, sans-serif);
  transform: translateX(-50%);
}

.draw-toolbar.open {
  display: flex;
}

.draw-toolbar button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text, var(--ink));
  background: transparent;
  cursor: pointer;
  font: 500 13px/1 var(--font, Inter, sans-serif);
}

.draw-toolbar button:hover,
.draw-toolbar button.active {
  border-color: var(--accent, var(--teal));
  background: var(--accent-light, color-mix(in srgb, var(--surface) 84%, var(--teal)));
}

.draw-toolbar .draw-highlighter-tool {
  font-size: 20px;
}

.draw-toolbar .draw-swatch {
  width: 24px;
  min-width: 24px;
  height: 24px;
  padding: 0;
  border: 2px solid var(--card-bg, var(--surface));
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--border, var(--line));
}

.draw-toolbar .draw-swatch.active {
  border-color: var(--card-bg, var(--surface));
  box-shadow: 0 0 0 2px var(--text, var(--ink));
}

.draw-divider {
  flex: 0 0 auto;
  width: 1px;
  height: 22px;
  margin: 0 2px;
  background: var(--border, var(--line));
}

.draw-toolbar .draw-clear {
  color: var(--red, #e5484d);
}

.draw-toolbar .draw-exit {
  font-size: 20px;
}

.draw-error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 1200;
  padding: 10px 18px;
  border: 1px solid var(--red, #e5484d);
  border-left-width: 4px;
  border-radius: 8px;
  color: var(--text, var(--ink));
  background: var(--card-bg, var(--surface));
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
  font: 400 14px/1.4 var(--font, Inter, sans-serif);
  transform: translateX(-50%);
}

@media (max-width: 600px) {
  .draw-toolbar {
    top: 64px;
    justify-content: flex-start;
  }
}

@media print {
  .draw-toggle,
  .draw-toolbar {
    display: none !important;
  }
}

/* Floating mode buttons: draw + AI select */
.draw-fab-stack {
  position: fixed;
  right: 18px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 60;
}
.draw-fab-stack .draw-toggle {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  font-size: 19px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.draw-fab-stack .draw-toggle:hover::after {
  top: auto;
  bottom: 0;
  right: calc(100% + 10px);
}

/* Pulse the AI tooltip when summoned via the floating button */
.ai-tooltip.draw-pulse {
  animation: drawTooltipPulse 0.6s ease;
}
@keyframes drawTooltipPulse {
  0% { transform: scale(0.92); box-shadow: 0 0 0 5px rgba(147, 51, 234, 0.3); }
  100% { transform: scale(1); box-shadow: none; }
}

/* Touch devices (tablets, e-readers): bigger tap targets */
@media (pointer: coarse) {
  .draw-fab-stack .draw-toggle {
    width: 56px;
    height: 56px;
    min-width: 56px;
    font-size: 24px;
  }
  .ai-tooltip button {
    padding: 12px 18px;
    font-size: 16px;
  }
}
