/* ============================================
   LINE TOOL CONTEXT STYLES
   ============================================ */

/* Line Tool Container */
.toolctx-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.toolctx-line .label {
  min-width: 54px;
  text-align: right;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary, #374151);
}

/* ============================================
   PENCIL TOOL CONTEXT STYLES
   ============================================ */

/* Pencil Tool Container */
.toolctx-pencil {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.toolctx-pencil .label {
  min-width: 54px;
  text-align: right;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary, #374151);
}

.toolctx-pencil .hint {
  font-size: 12px;
  color: var(--muted, #9ca3af);
  margin-left: 8px;
  font-style: italic;
}

.toolctx-pencil .checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  font-size: 14px;
  cursor: pointer;
}

.toolctx-pencil .checkbox-label input[type="checkbox"] {
  cursor: pointer;
}

/* ============================================
   SHARED SLIDER STYLES
   ============================================ */

.toolctx-line .slider,
.toolctx-pencil .slider {
  width: clamp(160px, 24vw, 360px);
  height: 6px;
  border-radius: 3px;
  background: #e5e7eb;
  outline: none;
  transition: opacity 0.2s;
}

.toolctx-line .slider:hover,
.toolctx-pencil .slider:hover {
  opacity: 0.8;
}

/* Restore focus ring for keyboard users — the outline: none above suppresses
   the global *:focus-visible rule, so we re-apply it explicitly here. */
.toolctx-line .slider:focus-visible,
.toolctx-pencil .slider:focus-visible {
  outline: 2px solid var(--accent, #0ea5e9);
  outline-offset: 3px;
}

/* Webkit Slider Thumb */
.toolctx-line .slider::-webkit-slider-thumb,
.toolctx-pencil .slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent, #0ea5e9);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.toolctx-line .slider::-webkit-slider-thumb:hover,
.toolctx-pencil .slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

/* Firefox Slider Thumb */
.toolctx-line .slider::-moz-range-thumb,
.toolctx-pencil .slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent, #0ea5e9);
  cursor: pointer;
  border: none;
  transition: transform 0.15s ease;
}

.toolctx-line .slider::-moz-range-thumb:hover,
.toolctx-pencil .slider::-moz-range-thumb:hover {
  transform: scale(1.1);
}

/* ============================================
   NUMBER INPUT STYLES
   ============================================ */

.toolctx-line .num,
.toolctx-pencil .num {
  width: 50px;
  padding: 4px 8px;
  border: 1px solid #d9dfea;
  border-radius: 6px;
  text-align: center;
  font-size: 14px;
  background: #fff;
  transition: border-color 0.15s ease;
}

.toolctx-line .num:hover,
.toolctx-pencil .num:hover {
  border-color: #9ca3af;
}

.toolctx-line .num:focus,
.toolctx-pencil .num:focus {
  border-color: var(--accent, #0ea5e9);
  outline: none;
  box-shadow: 0 0 0 3px rgb(14 165 233 / 0.1);
}

/* ============================================
   TOOL SUBMENU (Pop-out)
   ============================================ */

.tool-submenu {
  position: fixed !important;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  background: #fff;
  border: 1px solid #e6e8ee;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.12), 0 2px 8px rgb(0 0 0 / 0.08);
  opacity: 0;
  transform: translateX(-8px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
}

.tool-submenu.show {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: all;
}

.tool-submenu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: #fff;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.tool-submenu-btn:hover {
  background: #f0f2f5;
  border-color: #e6e8ee;
}

.tool-submenu-btn.active {
  background: #f0f9ff;
  border-color: #0ea5e9;
}

.tool-submenu-btn.active::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 8px;
  padding: 1px;
  background: linear-gradient(135deg, #0ea5e9, #06b6d4);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.3;
}

.tool-submenu-btn svg {
  width: 20px;
  height: 20px;
  color: #5b657a;
  transition: color 0.15s ease;
}

.tool-submenu-btn:hover svg {
  color: var(--ink, #1f2937);
}

.tool-submenu-btn.active svg {
  color: #0ea5e9;
}

/* ============================================
   CURVE PREVIEW STYLES
   ============================================ */

.curve-preview-path {
  stroke-dasharray: 5, 5;
  animation: dash 0.5s linear infinite;
}

@keyframes dash {
  to {
    stroke-dashoffset: -10;
  }
}

.curve-control-point {
  fill: #fff;
  stroke: #0ea5e9;
  stroke-width: 2;
  cursor: move;
  transition: transform 0.15s ease;
}

.curve-control-point:hover {
  transform: scale(1.2);
}

.curve-control-line {
  stroke: #0ea5e9;
  stroke-width: 1;
  stroke-dasharray: 2, 2;
  opacity: 0.5;
  pointer-events: none;
}

.control-dot {
  filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.1));
}

/* ============================================
   PRINT PREVIEW CONTEXT STYLES
   ============================================ */

.toolctx-print-preview {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}

.toolctx-print-preview .label {
  min-width: 80px;
  text-align: right;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary, #374151);
}

.toolctx-print-preview .hint {
  font-size: 13px;
  color: var(--muted, #6b7280);
  flex: 1;
}

.btn-clear-area {
  padding: 6px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-clear-area:hover {
  background: #f9fafb;
  border-color: #d1d5db;
  color: #111827;
}

.btn-clear-area:active {
  background: #f3f4f6;
  transform: scale(0.98);
}

.btn-clear-area:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

#printPreviewRect {
  animation: printPreviewPulse 2s ease-in-out infinite;
}

@keyframes printPreviewPulse {
  0%, 100% {
    stroke-opacity: 0.7;
  }
  50% {
    stroke-opacity: 0.9;
  }
}

#printPreviewLayer {
  pointer-events: none;
}

/* ============================================
   LINE STYLE AND ARROW GROUPS
   ============================================ */

.line-style-group,
.arrow-type-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.style-buttons,
.arrow-buttons {
  display: inline-flex;
  gap: 4px;
  padding: 2px;
  background: #f0f2f5;
  border-radius: 8px;
  border: 1px solid #d9dfea;
}

.style-btn,
.arrow-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.style-btn:hover,
.arrow-btn:hover {
  background: rgb(255 255 255 / 0.6);
}

.style-btn.active,
.arrow-btn.active {
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.1);
}

