/* ── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f1a;
  --bg2: #1a1a2e;
  --bg3: #16213e;
  --panel: #1e1e3a;
  --panel2: #252545;
  --border: #2e2e5e;
  --text: #e0e0f0;
  --text2: #9090b0;
  --text3: #6060a0;
  --accent: #7c5cbf;
  --accent2: #a07ee8;
  --success: #00b894;
  --error: #e17055;
  --warn: #fdcb6e;

  /* Category colors (match graph.js) */
  --cat-family: #e17055;
  --cat-friend: #00b894;
  --cat-mitre: #0984e3;
  --cat-work: #74b9ff;
  --cat-neighbor: #fdcb6e;
  --cat-church: #a29bfe;
  --cat-school: #fd79a8;
  --cat-medical: #55efc4;
  --cat-company: #636e72;
  --cat-virtual: #b2bec3;
  --cat-other: #8395a7;

  --sidebar-toggle-w: 22px;
  --sidebar-list-w: 220px;
  --sidebar-w: calc(var(--sidebar-controls-w) + var(--sidebar-toggle-w) + var(--sidebar-list-w));
  --sidebar-controls-w: 220px;
  --detail-w: 320px;
  --header-h: 52px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Layout ─────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100vh; }

/* Header */
.app-header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 10;
}

.app-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent2);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.app-title span { color: var(--text2); font-weight: 400; }

.header-divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--panel2); color: var(--text); }
.btn-icon { padding: 6px 10px; }

#file-label {
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.header-stats {
  margin-left: auto;
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text2);
  flex-shrink: 0;
}

.stat-item { display: flex; flex-direction: column; align-items: center; }
.stat-value { font-size: 16px; font-weight: 700; color: var(--accent2); line-height: 1; }
.stat-label { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }

/* Main layout */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.22s ease;
}

.sidebar.collapsed {
  width: calc(var(--sidebar-toggle-w) + var(--sidebar-list-w));
}

.sidebar-controls {
  width: var(--sidebar-controls-w);
  min-width: var(--sidebar-controls-w);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: width 0.22s ease, min-width 0.22s ease, opacity 0.18s ease, border-right-width 0.22s ease;
}

.sidebar.collapsed .sidebar-controls {
  width: 0;
  min-width: 0;
  border-right-width: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.sidebar-controls::-webkit-scrollbar,
.sidebar-list::-webkit-scrollbar {
  width: 4px;
}

.sidebar-controls::-webkit-scrollbar-track,
.sidebar-list::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-controls::-webkit-scrollbar-thumb,
.sidebar-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.sidebar-list {
  width: var(--sidebar-list-w);
  min-width: var(--sidebar-list-w);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 10px;
}

.sidebar-collapse-btn {
  width: var(--sidebar-toggle-w);
  min-width: var(--sidebar-toggle-w);
  border: none;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(37,37,69,0.92), rgba(22,33,62,0.92));
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
}

.sidebar-collapse-btn:hover {
  background: linear-gradient(180deg, rgba(53,53,92,0.96), rgba(28,40,72,0.96));
  color: var(--text);
}

.sidebar-collapse-icon {
  font-size: 18px;
  line-height: 1;
  transition: color 0.15s ease;
}

.sidebar-section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  margin-bottom: 8px;
}

/* Search */
.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px 7px 32px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text3); }
.sidebar-inline-control {
  margin-top: 12px;
}

.contact-sort-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.contact-sort-row .form-label {
  margin: 0;
  white-space: nowrap;
}

.contact-sort-row .form-control {
  flex: 1;
  min-width: 0;
}
.toggle-row.disabled {
  opacity: 0.5;
}
.toggle-row.disabled .toggle-label {
  text-decoration: line-through;
}

.compact-control {
  padding: 7px 10px;
  font-size: 12px;
}

.inline-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.sidebar-help {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text3);
  line-height: 1.4;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--text3);
  pointer-events: none;
}

/* Category filters */
#category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.filter-btn {
  --filter-accent: var(--cat-other);
  --filter-active-fg: #fff;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--panel2);
  color: var(--text2);
  transition: all 0.15s;
}

.filter-btn:hover { border-color: var(--border); color: var(--text); }
.filter-btn.active { color: #fff; }

.filter-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
  background: var(--filter-accent);
}

