:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --panel-2: #1b2640;
  --line: #2a3756;
  --text: #e6ecf5;
  --muted: #93a1bd;
  --accent: #14b8a6;
  --accent-ink: #042f2b;
  --me: #fde047;
  --danger: #f87171;
  --radius: 14px;
  --tabs-h: 64px;
  --top-h: 52px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fb; --panel: #ffffff; --panel-2: #eef2f8; --line: #d7deea;
    --text: #0f172a; --muted: #5b6780; --accent: #0f766e; --accent-ink: #ffffff; --me: #ca8a04;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h2 { margin: 18px 0 6px; font-size: 1.15rem; }
h3 { margin: 20px 0 8px; font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--danger); min-height: 1.2em; }

/* Login */
.login { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; }
.login img { border-radius: 22px; }
.login h1 { margin: 6px 0 0; }
.login p { color: var(--muted); max-width: 300px; }

/* Layout */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar { height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0; display: flex; align-items: center; gap: 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; flex: 1; }
.brand img { border-radius: 7px; }
.badge { font-size: .72rem; padding: 3px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.live { color: var(--accent); border-color: var(--accent); }
.avatar { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2) center/cover; cursor: pointer; font-weight: 700; }
main { flex: 1; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.view.scroll { overflow-y: auto; padding: 12px 14px calc(var(--tabs-h) + 90px); }
.graph { position: absolute; inset: 0; bottom: var(--tabs-h); }
.graph-tools, .legend { position: absolute; top: 10px; left: 10px; right: 10px; z-index: 2; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none; }
.graph-tools > *, .legend > * { pointer-events: auto; }
.legend span { font-size: .75rem; background: var(--panel); border: 1px solid var(--line); padding: 3px 8px; border-radius: 99px; display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.empty { position: absolute; left: 14px; right: 90px; bottom: calc(var(--tabs-h) + 18px); text-align: center; color: var(--muted); pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 14px; font-size: .9rem; z-index: 2; }

/* Tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border-top: 1px solid var(--line); z-index: 5; }
.tabs button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .74rem; color: var(--muted); position: relative; cursor: pointer; }
.tabs button span { font-size: 1.25rem; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); }
.tabs button.active span { filter: none; opacity: 1; }
.dot { position: absolute; top: 10px; right: calc(50% - 16px); width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.fab { position: fixed; right: 18px; bottom: calc(var(--tabs-h) + 18px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 2rem; line-height: 1; box-shadow: 0 6px 20px rgba(0,0,0,.35); z-index: 6; cursor: pointer; }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: none; }
.btn.sm { padding: 6px 10px; font-size: .85rem; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: .82rem; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row > input { flex: 1; min-width: 0; }
input, select, textarea { width: 100%; padding: 11px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel-2); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
label.field { display: block; margin: 10px 0; font-size: .82rem; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { margin-top: 4px; color: var(--text); font-size: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; }

/* Lists */
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.list li { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 13px; display: flex; align-items: center; gap: 12px; }
.list li.tap { cursor: pointer; }
.list .meta { flex: 1; min-width: 0; }
.list .name { font-weight: 650; }
.list .sub { color: var(--muted); font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .empty-li { color: var(--muted); justify-content: center; border-style: dashed; }
.initials { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .9rem; flex-shrink: 0; color: #0b1220; }
.tag { display: inline-block; font-size: .72rem; padding: 2px 7px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); margin: 2px 3px 0 0; color: var(--muted); }

/* Sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--panel); border-radius: 20px 20px 0 0; border-top: 1px solid var(--line); z-index: 21; padding: 6px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
@media (min-width: 720px) { .sheet { left: 50%; width: 560px; transform: translateX(-50%); } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (min-width: 720px) { @keyframes up { from { transform: translate(-50%, 30px); opacity: 0; } } }
.grip { width: 42px; height: 5px; border-radius: 9px; background: var(--line); margin: 6px auto 8px; }
.sheet h2 { margin-top: 6px; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 8px 0; font-size: .88rem; }
.chain a { color: var(--accent); text-decoration: none; cursor: pointer; font-weight: 600; }
.chain .arrow { color: var(--muted); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 10px 0; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.sheet .actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.sheet .actions .btn { flex: 1; }
.multi { max-height: 170px; overflow-y: auto; border: 1px solid var(--line); border-radius: 11px; padding: 6px; background: var(--panel-2); margin-top: 4px; }
.multi label { display: flex; align-items: center; gap: 8px; padding: 5px 4px; color: var(--text); font-size: .95rem; }
.multi input { width: auto; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 90px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 11px; z-index: 40; font-size: .9rem; max-width: 90vw; }

/* vis-network tooltip */
div.vis-tooltip { background: var(--panel) !important; color: var(--text) !important; border: 1px solid var(--line) !important; border-radius: 8px !important; font-family: inherit !important; }

.knows-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 2px 0; }
.knows-row > label { flex: 1; min-width: 140px; }
.knows-row .intro-sel { width: auto; flex: 1 1 160px; padding: 6px 8px; font-size: .85rem; margin-left: 26px; }
.knows-row .intro-sel[hidden] { display: none; }
.intro-me { color: var(--me); font-size: .82rem; font-weight: 600; }
div.field { display: block; margin: 10px 0; font-size: .82rem; color: var(--muted); }

.check-row { display: flex; align-items: flex-start; gap: 10px; margin: 4px 0 10px; font-size: .92rem; cursor: pointer; }
.check-row input { width: 20px; height: 20px; margin-top: 2px; flex-shrink: 0; accent-color: var(--accent); }
.check-row[hidden] { display: none; }
