* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: clip !important;
  background-color: #1e1e1e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: geometricPrecision;
}

/* Rulers */
#rulerCorner {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 22px;
  height: 22px;
  background-color: #1b1e22;
  border-right: 1px solid #2d3239;
  border-bottom: 1px solid #2d3239;
  z-index: 100;
}

#rulerTop {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 22px;
  background-color: #f8fafc;
  border-bottom: 1px solid #cbd5e1;
  z-index: 90;
  overflow: hidden;
}

#rulerTopCanvas {
  display: block;
  width: 100%;
  height: 22px;
}

#rulerLeft {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 22px;
  background-color: #f8fafc;
  border-right: 1px solid #cbd5e1;
  z-index: 90;
  overflow: hidden;
}

#rulerLeftCanvas {
  display: block;
  width: 22px;
  height: 100%;
}

#canvasViewport {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: clip !important;
  overscroll-behavior: none;
  contain: strict;
  outline: none;
  cursor: default;
  background-color: #e2e8f0;
  transition: outline 0.15s ease;
}

#canvasViewport.canvas-drop-active {
  outline: 2px dashed #0284c7 !important;
  outline-offset: -4px;
}

#canvasViewport.panning {
  cursor: grab !important;
}

#canvasViewport.panning:active {
  cursor: grabbing !important;
}

#canvasViewport.hold-mode,
#canvasViewport.hold-mode * {
  cursor: grab !important;
}

#canvasViewport.hold-mode.panning,
#canvasViewport.hold-mode.panning *,
#canvasViewport.hold-mode:active,
#canvasViewport.hold-mode:active * {
  cursor: grabbing !important;
}

#canvasContainer {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#svgCanvas {
  display: block;
  background: #ffffff;
  box-shadow: none;
  border: none !important;
  outline: 1px solid #cbd5e1;
  outline-offset: 0;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
  image-rendering: high-quality;
  overflow: visible !important;
}

#svgCanvas text {
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
}

#svgCanvas path,
#svgCanvas line,
#svgCanvas polygon,
#svgCanvas polyline,
#svgCanvas rect,
#svgCanvas circle,
#svgCanvas ellipse {
  shape-rendering: geometricPrecision;
}

#svgCanvas image {
  image-rendering: high-quality;
  image-rendering: -webkit-optimize-contrast;
}

/* Floating Vertical Tool Strip (Right edge) */
.floating-tools {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 22px;
  padding: 8px 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.16);
  z-index: 50;
  gap: 3px;
}

.floating-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #374151;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.floating-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.floating-btn:active {
  background: #e2e8f0;
}

.floating-btn.active {
  background: #eff6ff !important;
  color: #2563eb !important;
}

.floating-badge {
  font-size: 10px;
  font-weight: 600;
  border-radius: 8px;
  width: 36px;
  height: 22px;
  background: #f8fafc;
  color: #475569;
}

.floating-separator {
  width: 20px;
  height: 1px;
  background: #e2e8f0;
  margin: 3px 0;
}

.zoom-slider-wrap {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2px 0;
}

.zoom-slider {
  writing-mode: vertical-lr;
  direction: rtl;
  -webkit-appearance: slider-vertical;
  width: 6px;
  height: 72px;
  accent-color: #2563eb;
  cursor: pointer;
}

/* Object Styles */
.scientific-object {
  cursor: move;
  contain: layout paint;
}

.scientific-object.locked {
  cursor: not-allowed;
}

.scientific-object:hover:not(.selected) {
  cursor: move;
}

.scientific-object.selected {
  outline: none;
}

/* When Layer Color option is selected, replace 4-way move cursor with cursor arrow/pointer */
.sublayer-select-mode,
.sublayer-select-mode *,
.sublayer-select-mode #svgCanvas,
.sublayer-select-mode #svgCanvas *,
.sublayer-select-mode .scientific-object,
.sublayer-select-mode .scientific-object:hover,
.sublayer-select-mode .scientific-object.selected,
.sublayer-select-mode .diagram-connector-group,
.sublayer-select-mode #selectionBox,
.sublayer-select-mode #selectionOverlay {
  cursor: default !important;
}

