/* ── Graph overlay ───────────────────────────────────── */
.graph-toggle {
  display: inline-block; margin-left: 0.75rem;
  padding: 0.3rem 0.7rem; font-size: 0.78rem; font-weight: 500;
  background: var(--color-btn-primary); color: #fff;
  border: none; border-radius: var(--radius-button); cursor: pointer;
  transition: background var(--duration, 0.15s) ease;
}
.graph-toggle:hover { background: var(--color-btn-primary-hover); }

.graph-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--color-bg); display: none;
  flex-direction: column;
}
.graph-overlay.visible { display: flex; }

.graph-toolbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 1.25rem;
  background: var(--dark-bg); border-bottom: 1px solid var(--dark-border);
  color: var(--dark-text); font-size: var(--text-sm, 0.82rem);
}
.graph-toolbar h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.graph-toolbar .spacer { flex: 1; }
.graph-toolbar button {
  padding: 0.3rem 0.65rem; font-size: 0.78rem;
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: var(--radius-button);
  cursor: pointer;
}
.graph-toolbar button:hover { background: var(--color-hover-bg); }

.graph-stats {
  font-size: 0.72rem; color: var(--dark-text-muted);
}
.graph-scope {
  font-size: 0.72rem; color: var(--dark-text-muted);
  margin-left: 0.6rem; padding: 0.15rem 0.5rem;
  background: rgba(255,255,255,0.06); border-radius: var(--radius-sm);
}
.graph-scope a {
  color: var(--color-primary); text-decoration: none; font-size: 0.68rem;
}
.graph-scope a:hover { color: var(--color-primary-hover); text-decoration: underline; }

.graph-legend {
  position: absolute; left: 1.25rem; bottom: 1.25rem;
  display: flex; flex-direction: column; gap: 0.45rem;
  background: var(--color-surface); border: 1px solid var(--color-border-light);
  border-radius: var(--radius-card); padding: 0.65rem 0.85rem;
  font-size: 0.7rem; color: var(--color-text-secondary);
  box-shadow: var(--shadow-card); z-index: 1;
  width: fit-content; max-width: calc(100% - 2.5rem);
  transition: padding 0.25s ease;
}
.graph-legend.collapsed {
  padding: 0.45rem 0.7rem;
}
.graph-legend .legend-title {
  font-weight: 600; color: var(--color-text);
  display: inline-flex; align-items: center; gap: 0.35rem;
  align-self: flex-start;
  cursor: pointer; user-select: none;
}
.graph-legend .legend-items {
  display: flex; flex-wrap: wrap; gap: 0.35rem 0.45rem;
  align-items: center; justify-content: flex-start;
  overflow: hidden;
}
.graph-legend.collapsed .legend-items {
  display: none;
}
.graph-legend .legend-item {
  display: inline-flex; align-items: center; gap: 0.4rem;
  cursor: pointer; padding: 0.1rem 0.25rem; border-radius: 3px;
  transition: background 0.15s;
  white-space: nowrap;
}
.graph-legend .legend-item:hover { background: rgba(130,130,130,0.15); }
.graph-legend .legend-item.active { background: rgba(130,130,130,0.25); font-weight: 600; }
.graph-legend .legend-item.dimmed { opacity: 0.4; }
.graph-legend .legend-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}

@media (max-width: 900px) {
  .graph-legend {
    left: 1rem; bottom: 1rem;
    max-width: calc(100% - 2rem);
  }
}

@media (max-width: 640px) {
  .graph-legend {
    padding: 0.55rem 0.7rem;
  }
  .graph-legend .legend-items {
    gap: 0.25rem 0.35rem;
  }
}

.graph-tooltip {
  position: absolute; pointer-events: none;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-small); padding: 0.4rem 0.65rem;
  font-size: 0.72rem; color: var(--color-text);
  box-shadow: var(--shadow-card); z-index: 2;
  display: none; max-width: 280px;
}
.graph-tooltip .tt-path { color: var(--color-text-muted); font-size: 0.65rem; }
.graph-tooltip .tt-refs { color: var(--color-primary); margin-top: 0.15rem; }

