/* Mindmap App Styles */
* { box-sizing: border-box; }

:root, .theme-light {
  --bg-color: #f6f7f9;
  --grid-color: #e0e2e6;
  --ui-bg: #ffffff;
  --ui-border: #d0d4dc;
  --text-color: #1f2937;
  --muted-color: #6b7280;
  --accent-color: #3b82f6;
  --accent-text: #ffffff;
  --selected-color: #ef4444;
  --node-stroke: #111827;
  --edge-color: #9ca3af;
  --guide-color: #f59e0b;
  --shadow: 0 6px 20px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.theme-dark {
  --bg-color: #111827;
  --grid-color: #1f2937;
  --ui-bg: #1f2937;
  --ui-border: #374151;
  --text-color: #f9fafb;
  --muted-color: #9ca3af;
  --accent-color: #60a5fa;
  --accent-text: #111827;
  --selected-color: #f87171;
  --node-stroke: #e5e7eb;
  --edge-color: #4b5563;
  --guide-color: #fbbf24;
  --shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.theme-high-contrast {
  --bg-color: #ffffff;
  --grid-color: #000000;
  --ui-bg: #ffffff;
  --ui-border: #000000;
  --text-color: #000000;
  --muted-color: #000000;
  --accent-color: #0000ff;
  --accent-text: #ffffff;
  --selected-color: #ff0000;
  --node-stroke: #000000;
  --edge-color: #000000;
  --guide-color: #ff00ff;
  --shadow: 4px 4px 0 #000000;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text-color);
  background: var(--bg-color);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
#canvas.panning { cursor: grabbing; }
#canvas.connecting { cursor: crosshair; }
#canvas .node-group { cursor: pointer; user-select: none; -webkit-user-select: none; }
#canvas text { pointer-events: none; user-select: none; -webkit-user-select: none; }
#grid-pattern path { stroke: var(--grid-color); }
#grid-bg { fill: var(--bg-color); }

.edge {
  fill: none;
  stroke: var(--edge-color);
  stroke-width: 2;
  pointer-events: stroke;
  transition: stroke-width 0.15s, stroke 0.15s;
}
.edge:hover { stroke-width: 4; stroke: var(--selected-color); }
.edge.hierarchical { stroke-dasharray: none; }
.edge.arbitrary { stroke-dasharray: 6, 4; }
.edge.focus-dim { opacity: 0.2; }

.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 16;
  pointer-events: stroke;
  cursor: pointer;
}

.edge-delete {
  pointer-events: all;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.edge-hit:hover + .edge-delete, .edge-delete:hover { opacity: 1; }

.guide-line {
  stroke: var(--guide-color);
  stroke-width: 1;
  stroke-dasharray: 4, 4;
  pointer-events: none;
  opacity: 0.7;
}

.lasso {
  fill: rgba(59, 130, 246, 0.15);
  stroke: var(--accent-color);
  stroke-width: 1;
  stroke-dasharray: 4, 4;
  pointer-events: none;
}

.ui-cluster {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
}

#top-left { top: 16px; left: 16px; }
#top-right { top: 16px; right: 16px; }
#bottom-left { bottom: 16px; left: 16px; flex-wrap: wrap; max-width: 80vw; }
#bottom-right { bottom: 16px; right: 16px; }

.icon-btn, .fab, .close-btn, button {
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  color: var(--text-color);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.icon-btn {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
}
.icon-btn:hover { background: var(--accent-color); color: var(--accent-text); }

.fab {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-color);
  color: var(--accent-text);
  border: none;
}
.fab:hover { filter: brightness(1.1); }

.hint {
  position: absolute;
  bottom: 76px;
  right: 16px;
  font-size: 12px;
  color: var(--muted-color);
  pointer-events: none;
  background: var(--ui-bg);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ui-border);
  opacity: 0.8;
}

#breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 13px;
  background: var(--ui-bg);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ui-border);
  box-shadow: var(--shadow);
  max-width: 70vw;
}

