:root {
  --bg: #f7f7f5; --surface: #ffffff; --line: #e4e4e0; --line-strong: #d0d0ca;
  --text: #1b1b1d; --muted: #6b6b70; --accent: #2457d6; --accent-ink: #ffffff; --accent-soft: #e8eefc;
  --ok: #1f7a46; --warn: #9a5b00; --warn-soft: #fff4e0; --err: #b42318; --mark: #fde68a;
  --radius: 10px; --top: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151517; --surface: #1e1e21; --line: #2e2e33; --line-strong: #3d3d43;
    --text: #ececef; --muted: #9a9aa2; --accent: #7aa2ff; --accent-ink: #0d1530; --accent-soft: #1f2a44;
    --ok: #4cc38a; --warn: #f0b45a; --warn-soft: #2d2412; --err: #ff6b5f; --mark: #6b5212;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin: 24px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* шапка */
.top {
  position: sticky; top: 0; z-index: 20; height: var(--top);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.brand:hover { text-decoration: none; }
#count { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 4px; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tabs a {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px;
  color: var(--muted); font-size: 15px;
}
.tabs a:hover { text-decoration: none; color: var(--text); background: var(--surface); }
.tabs a.on { color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.tabs svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.logout { margin-left: auto; }
button.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; padding: 8px; }
button.link:hover { color: var(--text); }

main { max-width: 760px; margin: 0 auto; padding: 24px 20px 96px; }
main:has(.graph-view:not([hidden])) { max-width: none; padding: 0; }

/* поля и кнопки */
textarea, input[type=text], input[type=search], input:not([type]), input[type=password] {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 10px 12px; outline: none;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
textarea:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button { font: inherit; cursor: pointer; }
.primary, .secondary {
  border-radius: var(--radius); padding: 10px 18px; font-size: 16px; font-weight: 600; min-height: 44px;
  border: 1px solid transparent;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:disabled { opacity: .55; cursor: progress; }
.secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.secondary:hover { border-color: var(--muted); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.status { color: var(--muted); font-size: 14px; }
.status.err { color: var(--err); }
.status.ok { color: var(--ok); }

/* форма */
.add-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.add-head h1 { margin: 0; }
#person-form { margin-top: 8px; }
select {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 10px 12px; min-height: 44px;
}
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.badge { font-size: 12px; font-weight: 600; border-radius: 6px; padding: 2px 8px; border: 1px solid var(--line-strong); color: var(--muted); }
.badge.new { color: var(--ok); border-color: currentColor; }
.field { display: block; margin-top: 16px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.field textarea { min-height: 64px; }
.was { display: block; font-size: 13px; color: var(--muted); margin-top: 6px; }
.similar { margin-top: 10px; padding: 12px; border-radius: var(--radius); background: var(--warn-soft); display: flex; flex-direction: column; gap: 6px; }
.similar > span { font-size: 14px; }
.similar button {
  text-align: left; background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 8px 12px; min-height: 44px; font-weight: 600;
}
.similar button small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.similar button:hover { border-color: var(--accent); }
.fact { display: flex; gap: 6px; margin-top: 6px; }
.fact input { flex: 1; }
.x { width: 44px; min-height: 44px; flex: none; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); border-radius: var(--radius); font-size: 18px; }
.x:hover { color: var(--err); border-color: var(--err); }
.add-more { margin-top: 6px; background: none; border: 0; color: var(--accent); padding: 10px 0; font-size: 15px; min-height: 44px; }
.link-edit {
  display: grid; grid-template-columns: 1.3fr 1fr 1fr 44px; gap: 8px; align-items: end;
  padding: 10px; margin-top: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.link-edit label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 10px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 24px; }
.done { margin-top: 20px; }
.done ul { margin: 6px 0 10px; padding-left: 20px; }
.done li { margin: 4px 0; }

/* поиск */
.search { position: sticky; top: var(--top); background: var(--bg); padding: 4px 0 12px; z-index: 5; }
.results { display: flex; flex-direction: column; gap: 8px; }
.hit {
  position: relative; display: block; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.hit:hover { text-decoration: none; border-color: var(--line-strong); }
.hit-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hit-name { font-weight: 650; }
.hit-kind { font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; align-self: center; }
.hit-text { font-size: 14px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.empty { color: var(--muted); padding: 24px 0; }

/* человек */
.back { display: inline-block; margin-bottom: 12px; font-size: 15px; }
.meta { color: var(--muted); font-size: 14px; margin: 2px 0 12px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 0; }
.tag { font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; }
.note { margin-top: 16px; }
.note p { margin: 0 0 10px; }
.note ul { margin: 0 0 12px; padding-left: 20px; }
.note li { margin: 4px 0; }
.note h3 { font-size: 15px; margin: 18px 0 6px; }
.note blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.note .src { color: var(--muted); font-size: 13px; }
.links { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.links li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.links li:first-child { border-top: 0; }
.links li span { color: var(--muted); font-size: 14px; text-align: right; }
.editor textarea { min-height: 60vh; font: 14px/1.5 ui-monospace, "SF Mono", Menlo, monospace; }

/* граф */
.graph-view { position: relative; height: calc(100dvh - var(--top)); }
#net { position: absolute; inset: 0; }
.graph-bar { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3; display: flex; gap: 10px; flex-wrap: wrap; pointer-events: none; }
.graph-bar > * { pointer-events: auto; }
.graph-bar input { width: 260px; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.legend button {
  display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 5px 10px; min-height: 32px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
}
.legend button.off { opacity: .4; }
.gcard {
  position: absolute; right: 12px; bottom: 12px; width: 340px; max-height: 55%; overflow: auto; z-index: 3;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.gcard h3 { margin: 0; font-size: 17px; }
.gcard p { margin: 6px 0 10px; font-size: 14px; }
.gcard .close { position: absolute; top: 4px; right: 4px; width: 44px; height: 44px; background: none; border: 0; color: var(--muted); font-size: 20px; }

/* вход */
.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.login label { display: block; font-size: 14px; color: var(--muted); margin-top: 14px; }
.login label input { margin-top: 4px; }
.login button { width: 100%; margin-top: 20px; }
.error { color: var(--err); }

@media (max-width: 640px) {
  :root { --top: 52px; }
  .top { padding: 0 16px; }
  main { padding: 16px 16px calc(88px + env(safe-area-inset-bottom)); }
  .hide-phone { display: none; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 30; gap: 0;
    background: var(--surface); border-top: 1px solid var(--line); padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
  }
  .tabs a { flex: 1; flex-direction: column; gap: 2px; font-size: 12px; padding: 6px 4px; min-height: 52px; justify-content: center; }
  .tabs a.on { box-shadow: none; background: none; color: var(--accent); }
  .tabs svg { width: 22px; height: 22px; }
  .graph-view { height: calc(100dvh - var(--top) - 64px - env(safe-area-inset-bottom)); }
  .graph-bar input { width: 100%; }
  .legend { display: none; }
  .gcard { left: 12px; right: 12px; width: auto; }
  .link-edit { grid-template-columns: 1fr 44px; }
  .link-edit label { grid-column: 1; }
  .link-edit .x { grid-column: 2; grid-row: 1; align-self: end; }
  h1 { font-size: 22px; }
}
