.password-wrap { position: relative; }
.password-toggle {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text3); cursor: pointer;
  font-size: 14px; padding: 0;
}
.password-toggle:hover { color: var(--text2); }

/* ─── MODAL OFFSET (below topbar) ───────────────────────────────────────────── */
.modal-overlay {
  top: 52px;
  inset: 52px 0 0 0;
}

/* ─── EDITOR LAYOUT ─────────────────────────────────────────────────────────── */
.editor-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ─── TOP BAR ────────────────────────────────────────────────────────────────── */
.editor-topbar {
  height: 52px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 9px;
  flex-shrink: 0;
  z-index: 10;
}
.topbar-logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 700; color: var(--text);
  margin-right: 2px;
}
.topbar-logo-icon {
  width: 26px; height: 26px;
  object-fit: cover;
}
.topbar-divider { width: 1px; height: 22px; background: var(--border); }
.topbar-left   { display: flex; align-items: center; gap: 9px; flex: 1 1 auto; min-width: 0; }
.topbar-center { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.topbar-right  { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; justify-content: flex-end; }
/* Single row, ever: buttons never wrap their label and the bar never wraps. */
.editor-topbar { flex-wrap: nowrap; }
.topbar-left, .topbar-center, .topbar-right { flex-wrap: nowrap; }
/* Every topbar button: one line, contents centered. */
.topbar-center button, .topbar-right button {
  white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
/* Flat, square buttons across the editor chrome (no borders, no rounded corners). */
.editor-topbar button { border: 0 !important; border-radius: 0 !important; }
/* All center-topbar action buttons (incl. the viewer's Share / Suggest changes)
   share one box so the row reads as symmetric. Fixed height + line-height:1
   neutralizes the taller line-box of the fullwidth ＋ / ▶ / 🔗 glyphs. */
#publishBtn, #addNodeBtn, #shareBtn, #viewerSaveBtn {
  min-width: 124px;
  height: 34px;
  box-sizing: border-box;
  padding: 0 16px;
  line-height: 1;
  font-size: 13px;
}
.topbar-menu { border-radius: 0; }
.topbar-menu-item { border-radius: 0; }
/* The title is the only element allowed to shrink when space is tight. */
.topbar-title-wrap { min-width: 0; flex: 1 1 auto; }
.topbar-title { max-width: 100%; }

/* Overflow "More" menu (Export / Clean / Delete live here to declutter the bar) */
.topbar-more { position: relative; display: inline-flex; }
.topbar-more-btn {
  width: 34px; height: 32px; border-radius: 8px;
  background: transparent; border: 1px solid var(--border); color: var(--text2);
  font-size: 18px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.topbar-more-btn:hover { color: var(--text); border-color: var(--text3); }
.topbar-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px; min-width: 200px;
  box-shadow: 0 12px 32px rgba(0,0,0,.45); z-index: 50;
  flex-direction: column; gap: 2px;
}
/* The Organize submenu holds two short labels, so it hugs them instead of
   taking the 200px the wider menus (Export, Colour legend) need. Below 900px
   mobile.css turns every menu into a full width sheet, so leave that alone. */
@media (min-width: 901px) {
  #layoutMenu { min-width: 0; width: max-content; }
}
.topbar-menu-item {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; background: transparent; border: none;
  color: var(--text2); font-size: 13px; padding: 9px 10px; border-radius: 7px; cursor: pointer;
}
.topbar-menu-item:hover { background: var(--surface2); color: var(--text); }
.topbar-menu-item.danger { color: #fda4af; }
.topbar-menu-item.danger:hover { background: rgba(239,68,68,.14); color: #fff; }
.topbar-menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.topbar-title-wrap { }
.topbar-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  background: transparent; border: 1px solid transparent;
  border-radius: 5px; padding: 4px 10px; width: 200px; transition: all .2s;
}
.topbar-title:hover { border-color: var(--border); background: var(--surface); }
.topbar-title:focus { border-color: var(--accent); background: var(--surface); outline: none; }

.zoom-controls {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px;
}
.zoom-display {
  font-size: 12px; font-weight: 600; color: var(--text2);
  min-width: 38px; text-align: center;
}
.tool-btn {
  width: 26px; height: 26px; border-radius: 4px;
  background: transparent; color: var(--text2);
  border: 1px solid transparent; display: flex;
  align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer; transition: all .15s;
}
.tool-btn:hover { background: var(--surface2); color: var(--text); }

.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: 2px; }
.topbar-user {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; cursor: pointer;
  text-decoration: none;
}
.topbar-user--anon {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text3);
}

