/* =============================================================================
   ILS Draw Tools CSS — Styles for the interactive drawing toolbar and UI
   Companion to ils-draw-tools.js | v1.0
   Prefix: dt-

   Covers:
     1.  Toolbar container  (.dt-toolbar)
     2.  Tool buttons       (.dt-tool-btn)
     3.  Group separator    (.dt-toolbar-sep)
     4.  Compact & vertical variants
     5.  Action bar         (.dt-action-bar / .dt-action-btn)
     6.  Status / hint bar  (.dt-status-bar)
     7.  Snap toggle        (.dt-snap-toggle)
     8.  Coordinate display (.dt-coord-display)
     9.  Board cursor rules (applied to .geo-board-wrap)
    10.  Dark mode
    11.  Responsive
   ============================================================================= */

/* =============================================================================
   1. TOOLBAR CONTAINER
   ============================================================================= */

.dt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 14px;
  margin: 8px 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  user-select: none;
}

.dark .dt-toolbar {
  background: #1e293b;
  border-color: #334155;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
}

/* =============================================================================
   2. TOOL BUTTONS
   ============================================================================= */

.dt-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  border-radius: 9px;
  background: transparent;
  border: 1.5px solid transparent;
  color: #475569;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    transform 0.12s ease,
    box-shadow 0.18s ease;
  white-space: nowrap;
  line-height: 1;
  position: relative;
}

.dt-tool-btn:hover {
  background: #eef2ff;
  border-color: #c7d2fe;
  color: #4338ca;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.12);
}

.dt-tool-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.dt-tool-btn.dt-tool-active {
  background: #eef2ff;
  border-color: #6366f1;
  color: #4338ca;
  box-shadow:
    0 0 0 2px rgba(99, 102, 241, 0.18),
    0 2px 8px rgba(99, 102, 241, 0.14);
}

/* Coloured top-accent bar on active button */
.dt-tool-btn.dt-tool-active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 6px;
  right: 6px;
  height: 2.5px;
  border-radius: 0 0 3px 3px;
  background: #6366f1;
}

/* ── Icon ── */
.dt-tool-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

/* SVG icons — size + inherit button colour via currentColor */
.dt-tool-icon svg {
  width: 18px;
  height: 18px;
  display: block;
  flex-shrink: 0;
  pointer-events: none;
  /* stroke/fill set inline on the <svg> element; colour flows via currentColor */
}

/* Emoji / text fallback */
.dt-tool-icon:not(:has(svg)) {
  font-size: 16px;
  line-height: 1;
  text-align: center;
}

.dt-tool-btn:hover .dt-tool-icon {
  transform: scale(1.15);
}

.dt-tool-btn.dt-tool-active .dt-tool-icon {
  transform: scale(1.1);
}

/* ── Label ── */
.dt-tool-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
}

/* ── Keyboard shortcut badge ── */
.dt-tool-shortcut {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 4px;
  background: #dde1f8;
  color: #4338ca;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  opacity: 0.85;
}

.dt-tool-btn.dt-tool-active .dt-tool-shortcut {
  background: #c7d2fe;
}

/* Dark mode — buttons */
.dark .dt-tool-btn {
  color: #94a3b8;
}

.dark .dt-tool-btn:hover {
  background: #1e1b4b;
  border-color: #4338ca;
  color: #a5b4fc;
}

.dark .dt-tool-btn.dt-tool-active {
  background: #1e1b4b;
  border-color: #818cf8;
  color: #c7d2fe;
  box-shadow:
    0 0 0 2px rgba(129, 140, 248, 0.2),
    0 2px 8px rgba(129, 140, 248, 0.14);
}

.dark .dt-tool-btn.dt-tool-active::before {
  background: #818cf8;
}

.dark .dt-tool-shortcut {
  background: #312e81;
  color: #a5b4fc;
}

.dark .dt-tool-btn.dt-tool-active .dt-tool-shortcut {
  background: #4338ca;
}

/* =============================================================================
   3. GROUP SEPARATOR
   ============================================================================= */

.dt-toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 28px;
  background: #e2e8f0;
  margin: 0 2px;
  border-radius: 1px;
  flex-shrink: 0;
}

.dark .dt-toolbar-sep {
  background: #334155;
}

/* =============================================================================
   4. COMPACT & VERTICAL VARIANTS
   ============================================================================= */

/* Compact: icons only, no text labels */
.dt-toolbar-compact .dt-tool-btn {
  padding: 7px 8px;
  gap: 0;
}