.crumb {
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.crumb:hover { background: var(--accent-color); color: var(--accent-text); }
.crumb-sep { color: var(--muted-color); }
.crumb-active { font-weight: 700; }

.parent-selector {
  margin-left: 8px;
  font-size: 12px;
  color: var(--muted-color);
  cursor: pointer;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  padding: 2px 6px;
  background: transparent;
}
.parent-selector:hover { background: var(--accent-color); color: var(--accent-text); }

.menu {
  position: absolute;
  z-index: 50;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  min-width: 180px;
  overflow: hidden;
}
.menu-item {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--ui-border);
}
.menu-item:last-child { border-bottom: none; }
.menu-item:hover { background: var(--accent-color); color: var(--accent-text); }
.menu.hidden { display: none; }
.menu-separator {
  height: 8px;
  margin: 0;
}
.submenu .menu-item { color: var(--text-color); }
.submenu .menu-item:hover { color: var(--accent-text); }
.menu-item-danger { color: #e11d48; }
.menu-item-danger:hover { background: #e11d48; color: white; }

#btn-menu {
  font-size: 18px;
  line-height: 1;
  padding: 6px;
  background: transparent;
  border: none;
  box-shadow: none;
}
#btn-menu:hover { background: transparent; color: var(--accent-color); }
#btn-undo, #btn-redo {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 6px;
}
#btn-undo:hover, #btn-redo:hover { color: var(--accent-color); }
.icon-btn svg, .close-btn svg, .fab svg {
  width: 18px;
  height: 18px;
  display: block;
}
#app-menu { overflow: visible; }
.menu-item.has-submenu { position: relative; display: flex; align-items: center; justify-content: space-between; }
.submenu-icon {
  width: 12px;
  height: 12px;
  margin-left: 8px;
  opacity: 0.7;
}
.submenu-icon svg { width: 12px; height: 12px; }
.submenu {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  min-width: 120px;
  z-index: 60;
  overflow: hidden;
}
.menu-item.has-submenu:hover > .submenu,
.menu-item.has-submenu:focus-within > .submenu { display: block; }
.submenu .menu-item { border-bottom: 1px solid var(--ui-border); }
.submenu .menu-item:last-child { border-bottom: none; }

.panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 360px;
  max-width: 90vw;
  max-height: 80vh;
  overflow: hidden;
}
.panel.hidden { display: none; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--ui-border);
  background: rgba(0,0,0,0.03);
}
.panel-header h2 { margin: 0; font-size: 16px; }
#quick-search .panel-header { flex-wrap: wrap; gap: 8px; }
#quick-search .panel-header h2 { width: 100%; }
#search-input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg-color);
  color: var(--text-color);
}
.close-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  border: none;
  background: transparent;
  box-shadow: none;
}
.close-btn:hover { background: var(--accent-color); color: var(--accent-text); }

.panel-body {
  padding: 16px;
  overflow-y: auto;
  max-height: 60vh;
}
.panel-body label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 13px;
}
.panel-body label > span:first-child { flex: 1; }
.panel-body input[type="color"], .panel-body input[type="range"], .panel-body select {
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  background: var(--bg-color);
  color: var(--text-color);
  padding: 4px;
}
.panel-body input[type="range"] { flex: 1; }
.palette-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.palette-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--ui-border);
}
.palette-swatch:hover, .palette-swatch.active { transform: scale(1.15); border-color: var(--text-color); }

.search-result {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.search-result:hover { background: var(--bg-color); border-color: var(--ui-border); }
.search-match { color: var(--accent-color); font-weight: 700; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }
.dialog {
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 360px;
  max-width: 90vw;
  padding: 20px;
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.dialog-header h3 { margin: 0; font-size: 16px; }
.dialog-header .close-btn { margin-left: 8px; }
.dialog-body { margin-bottom: 16px; }
.dialog-body label { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 500; }
.dialog-body label:last-child { margin-bottom: 0; }
.dialog-body input[type="text"], .dialog-body input[type="color"], .dialog-body input[type="url"], .dialog-body input[type="file"], .dialog-body select, .dialog-body textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  margin-top: 4px;
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-sm);
  background: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font);
  font-size: 13px;
}
.dialog-body .checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.dialog-body .checkbox-row input { width: auto; }
.dialog-actions { display: flex; flex-direction: column; gap: 10px; }
.dialog-actions button { width: 100%; padding: 10px 14px; font-size: 13px; font-weight: 600; }
.dialog-actions button.full-width { width: 100%; }
.dialog-actions button.primary { background: var(--accent-color); color: var(--accent-text); border-color: var(--accent-color); }

.hidden { display: none !important; }

/* Beat #canvas text { pointer-events: none } so title/subtitle can receive dblclick */
#canvas .node-title,
#canvas .node-subtitle {
  pointer-events: auto;
  cursor: text;
}
.node-title {
  font-weight: 700;
  fill: var(--text-color);
  text-anchor: middle;
  dominant-baseline: central;
}
.node-subtitle {
  font-size: 11px;
  fill: var(--muted-color);
  text-anchor: middle;
  dominant-baseline: central;
}

@media print {
  .ui-cluster, .menu, .panel, .overlay { display: none !important; }
  #app { overflow: visible; }
  #canvas { position: static; }
}