.topbar-user-wrap {
  position: relative;
}
.topbar-user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 140px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 100;
  overflow: hidden;
}
.topbar-user-dropdown.open { display: block; }
.topbar-dropdown-item {
  display: block; width: 100%;
  padding: 9px 14px;
  font-size: 13px; font-weight: 500;
  color: var(--text2); text-decoration: none;
  background: transparent; border: none;
  text-align: left; cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: background .15s;
}
.topbar-dropdown-item:hover { background: var(--surface); color: var(--text); }
.topbar-dropdown-item--danger:hover { background: rgba(239,68,68,0.1); color: #ef4444; }
.topbar-dropdown-divider { height: 1px; background: var(--border); margin: 2px 0; }

/* ─── CANVAS AREA ────────────────────────────────────────────────────────────── */
.editor-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  background: var(--bg);
  /* dot grid */
  background-image: radial-gradient(circle, var(--border) 1px, transparent 0);
  background-size: 28px 28px;
}
.editor-canvas-wrap.panning { cursor: grabbing; }

/* ─── THE RAIL — lives inside .scene, moves with events (Excalidraw style) ───── */
.rail {
  position: absolute;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.6);
  pointer-events: none;
  z-index: 1;
}

/* ─── SCENE — the infinite canvas transformed by JS (pan + zoom) ─────────────── */
.scene {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  pointer-events: none;
}

/* ─── EVENT CARDS ────────────────────────────────────────────────────────────── */
/* Each event is absolutely positioned by JS: left = screenX, top = 50%          */
.tl-event {
  position: absolute;
  top: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: all;
  cursor: pointer;
}

/* above: card grows upward from the line
   translateY(-100%) → bottom of element = 50% (the line)
   +6px   → dot center (6px from bottom) sits exactly ON the line               */
.tl-event.above {
  transform: translateX(-50%) translateY(calc(-100% + 6px));
}

/* below: card grows downward from the line
   -6px   → dot center (6px from top) sits exactly ON the line                  */
.tl-event.below {
  transform: translateX(-50%) translateY(-6px);
}

/* Connector: a vertical line from dot to card */
.tl-connector {
  width: 2px;
  flex-shrink: 0;
}
.tl-event.above .tl-connector {
  background: linear-gradient(to top, var(--accent2), transparent);
}
.tl-event.below .tl-connector {
  background: linear-gradient(to bottom, var(--accent2), transparent);
}

/* Dot on the line */
.tl-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  flex-shrink: 0;
  z-index: 3;
  transition: transform .2s;
}
.tl-event:hover .tl-dot { transform: scale(1.4); }

/* Event card */
.tl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  width: 160px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  transition: border-color .2s, box-shadow .2s, transform .15s;
}
.tl-card:hover {
  border-color: var(--border2);
  box-shadow: 0 6px 28px rgba(0,0,0,0.45);
  transform: translateY(-1px);
}
.tl-card.selected {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(168,85,247,0.2);
}

