/* ─────────────────────────────────────────────
   TOKENS
───────────────────────────────────────────── */
:root {
  --bg:          #111318;
  --surface:     #181c23;
  --surface2:    #1e2330;
  --surface3:    #252a36;
  --border:      rgba(255,255,255,0.07);
  --border-med:  rgba(255,255,255,0.11);
  --border-hi:   rgba(255,255,255,0.18);

  --text:        #e8eaf0;
  --text-sub:    #8b91a8;
  --text-muted:  #555c72;

  --accent:      #5b73f5;
  --accent-h:    #6b84ff;
  --accent-dim:  rgba(91,115,245,0.15);
  --accent-glow: rgba(91,115,245,0.25);

  --radius-sm:   6px;
  --radius:      8px;
  --radius-lg:   12px;

  /* Status palette */
  --c-new:       #3b82f6;
  --c-planned:   #8b5cf6;
  --c-inprog:    #f59e0b;
  --c-done:      #22c55e;
  --c-cancel:    #ef4444;
  --c-hold:      #6b7280;

  --topbar-h:    52px;
}

/* ─────────────────────────────────────────────
   RESET
───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─────────────────────────────────────────────
   TOPBAR
───────────────────────────────────────────── */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  background: rgba(17,19,24,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  gap: 16px;
}
#topbar-left { display: flex; align-items: center; gap: 12px; }
#app-wordmark { display: flex; align-items: center; }
#app-title-text {
  font-size: 15px; font-weight: 600;
  color: var(--text); letter-spacing: -0.2px;
}
.topbar-sub {
  font-size: 12px; color: var(--text-muted);
  padding-left: 12px; border-left: 1px solid var(--border-med);
}
#topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-divider { width: 1px; height: 20px; background: var(--border-med); margin: 0 4px; }
.admin-badge {
  font-size: 11px; font-weight: 500;
  background: var(--accent-dim); color: var(--accent-h);
  padding: 2px 8px; border-radius: 100px;
  border: 1px solid rgba(91,115,245,0.25);
  letter-spacing: 0.3px;
}
#zoom-group {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 2px;
  margin-left: 8px;
}
#zoom-label {
  font-size: 12px; color: var(--text-sub);
  min-width: 38px; text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ─────────────────────────────────────────────
   BUTTONS
───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  border-radius: var(--radius-sm); border: none; cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s, opacity 0.15s;
  text-decoration: none; white-space: nowrap;
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary {
  background: var(--accent); color: #fff; padding: 8px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.btn-primary:hover { background: var(--accent-h); box-shadow: 0 0 0 3px var(--accent-glow); }
.btn-secondary {
  background: var(--surface3); color: var(--text);
  border: 1px solid var(--border-med); padding: 7px 14px;
}
.btn-secondary:hover { background: var(--surface3); border-color: var(--border-hi); }
.btn-ghost {
  background: transparent; color: var(--text-sub); padding: 5px 10px;
}
.btn-ghost:hover { background: var(--surface3); color: var(--text); }
.btn-danger {
  background: rgba(239,68,68,0.12); color: #f87171;
  border: 1px solid rgba(239,68,68,0.25); padding: 7px 14px;
}
.btn-danger:hover { background: rgba(239,68,68,0.2); }
.icon-btn { padding: 5px 7px; }
.w-full { width: 100%; justify-content: center; }
.text-muted { color: var(--text-muted) !important; }

/* ─────────────────────────────────────────────
   CANVAS
───────────────────────────────────────────── */
#canvas-wrap {
  position: fixed;
  top: var(--topbar-h); left: 0; right: 0; bottom: 0;
  overflow: hidden;
  cursor: grab;
  background: var(--bg);
  /* Dot grid */
  background-image: radial-gradient(circle, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 28px 28px;
}
#canvas-wrap.dragging { cursor: grabbing; }
#canvas, #lines-svg {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
#lines-svg { pointer-events: none; overflow: visible; }

/* ─────────────────────────────────────────────
   NODES
───────────────────────────────────────────── */
.node {
  position: absolute;
  width: 210px;
  background: var(--surface);
  border: 1px solid var(--border-med);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  overflow: hidden;
}
.node:hover {
  border-color: var(--border-hi);
  box-shadow: 0 4px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
  transform: translateY(-1px);
}
.node.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 24px var(--accent-glow);
}
.node.sub {
  width: 190px;
  background: var(--surface2);
}
.node-status-strip {
  height: 3px;
  width: 100%;
}
.node-body { padding: 12px 14px 14px; }
.node-eyebrow {
  font-size: 10px; font-weight: 500;
  color: var(--text-muted); letter-spacing: 0.5px;
  text-transform: uppercase; margin-bottom: 5px;
}
.node-title {
  font-size: 13px; font-weight: 600;
  color: var(--text); line-height: 1.35;
  margin-bottom: 8px;
}
.node-footer {
  display: flex; align-items: center; justify-content: space-between;
}
.status-pill {
  font-size: 10px; font-weight: 500;
  padding: 2px 7px; border-radius: 100px;
  letter-spacing: 0.3px;
}
.current-badge {
  font-size: 9px; font-weight: 600;
  background: var(--accent); color: #fff;
  padding: 2px 7px; border-radius: 100px;
  letter-spacing: 0.5px; text-transform: uppercase;
}

