* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #0f172a; color: #e2e8f0;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#topbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 6px 10px; background: #1e293b; border-bottom: 1px solid #334155;
}
#topbar .group { position: relative; display: flex; gap: 4px; align-items: center; padding: 0 6px; }
#topbar .group + .group:not(.right)::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 2px;
  bottom: 2px;
  width: 1px;
  background: #334155;
}
#topbar .right { margin-left: auto; }
.file-menu { position: relative; }
.menu-panel {
  position: absolute; top: calc(100% + 6px); right: 6px; z-index: 20;
  min-width: 120px; padding: 6px; display: flex; flex-direction: column; gap: 4px;
  background: #1e293b; border: 1px solid #475569; border-radius: 6px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.28);
}
.menu-panel.hidden { display: none; }
.menu-panel button { width: 100%; text-align: left; white-space: nowrap; }

button {
  background: #334155; color: #e2e8f0; border: 1px solid #475569;
  padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 12px;
}
button:hover { background: #475569; }
button.active { background: #2563eb; border-color: #3b82f6; }
button.icon-btn {
  width: 28px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}

select, input[type="text"], input:not([type]) {
  background: #0f172a; color: #e2e8f0; border: 1px solid #475569;
  padding: 3px 6px; border-radius: 4px; font-size: 12px;
}
input[type="color"] { width: 28px; height: 24px; padding: 0; border: 1px solid #475569; background: transparent; }

label { display: inline-flex; gap: 4px; align-items: center; }

#main { position: relative; height: calc(100% - 40px); display: flex; }

#canvas-wrap { flex: 1; position: relative; overflow: hidden; background:
  radial-gradient(circle at 1px 1px, #1e293b 1px, transparent 0) 0 0 / 24px 24px,
  #0b1220;
}
#canvas { width: 100%; height: 100%; display: block; user-select: none; }

#legend {
  width: 280px; background: #1e293b; border-left: 1px solid #334155;
  overflow-y: auto; padding: 8px;
  transition: width 0.15s ease;
}
#legend.collapsed { width: 76px; padding: 6px 4px; overflow: hidden; }
#legend.collapsed > .legend-section { border-bottom: none; text-align: center; }
#legend.collapsed > .legend-section h3 { font-size: 0; }
#legend.collapsed > .legend-section h3 button.mini { font-size: 14px; display: block; margin: 0 auto; }
#legend.collapsed #legend-body { display: none; }

#legend-strip { display: none; flex-direction: column; align-items: center; gap: 7px; padding: 4px 0; }
#legend.collapsed #legend-strip { display: flex; }
.strip-item {
  width: 24px; height: 24px; border-radius: 5px;
  border: 1.5px solid rgba(255,255,255,0.15);
  cursor: grab; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.strip-item.member, .strip-item.milestone {
  width: auto; height: auto; border: 0; border-radius: 0; background: transparent;
}
.strip-item.member svg { width: 28px; height: 28px; overflow: visible; }
.strip-item.milestone svg { width: 70px; height: 46px; overflow: visible; }
.strip-item svg text { font-family: system-ui, sans-serif; pointer-events: none; }
.strip-divider { width: 48px; height: 1px; background: #334155; flex-shrink: 0; }
#legend h3, #legend h4 { margin: 6px 0; font-size: 12px; text-transform: uppercase; color: #94a3b8; letter-spacing: 0.06em; }
.legend-section { border-bottom: 1px solid #334155; padding-bottom: 6px; margin-bottom: 6px; }
.legend-section .row { display: flex; gap: 4px; align-items: center; margin: 4px 0; }
.legend-section .row input { flex: 1; min-width: 0; }
.hint { color: #94a3b8; font-size: 11px; }
button.mini { padding: 0 6px; font-size: 11px; }

.legend-item {
  display: flex; align-items: center; gap: 6px; padding: 3px 0;
}
.swatch { width: 16px; height: 16px; border-radius: 3px; border: 1px solid #475569; flex-shrink: 0; }
.token-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px;
  background: #0f172a; border: 1px solid #475569; border-radius: 10px; cursor: grab;
}
.token-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-item button.del { padding: 0 4px; font-size: 11px; }

#inspector, #area-inspector {
  position: absolute; right: var(--legend-offset, 296px); top: 8px; width: 240px;
  background: #1e293b; border: 1px solid #334155; border-radius: 6px;
  padding: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 5;
  transition: right 0.15s ease;
}
#inspector.hidden, #area-inspector.hidden { display: none; }

.state-btn {
  flex: 1; padding: 6px 8px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: #1e293b; border: 1.5px solid #475569; color: #94a3b8;
  cursor: pointer; transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.state-btn:hover { border-color: #64748b; color: #e2e8f0; }
.state-btn.active.cancelled-btn { background: #7f1d1d; border-color: #ef4444; color: #fca5a5; }
.state-btn.active:not(.cancelled-btn) { background: #14532d; border-color: #22c55e; color: #86efac; }
#inspector label, #area-inspector label { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
#inspector input, #inspector select, #area-inspector input { flex: 1; min-width: 0; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; margin-right: 4px; }
.dot.online { background: #22c55e; }

/* SVG node styles */
.node-shape {
  fill: var(--node-color, #3b82f6);
  stroke: #1e293b; stroke-width: 1.5;
  cursor: move;
}
.node-shape.done { stroke: #22c55e; stroke-width: 3; }
.node-shape.subgraph { stroke-dasharray: 7 4; }
.node-shape.subgraph.expanded { fill-opacity: 0.35; }
.node-shape.dimmed { opacity: 0.5; }
.node-shape.cancelled-overlay { fill: url(#cancelHatch); opacity: 0.6; pointer-events: none; }
.node-shape.selected { stroke: #f59e0b; stroke-width: 3; stroke-dasharray: 4 2; }
.node-label { fill: #f8fafc; font-size: 12px; pointer-events: none; text-anchor: middle; dominant-baseline: middle; }
.node-label-html {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #f8fafc;
  font: 12px/1.35 system-ui, sans-serif;
  word-break: break-word;
  overflow: hidden;
  padding: 6px;
  box-sizing: border-box;
}
.subgraph-label-expanded {
  align-items: flex-start;
  padding: 12px 42px 6px;
  color: #e0f2fe;
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(15, 23, 42, 0.9);
}
.subgraph-toggle { cursor: pointer; }
.subgraph-toggle-bg { fill: #0f172a; fill-opacity: 0.78; stroke: #cbd5e1; stroke-width: 1; }
.subgraph-count {
  fill: #f8fafc; font-size: 13px; font-weight: 700;
  text-anchor: middle; dominant-baseline: middle; pointer-events: none; user-select: none;
}
.subgraph-count { fill: #cbd5e1; font-size: 11px; }
.subgraph-toggle-eye { pointer-events: none; }
.subgraph-eye-outline {
  fill: none;
  stroke: #f8fafc;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.subgraph-eye-pupil { fill: #f8fafc; }
.subgraph-eye-slash {
  stroke: #f8fafc;
  stroke-width: 2;
  stroke-linecap: round;
}
.subgraph-drop-hint { pointer-events: none; }
.subgraph-drop-outline {
  fill: rgba(14, 165, 233, 0.12);
  stroke: #38bdf8;
  stroke-width: 3;
  stroke-dasharray: 10 6;
  animation: subgraph-drop-pulse 0.9s ease-in-out infinite;
}
.subgraph-drop-label-bg { fill: #0f172a; stroke: #38bdf8; stroke-width: 1; }
.subgraph-drop-label {
  fill: #e0f2fe; font-size: 12px; font-weight: 700;
  text-anchor: middle; dominant-baseline: middle; pointer-events: none; user-select: none;
}
@keyframes subgraph-drop-pulse {
  0%, 100% { stroke-width: 2; fill-opacity: 0.08; }
  50% { stroke-width: 5; fill-opacity: 0.22; }
}
.edge-line { stroke: #94a3b8; stroke-width: 2; fill: none; marker-end: url(#arrowhead); cursor: pointer; pointer-events: none; }
.edge-line.green { stroke: #22c55e; marker-end: url(#arrowhead-green); }
.edge-line.dashed { stroke-dasharray: 6 4; }
.edge-line.dimmed { opacity: 0.5; }
.edge-line.selected { stroke: #f59e0b; }
.edge-hit { stroke: transparent; stroke-width: 24; fill: none; cursor: pointer; stroke-linecap: round; stroke-linejoin: round; }
.filtered-out { opacity: 0.2; }
[data-kind="edge"].hover-path .edge-line { stroke: #f59e0b; marker-end: url(#arrowhead-orange); opacity: 1; }
.handle { fill: #f59e0b; stroke: #1e293b; stroke-width: 1; cursor: crosshair; opacity: 0; }
.node-group:hover .handle { opacity: 1; }
.area-rect { fill: var(--area-color, #1e293b); fill-opacity: 0.18; stroke: var(--area-color, #475569); stroke-width: 1; stroke-dasharray: 4 4; pointer-events: none; }
.area-rect.selected { stroke: #f59e0b; stroke-width: 2; }
.area-hit { fill: transparent; stroke: none; cursor: move; pointer-events: all; }
.area-letter { fill: var(--area-color, #475569); fill-opacity: 0.25; font-weight: 900; pointer-events: none; text-anchor: middle; dominant-baseline: middle; }
.area-label { fill: #94a3b8; font-size: 11px; text-anchor: start; pointer-events: none; }
.area-handle { fill: #f59e0b; stroke: #1e293b; stroke-width: 1; cursor: nwse-resize; }
.area-handle.ne, .area-handle.sw { cursor: nesw-resize; }
.area-handle.n, .area-handle.s { cursor: ns-resize; }
.area-handle.e, .area-handle.w { cursor: ew-resize; }
.area-lock { cursor: pointer; }
.area-lock-bg { fill: #1e293b; fill-opacity: 0.7; stroke: #475569; }
.area-lock-icon { fill: #e2e8f0; font-size: 12px; text-anchor: middle; dominant-baseline: middle; pointer-events: none; user-select: none; }
.milestone-shape { fill: var(--ms-color, #facc15); stroke: #1e293b; stroke-width: 1.5; cursor: move; }
.milestone-label { fill: #1e293b; font-weight: 600; font-size: 11px; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.token { stroke: #fff; stroke-width: 1.5; cursor: pointer; }
.subgraph-child-token { opacity: 0.82; cursor: default; }
.selection-rect { fill: rgba(245, 158, 11, 0.1); stroke: #f59e0b; stroke-width: 1; stroke-dasharray: 4 2; }
.node-resize-handle { fill: #f8fafc; stroke: #0f172a; stroke-width: 1; }
.node-resize-handle:hover { fill: #f59e0b; }
.cursor-other { pointer-events: none; }

/* Kanban view */
#kanban-view {
  position: absolute; inset: 0;
  background: #0b1220;
  overflow: auto;
  padding: 12px;
}
#kanban-view.hidden { display: none; }
#kanban-board { display: flex; flex-direction: column; gap: 16px; min-width: 720px; }

.kanban-swimlane {
  background: #111a2d; border: 1px solid #334155; border-radius: 6px;
  overflow: hidden;
}
.kanban-swimlane-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: #1e293b; border-bottom: 1px solid #334155;
  font-weight: 600;
}
.kanban-swimlane-header .member-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.2);
}
.kanban-swimlane-header .member-count { color: #94a3b8; font-weight: 400; font-size: 11px; }

.kanban-columns {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1px;
  background: #334155; min-height: 80px;
}
.kanban-column {
  background: #111a2d;
  padding: 8px;
  min-height: 80px;
  display: flex; flex-direction: column; gap: 6px;
}
.kanban-column.drag-over { background: #18253f; }
.kanban-column.locked { background: #0e1424; }
.kanban-column-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #94a3b8; padding-bottom: 4px; border-bottom: 1px solid #1e293b;
  display: flex; justify-content: space-between; align-items: center;
}
.kanban-column-title .col-count { color: #64748b; font-weight: 400; }

.kanban-card {
  background: #1e293b; border-left: 4px solid var(--node-color, #3b82f6);
  border-radius: 4px; padding: 6px 8px;
  cursor: grab; user-select: none;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; line-height: 1.35;
  border-top: 1px solid #334155; border-right: 1px solid #334155; border-bottom: 1px solid #334155;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.4; }
.kanban-card .card-label { color: #f1f5f9; word-break: break-word; }
.kanban-card .card-meta {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  font-size: 10px; color: #94a3b8;
}
.kanban-card .card-token {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  font-size: 10px; font-weight: 600; color: #fff; line-height: 1;
}
.kanban-card.locked { cursor: default; opacity: 0.85; }

#main.kanban-mode #inspector,
#main.kanban-mode #area-inspector { display: none !important; }

#inline-editor {
  position: absolute; display: none;
  text-align: center;
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  font: 13px/1.4 system-ui, -apple-system, sans-serif;
  border: 2px solid #f59e0b; border-radius: 6px;
  padding: 6px 8px; outline: none; z-index: 200;
  word-break: break-word; cursor: text;
  box-sizing: border-box; min-width: 60px; min-height: 28px;
  white-space: pre-wrap; overflow: auto;
}