.dt-toolbar-compact .dt-tool-icon {
  width: 24px;
  height: 24px;
}

.dt-toolbar-compact .dt-tool-icon svg {
  width: 20px;
  height: 20px;
}

/* Vertical toolbar */
.dt-toolbar-vertical {
  flex-direction: column;
  align-items: stretch;
  padding: 8px 6px;
  gap: 3px;
  width: auto;
}

.dt-toolbar-vertical .dt-tool-btn {
  justify-content: flex-start;
  padding: 7px 12px;
}

.dt-toolbar-vertical .dt-toolbar-sep {
  width: 100%;
  height: 1px;
  margin: 3px 0;
}

.dt-toolbar-vertical .dt-tool-btn.dt-tool-active::before {
  top: 6px;
  bottom: 6px;
  left: 0;
  right: auto;
  width: 2.5px;
  height: auto;
  border-radius: 0 3px 3px 0;
}

/* =============================================================================
   5. ACTION BAR  (Undo / Clear)
   ============================================================================= */

.dt-action-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin: 6px 0;
}

.dt-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  border: 1.5px solid transparent;
}

/* Undo button */
.dt-undo-btn {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #334155;
}

.dt-undo-btn:hover {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
}

.dt-undo-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Clear button */
.dt-clear-btn {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.dt-clear-btn:hover {
  background: #fee2e2;
  border-color: #ef4444;
  color: #b91c1c;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.15);
}

.dt-clear-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.dt-action-icon {
  font-size: 15px;
}

/* Dark mode — action bar */
.dark .dt-undo-btn {
  background: #1e293b;
  border-color: #475569;
  color: #cbd5e1;
}

.dark .dt-undo-btn:hover {
  background: #1e3a5f;
  border-color: #3b82f6;
  color: #60a5fa;
}

.dark .dt-clear-btn {
  background: #1e1010;
  border-color: #7f1d1d;
  color: #fca5a5;
}

.dark .dt-clear-btn:hover {
  background: #450a0a;
  border-color: #ef4444;
  color: #f87171;
}

/* =============================================================================
   6. STATUS / HINT BAR
   ============================================================================= */

.dt-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  margin: 6px 0;
  transition: all 0.25s ease;
  border: 1.5px solid transparent;
}

/* Info (default) */
.dt-status-info {
  background: #fffbeb;
  border-color: #fcd34d;
  color: #92400e;
}

/* Warning */
.dt-status-warn {
  background: #fff7ed;
  border-color: #fdba74;
  color: #9a3412;
}

/* Success */
.dt-status-success {
  background: #f0fdf4;
  border-color: #86efac;
  color: #166534;
}

.dt-status-icon {
  font-size: 17px;
  flex-shrink: 0;
}

.dt-status-msg {
  flex: 1;
}

/* Dark mode — status bar */
.dark .dt-status-info {
  background: #422006;
  border-color: #f59e0b;
  color: #fef3c7;
}

.dark .dt-status-warn {
  background: #431407;
  border-color: #f97316;
  color: #fed7aa;
}

.dark .dt-status-success {
  background: #052e16;
  border-color: #4ade80;
  color: #bbf7d0;
}

/* =============================================================================
   7. SNAP TOGGLE BUTTON
   ============================================================================= */

.dt-snap-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 9px;
  background: #f1f5f9;
  border: 1.5px solid #cbd5e1;
  color: #64748b;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dt-snap-toggle:hover {
  border-color: #6366f1;
  background: #eef2ff;
  color: #4338ca;
}

.dt-snap-toggle.dt-snap-on {
  background: #eef2ff;
  border-color: #6366f1;
  color: #4338ca;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.dt-snap-icon {
  font-size: 16px;
}

.dt-snap-label {
  font-size: 12px;
}

/* Animated grid-dot indicator when snap is ON */
.dt-snap-toggle.dt-snap-on .dt-snap-icon {
  animation: dt-snap-pulse 1.8s ease-in-out infinite;
}

@keyframes dt-snap-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.dark .dt-snap-toggle {
  background: #1e293b;
  border-color: #475569;
  color: #94a3b8;
}

.dark .dt-snap-toggle:hover {
  background: #1e1b4b;
  border-color: #818cf8;
  color: #a5b4fc;
}

.dark .dt-snap-toggle.dt-snap-on {
  background: #1e1b4b;
  border-color: #818cf8;
  color: #c7d2fe;
  box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.2);
}

/* =============================================================================
   8. COORDINATE DISPLAY
   ============================================================================= */