.filter-count {
  font-size: 10px;
  opacity: 0.7;
}

.filter-btn.active {
  background: var(--filter-accent);
  border-color: var(--filter-accent);
  color: var(--filter-active-fg);
}

/* Toggles */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.toggle-row:last-child { margin-bottom: 0; }
.toggle-label { font-size: 12px; color: var(--text2); }

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 9px;
  transition: 0.2s;
  cursor: pointer;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 12px; height: 12px;
  left: 2px; top: 2px;
  background: var(--text3);
  border-radius: 50%;
  transition: 0.2s;
}

.toggle-switch input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(14px); background: #fff; }

/* Contact list */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.list-header-title { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; }
#list-count { font-size: 11px; color: var(--text3); }

#contact-list {
  overflow-y: auto;
  flex: 1;
}

.contact-item {
  --contact-accent: var(--cat-other);
  --contact-accent-soft: rgba(131, 149, 167, 0.16);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  border-left: 3px solid var(--contact-accent);
  background:
    linear-gradient(90deg, var(--contact-accent-soft) 0, rgba(0,0,0,0) 44px),
    transparent;
}

.contact-item:hover {
  background:
    linear-gradient(90deg, var(--contact-accent-soft) 0, rgba(0,0,0,0) 44px),
    var(--panel2);
}

.contact-item.active {
  background:
    linear-gradient(90deg, var(--contact-accent-soft) 0, rgba(0,0,0,0) 44px),
    rgba(124, 92, 191, 0.2);
}

.contact-export-cb {
  flex-shrink: 0;
  width: 13px; height: 13px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.contact-item:hover .contact-export-cb,
.contact-export-cb:checked { opacity: 1; }

.export-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(124, 92, 191, 0.15);
  border-bottom: 1px solid rgba(124, 92, 191, 0.3);
  font-size: 12px;
  color: var(--text2);
}
.export-bar-actions { display: flex; gap: 6px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

.contact-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--contact-accent);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.06);
}

.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-sub { font-size: 11px; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Graph area ──────────────────────────────────────────────────── */
.graph-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #12122a 0%, #0a0a14 100%);
}

#graph-container {
  width: 100%;
  height: 100%;
}

.view-toggle {
  display: flex;
  gap: 6px;
}

.view-toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.table-mode {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(18,18,42,0.98), rgba(10,10,20,0.98));
  z-index: 2;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(30, 30, 58, 0.9);
}

.table-toolbar-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.table-wrap {
  flex: 1;
  overflow: auto;
}

.contacts-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1240px;
}

.contacts-table th,
.contacts-table td {
  border-bottom: 1px solid rgba(255,255,255,0.08);
  border-right: 1px solid rgba(255,255,255,0.05);
  vertical-align: top;
}

.contacts-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(22, 33, 62, 0.98);
  color: var(--text2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  padding: 10px 12px;
}

.contacts-table th button {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.contacts-table td {
  padding: 8px 10px;
}

.contacts-table tr:hover td {
  background: rgba(255,255,255,0.03);
}

.table-cell-input,
.table-cell-textarea {
  width: 100%;
  background: rgba(15,15,26,0.7);
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
  outline: none;
}

.table-cell-input:focus,
.table-cell-textarea:focus {
  border-color: var(--accent);
  background: rgba(22,33,62,0.82);
}

.table-cell-textarea {
  resize: vertical;
  min-height: 54px;
  line-height: 1.35;
}

.table-cell-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.table-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(255,255,255,0.08);
  color: var(--text2);
}

.table-row-actions {
  display: flex;
  gap: 6px;
}

.table-empty {
  padding: 24px;
  color: var(--text3);
  font-size: 13px;
}

.graph-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Legend */
.graph-legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: rgba(30, 30, 58, 0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  backdrop-filter: blur(8px);
}

.legend-title { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }

.legend-items { display: flex; flex-direction: column; gap: 4px; }

.legend-item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text2); }

.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-line { width: 16px; height: 2px; flex-shrink: 0; }
.legend-hull { width: 16px; height: 10px; border-radius: 999px; flex-shrink: 0; }

.hull-label {
  fill: rgba(255, 255, 255, 0.92);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  paint-order: stroke;
  stroke: rgba(15, 15, 26, 0.88);
  stroke-width: 5px;
  stroke-linejoin: round;
}

