*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: #f7f7f5;
  overflow: hidden;
}

#root { width: 100vw; height: 100vh; display: flex; flex-direction: column; }

/* ---- toolbar ---- */
.toolbar {
  flex-shrink: 0;
  height: 44px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid #e8e8e6;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 6px;
  z-index: 100;
  position: relative;
}

/* Filters pinned to the absolute centre of the toolbar */
.toolbar-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}

.toolbar-title {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-right: 4px;
}

.toolbar-filename {
  font-size: 12px;
  color: #9ca3af;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-mountain {
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.toolbar-spacer { flex: 1; }

.tb-btn {
  height: 28px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: white;
  font-size: 12px;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  white-space: nowrap;
}
.tb-btn:hover { background: #f9fafb; border-color: #d1d5db; }
.tb-btn.primary {
  background: #374151;
  color: white;
  border-color: #374151;
}
.tb-btn.primary:hover { background: #1f2937; }
.tb-btn.active {
  background: #374151;
  color: white;
  border-color: #374151;
}
.tb-btn.reopen {
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
}
.tb-btn.reopen:hover { background: #dbeafe; }

/* ---- canvas ---- */
.scroll-wrap { flex: 1; overflow: auto; }
.canvas { position: relative; }

/* ---- nodes ---- */
.node-el {
  position: absolute;
  transition: opacity 0.3s;
}

/* Node pill - absolutely positioned inside node-el so the pill can
   expand on hover without changing node-el's height or displacing
   the + button and connector lines */
.node-pill {
  position: relative;
  width: 172px;
  min-height: 40px;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: white;
  cursor: text;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: filter 0.1s, box-shadow 0.15s, width 0.15s;
  overflow: hidden;
  white-space: nowrap;
}
.node-pill:hover { filter: brightness(1.08); }

/* Expand on hover - pin to bottom so the pill grows upward only,
   keeping edges and the collapse button below always visible */
.node-el:hover .node-pill {
  position: absolute;
  bottom: 0;
  top: auto;
  transform: none;
  width: auto !important;
  min-width: 172px;
  max-width: 400px;
  white-space: normal;
  overflow: visible;
  z-index: 20;
  box-shadow: 0 3px 14px rgba(0,0,0,0.18);
}

/* Pill text span */
.pill-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: inherit;
}
.pill-text.done {
  text-decoration: line-through;
  opacity: 0.65;
}

/* Checkbox inside pill */
.node-check {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1.5px solid rgba(255,255,255,0.55);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: white;
  font-size: 9px;
  font-weight: 700;
  transition: background 0.15s, border-color 0.15s;
}
.node-check:hover { border-color: rgba(255,255,255,0.9); }
.node-check.checked {
  background: rgba(255,255,255,0.28);
  border-color: rgba(255,255,255,0.9);
}

/* Node text input */
.node-input {
  height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border: 2px solid;
  outline: none;
  background: white;
  width: 100%;
}

/* side button - collapse/expand, floats beside node where + used to be */
.side-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  opacity: 1;
  z-index: 10;
  padding: 0;
  line-height: 1;
}

/* ---- floating controls (bottom-left: undo/redo + zoom) ---- */
.floating-controls {
  position: fixed;
  bottom: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid #e8e8e6;
  border-radius: 10px;
  padding: 5px 8px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.float-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: white;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  padding: 0;
}
.float-btn:hover { background: #f9fafb; }
.float-btn:disabled { opacity: 0.35; cursor: default; }
.float-btn:disabled:hover { background: white; }
.float-divider { width: 1px; height: 18px; background: #e5e7eb; margin: 0 2px; }
.float-zoom-label {
  font-size: 11px; color: #6b7280; font-weight: 500;
  min-width: 34px; text-align: center;
}

/* ★ flag button - inside pill, right of text */
.flag-btn {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.28);
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  line-height: 1;
}
.flag-btn:hover        { color: rgba(255,255,255,0.7); }
.flag-btn.flagged      { color: #FFD84D; }
.flag-btn.flagged:hover{ color: #FFE980; }

/* ‹ collapse/expand chevron - inside pill, rightmost */
.collapse-btn {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  line-height: 1;
}
.collapse-btn:hover { color: rgba(255,255,255,0.9); }

/* ⊘ block button - inside pill */
.block-btn {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.25);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  line-height: 1;
}
.block-btn:hover         { color: rgba(255,255,255,0.65); }
.block-btn.blocked       { color: #FF6B6B; }
.block-btn.blocked:hover { color: #FF9999; }

/* Blocked pill - desaturated but fully opaque so lines don't bleed through */
.node-pill.blocked { filter: grayscale(0.7) brightness(1.1); }

/* Flagged overrides for block button */
.node-pill.flagged .block-btn         { color: rgba(0,0,0,0.25); }
.node-pill.flagged .block-btn.blocked { color: #cc2200; }

/* Flagged pill - dark elements on yellow background */
.node-pill.flagged                    { color: #2a1a00; }
.node-pill.flagged .node-check        { border-color: rgba(0,0,0,0.35); color: #2a1a00; }
.node-pill.flagged .node-check.checked{ background: rgba(0,0,0,0.12); border-color: rgba(0,0,0,0.55); }
.node-pill.flagged .flag-btn          { color: rgba(0,0,0,0.35); }
.node-pill.flagged .flag-btn.flagged  { color: #9a6200; }
.node-pill.flagged .pill-text.done    { opacity: 0.45; }

/* ---- action toolbar (appears below pill on hover) ---- */
/* The toolbar lives inside .node-pill so bottom:-28px is measured from the
   pill's actual rendered bottom (handles tall/multi-line nodes correctly).
   Because it's a child of the pill, hover is never lost on diagonal movement. */
.node-toolbar {
  position: absolute;
  bottom: -28px;
  left: 0;
  display: flex;
  gap: 3px;
  align-items: center;
  padding-top: 8px;
  min-width: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s, transform 0.12s;
  transform: translateY(-3px);
  z-index: 30;
}
.node-el:hover .node-toolbar {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.tool-btn {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1.5px solid;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  padding: 0;
  line-height: 1;
  transition: background 0.1s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}
.tool-btn:hover { background: #f5f5f4; }
.tool-btn.t-blocked { color: #ef4444 !important; border-color: #ef4444 !important; }
.tool-btn.t-flagged { color: #d97706 !important; border-color: #d97706 !important; }
.tool-btn.t-linked  { color: #6366f1 !important; border-color: #6366f1 !important; }
.tool-btn.t-dim { opacity: 0.22; cursor: default; pointer-events: none; }

/* Pill highlight when it's the node being linked */
.node-pill.is-being-linked { box-shadow: 0 0 0 2.5px white, 0 0 0 4.5px #6366f1; }
/* Pill highlight on the dependency node when hovering the blocked node */
.node-pill.dep-highlight { box-shadow: 0 0 0 2.5px white, 0 0 0 4.5px #f59e0b; z-index: 25; }

/* ---- blocked toast ---- */
.blocked-toast {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: white;
  font-size: 12px;
  padding: 6px 16px;
  border-radius: 8px;
  z-index: 201;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ---- link mode banner ---- */
.link-banner {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: #4f46e5;
  color: white;
  font-size: 12px;
  padding: 6px 16px;
  border-radius: 8px;
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ---- hint bar ---- */
.hint {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: #bbb;
  pointer-events: none;
  white-space: nowrap;
}

/* ---- onboarding: centre the canvas in the scroll area ---- */
.scroll-wrap.onboarding-mode {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.zoom-wrapper-centered {
  flex: none;
}

/* ---- onboarding quote on the canvas ---- */
.onboarding-quote {
  position: absolute;
  top: 148px;
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  text-align: center;
  font-style: italic;
  font-size: 13px;
  font-family: Georgia, 'Palatino Linotype', Palatino, serif;
  line-height: 1.75;
  color: #b0b7c3;
  letter-spacing: 0.01em;
  text-wrap: balance;
  pointer-events: none;
  user-select: none;
}

/* ---- root node in onboarding: centre it relative to canvas + keep + toolbar always visible ---- */
.node-el.root-onboarding {
  left: 50% !important;
  transform: translateX(-50%);
}
.node-el.root-onboarding .node-toolbar {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ---- direction toggle button in floating controls ---- */
.float-btn-text {
  width: auto;
  padding: 0 7px;
  font-size: 10px;
  font-weight: 600;
  color: #6b7280;
  letter-spacing: 0.02em;
}