.style-btn.active::after,
.arrow-btn.active::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent, #0ea5e9);
}

.style-btn svg,
.arrow-btn svg {
  width: 18px;
  height: 18px;
  color: #6b7280;
  transition: color 0.15s ease;
}

.style-btn:hover svg,
.arrow-btn:hover svg {
  color: var(--ink, #1f2937);
}

.style-btn.active svg,
.arrow-btn.active svg {
  color: var(--accent, #0ea5e9);
}

.style-btn:focus-visible,
.arrow-btn:focus-visible {
  outline: 2px solid var(--accent, #0ea5e9);
  outline-offset: -1px;
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */

@media (max-width: 920px) {
  .toolctx-line .slider,
  .toolctx-pencil .slider {
    width: clamp(120px, 20vw, 240px);
  }

  .toolctx-pencil .hint,
  .toolctx-print-preview .hint {
    display: none;
  }

  .style-btn,
  .arrow-btn {
    width: 28px;
    height: 28px;
  }

  .style-btn svg,
  .arrow-btn svg {
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 640px) {
  .tool-submenu {
    flex-direction: row;
  }

  .tool-submenu.show {
    transform: translateX(0) scale(1);
  }

  .toolctx-line {
    flex-wrap: wrap;
    gap: 6px;
  }

  .toolctx-line .label {
    min-width: auto;
    text-align: left;
  }

  .line-style-group,
  .arrow-type-group {
    flex-wrap: wrap;
  }
}

/* ============================================
   DARK MODE STYLES
   ============================================ */

@media (prefers-color-scheme: dark) {
  .tool-submenu {
    background: #1f2937;
    border-color: #374151;
    box-shadow: 0 4px 12px rgb(0 0 0 / 0.3);
  }

  .tool-submenu-btn {
    background: #1f2937;
  }

  .tool-submenu-btn:hover {
    background: #374151;
    border-color: #4b5563;
  }

  .tool-submenu-btn.active {
    background: #1e3a5f;
    border-color: #0ea5e9;
  }

  .style-buttons,
  .arrow-buttons {
    background: #374151;
    border-color: #4b5563;
  }

  .style-btn.active,
  .arrow-btn.active {
    background: #1f2937;
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  }

  .style-btn:hover,
  .arrow-btn:hover {
    background: rgb(55 65 81 / 0.6);
  }

  .toolctx-line .num,
  .toolctx-pencil .num,
  .btn-clear-area {
    background: #1f2937;
    border-color: #4b5563;
    color: #e5e7eb;
  }

  .toolctx-line .num:hover,
  .toolctx-pencil .num:hover,
  .btn-clear-area:hover {
    background: #374151;
    border-color: #6b7280;
    color: #f3f4f6;
  }

  .btn-clear-area:disabled {
    opacity: 0.35;
  }

  .toolctx-line .slider,
  .toolctx-pencil .slider {
    background: #374151;
  }

  .toolctx-line .label,
  .toolctx-pencil .label,
  .toolctx-print-preview .label {
    color: #e5e7eb;
  }

  .toolctx-pencil .hint,
  .toolctx-print-preview .hint {
    color: #9ca3af;
  }
}

/* ============================================
   ACCESSIBILITY STYLES
   ============================================ */

*:focus-visible {
  outline: 2px solid var(--accent, #0ea5e9);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .style-btn.active,
  .arrow-btn.active,
  .tool-submenu-btn.active {
    outline: 2px solid currentColor;
  }

  .tool-submenu {
    border-width: 2px;
  }

  .curve-control-line {
    opacity: 1;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .curve-preview-path {
    animation: none;
  }

  #printPreviewRect {
    animation: none;
  }
}