/* RMT Flow Clinical Annotation Workspace */
.annot-page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2rem;
}

.annot-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.annot-hero h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--slate-800);
  margin-bottom: 0.35rem;
}

.annot-hero p {
  color: var(--slate-600);
  font-size: 0.9375rem;
  max-width: 52ch;
}

.privacy-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #ecfdf5;
  color: #0f766e;
  border: 1px solid #99f6e4;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.privacy-chip svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.annot-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 960px) {
  .annot-layout {
    grid-template-columns: 1fr;
  }
}

.annot-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.annot-panel {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.annot-panel h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--slate-600);
  margin-bottom: 0.75rem;
  font-weight: 700;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 52px;
  padding: 0.4rem 0.25rem;
  border: 1px solid var(--slate-200);
  border-radius: 0.5rem;
  background: var(--slate-50);
  color: var(--slate-800);
  cursor: pointer;
  font-size: 0.625rem;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
}

.tool-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}

.tool-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.tool-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #cbd5e1;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, box-shadow 0.12s;
}

.swatch:hover { transform: scale(1.08); }

.swatch.active {
  box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px rgba(15, 118, 110, 0.2);
}

.swatch-custom {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px dashed var(--slate-200);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  background: conic-gradient(from 0deg, #e11d48, #f59e0b, #14b8a6, #2563eb, #e11d48);
}

.swatch-custom input {
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: none;
}

.stroke-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.stroke-row label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--slate-600);
  white-space: nowrap;
}

.stroke-row input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.stroke-val {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--slate-800);
  min-width: 1.75rem;
  text-align: right;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.85rem;
}

.action-row .btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  font-size: 0.8125rem;
  gap: 0.35rem;
}

.action-row .btn svg {
  width: 14px;
  height: 14px;
}

.legend-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.8125rem;
  color: var(--slate-800);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08);
}

.legend-sym {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--slate-600);
  min-width: 1.1rem;
}

.legend-note {
  margin-top: 0.65rem;
  font-size: 0.6875rem;
  color: var(--slate-600);
  line-height: 1.4;
}

.save-block .form-group {
  margin-bottom: 0.75rem;
}

.save-block input[type="text"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.save-block input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.save-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.library-list {
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.library-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--slate-200);
  border-radius: 0.5rem;
  background: var(--slate-50);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.library-item:hover,
.library-item.active {
  border-color: var(--primary-light);
  background: #f0fdfa;
}

.library-item .lib-meta {
  flex: 1;
  min-width: 0;
}

.library-item .lib-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--slate-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-item .lib-date {
  font-size: 0.6875rem;
  color: var(--slate-600);
}

.library-item .lib-del {
  background: none;
  border: none;
  color: var(--red-600);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 0.25rem;
  opacity: 0.7;
}

.library-item .lib-del:hover { opacity: 1; background: #fef2f2; }

.library-empty,
.library-loading {
  font-size: 0.8125rem;
  color: var(--slate-600);
  font-style: italic;
  padding: 0.5rem 0;
}

/* Stage */
.annot-stage-wrap {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
  padding: 1rem;
  min-width: 0;
}

.stage-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.view-toggle {
  display: inline-flex;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  border-radius: 999px;
  padding: 0.2rem;
  gap: 0.15rem;
}

.view-toggle button {
  border: none;
  background: transparent;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--slate-600);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.view-toggle button.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgb(15 118 110 / 0.35);
}

.view-toggle button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.stage-hint {
  font-size: 0.75rem;
  color: var(--slate-600);
}

.zoom-chrome {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.zoom-label {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--slate-800);
  min-width: 3.25rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.zoom-reset-btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.diagram-stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  aspect-ratio: 4 / 9;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--slate-200);
  background:
    linear-gradient(90deg, rgba(148, 163, 184, 0.07) 1px, transparent 1px),
    linear-gradient(rgba(148, 163, 184, 0.07) 1px, transparent 1px),
    #f8fafc;
  background-size: 24px 24px, 24px 24px, auto;
  touch-action: none;
  user-select: none;
  overscroll-behavior: contain;
}

.diagram-viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  will-change: transform;
}

.diagram-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  z-index: 1;
  padding: 0.5rem;
}

#annotCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  cursor: crosshair;
  touch-action: none;
}

#annotCanvas.cursor-pen { cursor: crosshair; }
#annotCanvas.cursor-marker { cursor: cell; }
#annotCanvas.cursor-pain { cursor: crosshair; }
#annotCanvas.cursor-circle { cursor: crosshair; }
#annotCanvas.cursor-arrow { cursor: crosshair; }
#annotCanvas.cursor-text { cursor: text; }
#annotCanvas.cursor-eraser { cursor: cell; }
#annotCanvas.cursor-pan { cursor: grab; }
#annotCanvas.cursor-panning { cursor: grabbing; }
.diagram-stage.is-panning #annotCanvas { cursor: grabbing; }
.diagram-stage.is-space-pan #annotCanvas { cursor: grab; }

.stage-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--slate-600);
}

/* Toast */
.annot-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  min-width: 220px;
  max-width: 360px;
  padding: 0.85rem 1.1rem;
  border-radius: 0.65rem;
  background: var(--slate-800);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgb(0 0 0 / 0.2);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.annot-toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.annot-toast.success { background: #0f766e; }
.annot-toast.error { background: #b91c1c; }

/* Text note modal */
.annot-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 0.45);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.annot-modal {
  background: #fff;
  border-radius: 0.75rem;
  padding: 1.25rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 40px rgb(0 0 0 / 0.2);
}

.annot-modal h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.annot-modal input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  margin-bottom: 0.85rem;
}

.annot-modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

@media (max-width: 768px) {
  .annot-page { padding: 1rem 0.75rem 2rem; }
  .tool-grid { grid-template-columns: repeat(4, 1fr); }
  .diagram-stage { max-width: 100%; }
  .annot-toast { left: 1rem; right: 1rem; bottom: 1rem; }
  .stage-top { flex-direction: column; align-items: stretch; }
  .zoom-chrome { margin-left: 0; justify-content: flex-end; }
}

.save-hint {
  margin-top: 0.65rem;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--slate-500);
}
