:root {
  --bg: #f4f5f7;
  --toolbar-bg: #ffffff;
  --border: #e0e2e6;
  --accent: #4262ff;
  --text: #1a1a1a;
  --danger: #e5484d;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  user-select: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ---------- Top bar ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
}
.topbar-group { display: flex; align-items: center; gap: 6px; }
.topbar-title span {
  font-weight: 600;
  font-size: 15px;
  padding: 6px 10px;
  border-radius: 6px;
  outline: none;
}
.topbar-title span:focus { background: var(--bg); }

.icon-btn {
  width: 32px; height: 32px;
  border-radius: 6px;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
}
.icon-btn:hover { background: var(--bg); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn:disabled:hover { background: none; }
.icon-btn.small { width: 26px; height: 26px; font-size: 12px; }
.icon-btn.active { background: var(--accent); color: #fff; }
.icon-btn svg { width: 18px; height: 18px; fill: var(--text); stroke: var(--text); }
.icon-btn.active svg { fill: #fff; stroke: #fff; }

.text-btn {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}
.text-btn:hover { background: var(--bg); }
.text-btn.danger { color: var(--danger); }
.text-btn.active { background: var(--accent); color: #fff; }

/* ---------- Dropdown (boards) ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: 38px; left: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 6px;
  z-index: 200;
}
.dropdown-menu .board-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.dropdown-menu .board-item:hover { background: var(--bg); }
.dropdown-menu .board-item.current { font-weight: 700; color: var(--accent); }
.dropdown-menu .board-item.incompatible { color: var(--text-muted, #9aa0a8); cursor: not-allowed; }
.dropdown-menu .board-item.incompatible:hover { background: none; }
.dropdown-menu .board-item button { font-size: 11px; padding: 2px 6px; }
.dropdown-menu hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

/* ---------- Read-only (viewer role on a shared/public board) ----------
   Server already rejects PUT /api/boards/:id from a viewer (403) — this is
   just UX so the toolbar/inspector don't dangle controls that would fail
   silently. Panning/zooming/selecting-nothing still works. */
body.read-only #toolbar,
body.read-only #inspector {
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- Left toolbar ---------- */
#toolbar {
  position: fixed;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 90;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  max-height: 90vh;
  overflow-y: auto;
}
.tool-btn {
  width: 40px; height: 40px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.tool-btn svg {
  width: 20px; height: 20px;
  fill: var(--text);
  stroke: var(--text);
}
.tool-btn:hover { background: var(--bg); }
.tool-btn.active { background: var(--accent); }
.tool-btn.active svg { fill: #fff; stroke: #fff; }

/* ---------- Canvas ---------- */
#canvas-area {
  position: absolute;
  top: 52px; left: 0; right: 0; bottom: 0;
  overflow: hidden;
  background-image: radial-gradient(circle, #d6d8dc 1px, transparent 1px);
  background-size: 24px 24px;
}
#viewport {
  position: absolute;
  inset: 0;
}
#world {
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 0;
  transform-origin: 0 0;
}

/* Elements */
.el {
  position: absolute;
  box-sizing: border-box;
}
.el.selected { outline: 1.5px solid var(--accent); outline-offset: 2px; }
.el.locked { outline: 2px dashed #999; }
.el.in-group { outline: 1px dotted rgba(66,98,255,0.4); }
/* Shown on the shape a connector (arrow/line) endpoint is about to snap to. */
.el.connect-target { box-shadow: 0 0 0 3px rgba(66,98,255,0.4); }

/* Only box-like elements get the rectangular selection outline.
   Lines/arrows/pen/comments rely on their own handles instead, so we
   explicitly opt them OUT of the generic outline to avoid the "square
   around a diagonal line" look. */
.el-line.selected, .el-arrow.selected, .el-pen.selected, .el-comment.selected {
  outline: none;
}

[contenteditable="true"] {
  user-select: text;
  cursor: text;
}

.el-sticky {
  background: #fff9b1;
  border-radius: 4px;
  box-shadow: 1px 2px 6px rgba(0,0,0,0.15);
  padding: 10px;
  font-size: 14px;
  line-height: 1.3;
  overflow: auto;
  white-space: pre-wrap;
  outline: none;
  cursor: move;
}

.el-text {
  background: transparent;
  font-size: 18px;
  line-height: 1.3;
  padding: 4px;
  overflow: auto;
  white-space: pre-wrap;
  outline: none;
  cursor: move;
  min-width: 40px;
}

.el-rect, .el-ellipse, .el-diamond, .el-triangle, .el-parallelogram, .el-pentagon, .el-hexagon, .el-star {
  border: 2px solid #333;
  background: #bde0fe;
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
  overflow: hidden;
  white-space: pre-wrap;
  line-height: 1.25;
  outline-offset: 2px;
}
.el-rect { border-radius: 4px; }
.el-ellipse { border-radius: 50%; }
.el-diamond { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); padding: 16px 24px; }
.el-triangle { clip-path: polygon(50% 0%, 100% 100%, 0% 100%); padding-top: 22px; }
.el-parallelogram { clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%); }
.el-pentagon { clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%); padding-top: 20px; }
.el-hexagon { clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%); }
.el-star { clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); font-size: 11px !important; }