.tl-date {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.tl-title {
  font-size: 12px; font-weight: 700;
  color: var(--text); line-height: 1.3; margin-bottom: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tl-desc {
  font-size: 11px; color: var(--text3); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}

/* Card actions (view / edit / delete) */
.tl-actions {
  display: flex; justify-content: center; gap: 4px;
  margin-bottom: 8px;
  opacity: 0; transition: opacity .15s;
  height: 0; overflow: hidden;
  transition: opacity .15s, height .15s, margin-bottom .15s;
}
.tl-card:hover .tl-actions {
  opacity: 1; height: 24px; margin-bottom: 8px;
}
.tl-action-btn {
  width: 20px; height: 20px; border-radius: 4px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text3); display: flex; align-items: center;
  justify-content: center; font-size: 10px; cursor: pointer;
  transition: all .15s;
}
.tl-action-btn:hover { color: var(--text); }
.tl-action-btn.del:hover { color: var(--red); }

/* color top borders */
.tl-card[data-color="purple"] { border-top: 2px solid var(--accent); }
.tl-card[data-color="cyan"]   { border-top: 2px solid var(--cyan);   }
.tl-card[data-color="blue"]   { border-top: 2px solid var(--blue);   }
.tl-card[data-color="green"]  { border-top: 2px solid var(--green);  }
.tl-card[data-color="red"]    { border-top: 2px solid var(--red);    }

/* ─── YEAR MARKERS ───────────────────────────────────────────────────────────── */
/* Positioned by JS at the same screenX as their date, always below the line     */
.tl-marker {
  position: absolute;
  top: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
.tl-marker-tick {
  width: 1px; height: 8px;
  background: rgba(255,255,255,0.15);
  margin-top: 0;
}
.tl-marker-label {
  font-size: 10px; color: var(--text3);
  font-weight: 500; margin-top: 3px; white-space: nowrap;
}

/* ─── GAP LABELS ─────────────────────────────────────────────────────────────── */
.tl-gap-label {
  position: absolute;
  top: 50%;
  transform: translateX(-50%) translateY(-22px);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 10px;
  color: var(--text3);
  white-space: nowrap;
  pointer-events: none;
  font-style: italic;
  letter-spacing: 0.03em;
}

/* ─── ORIGIN MARKER ─────────────────────────────────────────────────────────── */
.origin-marker {
  position: absolute;
  top: 50%;
  /* -8px = half of the 16px dot, so the dot CENTER sits exactly on the line */
  transform: translateX(-50%) translateY(-8px);
  display: flex; flex-direction: column; align-items: center;
  pointer-events: none; z-index: 200;
}
.origin-dot-wrap {
  position: relative;
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
}
.origin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: #ef4444; border: 3px solid #fff;
  box-shadow: 0 0 0 2px #ef4444, 0 0 16px rgba(239,68,68,0.7);
  position: relative; z-index: 2;
}
.origin-pulse {
  position: absolute;
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(239,68,68,0.2);
  top: 50%; left: 50%;
  margin-top: -16px; margin-left: -16px;
  animation: oPulse 2.4s ease-out infinite;
}
@keyframes oPulse {
  0%   { transform: scale(.6); opacity: .8; }
  100% { transform: scale(2.2); opacity: 0; }
}
.origin-label {
  margin-top: 6px; font-size: 9px; font-weight: 800;
  letter-spacing: .12em; color: #ef4444; text-transform: uppercase;
  text-shadow: 0 0 8px rgba(239,68,68,.5);
}

/* ─── TOGGLE SWITCH ─────────────────────────────────────────────────────────── */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 24px; transition: all .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  left: 2px; top: 2px;
  background: var(--text3); transition: all .2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); background: #fff; }

/* ─── PUBLISH BUTTON ─────────────────────────────────────────────────────────── */
.btn-publish {
  display: flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  border: none;
  border-radius: 0;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  box-shadow: 0 2px 12px rgba(16,185,129,0.35);
  transition: all .2s;
  white-space: nowrap;
}
.btn-publish:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 18px rgba(16,185,129,0.5);
}
.publish-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f472b6;
  box-shadow: 0 0 6px #f472b6;
  animation: oPulse 1.1s ease-out infinite;
  flex-shrink: 0;
}