.sublayer-select-mode .scientific-object path,
.sublayer-select-mode .scientific-object rect,
.sublayer-select-mode .scientific-object circle,
.sublayer-select-mode .scientific-object ellipse,
.sublayer-select-mode .scientific-object polygon,
.sublayer-select-mode .scientific-object polyline,
.sublayer-select-mode .scientific-object line,
.sublayer-select-mode .scientific-object text,
.sublayer-select-mode .scientific-object [data-sublayer-key] {
  cursor: pointer !important;
}

/* ========================================================================= */
/* Sublayer Isolation Mode: Selected layer shows vivid color, rest turns gray */
/* ========================================================================= */
.scientific-object.sublayer-isolation-active path,
.scientific-object.sublayer-isolation-active rect,
.scientific-object.sublayer-isolation-active circle,
.scientific-object.sublayer-isolation-active polygon,
.scientific-object.sublayer-isolation-active polyline,
.scientific-object.sublayer-isolation-active ellipse,
.scientific-object.sublayer-isolation-active line,
.scientific-object.sublayer-isolation-active text,
.scientific-object.sublayer-isolation-active use,
.scientific-object.sublayer-isolation-active image {
  filter: grayscale(100%) brightness(0.85) !important;
  opacity: 0.4 !important;
  transition: filter 0.15s ease, opacity 0.15s ease;
}

/* Selected sublayer remains in 100% full vibrant color (no grayscale) */
.scientific-object.sublayer-isolation-active .sublayer-active-isolated,
.scientific-object.sublayer-isolation-active [data-active-isolated-sublayer="true"],
.scientific-object.sublayer-isolation-active .sublayer-active-isolated * {
  filter: none !important;
  opacity: 1 !important;
}

/* Connectors */
.diagram-connector-group {
  cursor: move;
}

.diagram-connector {
  cursor: move;
  fill: none;
  pointer-events: stroke;
}

.diagram-connector-hit {
  cursor: move;
  fill: none;
  pointer-events: stroke;
}

.diagram-connector-group:hover .diagram-connector {
  stroke-width: 2.5px;
}

.diagram-connector-group.selected .diagram-connector {
  stroke: #0284c7;
}

.connector-handles {
  pointer-events: all;
}

.connector-handle {
  pointer-events: all;
  transition: r 0.12s ease, fill 0.12s ease, stroke 0.12s ease;
}

.connector-handle-vertex {
  cursor: grab;
}

.connector-handle-vertex:hover {
  r: 7.5 !important;
  fill: #0369a1 !important;
  stroke: #ffffff !important;
  cursor: grabbing;
}

.connector-handle-midpoint {
  cursor: crosshair;
}

.connector-handle-midpoint:hover {
  r: 7 !important;
  fill: #0284c7 !important;
  stroke: #ffffff !important;
}

/* Anchor Points */
.anchor-point {
  fill: #ffffff;
  stroke: #0284c7;
  stroke-width: 2;
  cursor: crosshair;
  transition: r 0.15s ease;
}

.anchor-point:hover {
  r: 6;
  fill: #0284c7;
}