.graph-accessible-summary {
  position: absolute; top: 1rem; left: 1rem; z-index: 1;
  max-width: min(360px, calc(100% - 2rem));
  padding: 0.7rem 0.85rem;
  background: var(--color-surface);
  border: 1px solid var(--dark-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  color: var(--dark-text);
  font-size: 0.72rem;
  line-height: 1.45;
}
.graph-panel-titlerow {
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; user-select: none; margin-bottom: 0.35rem;
}
.graph-panel-arrow {
  font-size: 0.65rem; color: var(--dark-text-muted);
  padding-left: 0.4rem; flex-shrink: 0;
}
.graph-accessible-summary h3 {
  margin: 0;
  font-size: 0.76rem;
}
.graph-accessible-summary p {
  margin: 0 0 0.3rem;
}
.graph-accessible-summary ul {
  margin: 0.2rem 0 0.45rem 1rem;
  padding: 0;
}
.graph-summary-label {
  font-weight: 600;
  color: var(--color-text-secondary);
}

.graph-term {
  text-decoration: underline dotted;
  text-decoration-color: var(--dark-text-muted);
  text-underline-offset: 2px;
  cursor: help;
}

.graph-hub-link {
  background: none; border: none; padding: 0;
  font: inherit; font-size: inherit;
  color: var(--color-primary);
  cursor: pointer; text-align: left;
  text-decoration: underline; text-decoration-style: dotted;
}
.graph-hub-link:hover {
  color: var(--color-primary-hover);
  text-decoration-style: solid;
}
.graph-hub-meta {
  color: var(--dark-text-muted);
}
.graph-hub-more {
  background: none; border: none; padding: 0.1rem 0;
  font: inherit; font-size: 0.68rem;
  color: var(--color-primary);
  cursor: pointer; display: block; margin-top: 0.2rem;
}
.graph-hub-more:hover { color: var(--color-primary-hover); text-decoration: underline; }

/* ── Graph file preview panel ──────────────────────── */
.graph-preview {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(420px, 45%); z-index: 3;
  background: var(--color-surface); border-left: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  box-shadow: -4px 0 16px rgba(0,0,0,0.15);
  transform: translateX(100%); transition: transform 0.2s ease;
}
.graph-preview.visible { transform: translateX(0); }
.graph-preview-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.9rem 1.3rem; border-bottom: 1px solid var(--color-border-light);
  background: var(--color-surface-elevated, var(--color-surface));
}
.graph-preview-header h3 {
  flex: 1; font-size: 0.85rem; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.graph-preview-header button {
  font-size: 0.7rem; padding: 0.2rem 0.55rem; cursor: pointer;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-small); color: var(--color-text-secondary);
}
.graph-preview-header button:hover { background: var(--color-hover-bg); }
.graph-preview-meta {
  padding: 0.6rem 1.3rem; display: flex; gap: 0.4rem; flex-wrap: wrap;
}
.preview-tag {
  font-size: 0.62rem; padding: 0.12rem 0.4rem;
  background: rgba(130,130,130,0.15); border-radius: 3px;
  color: var(--color-text-secondary);
}
.preview-trust-high { background: rgba(76,175,80,0.18); color: #66bb6a; }
.preview-trust-med  { background: rgba(255,193,7,0.18); color: #ffc107; }
.preview-trust-low  { background: rgba(244,67,54,0.18); color: #ef5350; }
.graph-preview-body {
  flex: 1; overflow-y: auto; padding: 1rem 1.3rem;
  font-size: 0.78rem; line-height: 1.55;
}
.graph-preview-resize {
  position: absolute; top: 0; left: -4px; bottom: 0; width: 8px;
  cursor: col-resize; z-index: 4;
}
.graph-preview-resize:hover,
.graph-preview-resize.active {
  background: var(--color-primary); opacity: 0.25;
}

/* ── Preview tabs (Content / Connections) ─────────── */
.graph-preview-tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--color-border-light);
  background: var(--color-surface-elevated, var(--color-surface));
}
.preview-tab {
  flex: 1; padding: 0.45rem 0; text-align: center;
  font-size: 0.72rem; font-weight: 500; cursor: pointer;
  color: var(--color-text-secondary); background: none;
  border: none; border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.preview-tab:hover { color: var(--color-text); }
.preview-tab.active {
  color: var(--color-primary); border-bottom-color: var(--color-primary);
}

/* ── Connection panel ─────────────────────────────── */
#graph-preview-connections {
  flex: 1; overflow-y: auto; padding: 0.65rem 1rem;
  font-size: 0.78rem;
}
.connections-add {
  position: relative; margin-bottom: 0.65rem;
}
.connections-add input {
  width: 100%; box-sizing: border-box;
  padding: 0.35rem 0.55rem; font-size: 0.75rem;
  border: 1px solid var(--color-border); border-radius: var(--radius-small);
  background: var(--color-bg); color: var(--color-text);
}
.connections-add input:focus { outline: none; border-color: var(--color-primary); }
.connection-dropdown {
  position: absolute; left: 0; right: 0; top: 100%;
  max-height: 200px; overflow-y: auto; z-index: 10;
  background: var(--color-surface-elevated, var(--color-surface));
  border: 1px solid var(--color-border); border-top: none;
  border-radius: 0 0 var(--radius-small) var(--radius-small);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.connection-dropdown-item {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.35rem 0.55rem; cursor: pointer; font-size: 0.73rem;
}
.connection-dropdown-item:hover {
  background: var(--color-hover-bg);
}
.connections-section-label {
  font-size: 0.65rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--color-text-secondary);
  margin: 0.65rem 0 0.3rem; padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--color-border-light);
}
.connection-row {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.2rem; border-radius: var(--radius-small);
  cursor: pointer; transition: background 0.12s;
}
.connection-row:hover { background: var(--color-hover-bg); }
.conn-domain-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.conn-label {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.75rem;
}
.connection-badge {
  font-size: 0.58rem; padding: 0.08rem 0.35rem;
  border-radius: 3px; font-weight: 500; flex-shrink: 0;
}
.connection-badge-frontmatter {
  background: rgba(76,175,80,0.15); color: #66bb6a;
}
.connection-badge-body {
  background: rgba(130,130,130,0.15); color: var(--color-text-secondary);
}
.connection-badge-inbound {
  background: rgba(100,181,246,0.15); color: #64b5f6;
}
.conn-remove {
  padding: 0; width: 18px; height: 18px;
  font-size: 0.85rem; line-height: 1; text-align: center;
  background: none; border: 1px solid transparent; border-radius: 3px;
  color: var(--color-text-secondary); cursor: pointer;
  opacity: 0; transition: opacity 0.12s;
}
.connection-row:hover .conn-remove { opacity: 1; }
.conn-remove:hover {
  background: rgba(244,67,54,0.15); border-color: rgba(244,67,54,0.3);
  color: #ef5350;
}
.connections-empty {
  color: var(--color-text-secondary); font-size: 0.73rem;
  padding: 0.5rem 0;
}