/* ─── PUBLISH MODAL OPTIONS ──────────────────────────────────────────────────── */
.publish-option {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all .2s;
  margin-bottom: 10px;
  background: var(--bg3);
}
.publish-option:hover {
  border-color: var(--border2);
  background: var(--surface);
  transform: translateY(-1px);
}
/* Selectable visibility cards (radio-style) */
.vis-option { position: relative; margin-bottom: 0; }
.vis-option.selected {
  border-color: var(--accent);
  background: rgba(124,58,237,0.10);
}
.vis-option.selected::after {
  content: '✓';
  position: absolute; top: 14px; right: 16px;
  color: var(--accent3); font-weight: 700; font-size: 15px;
}
.vis-option.disabled {
  opacity: .45; cursor: not-allowed; pointer-events: none;
}
.publish-option-featured {
  border-color: rgba(124,58,237,0.35);
  background: rgba(124,58,237,0.07);
}
.publish-option-featured:hover {
  border-color: var(--accent);
  background: rgba(124,58,237,0.12);
}
.publish-option-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.publish-option-body { flex: 1; }
.publish-option-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.publish-option-desc {
  font-size: 12px;
  color: var(--text3);
  line-height: 1.5;
}
.publish-option-arrow {
  font-size: 18px;
  color: var(--text3);
  transition: transform .2s;
}
.publish-option:hover .publish-option-arrow { transform: translateX(4px); color: var(--text2); }

/* ─── RESET BUTTON ───────────────────────────────────────────────────────────── */
.btn-reset {
  background: transparent;
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all .2s;
  white-space: nowrap;
}
.btn-reset:hover {
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.6);
  color: #fff;
}
#cleanEventsBtn:hover {
  background: rgba(249,115,22,0.15);
  border-color: rgba(249,115,22,0.6);
  color: #fff;
}
#presentBtn:hover {
  background: rgba(234,179,8,0.15);
  border-color: rgba(234,179,8,0.6);
  color: #fff;
}
#exportBtn:hover {
  background: rgba(59,130,246,0.15);
  border-color: rgba(59,130,246,0.6);
  color: #fff;
}

/* ─── RECENTER BUTTON (in topbar) ───────────────────────────────────────────── */
.recenter-topbar-btn {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all .2s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.recenter-topbar-btn:hover {
  background: var(--border2);
  border-color: var(--accent2);
  color: var(--text);
}

/* ─── MINIMAP ────────────────────────────────────────────────────────────────── */
.minimap {
  position: absolute; bottom: 40px; right: 20px;
  width: 180px; height: 48px;
  background: rgba(17,17,24,.9); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; z-index: 20; backdrop-filter: blur(8px);
  cursor: pointer; touch-action: none;
}
.minimap-timeline {
  position: absolute; top: 50%; left: 0; right: 0;
  height: 2px; background: var(--border2); transform: translateY(-50%);
}
.minimap-viewport {
  position: absolute; top: 4px; bottom: 4px;
  background: rgba(124,58,237,.15);
  border: 1px solid rgba(124,58,237,.4); border-radius: 3px;
  transition: left .1s, width .1s;
  cursor: grab;
}
.minimap.dragging { cursor: grabbing; }
.minimap.dragging .minimap-viewport { transition: none; cursor: grabbing; }
.minimap-dot {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 5px; height: 5px; border-radius: 50%;
}

/* ─── HELP PANEL ─────────────────────────────────────────────────────────────── */
.help-panel {
  position: absolute; bottom: 40px; left: 20px;
  background: rgba(17,17,24,.9); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; z-index: 20;
  backdrop-filter: blur(8px); min-width: 180px;
}
.help-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 6px; font-size: 11px; color: var(--text3);
}
.help-row:last-child { margin-bottom: 0; }
.help-key {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px;
  font-size: 10px; color: var(--text2); font-family: monospace;
}