/* Selection and Transform Box */
.selection-rect {
  fill: rgba(37, 99, 235, 0.07);
  stroke: #2563eb;
  stroke-width: 1.5;
  stroke-dasharray: none;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.sel-handle {
  fill: #ffffff;
  stroke: #2563eb;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  pointer-events: all;
  transition: fill 0.1s ease, stroke 0.1s ease;
}

.sel-handle:hover {
  fill: #2563eb;
  stroke: #1d4ed8;
}

.handle-nw, .handle-se { cursor: nwse-resize; }
.handle-ne, .handle-sw { cursor: nesw-resize; }
.handle-n,  .handle-s  { cursor: ns-resize; }
.handle-e,  .handle-w  { cursor: ew-resize; }

.rot-line {
  stroke: #2563eb;
  stroke-width: 1.5;
}

.handle-rot {
  cursor: grab;
}

.handle-rot:hover circle {
  fill: #dbeafe;
  stroke: #1d4ed8;
}

.handle-rot:active {
  cursor: grabbing;
}

/* Rubberband box */
.rubberband-box {
  fill: rgba(37, 99, 235, 0.1);
  stroke: #2563eb;
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

/* Alignment Guides */
.snap-guide {
  stroke: #ec4899;
  stroke-width: 1.25;
  stroke-dasharray: 4 4;
}

/* Inline text editor floating toolbar */
.inline-text-toolbar {
  position: absolute;
  z-index: 1005;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16), 0 2px 6px rgba(0, 0, 0, 0.08);
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity 0.15s ease;
}

.itt-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.itt-divider {
  width: 1px;
  height: 20px;
  background: #e2e8f0;
  margin: 0 2px;
}

.itt-select {
  height: 26px;
  font-size: 11.5px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #f8fafc;
  color: #1e293b;
  padding: 0 4px;
  outline: none;
  cursor: pointer;
  font-family: inherit;
}

.itt-select:focus {
  border-color: #0284c7;
}

.itt-font-select {
  max-width: 110px;
}

.itt-btn {
  height: 26px;
  min-width: 24px;
  padding: 0 6px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #ffffff;
  color: #334155;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  outline: none;
  transition: all 0.12s ease;
}

.itt-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #0f172a;
}

.itt-btn.active {
  background: #e0f2fe;
  color: #0284c7;
  border-color: #38bdf8;
  font-weight: 700;
}

.itt-size-input {
  width: 36px;
  height: 24px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #1e293b;
  outline: none;
  margin: 0 2px;
  -moz-appearance: textfield;
}

.itt-size-input::-webkit-outer-spin-button,
.itt-size-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.itt-swatches {
  display: flex;
  align-items: center;
  gap: 3px;
}

.itt-swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  cursor: pointer;
  padding: 0;
  outline: none;
  box-sizing: border-box;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.itt-swatch:hover {
  transform: scale(1.25);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.itt-swatch.active {
  outline: 2px solid #0284c7;
  outline-offset: 1px;
}

.itt-color-picker-label {
  position: relative;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
  border: 1px dashed #94a3b8;
  background: #f8fafc;
  margin-left: 2px;
}

.itt-color-picker {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  left: 0;
  top: 0;
}

.itt-color-picker-icon {
  font-size: 11px;
  pointer-events: none;
}

.itt-btn-done {
  background: #0284c7;
  color: #ffffff;
  border: 1px solid #0284c7;
  font-weight: 700;
  padding: 0 8px;
}

.itt-btn-done:hover {
  background: #0369a1;
  border-color: #0369a1;
  color: #ffffff;
}

/* Inline text editor */
.inline-text-editor {
  position: absolute;
  border: 1.5px solid #2563eb;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.95);
  padding: 4px 6px;
  font-family: inherit;
  font-size: 14px;
  color: #0f172a;
  outline: none;
  resize: none;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  user-select: text;
  -webkit-user-select: text;
}

/* Floating Selection Context Toolbar (BioRender Style - Image 1) */
.selection-floating-toolbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 3px 6px;
  gap: 2px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.14), 0 1px 3px rgba(0, 0, 0, 0.06);
  z-index: 300;
  white-space: nowrap;
  user-select: none;
}

.sft-drag {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px 4px 4px;
  cursor: grab;
  border-right: 1px solid #f1f5f9;
  margin-right: 2px;
}

.sft-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 4px 7px;
  min-width: 42px;
  height: 44px;
  cursor: pointer;
  color: #475569;
  transition: all 0.12s ease;
}

.sft-btn span {
  font-size: 10px;
  font-weight: 500;
  margin-top: 2px;
  line-height: 1;
}

.sft-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.sft-btn:hover svg {
  stroke: #0f172a;
}

.sft-btn:active {
  background: #e2e8f0;
}

.sft-ai {
  color: #7c3aed;
}