/* ── Toast notification ──────────────────────────── */
.graph-toast {
  position: fixed; bottom: 1.5rem; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--color-surface-elevated, var(--color-surface));
  color: var(--color-text); border: 1px solid var(--color-border);
  padding: 0.45rem 1rem; border-radius: var(--radius-button);
  font-size: 0.75rem; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  opacity: 0; transition: opacity 0.25s, transform 0.25s;
  z-index: 1100; pointer-events: none;
}
.graph-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.graph-toast-error { border-color: rgba(244,67,54,0.4); color: #ef5350; }

.graph-progress {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  text-align: center; color: var(--color-text-secondary); z-index: 2;
}
.graph-progress .spinner {
  width: 32px; height: 32px; margin: 0 auto 0.75rem;
  border: 3px solid var(--color-border); border-top-color: var(--color-primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Analysis modal ───────────────────────────────── */
.analysis-backdrop {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(20,18,16,0.65); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
}
.analysis-backdrop.visible { display: flex; }
.analysis-modal {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: 0 12px 48px rgba(0,0,0,0.4);
  width: min(860px, 90%); max-height: 85vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.analysis-modal-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.85rem 1.2rem; border-bottom: 1px solid var(--color-border-light);
  background: var(--color-surface-elevated, var(--color-surface));
}
.analysis-modal-header h3 { flex: 1; font-size: 0.95rem; margin: 0; }
.analysis-modal-header button {
  font-size: 0.7rem; padding: 0.2rem 0.55rem; cursor: pointer;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-small); color: var(--color-text-secondary);
}
.analysis-modal-header button:hover { background: var(--color-hover-bg); }
.analysis-modal-body {
  flex: 1; overflow-y: auto; padding: 1rem 1.2rem;
  font-size: 0.8rem; line-height: 1.55;
}
.analysis-cards {
  display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.analysis-card {
  flex: 1; min-width: 100px; padding: 0.6rem 0.8rem;
  background: rgba(130,130,130,0.08); border-radius: var(--radius-small);
  text-align: center;
}
.analysis-card .card-value {
  font-size: 1.3rem; font-weight: 700; color: var(--color-text);
}
.analysis-card .card-label {
  font-size: 0.62rem; color: var(--color-text-secondary); margin-top: 0.15rem;
}
.analysis-section { margin-bottom: 1rem; }
.analysis-section h4 {
  font-size: 0.78rem; margin: 0 0 0.4rem; color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border-fine); padding-bottom: 0.2rem;
}
.analysis-table {
  width: 100%; border-collapse: collapse; font-size: 0.74rem;
}
.analysis-table th {
  text-align: left; padding: 0.3rem 0.5rem; font-weight: 600;
  color: var(--color-text-secondary); border-bottom: 1px solid var(--color-border-light);
}
.analysis-table td {
  padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--color-border-fine);
}
.analysis-table tr.clickable { cursor: pointer; }
.analysis-table tr.clickable:hover { background: var(--color-hover-bg); }
.analysis-table tr.hover-highlight td { background: rgba(130,130,130,0.12); }
.badge-sparse { color: #ef5350; font-weight: 600; }
.badge-dense  { color: #ffa726; font-weight: 600; }
.badge-healthy { color: #66bb6a; font-weight: 600; }
.badge-bridge { color: #42a5f5; }
.badge-hub    { color: #ab47bc; }
.badge-orphan { color: #ef5350; }
.analysis-node-link {
  color: var(--color-primary); cursor: pointer; text-decoration: none;
  border-bottom: 1px dashed var(--color-hover-border);
}
.analysis-node-link:hover { border-bottom-style: solid; }
.analysis-insufficient {
  text-align: center; padding: 2rem; color: var(--color-text-secondary);
}

/* ── 3D perspective mode ─────────────────────────── */
.graph-canvas-wrap.perspective-3d {
  /* CSS perspective kept for potential UI overlays; main rotation is canvas-based */
}
#graph-3d-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* ── 3D rotation indicator ───────────────────────── */
.graph-rotation-hint {
  position: absolute; bottom: 1.25rem; right: 1.25rem;
  z-index: 3; padding: 0.4rem 0.65rem;
  background: var(--color-surface); border: 1px solid var(--color-border-light);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  font-size: 0.65rem; color: var(--color-text-secondary);
  pointer-events: none; opacity: 0;
  transition: opacity 0.3s ease;
}
.graph-canvas-wrap.perspective-3d .graph-rotation-hint {
  opacity: 1; pointer-events: auto;
}
.graph-rotation-hint kbd {
  display: inline-block; padding: 0.1rem 0.3rem;
  background: rgba(130,130,130,0.15); border-radius: 3px;
  font-family: var(--font-mono, monospace); font-size: 0.6rem;
}
.graph-rotation-values {
  margin-top: 0.2rem; font-family: var(--font-mono, monospace);
  font-size: 0.58rem; color: var(--color-text-faint);
}