/* ─── COLOUR LEGEND (canvas panel) ───────────────────────────────────────────── */
.sw-legend {
  position: absolute; bottom: 40px; right: 20px;
  background: rgba(17,17,24,.9); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; z-index: 20;
  backdrop-filter: blur(8px); min-width: 150px; max-width: 240px;
}
.sw-legend-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 8px;
}
.sw-legend-title {
  font-size: 10px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text3);
}
.sw-legend-toggle {
  background: transparent; border: 0; color: var(--text3);
  cursor: pointer; font-size: 12px; line-height: 1; padding: 0;
}
.sw-legend-body { display: flex; flex-direction: column; gap: 6px; }
/* Each entry is a filter switch: it narrows the canvas to that colour and the
   active one stays lit until clicked again. */
.sw-legend-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  padding: 3px 6px; margin: 0; font-family: inherit; text-align: left;
  cursor: pointer; transition: background .12s, border-color .12s;
}
.sw-legend-row:hover { background: var(--surface2); }
.sw-legend-row.active { background: var(--surface2); border-color: var(--border2); }
.sw-legend-row.active .sw-legend-label { color: var(--text); font-weight: 700; }
.sw-legend-row:focus-visible { outline: 2px solid var(--accent2); outline-offset: -2px; }
.sw-legend-count {
  margin-left: auto; font-size: 10px; font-weight: 700; color: var(--text3);
  font-variant-numeric: tabular-nums;
}
.sw-legend-row.active .sw-legend-count { color: var(--accent3); }
.sw-legend-swatch {
  width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}
.sw-legend-label {
  font-size: 12px; color: var(--text); line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sw-legend-empty { font-size: 11px; color: var(--text3); font-style: italic; }
.sw-legend-edit {
  margin-top: 10px; width: 100%; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text2);
  font-size: 11px; font-weight: 600; padding: 5px 8px; cursor: pointer;
  font-family: inherit;
}
.sw-legend-edit:hover { color: var(--text); border-color: var(--accent); }

/* A bare swatch shown on a node head when its colour has no legend label. */
.sw-color-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; display: inline-block;
}

/* The current colour's meaning, shown under the picker in the node modal. */
.color-hint { margin-top: 8px; font-size: 12px; color: var(--text2); min-height: 16px; }
.color-hint.is-empty { color: var(--text3); font-style: italic; }

/* ─── COLOUR LEGEND (editor modal rows) ──────────────────────────────────────── */
.legend-edit-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.legend-edit-swatch {
  width: 20px; height: 20px; border-radius: 5px; flex-shrink: 0; margin-top: 8px;
  border: 1px solid rgba(255,255,255,.15);
}
.legend-edit-fields { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.legend-edit-fields .form-input { margin: 0; }

/* ─── EMPTY STATE ────────────────────────────────────────────────────────────── */
.empty-state {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center;
  pointer-events: none; z-index: 5;
}
.empty-state-icon { font-size: 40px; margin-bottom: 10px; opacity: .3; line-height: 1; }
.empty-state-text { font-size: 14px; color: var(--text3); }
.empty-state-hint { font-size: 12px; color: var(--text3); margin-top: 4px; opacity: .6; }

/* ─── STATUS BAR ─────────────────────────────────────────────────────────────── */
.editor-statusbar {
  height: 26px; background: var(--bg2); border-top: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px;
  gap: 20px; flex-shrink: 0;
}
.statusbar-item {
  font-size: 11px; color: var(--text3); display: flex; align-items: center; gap: 5px;
}
.statusbar-item span { color: var(--text2); }

/* ─── SEARCH ─────────────────────────────────────────────────────────────────── */
.tl-card.search-match {
  outline: 1px solid rgba(167,139,250,.5);
}
.tl-card.search-focus {
  outline: 2px solid #a78bfa;
  box-shadow: 0 0 0 3px rgba(167,139,250,.25), var(--shadow);
}
#searchPrev:hover, #searchNext:hover {
  background: var(--bg3) !important;
  color: var(--text) !important;
}

