:root {
  --bg: #0b0e14;
  --panel: #121722;
  --panel-2: #171d2a;
  --line: #232b3a;
  --text: #e6ebf5;
  --muted: #8b95a9;
  --muted-2: #5b6577;
  --accent: #f5b642;
  --accent-2: #6ea8fe;
  --danger: #ff6b6b;
  --radius: 12px;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 300px 1fr 340px; grid-template-rows: auto 1fr; height: 100vh; }
header {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand small { color: var(--muted); font-weight: 500; }

.query-bar { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.query-bar label { color: var(--muted); font-size: 13px; }
.query-bar select { max-width: 150px; }

.sidebar { grid-column: 1; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.canvas-wrap { grid-column: 2; position: relative; min-height: 0; background:
  radial-gradient(circle at 50% 40%, #131a27 0%, #0b0e14 70%); }
#graph { width: 100%; height: 100%; display: block; cursor: grab; }
.detail-panel { grid-column: 3; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; min-height: 0; }

/* ---------- sidebar ---------- */
.sidebar .search-row { padding: 12px; border-bottom: 1px solid var(--line); }
input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; width: 100%; outline: none;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-2); }

.list-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
#people-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.person-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.person-row:hover { background: var(--panel-2); }
.person-row.active { background: #1c2635; outline: 1px solid var(--accent-2); }
.person-name { font-size: 14px; font-weight: 600; }
.person-sub { font-size: 12px; color: var(--muted); }
.person-meta { min-width: 0; overflow: hidden; }
.person-meta > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #0d1117; flex: none; }
.avatar.lg { width: 52px; height: 52px; font-size: 18px; }

.toolbar { padding: 10px 12px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toolbar .primary { grid-column: 1 / -1; }

/* ---------- buttons ---------- */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 9px 12px; font-size: 13px; cursor: pointer; font-family: inherit;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #1e2735; }
.btn.primary { background: var(--accent); color: #221a05; border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.accent { background: var(--accent-2); color: #06122b; border-color: var(--accent-2); font-weight: 600; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #3a2530; }
.btn.danger:hover { background: #2a1a20; }
.btn.disabled { opacity: .6; cursor: not-allowed; }

/* ---------- canvas overlays ---------- */
.canvas-hint { position: absolute; left: 14px; bottom: 12px; color: var(--muted-2); font-size: 12px; pointer-events: none; }
.canvas-tools { position: absolute; right: 14px; top: 12px; display: flex; gap: 8px; }

/* ---------- detail panel ---------- */
.detail-panel { padding: 16px; }
.detail-empty { color: var(--muted); font-size: 14px; line-height: 1.6; padding: 20px 4px; }
.detail-empty.small { padding: 8px 2px; font-size: 13px; }
.detail-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.detail-name { font-size: 20px; font-weight: 700; cursor: pointer; }
.detail-name:hover { color: var(--accent); }
.detail-role { font-size: 13px; color: var(--muted); cursor: pointer; }
.detail-role:hover { color: var(--accent-2); }
.detail-label { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.chip { background: #1d2634; border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.chip.add { cursor: pointer; color: var(--accent-2); border-style: dashed; }
.chip.add:hover { background: #1a2434; }
.chip-x { cursor: pointer; color: var(--muted); font-weight: 700; }
.chip-x:hover { color: var(--danger); }

.conn-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.conn-text { flex: 1; font-size: 13px; }
.conn-text b { color: var(--accent); font-weight: 600; }
.linkish { background: none; border: none; color: var(--accent-2); cursor: pointer; font-size: 12px; padding: 2px 4px; }
.linkish.danger { color: var(--danger); font-weight: 700; }

.note { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.note-text { font-size: 13px; line-height: 1.45; }
.note-ts { font-size: 11px; color: var(--muted-2); margin-top: 4px; }

/* ---------- query result ---------- */
#q-result { margin-left: 8px; font-size: 13px; max-width: 380px; }
.q-yes { color: #63e6be; }
.q-none { color: var(--muted); }
.q-chain { margin-top: 3px; color: var(--text); }
.q-arrow { color: var(--accent); font-weight: 600; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(5, 8, 14, .6); backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal.open { display: flex; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: min(520px, 92vw); max-height: 88vh; overflow-y: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-card h3 { margin: 0 0 4px; }
.modal-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.checkbox input { width: auto; }

/* voice */
#vm-mic { width: 100%; padding: 14px; font-size: 15px; margin-bottom: 12px; }
#vm-mic.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,107,107,.5); } 50% { box-shadow: 0 0 0 10px rgba(255,107,107,0); } }
#vm-text { min-height: 90px; resize: vertical; }
.vm-hint { font-size: 12px; color: var(--muted-2); margin: 6px 0 10px; line-height: 1.5; }
#vm-review { display: none; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
#vm-review.open { display: block; }
.vr-badge { font-size: 12px; color: var(--accent); background: #211a08; border: 1px solid #3a2f10; border-radius: 7px; padding: 6px 9px; margin-bottom: 8px; }
.vr-summary { font-size: 13px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; margin-bottom: 10px; line-height: 1.45; }
.ai-settings { margin: 4px 0 12px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; background: var(--panel-2); }
.ai-settings summary { cursor: pointer; font-size: 13px; color: var(--muted); padding: 4px 0; }
.ai-settings summary:hover { color: var(--text); }
.ai-settings[open] summary { margin-bottom: 6px; }
.ai-settings code { background: #0d1117; padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.vr-field { margin-bottom: 8px; }
.vr-label { font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
.vr-inline { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vr-check { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
.vr-check input { width: auto; }
#vm-save { display: none; }

.empty { color: var(--muted-2); font-size: 13px; padding: 16px 8px; text-align: center; }

/* ---------- toast ---------- */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1c2534; border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- responsive ---------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .sidebar { grid-column: 1; grid-row: 2; max-height: 30vh; }
  .canvas-wrap { grid-column: 1; grid-row: 3; }
  .detail-panel { display: none; }
  .query-bar { width: 100%; }
}