.hull-label-geo-country,
.hull-label-geo-state,
.hull-label-geo-city,
.hull-label-geo-street {
  fill: rgba(226, 232, 255, 0.94);
}

.hull-label-likely-surname {
  fill: rgba(255, 233, 224, 0.96);
}

.hull-label-likely-tag {
  fill: rgba(214, 236, 255, 0.96);
}

/* ── Detail panel ────────────────────────────────────────────────── */
.detail-panel {
  width: var(--detail-w);
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.detail-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background-size: cover;
  background-position: center;
  letter-spacing: 0.02em;
}

/* Avatar colors by category */
.detail-avatar.category-family { background-color: var(--cat-family); }
.detail-avatar.category-friend { background-color: var(--cat-friend); }
.detail-avatar.category-mitre { background-color: var(--cat-mitre); }
.detail-avatar.category-work { background-color: var(--cat-work); color: #111; }
.detail-avatar.category-neighbor { background-color: var(--cat-neighbor); color: #111; }
.detail-avatar.category-church { background-color: var(--cat-church); }
.detail-avatar.category-school { background-color: var(--cat-school); }
.detail-avatar.category-medical { background-color: var(--cat-medical); color: #111; }
.detail-avatar.category-company { background-color: var(--cat-company); }
.detail-avatar.category-virtual { background-color: var(--cat-virtual); color: #111; }
.detail-avatar.category-other { background-color: var(--cat-other); }

.detail-meta { flex: 1; min-width: 0; }
.detail-name-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
#detail-name { font-size: 16px; font-weight: 600; color: var(--text); line-height: 1.2; }
#detail-org { font-size: 12px; color: var(--text2); margin-top: 3px; }
#detail-title-text { font-size: 11px; color: var(--text3); }

.category-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.category-badge.category-family { background: var(--cat-family); color: #fff; }
.category-badge.category-friend { background: var(--cat-friend); color: #fff; }
.category-badge.category-mitre { background: var(--cat-mitre); color: #fff; }
.category-badge.category-work { background: var(--cat-work); color: #111; }
.category-badge.category-neighbor { background: var(--cat-neighbor); color: #111; }
.category-badge.category-church { background: var(--cat-church); color: #fff; }
.category-badge.category-school { background: var(--cat-school); color: #fff; }
.category-badge.category-medical { background: var(--cat-medical); color: #111; }
.category-badge.category-company { background: var(--cat-company); color: #fff; }
.category-badge.category-virtual { background: var(--cat-virtual); color: #111; }
.category-badge.category-other { background: var(--cat-other); color: #fff; }

.detail-body { flex: 1; overflow-y: auto; padding: 12px 16px; }
.detail-body::-webkit-scrollbar { width: 4px; }
.detail-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.detail-section { margin-bottom: 16px; }
.detail-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  margin-bottom: 8px;
}

.detail-section-actions {
  display: flex;
  margin-bottom: 10px;
}

.detail-section-actions .btn {
  width: 100%;
}

.detail-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.detail-edit-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-edit-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.detail-edit-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.detail-edit-checkbox input {
  margin-top: 2px;
}

.detail-edit-checkbox-title {
  font-size: 13px;
  color: var(--text);
}

.detail-edit-label {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-edit-multi {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-edit-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: var(--bg3);
}

.detail-edit-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.detail-edit-inline .form-control {
  flex: 1;
  min-width: 0;
}

.detail-edit-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-edit-meta {
  align-items: stretch;
}

.detail-edit-footer {
  justify-content: space-between;
  margin-top: 4px;
}

.detail-type-select {
  flex: 0 0 170px;
}

.detail-edit-inline .detail-type-input {
  flex: 1;
}

.detail-preferred-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text2);
  flex: 0 0 auto;
}

.detail-edit-grid-span {
  grid-column: 1 / -1;
}

@media (max-width: 720px) {
  .detail-edit-meta {
    flex-wrap: wrap;
  }

  .detail-type-select {
    flex: 1 1 180px;
  }

  .detail-edit-inline .detail-type-input {
    flex: 1 1 180px;
  }
}

.detail-edit-help {
  font-size: 11px;
  color: var(--text3);
}

.address-lines {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.photo-edit-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg3);
}

.photo-edit-preview {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  background-color: var(--panel2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.photo-edit-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }

.detail-field { flex: 1; min-width: 0; }
.detail-value { font-size: 13px; color: var(--text); word-break: break-word; }
.detail-value a { color: var(--accent2); text-decoration: none; }
.detail-value a:hover { text-decoration: underline; }
.detail-label { font-size: 11px; color: var(--text3); margin-top: 1px; }

.detail-notes-inline,
.detail-notes-editing {
  width: 100%;
  font-size: 12px;
  color: var(--text2);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  resize: vertical;
  min-height: 92px;
  outline: none;
  font-family: inherit;
}

.detail-notes-inline:focus,
.detail-notes-editing:focus {
  border-color: var(--accent);
  background: rgba(22,33,62,0.82);
}

/* Relationships in detail panel */
.rel-section-header {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  margin-bottom: 6px;
  margin-top: 12px;
}

.rel-section-header:first-child { margin-top: 0; }

.rel-section-header.inferred {
  color: var(--text3);
  opacity: 0.7;
}

.rel-section-header.rel-referenced-header {
  color: var(--text3);
  opacity: 0.75;
  font-style: italic;
}

.rel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  margin-bottom: 4px;
  background: var(--panel2);
  transition: background 0.1s;
}

.rel-item.rel-item-editing {
  flex-wrap: wrap;
  align-items: flex-start;
}

.rel-item:hover { background: var(--bg3); }

.rel-item.rel-inferred { opacity: 0.7; }

.rel-item.rel-referenced {
  opacity: 0.75;
  border-left: 2px dashed var(--border);
  padding-left: 6px;
}

.rel-via {
  font-size: 10px;
  color: var(--text3);
  font-style: italic;
  white-space: nowrap;
  flex-shrink: 0;
}

.rel-type {
  font-size: 11px;
  font-weight: 600;
  min-width: 80px;
  color: var(--text3);
}

.rel-name { font-size: 13px; color: var(--text); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.rel-item.rel-family .rel-type { color: var(--cat-family); }
.rel-item.rel-friend .rel-type { color: var(--cat-friend); }
.rel-item.rel-work .rel-type { color: var(--cat-work); }
.rel-item.rel-neighbor .rel-type { color: var(--cat-neighbor); }

/* Override category colors for referenced (implied) relationships */
.rel-item.rel-referenced .rel-type { color: #ffe033; }

/* ── Inline relationship type editor ─────────────────────────────── */
.btn-edit-rel {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
  line-height: 1;
  margin-left: auto;
}
.rel-item:hover .btn-edit-rel { opacity: 1; }
.btn-edit-rel:hover { color: var(--text); background: var(--bg3); }

.rel-type-select {
  font-size: 11px;
  font-weight: 600;
  background: var(--bg2);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  padding: 1px 3px;
  min-width: 100px;
  cursor: pointer;
}

.rel-name-input {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  background: var(--bg2);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  padding: 3px 6px;
}

.rel-edit-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.rel-edit-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex: 0 0 auto;
}

.rel-item.rel-item-editing .rel-type-select,
.rel-item.rel-item-editing .rel-custom-input {
  flex: 1 1 100%;
}

.rel-item.rel-item-editing .rel-name-input {
  flex: 1 1 auto;
}

.btn-edit-confirm,
.btn-edit-cancel,
.btn-edit-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  border-radius: 4px;
  flex-shrink: 0;
}
.btn-edit-confirm { color: #4caf50; }
.btn-edit-confirm:hover { background: rgba(76,175,80,0.15); }
.btn-edit-cancel { color: var(--text3); }
.btn-edit-cancel:hover { background: var(--bg3); }
.btn-edit-delete { color: #ff7b72; }
.btn-edit-delete:hover { background: rgba(255,123,114,0.15); }

/* suggestion type is now an inline select */
.suggestion-type-select {
  font-size: 12px;
  font-weight: 600;
  color: #f0a500;
  background: transparent;
  border: 1px solid #f0a500;
  border-radius: 4px;
  padding: 0 4px;
  cursor: pointer;
  vertical-align: middle;
}
.suggestion-type-select option {
  color: var(--text);
  background: var(--bg2);
}

/* Freeform custom type input (inline edit + suggestions) */
.rel-custom-input {
  font-size: 11px;
  background: var(--bg2);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  padding: 1px 5px;
  width: 100px;
  vertical-align: middle;
}

.rel-empty { font-size: 13px; color: var(--text3); text-align: center; padding: 16px; }
.rel-more { font-size: 11px; color: var(--text3); text-align: center; padding: 4px; }

/* ── Suggested Additions ─────────────────────────────────────────── */
.suggestions-title {
  display: flex;
  align-items: center;
  gap: 6px;
}
.suggestions-badge {
  background: #f0a500;
  color: #1a1a2e;
  font-size: 10px;
  font-weight: 700;
  border-radius: 8px;
  padding: 1px 6px;
  line-height: 1.6;
}
.suggestion-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-body { flex: 1; min-width: 0; }
.suggestion-action {
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
}
.suggestion-action strong { color: #fff; }
.suggestion-type {
  color: #f0a500;
  font-weight: 600;
}
.suggestion-reason {
  font-size: 11px;
  color: var(--text3);
  margin-top: 3px;
  line-height: 1.4;
}
.suggestion-btns {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.detail-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

/* ── Drop zone overlay ───────────────────────────────────────────── */
.drop-zone {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 20, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.drop-zone.drag-over .drop-content {
  border-color: var(--accent2);
  transform: scale(1.02);
}

.drop-content {
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: 20px;
  padding: 48px 64px;
  transition: all 0.2s;
}

.drop-icon { font-size: 64px; margin-bottom: 16px; }
.drop-title { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.drop-sub { font-size: 14px; color: var(--text2); margin-bottom: 24px; }

/* ── Loading overlay ─────────────────────────────────────────────── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 20, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-msg { font-size: 14px; color: var(--text2); }

/* ── Tooltip ─────────────────────────────────────────────────────── */
.graph-tooltip {
  position: fixed;
  background: rgba(30, 30, 58, 0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  z-index: 999;
  max-width: 200px;
  transition: opacity 0.1s;
  backdrop-filter: blur(8px);
}

.graph-tooltip strong { color: var(--accent2); display: block; }
.graph-tooltip em { font-style: normal; color: var(--text2); font-size: 11px; }

/* ── Toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--text);
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--error); }

.tag-autocomplete {
  position: fixed;
  min-width: 180px;
  max-width: 280px;
  max-height: 220px;
  overflow-y: auto;
  background: rgba(30, 30, 58, 0.97);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  padding: 6px;
  z-index: 1200;
  backdrop-filter: blur(10px);
}

.tag-autocomplete-item {
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
}

.tag-autocomplete-item:hover,
.tag-autocomplete-item.active {
  background: rgba(124, 92, 191, 0.22);
  color: var(--text);
}

.tag-autocomplete-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text3);
}

/* ── Modal ───────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 400px;
  max-width: 90vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 16px; font-weight: 600; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
}

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }

.form-control {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.form-control:focus { border-color: var(--accent); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}
.bulk-warning {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 107, 107, 0.35);
  border-radius: 10px;
  background: rgba(255, 107, 107, 0.08);
  color: #ffd6d6;
  font-size: 13px;
  line-height: 1.45;
}
.bulk-modal {
  width: 760px;
  max-width: 96vw;
}
.bulk-section {
  margin-bottom: 18px;
}
.bulk-section-title {
  margin-bottom: 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text3);
}
.bulk-rule-group {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.025);
}
.bulk-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.bulk-group-children {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bulk-condition-row,
.bulk-action-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.2fr) minmax(120px, 1fr) minmax(140px, 1.2fr) auto;
  gap: 8px;
  align-items: center;
}
.bulk-action-row {
  grid-template-columns: minmax(120px, 0.8fr) minmax(160px, 1fr) minmax(180px, 1.2fr);
}
.bulk-group-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.bulk-preview {
  min-height: 40px;
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  color: var(--text2);
  font-size: 13px;
  line-height: 1.4;
}
.bulk-summary {
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}
.bulk-samples {
  margin-top: 12px;
}
.bulk-samples-title {
  margin-bottom: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
}
.bulk-samples-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.bulk-sample-pill {
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: var(--text2);
  font-size: 12px;
}
.bulk-confirm {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
}
.bulk-operator-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ── Scrollbar (global) ──────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Graph SVG elements ──────────────────────────────────────────── */
.node-label {
  user-select: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8), 0 0 6px rgba(0,0,0,0.6);
  font-weight: 500;
}