/* ─── COLOR PICKER ───────────────────────────────────────────────────────────── */
.color-picker { display: flex; gap: 8px; }
.color-opt {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: all .15s;
}
.color-opt.selected { border-color: #fff; transform: scale(1.15); }

/* ════════════════════════════════════════════════════════════════════════════
   SPIDERWEB — graph (teia) specific styles
   ════════════════════════════════════════════════════════════════════════════ */

/* Edge layer: an SVG anchored at the scene centre (world origin = 0,0), so we
   can draw connections using world coordinates directly. */
.sw-edges {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}
.sw-edge { stroke: var(--border2); stroke-width: 2; transition: stroke .15s; }
/* Spine of the web: any edge touching a protagonist (see "protagonists" in
   web.js). Lines stay readable when the cards are too small to read, so this
   works at every zoom level. Selection below still wins over it. */
.sw-edge.lead { stroke: rgba(241,240,255,.5); stroke-width: 3.2; }
.sw-edge.hl { stroke: var(--accent2); stroke-width: 3; }
.sw-edge-hit { stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
.sw-arrow { fill: var(--border2); }
.sw-arrow.lead { fill: rgba(241,240,255,.5); }
.sw-edge-label-bg { fill: var(--bg2); opacity: .9; }
.sw-edge-label {
  fill: var(--text2); font-size: 11px; font-family: 'Inter', sans-serif;
  font-weight: 600; pointer-events: none; text-anchor: middle;
}

/* Node card — a graph node, centred on its (x,y) world position. */
.sw-node {
  position: absolute;
  left: 0; top: 0; /* set via calc(50% + x/y) by JS */
  /* Size carries how connected the node is (see "degree scale" in web.js):
     a hub renders about a third larger than a leaf. Kept narrow on purpose so
     the canvas stays readable. */
  transform: translate(-50%, -50%) scale(var(--node-scale, 1));
  transition: transform .18s ease;
  width: 200px;
  pointer-events: all;
  cursor: grab;
  z-index: 10;
}
.sw-node.dragging { cursor: grabbing; z-index: 60; }
.sw-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  transition: border-color .15s, box-shadow .15s, transform .12s;
}
/* Hover only touches the three sides, never the top stripe: this selector
   outranks the [data-color] rules below, so a border-color shorthand here
   would repaint the type stripe with the neutral colour. */
.sw-node:hover .sw-card {
  border-right-color: var(--border2);
  border-bottom-color: var(--border2);
  border-left-color: var(--border2);
  box-shadow: 0 10px 34px rgba(0,0,0,0.55);
}
.sw-node.selected .sw-card { box-shadow: 0 0 0 3px rgba(168,85,247,0.35), 0 10px 34px rgba(0,0,0,0.55); }
.sw-node.linking-source .sw-card { box-shadow: 0 0 0 3px rgba(6,182,212,0.55); }
.sw-node.search-focus .sw-card { box-shadow: 0 0 0 3px rgba(167,139,250,.6); }

.sw-card[data-color="purple"] { border-top-color: var(--accent); }
.sw-card[data-color="cyan"]   { border-top-color: var(--cyan);   }
.sw-card[data-color="blue"]   { border-top-color: var(--blue);   }
.sw-card[data-color="green"]  { border-top-color: var(--green);  }
.sw-card[data-color="red"]    { border-top-color: var(--red);    }

.sw-node-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.sw-level {
  font-size: 9px; font-weight: 800; color: var(--text2);
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 5px; padding: 1px 5px; flex-shrink: 0;
}
.sw-type-badge {
  font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  padding: 2px 6px; border-radius: 20px; color: #fff; flex-shrink: 0;
}
.sw-node-date { font-size: 10px; color: var(--text3); font-weight: 600; margin-left: auto; }
.sw-node-title {
  font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sw-node-desc {
  font-size: 11px; color: var(--text3); line-height: 1.5; margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sw-node-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.sw-tag {
  font-size: 9px; font-weight: 600; color: var(--text2);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 1px 7px;
}

/* Per-node action buttons (revealed on hover). */
.sw-actions {
  display: flex; gap: 4px; justify-content: flex-end;
  opacity: 0; height: 0; overflow: hidden;
  transition: opacity .15s, height .15s, margin .15s;
}
.sw-node:hover .sw-actions { opacity: 1; height: 22px; margin-top: 8px; }
.sw-act {
  width: 22px; height: 22px; border-radius: 5px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text3); display: flex; align-items: center; justify-content: center;
  font-size: 11px; cursor: pointer; transition: all .15s;
}
.sw-act:hover { color: var(--text); border-color: var(--text3); }
.sw-act.link:hover { color: var(--cyan); border-color: var(--cyan); }
.sw-act.del:hover { color: var(--red); border-color: var(--red); }

/* Linking-mode banner */
.sw-link-banner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(6,182,212,.15); border: 1px solid rgba(6,182,212,.5);
  color: #a5f3fc; padding: 8px 16px; border-radius: 10px; font-size: 13px;
  z-index: 700; display: none; align-items: center; gap: 10px; backdrop-filter: blur(8px);
}
.sw-link-banner.show { display: flex; }
.sw-link-banner button {
  background: transparent; border: 1px solid rgba(6,182,212,.5); color: #a5f3fc;
  border-radius: 6px; padding: 2px 10px; font-size: 12px; cursor: pointer;
}

/* Tags input chips (modal) */
.sw-tags-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.sw-tags-input input {
  flex: 1; min-width: 80px; background: transparent; border: none;
  color: var(--text); font-size: 13px; outline: none;
}
.sw-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 20px;
  padding: 2px 4px 2px 9px; font-size: 11px; color: var(--text2);
}
.sw-chip button { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 13px; line-height: 1; }
.sw-chip button:hover { color: var(--red); }