.sft-ai span {
  color: #7c3aed;
  font-weight: 600;
}

.sft-ai:hover {
  background: #f5f3ff;
}

.sft-ai:hover svg {
  stroke: #6d28d9;
}

.sft-dots {
  min-width: 28px;
  height: 44px;
  padding: 4px 4px;
}

/* Canvas Right-Click Context Menu (BioRender Style - Image 2) */
.canvas-context-menu {
  position: fixed;
  width: 220px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 4px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 2px 6px rgba(0, 0, 0, 0.05);
  z-index: 99999;
  user-select: none;
}

.cmenu-item {
  display: flex;
  align-items: center;
  padding: 5px 12px;
  font-size: 11.5px;
  color: #1e293b;
  cursor: pointer;
  position: relative;
  transition: background 0.1s ease;
}

.cmenu-item:hover {
  background: #f1f5f9;
  color: #0284c7;
}

.cmenu-item:hover .cmenu-icon svg {
  stroke: #0284c7;
}

.cmenu-icon {
  width: 20px;
  margin-right: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.cmenu-label {
  flex: 1;
  font-weight: 500;
  white-space: nowrap;
}

.cmenu-shortcut {
  font-size: 10px;
  color: #94a3b8;
  margin-left: 12px;
  white-space: nowrap;
}

.cmenu-arrow {
  font-size: 13px;
  font-weight: bold;
  color: #94a3b8;
  margin-left: 6px;
}

.cmenu-divider {
  height: 1px;
  background: #e2e8f0;
  margin: 4px 0;
}

/* Context Menu Submenus */
.cmenu-submenu {
  display: none;
  position: absolute;
  left: calc(100% - 2px);
  top: -4px;
  width: 200px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 5px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 2px 6px rgba(0, 0, 0, 0.05);
  z-index: 501;
}

.cmenu-parent:hover > .cmenu-submenu {
  display: block;
}

/* =========================================================================
   Interactive Crop Tool Overlay & Floating Confirmation Bar
   ========================================================================= */
.crop-boundary-rect {
  fill: rgba(56, 189, 248, 0.04);
  stroke: #38bdf8;
  stroke-width: 2;
  stroke-dasharray: 5 3;
  cursor: move;
  pointer-events: all;
}

.crop-dim-overlay {
  fill: rgba(15, 23, 42, 0.65);
  fill-rule: evenodd;
  pointer-events: all;
}

.crop-grid-line {
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 1;
  stroke-dasharray: 2 2;
  pointer-events: none;
}

.crop-handle {
  fill: #ffffff;
  stroke: #0284c7;
  stroke-width: 2.5;
  pointer-events: all;
  transition: transform 0.1s ease, fill 0.1s ease;
}

.crop-handle:hover {
  fill: #38bdf8;
  stroke: #ffffff;
}

.crop-handle-nw, .crop-handle-se { cursor: nwse-resize; }
.crop-handle-ne, .crop-handle-sw { cursor: nesw-resize; }
.crop-handle-n,  .crop-handle-s  { cursor: ns-resize; }
.crop-handle-w,  .crop-handle-e  { cursor: ew-resize; }

.crop-floating-bar {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0f172a;
  border: 1px solid #38bdf8;
  border-radius: 8px;
  padding: 6px 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 0 15px rgba(56, 189, 248, 0.25);
  z-index: 400;
  user-select: none;
  font-family: inherit;
}

.crop-bar-title {
  font-size: 11.5px;
  font-weight: 700;
  color: #38bdf8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.crop-bar-divider {
  width: 1px;
  height: 16px;
  background: #334155;
}

.crop-bar-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 5px;
  color: #f8fafc;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.crop-bar-btn.apply {
  background: #0284c7;
  border-color: #38bdf8;
  color: #ffffff;
}

.crop-bar-btn.apply:hover {
  background: #0369a1;
}

.crop-bar-btn.cancel:hover {
  background: #334155;
  color: #ef4444;
}

.crop-bar-btn.reset:hover {
  background: #334155;
  color: #f59e0b;
}