.dt-coord-display {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 7px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  font-family: "Courier New", Courier, monospace;
  letter-spacing: 0.3px;
  min-width: 120px;
}

.dark .dt-coord-display {
  background: #0f172a;
  border-color: #334155;
  color: #64748b;
}

/* =============================================================================
   9. BOARD CURSOR RULES
   These classes are added/removed on the board wrapper (.geo-board-wrap)
   by the activity page to reflect the active tool.
   ============================================================================= */

/* Default JSXGraph cursor */
.dt-cursor-default {
  cursor: default;
}

/* Crosshair for all drawing tools */
.dt-cursor-draw {
  cursor: crosshair;
}

/* Grab / grabbing for move mode */
.dt-cursor-move {
  cursor: grab;
}
.dt-cursor-move:active {
  cursor: grabbing;
}

/* Eraser — custom SVG data-URI or closest native */
.dt-cursor-erase {
  cursor: cell;
}

/* Text tool */
.dt-cursor-text {
  cursor: text;
}

/* Pointer for perpendicular/parallel line selection */
.dt-cursor-pick {
  cursor: pointer;
}

/* =============================================================================
   10. PENDING STEP INDICATOR
   Small overlay badge on the board showing "Step 1 of 2" etc.
   ============================================================================= */

.dt-step-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 20;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.88);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
  animation: dt-badge-in 0.2s ease-out;
}

@keyframes dt-badge-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dark .dt-step-badge {
  background: rgba(129, 140, 248, 0.88);
}

/* =============================================================================
   11. DRAW TOOL COMPLETE FLASH
   Brief green flash overlay on the board when a shape is successfully completed.
   ============================================================================= */

.dt-complete-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: rgba(34, 197, 94, 0.07);
  border: 2px solid rgba(34, 197, 94, 0.3);
  opacity: 0;
  z-index: 15;
}

.dt-complete-flash.dt-flash-active {
  animation: dt-complete-glow 0.65s ease-out forwards;
}

@keyframes dt-complete-glow {
  0% {
    opacity: 1;
  }
  60% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
  }
}

.dark .dt-complete-flash {
  background: rgba(74, 222, 128, 0.05);
  border-color: rgba(74, 222, 128, 0.25);
}

/* =============================================================================
   12. FULL DRAW TOOLS PANEL (optional wrapper layout)
   Wrap toolbar + board + status in .dt-panel for a consistent stacked layout.
   ============================================================================= */

.dt-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
}

.dt-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Board area — ensures overlay elements position correctly */
.dt-panel .geo-board-wrap {
  position: relative;
}

/* =============================================================================
   13. RESPONSIVE
   ============================================================================= */

@media (max-width: 540px) {
  .dt-toolbar {
    gap: 3px;
    padding: 5px 6px;
  }

  .dt-tool-btn {
    padding: 6px 7px;
    gap: 4px;
    font-size: 12px;
  }

  .dt-tool-icon {
    width: 18px;
    height: 18px;
  }

  .dt-tool-icon svg {
    width: 16px;
    height: 16px;
  }

  .dt-tool-label {
    font-size: 11px;
  }

  .dt-tool-shortcut {
    display: none; /* hide shortcut badges on mobile */
  }

  .dt-action-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  .dt-status-bar {
    padding: 7px 10px;
    font-size: 12px;
    gap: 6px;
  }

  .dt-status-icon {
    font-size: 15px;
  }

  .dt-snap-toggle {
    padding: 6px 10px;
    font-size: 12px;
  }

  .dt-coord-display {
    font-size: 11px;
    padding: 3px 8px;
    min-width: 100px;
  }
}

@media (max-width: 380px) {
  .dt-tool-btn {
    padding: 5px 6px;
    font-size: 11px;
  }

  .dt-tool-icon {
    width: 16px;
    height: 16px;
  }

  .dt-tool-icon svg {
    width: 14px;
    height: 14px;
  }

  /* Collapse to icons-only at very small widths */
  .dt-tool-label {
    display: none;
  }

  .dt-action-btn {
    padding: 5px 10px;
    font-size: 11px;
  }

  .dt-toolbar-sep {
    height: 22px;
  }
}

/* =============================================================================
   14. PRINT — hide toolbars, show only the board
   ============================================================================= */

@media print {
  .dt-toolbar,
  .dt-action-bar,
  .dt-status-bar,
  .dt-snap-toggle,
  .dt-coord-display {
    display: none !important;
  }
}