/* Detail modal — bigger, for richer node content */
/* A hub can carry a dozen connections, so the panel is capped to the overlay
   and only the body scrolls: title, type and the footer buttons stay put. */
.sw-detail {
  max-width: 560px; padding: 0; overflow: hidden;
  display: flex; flex-direction: column;
  max-height: calc(100% - 32px);
}
.sw-detail-strip { height: 5px; width: 100%; flex-shrink: 0; }
.sw-detail-body { padding: 22px 26px; overflow-y: auto; min-height: 0; }
.sw-detail .modal-footer {
  flex-shrink: 0; margin-top: 0; border-top: 1px solid var(--border);
  background: var(--surface);
}
.sw-detail-title { font-size: 22px; font-weight: 800; color: var(--text); line-height: 1.2; }
.sw-detail-meta { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.sw-detail-desc {
  font-size: 14px; color: var(--text2); line-height: 1.75; margin-top: 16px;
  white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow-y: auto;
}
.sw-detail-section-label {
  font-size: 11px; font-weight: 700; color: var(--text3); text-transform: uppercase;
  letter-spacing: .06em; margin: 18px 0 8px;
}
/* Each connection is a button: clicking it flies the canvas to that node and
   opens its detail, so a card is a hop-off point into the rest of the web. */
.sw-conn-item {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text2);
  padding: 6px 8px; border: none; border-bottom: 1px solid var(--border);
  width: 100%; margin: 0; text-align: left; font-family: inherit;
  background: transparent; border-radius: 6px 6px 0 0; cursor: pointer;
  transition: background .12s, color .12s;
}
.sw-conn-item:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.sw-conn-item:focus-visible { outline: 2px solid var(--accent2); outline-offset: -2px; }
.sw-conn-item:disabled { cursor: default; opacity: .5; }
.sw-conn-rel { color: var(--text3); font-style: italic; }
.sw-conn-target { color: var(--text); font-weight: 600; }
.sw-conn-item:hover:not(:disabled) .sw-conn-rel { color: var(--text2); }