/* Status colour sets */
.s-new         { background: rgba(59,130,246,0.15);  color: #60a5fa; }
.s-planned     { background: rgba(139,92,246,0.15);  color: #a78bfa; }
.s-inprogress  { background: rgba(245,158,11,0.15);  color: #fbbf24; }
.s-completed   { background: rgba(34,197,94,0.15);   color: #4ade80; }
.s-cancelled   { background: rgba(239,68,68,0.15);   color: #f87171; }
.s-onhold      { background: rgba(107,114,128,0.15); color: #9ca3af; }

/* strip solid colours */
.strip-new        { background: #3b82f6; }
.strip-planned    { background: #8b5cf6; }
.strip-inprogress { background: #f59e0b; }
.strip-completed  { background: #22c55e; }
.strip-cancelled  { background: #ef4444; }
.strip-onhold     { background: #6b7280; }

/* dot in legend */
.dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; flex-shrink: 0;
}
.dot.s-completed   { background: #22c55e; }
.dot.s-inprogress  { background: #f59e0b; }
.dot.s-planned     { background: #8b5cf6; }
.dot.s-new         { background: #3b82f6; }
.dot.s-onhold      { background: #6b7280; }
.dot.s-cancelled   { background: #ef4444; }

/* Admin drag mode */
.node.draggable { cursor: move; }
.node.draggable:active { opacity: 0.8; }

/* ─────────────────────────────────────────────
   LEGEND
───────────────────────────────────────────── */
#legend {
  position: fixed; bottom: 20px; left: 20px; z-index: 50;
  background: rgba(24,28,35,0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex; flex-direction: column; gap: 5px;
}
.legend-item {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; color: var(--text-sub);
}

/* ─────────────────────────────────────────────
   OVERLAYS & MODALS
───────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.overlay.open { opacity: 1; pointer-events: all; }

/* Side drawer (node detail) */
.drawer {
  position: fixed; top: var(--topbar-h); right: 0; bottom: 0;
  width: min(520px, 95vw);
  background: var(--surface);
  border-left: 1px solid var(--border-med);
  display: flex; flex-direction: column;
  transform: translateX(30px);
  transition: transform 0.25s cubic-bezier(0.16,1,0.3,1);
  overflow: hidden;
}
.overlay.open .drawer { transform: translateX(0); }
.drawer-header {
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  flex-shrink: 0;
}
.drawer-eyebrow {
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;
}
.drawer-title {
  font-size: 20px; font-weight: 700; color: var(--text);
  letter-spacing: -0.3px; line-height: 1.25;
}
.drawer-meta { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.status-chip {
  font-size: 11px; font-weight: 500; padding: 3px 9px; border-radius: 100px;
}
.drawer-date { font-size: 11px; color: var(--text-muted); }
.drawer-body {
  flex: 1; overflow-y: auto; padding: 24px;
  scrollbar-width: thin; scrollbar-color: var(--surface3) transparent;
}
.drawer-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; flex-shrink: 0;
}

/* Centered modal card */
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border-med);
  border-radius: var(--radius-lg);
  width: min(440px, 95vw);
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
  transform: scale(0.97) translateY(6px);
  transition: transform 0.2s cubic-bezier(0.16,1,0.3,1);
  overflow: hidden;
}
.modal-card.wide  { width: min(680px, 95vw); }
.modal-card.narrow { width: min(340px, 95vw); }
.overlay.open .modal-card { transform: scale(1) translateY(0); }
.modal-card-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-card-header h3 { font-size: 15px; font-weight: 600; }
.modal-card-body { padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ─────────────────────────────────────────────
   FORMS
───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-row { display: flex; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.field-row .field { margin-bottom: 0; }
.field { margin-bottom: 14px; }
.flex-1 { flex: 1; min-width: 0; }
.flex-2 { flex: 2; min-width: 0; }
.field-label {
  font-size: 12px; font-weight: 500; color: var(--text-sub);
  letter-spacing: 0.2px;
}
.field-hint { font-weight: 400; color: var(--text-muted); margin-left: 6px; }
.input {
  background: var(--bg);
  border: 1px solid var(--border-med);
  border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 13px;
  padding: 8px 10px; outline: none; width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.input::placeholder { color: var(--text-muted); }
select.input { cursor: pointer; }
select.input option { background: #1e2330; }
.textarea-lg { min-height: 180px; resize: vertical; font-family: 'JetBrains Mono', monospace; font-size: 12px; line-height: 1.6; }
.field-error {
  font-size: 12px; color: #f87171;
  display: none;
}
.field-error.visible { display: block; }
.close-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 4px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.close-btn:hover { color: var(--text); background: var(--surface3); }

/* ─────────────────────────────────────────────
   MARKDOWN CONTENT
───────────────────────────────────────────── */
.md-content { font-size: 14px; line-height: 1.75; color: var(--text); }
.md-content h1, .md-content h2, .md-content h3 {
  color: var(--text); font-weight: 600; margin: 1.4em 0 0.5em;
  letter-spacing: -0.2px; line-height: 1.3;
}
.md-content h1 { font-size: 20px; }
.md-content h2 { font-size: 16px; }
.md-content h3 { font-size: 14px; }
.md-content h1:first-child, .md-content h2:first-child, .md-content h3:first-child { margin-top: 0; }
.md-content p { margin-bottom: 12px; }
.md-content p:last-child { margin-bottom: 0; }
.md-content strong { color: var(--text); font-weight: 600; }
.md-content em { color: var(--text-sub); }
.md-content a { color: var(--accent-h); text-decoration: none; }
.md-content a:hover { text-decoration: underline; }
.md-content code {
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
  background: var(--surface3); color: #c4a8ff;
  padding: 2px 6px; border-radius: 4px;
}
.md-content pre {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; overflow-x: auto; margin: 12px 0;
}
.md-content pre code { background: none; padding: 0; color: var(--text-sub); font-size: 12px; }
.md-content ul, .md-content ol { padding-left: 20px; margin-bottom: 12px; }
.md-content li { margin-bottom: 4px; }
.md-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px; margin: 12px 0;
  background: var(--accent-dim); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-sub);
}
.md-content img { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); margin: 8px 0; }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.md-content table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.md-content th, .md-content td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.md-content th { background: var(--surface2); font-weight: 600; }

/* ─────────────────────────────────────────────
   BOARD TAB BAR
───────────────────────────────────────────── */
#board-tabs {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  z-index: 90;
  height: 40px;
  background: rgba(17,19,24,0.97);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding: 0 16px;
  gap: 2px;
  backdrop-filter: blur(12px);
}
#board-tabs-list {
  display: flex;
  align-items: stretch;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
#board-tabs-list::-webkit-scrollbar { display: none; }

.board-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  user-select: none;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
  margin-bottom: -1px;
}
.board-tab:hover { color: var(--text-sub); }
.board-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.board-tab-edit {
  opacity: 0;
  transition: opacity 0.15s;
  display: flex; align-items: center;
  padding: 2px 3px;
  border-radius: 3px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.board-tab:hover .board-tab-edit,
.board-tab.active .board-tab-edit { opacity: 1; }
.board-tab-edit:hover { color: var(--text); background: var(--surface3); }

.tab-add-btn {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; align-self: center;
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted); cursor: pointer;
  margin-left: 4px;
  transition: all 0.15s;
  flex-shrink: 0;
}
.tab-add-btn:hover { color: var(--text); border-color: var(--border-hi); background: var(--surface3); }

/* Canvas needs to account for both topbar and tab bar */
#canvas-wrap {
  top: calc(var(--topbar-h) + 40px) !important;
}
#legend {
  bottom: 20px;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }

/* ─────────────────────────────────────────────
   TOAST
───────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 500;
  background: var(--surface2); border: 1px solid var(--border-med);
  border-radius: var(--radius); padding: 10px 16px;
  font-size: 13px; color: var(--text);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  opacity: 0; transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }

/* ─────────────────────────────────────────────
   LOADING
───────────────────────────────────────────── */
#loading {
  position: fixed; inset: 0; z-index: 300;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
}
.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border-med);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