.el-frame {
  border: 2px solid #888;
  background: rgba(255,255,255,0.35);
  cursor: move;
}
.el-frame .frame-label {
  position: absolute;
  top: -24px; left: 0;
  font-size: 12px;
  color: #555;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px 4px 0 0;
}

.el-line, .el-arrow, .el-pen { cursor: move; }
.el-line svg, .el-arrow svg, .el-pen svg { overflow: visible; }

/* Flowchart-style label riding the midpoint of a connector (see image 3 in
   the feature request — a caption like "Internet" sitting on the line). */
.connector-label {
  position: absolute;
  transform: translate(-50%, -50%);
  background: #fff;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--text);
  outline: none;
  cursor: text;
  white-space: pre;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.connector-label:empty {
  background: transparent;
  box-shadow: none;
  min-width: 14px;
  min-height: 14px;
  border: 1px dashed transparent;
}
.connector-label:empty:hover { border-color: var(--accent); }

.el-comment {
  width: 28px; height: 28px;
  border-radius: 50% 50% 50% 4px;
  background: #ff6b6b;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.el-comment.resolved { background: #8a8f98; }

/* ---------- Gantt / Cronograma widget ---------- */
.el-gantt {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: move;
  font-size: 12px;
}
.gantt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.gantt-title {
  font-weight: 700;
  font-size: 14px;
  outline: none;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: move;
}
.gantt-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.gantt-add-btn {
  background: var(--accent);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.gantt-fullscreen-btn {
  background: #eef0f2;
  color: var(--text);
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.gantt-fullscreen-btn:hover { background: #e2e4e8; }
.gantt-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}
.gantt-names-wrap {
  position: relative;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.gantt-names-resize {
  position: absolute;
  right: -3px;
  top: 0; bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 5;
}
.gantt-names-resize:hover { background: rgba(66,98,255,0.25); }
.gantt-names {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.gantt-names-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  border-top: 1px solid var(--border);
  background: var(--toolbar-bg);
}
.gantt-names-footer .gantt-add-btn,
.gantt-names-footer .gantt-add-blank-btn {
  width: 100%;
  text-align: center;
}
.gantt-add-blank-btn {
  background: none;
  border: 1px dashed #c4c8ce;
  color: #6b7280;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.gantt-add-blank-btn:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }
.gantt-names-spacer { height: 26px; flex-shrink: 0; border-bottom: 1px solid var(--border); }
.gantt-name-row-blank { opacity: 0.6; }
.gantt-blank-label { font-style: italic; }
.gantt-row-blank { position: relative; }
.gantt-row-blank::after {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  border-top: 1px dashed #d8dae0;
}
.gantt-name-row {
  height: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-bottom: 1px solid #f0f1f3;
  cursor: grab;
}
.gantt-row-dragging { background: #e7ebff; opacity: 0.75; }
.gantt-color-dot {
  appearance: none;
  -webkit-appearance: none;
  width: 18px; height: 18px;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.2);
  cursor: pointer;
  outline: none;
}
.gantt-color-dot:hover { box-shadow: 0 0 0 2px rgba(0,0,0,0.08); }
.gantt-name-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  outline: none;
  cursor: move;
}
.gantt-del-btn {
  flex-shrink: 0;
  font-size: 11px;
  color: #b0b4bb;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.gantt-del-btn:hover { background: #fde2e2; color: var(--danger); }
.gantt-name-row:hover .gantt-del-btn { opacity: 1; }
.gantt-timeline {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-x: auto;
  overflow-y: auto;
  position: relative;
}
.gantt-ruler {
  flex-shrink: 0;
  position: relative;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.gantt-ruler-months {
  position: relative;
  height: 20px;
  border-bottom: 1px solid var(--border);
  background: #f0f2f5;
}
.gantt-ruler-month-cell {
  position: absolute;
  top: 0; bottom: 0;
  border-right: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  color: #4b5563;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  white-space: nowrap;
}
.gantt-ruler-days {
  position: relative;
  height: 22px;
}
.gantt-day-cell {
  position: absolute;
  top: 0; bottom: 0;
  border-right: 1px solid #eef0f2;
  font-size: 11px;
  color: #8a8f98;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gantt-day-cell.today { color: var(--accent); font-weight: 700; }
.gantt-day-cell.weekend { background: #e4e7ec; }
.gantt-day-cell.weekend.today { background: transparent; }
.gantt-ruler-weekdays {
  position: relative;
  height: 16px;
  background: #3f4450;
}
.gantt-weekday-cell {
  position: absolute;
  top: 0; bottom: 0;
  border-right: 1px solid rgba(255,255,255,0.08);
  font-size: 9px;
  color: #d7dae0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gantt-weekday-cell.weekend { background: #262a30; color: #b9bec8; }
.gantt-rows-area { position: relative; flex: 1 0 auto; }
.gantt-weekend-band {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.045);
}
.gantt-grid-line {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: #eef0f2;
}
.gantt-grid-line-month { background: #dcdfe4; }
.gantt-today-line {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--accent);
  z-index: 1;
}
.gantt-row {
  height: 32px;
  min-height: 32px;
  position: relative;
  border-bottom: 1px solid #f0f1f3;
}
.gantt-bar {
  position: absolute;
  top: 4px;
  height: 24px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  z-index: 2;
}
.gantt-bar-label {
  font-size: 11px;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.gantt-bar-handle {
  position: absolute;
  top: 0; bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 3;
}
.gantt-bar-handle-start { left: 0; border-radius: 5px 0 0 5px; }
.gantt-bar-handle-end { right: 0; border-radius: 0 5px 5px 0; }
.gantt-bar-handle:hover { background: rgba(0,0,0,0.15); }
.gantt-link-handle {
  position: absolute;
  right: -8px;
  top: 50%;
  width: 14px; height: 14px;
  margin-top: -7px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  cursor: crosshair;
  opacity: 0;
  transition: opacity 0.12s ease;
  z-index: 4;
}
.gantt-bar:hover .gantt-link-handle,
.gantt-link-handle:hover {
  opacity: 1;
  transform: scale(1.15);
}
.gantt-links-svg { overflow: visible; z-index: 1; }
.gantt-link-path {
  cursor: pointer;
  pointer-events: stroke;
}
.gantt-link-path:hover { stroke: var(--danger) !important; stroke-width: 3; }
.gantt-link-path.selected { stroke: var(--accent) !important; stroke-width: 3; }

/* ---------- Gantt dates side panel (collapsible) ---------- */
.gantt-dates-panel {
  flex-shrink: 0;
  display: flex;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.gantt-dates-toggle {
  box-sizing: border-box;
  flex-shrink: 0;
  width: 22px;
  border: none;
  border-right: 1px solid var(--border);
  background: #eef0f2;
  color: #6b7280;
  cursor: pointer;
  font-size: 10px;
}
.gantt-dates-toggle:hover { background: #e2e4e8; color: var(--accent); }
.gantt-dates-col {
  width: 228px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}
.gantt-dates-header {
  flex-shrink: 0;
  display: flex;
  background: #3f4450;
}
.gantt-dates-h-cell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-right: 1px solid rgba(255,255,255,0.12);
  text-align: center;
}
.gantt-dates-h-cell:last-child { border-right: none; }
.gantt-dates-h-cell-responsible { flex: 1.6; justify-content: flex-start; padding-left: 8px; text-align: left; }
.gantt-dates-row {
  flex-shrink: 0;
  height: 32px;
  display: flex;
  border-bottom: 1px solid #f0f1f3;
}
.gantt-dates-cell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #333;
  border-right: 1px solid rgba(0,0,0,0.06);
}
.gantt-dates-cell:last-child { border-right: none; }
.gantt-dates-cell { cursor: text; outline: none; }
.gantt-dates-cell-responsible {
  flex: 1.6;
  min-width: 0;
  justify-content: flex-start;
  padding-left: 8px;
  text-align: left;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.gantt-dates-cell:hover { background: rgba(0,0,0,0.04); }
.gantt-dates-cell[contenteditable="true"] { background: #fff; box-shadow: inset 0 0 0 2px var(--accent); }
.gantt-dates-row-blank { background: #e6f4ea; }

/* ---------- Gantt fullscreen (in-app maximize) ---------- */
#gantt-fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg);
  display: flex;
}
#gantt-fullscreen-overlay .el-gantt.gantt-fullscreen-mode {
  position: static;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  cursor: default;
  flex: 1;
}
#gantt-fullscreen-overlay .el-gantt.gantt-fullscreen-mode .gantt-title,
#gantt-fullscreen-overlay .el-gantt.gantt-fullscreen-mode .gantt-name-row,
#gantt-fullscreen-overlay .el-gantt.gantt-fullscreen-mode .gantt-header {
  cursor: default;
}
body.gantt-fullscreen-active #topbar,
body.gantt-fullscreen-active #toolbar,
body.gantt-fullscreen-active #inspector,
body.gantt-fullscreen-active #zoom-controls,
body.gantt-fullscreen-active #minimap,
body.gantt-fullscreen-active #hint {
  display: none !important;
}

/* ---------- Gantt task color popover ---------- */
.gantt-color-popover {
  position: fixed;
  z-index: 600;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  padding: 8px;
}
.gantt-color-popover-swatches {
  display: grid;
  grid-template-columns: repeat(4, 22px);
  gap: 8px;
}
.gantt-color-popover-swatches button {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  padding: 0;
  cursor: pointer;
}
.gantt-color-popover-swatches button.selected { box-shadow: 0 0 0 2px var(--accent); }
.gantt-color-popover-add {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff !important;
  color: #6b7280;
  font-size: 14px;
  font-weight: 700;
  border-style: dashed !important;
  border-color: #c4c8ce !important;
}
.gantt-color-popover-add:hover { border-color: var(--accent) !important; color: var(--accent); }

/* Temporary preview line while dragging a dependency link */
#gantt-link-preview {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 550;
  overflow: visible;
}
#gantt-link-preview-line {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6,4;
}

/* Selection handles */
#selection-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.handle {
  position: absolute;
  width: 9px; height: 9px;
  background: #fff;
  border: 1.5px solid var(--accent);
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  pointer-events: all;
  z-index: 50;
}
.handle.point { border-radius: 50%; width: 10px; height: 10px; }
.handle.rotate { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.35); cursor: grab; }
.handle.nw, .handle.se { cursor: nwse-resize; }
.handle.ne, .handle.sw { cursor: nesw-resize; }
.group-outline {
  position: absolute;
  border: 1.5px dashed var(--accent);
  border-radius: 2px;
  pointer-events: none;
}
.resize-frame {
  position: absolute;
  border: 1px dashed rgba(66,98,255,0.55);
  pointer-events: none;
  box-sizing: border-box;
  z-index: 40;
}

/* Marquee selection box */
#marquee {
  position: absolute;
  border: 1px solid var(--accent);
  background: rgba(66, 98, 255, 0.1);
  pointer-events: none;
  z-index: 40;
}

/* Alignment guides */
#guides-layer { position: absolute; inset: 0; pointer-events: none; z-index: 45; }
.guide-line {
  position: absolute;
  background: #ff4fa3;
}
.guide-line.v { width: 1px; }
.guide-line.h { height: 1px; }

/* ---------- Inspector (right side panel) ---------- */
#inspector {
  position: fixed;
  right: 12px; top: 68px;
  width: 220px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  z-index: 95;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  transition: right 0.2s ease;
}
/* The layers sidebar docks to the same edge — slide the inspector out of
   its way instead of letting them overlap when both are open at once. */
body.layers-open #inspector { right: calc(12px + 260px); }
.insp-section { margin-bottom: 12px; }
.insp-section label { display: block; font-size: 11px; color: #6b7280; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .03em; }
.insp-section .row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 12px; }
.insp-section .row input[type="range"] { flex: 1; }
.insp-section .row select {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
  background: #fff;
}
.checkbox-row { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-bottom: 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.swatches button {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
}
.swatches button.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.align-btn.active { background: var(--accent); color: #fff; }
.insp-actions { display: flex; flex-wrap: wrap; gap: 4px; border-top: 1px solid var(--border); padding-top: 10px; }
.insp-actions .text-btn { flex: 1 1 auto; text-align: center; font-size: 12px; padding: 6px 4px; }

/* ---------- Context menu ---------- */
#context-menu {
  position: fixed;
  z-index: 300;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 190px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
#context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 6px;
}
#context-menu button:hover { background: var(--bg); }
#context-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------- Layers panel — docked right sidebar ---------- */
#layers-panel {
  position: fixed;
  right: 0; top: 52px; bottom: 0;
  width: 260px;
  background: var(--toolbar-bg);
  border-left: 1px solid var(--border);
  z-index: 95;
  box-shadow: -2px 0 10px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}
#layers-panel.open { transform: translateX(0); }
.layers-toggle-arrow {
  position: fixed;
  right: 0; top: 50%;
  transform: translateY(-50%);
  width: 20px; height: 46px;
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 8px 0 0 8px;
  z-index: 96;
  display: flex; align-items: center; justify-content: center;
  transition: right 0.2s ease;
}
.layers-toggle-arrow svg { width: 14px; height: 14px; fill: none; stroke: var(--text); transition: transform 0.2s ease; }
.layers-toggle-arrow:hover { background: var(--bg); }
.layers-toggle-arrow.open { right: 260px; }
.layers-toggle-arrow.open svg { transform: rotate(180deg); }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#layers-list { overflow-y: auto; padding: 6px; flex: 1; }
.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.layer-row:hover { background: var(--bg); }
.layer-row.selected { background: #e7ebff; }
.layer-row .layer-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row button { font-size: 12px; padding: 2px 4px; display: flex; align-items: center; }
.layer-icon svg, .layer-row button svg { width: 14px; height: 14px; fill: var(--text); stroke: var(--text); flex-shrink: 0; }

/* ---------- Custom confirm/alert modal ---------- */
.app-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.app-modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  padding: 20px;
  width: min(360px, calc(100vw - 32px));
}
.app-modal-message {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-line;
}
.app-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.app-modal-actions .text-btn.primary {
  background: var(--accent);
  color: #fff;
}
.app-modal-actions .text-btn.primary:hover { background: #324fd6; }
.app-modal-actions .text-btn.primary.danger { background: var(--danger); }
.app-modal-actions .text-btn.primary.danger:hover { background: #c53f43; }

/* ---------- Extra shapes flyout ---------- */
.shapes-menu {
  position: fixed;
  z-index: 200;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 6px;
  min-width: 180px;
}
.shape-flyout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 13px;
  text-align: left;
}
.shape-flyout-btn:hover { background: var(--bg); }
.shape-flyout-btn svg { width: 18px; height: 18px; fill: var(--text); flex-shrink: 0; }

/* ---------- Templates / sticker panels ---------- */
#templates-panel, #sticker-panel {
  position: fixed;
  left: 64px; top: 68px;
  width: 260px;
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  z-index: 95;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  padding: 6px;
}
.template-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 4px;
}
.template-btn:hover { background: var(--bg); }
.template-btn svg { width: 18px; height: 18px; fill: var(--text); stroke: var(--text); flex-shrink: 0; }
#sticker-panel {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 10px;
}
#sticker-panel button { font-size: 22px; border-radius: 6px; padding: 4px; }
#sticker-panel button:hover { background: var(--bg); }

/* ---------- Comment popover ---------- */
#comment-popover {
  position: fixed;
  z-index: 210;
  width: 220px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
#comment-textarea {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  font-family: inherit;
  font-size: 13px;
}
#comment-popover .row { justify-content: flex-end; display: flex; margin-top: 6px; }

/* ---------- Zoom controls ---------- */
#zoom-controls {
  position: fixed;
  right: 16px; bottom: 16px;
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  z-index: 90;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  transition: right 0.2s ease;
}
body.layers-open #zoom-controls { right: calc(16px + 260px); }
#zoom-level { font-size: 12px; width: 42px; text-align: center; }
.zoom-controls-sep { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }

/* ---------- Minimap ---------- */
#minimap {
  position: fixed;
  left: 16px; bottom: 16px;
  width: 180px; height: 120px;
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 90;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  overflow: hidden;
  cursor: pointer;
}
#minimap-inner { position: relative; width: 100%; height: 100%; }
.mini-el { position: absolute; background: #9db2ff; border-radius: 1px; }
#minimap-viewport {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: rgba(66,98,255,0.08);
  pointer-events: none;
}

#hint {
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  font-size: 11px;
  color: #8a8f98;
  background: rgba(255,255,255,0.8);
  padding: 4px 10px;
  border-radius: 20px;
  z-index: 80;
  pointer-events: none;
}
