:root {
  --bg: #f7f5f0; --card: #ffffff; --ink: #2b2b2b; --muted: #8a8578;
  --accent: #4a7c59; --accent-light: #e8f0ea; --line: #c9c2b2;
  --danger: #b04a4a; --warn-bg: #fff8e6;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }
.okmsg { color: var(--accent); font-size: 13px; }

/* --- auth --- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--card); border-radius: 16px; padding: 32px; width: 100%; max-width: 380px;
             box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.auth-card h1 { margin: 0 0 16px; font-size: 24px; }
.auth-card input, .modal-card input, .modal-card select, .modal-card textarea {
  width: 100%; padding: 10px 12px; margin: 6px 0; border: 1px solid var(--line);
  border-radius: 10px; font-size: 15px; }
button { background: var(--accent); color: #fff; border: none; border-radius: 10px;
         padding: 10px 16px; font-size: 15px; cursor: pointer; }
button.ghost { background: #eee9dc; color: var(--ink); }
button:hover { filter: brightness(1.07); }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab { flex: 1; background: #eee9dc; color: var(--ink); }
.tab.active { background: var(--accent); color: #fff; }

/* --- app --- */
#app { display: flex; flex-direction: column; height: 100vh; }
header { display: flex; align-items: center; gap: 10px; padding: 10px 16px;
         background: var(--card); border-bottom: 1px solid var(--line); z-index: 5; }
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
#search { flex: 0 1 260px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 20px; }
.spacer { flex: 1; }
#tree-wrap { flex: 1; overflow: hidden; position: relative; touch-action: none; }
#tree { width: 100%; height: 100%; display: block; }
#zoom-controls { position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
#zoom-controls button { width: 44px; height: 44px; border-radius: 50%; font-size: 20px;
  background: var(--card); color: var(--ink); box-shadow: 0 2px 10px rgba(0,0,0,.15); }

/* --- дерево --- */
.person-node { cursor: pointer; }
.person-node rect { fill: #fff; stroke: var(--line); stroke-width: 1.5; rx: 12; }
.person-node:hover rect { stroke: var(--accent); }
.person-node.selected rect { stroke: var(--accent); stroke-width: 3; }
.person-node.selected circle.node-circle { stroke: var(--accent); stroke-width: 3; }
/* путь родства — красный */
.person-node.on-path rect { stroke: #d33; stroke-width: 3; }
.person-node.on-path circle.node-circle { stroke: #d33; stroke-width: 3; }
.junction { fill: var(--ink); cursor: pointer; }
.junction:hover { fill: var(--accent); r: 8; }
.link.on-path + .junction, .junction.on-path { fill: #d33; }
.person-node.dimmed { opacity: .18; }
.person-node text { font-size: 13px; fill: var(--ink); pointer-events: none; }
.person-node .dates { font-size: 11px; fill: var(--muted); }
.link { stroke: #b9b2a0; stroke-width: 2; fill: none; }
.link.highlight { stroke: var(--accent); stroke-width: 3; }
.link.dimmed { opacity: .12; }
/* красный приоритет — ниже зелёного */
.link.on-path { stroke: #d33 !important; stroke-width: 3; }
.gen-label { font-size: 12px; fill: var(--muted); font-style: italic; }

/* --- боковая карточка --- */
.side-card { position: fixed; top: 0; right: 0; width: 340px; max-width: 92vw; height: 100vh;
  background: var(--card); box-shadow: -4px 0 24px rgba(0,0,0,.12); padding: 24px;
  overflow-y: auto; z-index: 20; }
.side-card .close { position: absolute; top: 12px; right: 12px; background: none; color: var(--muted); font-size: 18px; }
.side-card h2 { margin: 0 0 4px; font-size: 22px; }
.note { background: var(--warn-bg); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.relations { margin: 12px 0; font-size: 14px; }
.relations div { padding: 3px 0; }

/* --- модалки --- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex;
  align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.modal-card { background: var(--card); border-radius: 16px; padding: 24px; width: 100%; max-width: 440px;
  max-height: 90vh; overflow-y: auto; }
.modal-card.wide { max-width: 640px; }
.modal-card h2 { margin-top: 0; } .modal-card h3 { margin: 18px 0 8px; }
.row { display: flex; gap: 8px; } .row > * { flex: 1; }
.row.btns { margin-top: 12px; }
.modal-card textarea { min-height: 80px; resize: vertical; }
.pend-item { background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin: 8px 0; font-size: 14px; }
.pend-item .row { margin-top: 8px; }
.approve { background: var(--accent); } .reject { background: var(--danger); }
.badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: 12px; }
#add-person-btn { font-size: 20px; padding: 6px 14px; }

/* --- поля плашки --- */
.field { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0;
  border-bottom: 1px solid #f0ede4; font-size: 14px; }
.field span { color: var(--muted); }
.field b { font-weight: 600; text-align: right; }
#card-fields { margin: 12px 0; }
#card-sub { margin-bottom: 4px; }
.rel-row { display: flex; align-items: center; justify-content: space-between; padding: 3px 0; }
.rel-row a { color: var(--accent); text-decoration: none; }
.rel-row a:hover { text-decoration: underline; }
button.mini { padding: 2px 10px; font-size: 14px; border-radius: 12px; }

/* --- заметки --- */
#card-notes { margin-top: 14px; }
#card-notes h4 { margin: 0 0 8px; }
#card-my-note textarea { width: 100%; min-height: 60px; border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 14px; resize: vertical; }
.pub-note { background: var(--bg); border-radius: 8px; padding: 6px 10px; margin: 6px 0; font-size: 13px; }

/* --- кружки --- */
.person-node circle.node-circle { fill: #fff; stroke: var(--line); stroke-width: 1.5; }
.person-node:hover circle.node-circle { stroke: var(--accent); }
.person-node.selected circle.node-circle { stroke: var(--accent); stroke-width: 3; }
.person-node .initials { font-size: 17px; font-weight: 700; fill: var(--accent); pointer-events: none; }
.person-node .node-name { font-size: 12px; fill: var(--ink); pointer-events: none; }
.expander { fill: var(--accent); stroke: #fff; stroke-width: 2; cursor: pointer; }
.expander-text { fill: #fff; font-size: 16px; font-weight: 700; pointer-events: none; }

/* --- списки выбора --- */
.lk-item { padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.lk-item:hover { background: var(--accent-light); }
.lk-item.sel { background: var(--accent); color: #fff; }
#lk-list, #assoc-picker-list { border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin: 6px 0; }
/* --- сообщения --- */
.user-dot { fill: var(--accent); stroke: #fff; stroke-width: 2; }
.chat-card { max-width: 520px; display: flex; flex-direction: column; max-height: 80vh; }
.chat-head { display: flex; justify-content: space-between; align-items: center; }
.chat-head h2 { margin: 0; }
#chat-list { flex: 1; overflow-y: auto; min-height: 200px; max-height: 50vh;
  display: flex; flex-direction: column; gap: 8px; padding: 12px 4px; }
.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.msg .bubble { padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4;
  word-break: break-word; }
.msg.mine .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.theirs .bubble { background: var(--bg); border-bottom-left-radius: 4px; }
.msg-time { font-size: 10px; color: var(--muted); margin-top: 2px; }
.chat-input { display: flex; gap: 8px; margin-top: 8px; }
.chat-input input { flex: 1; border: 1px solid var(--line); border-radius: 20px;
  padding: 10px 14px; font-size: 14px; }
.chat-input button { border-radius: 50%; width: 42px; height: 42px; font-size: 18px; }
#msg-btn { position: relative; font-size: 18px; }
#msg-btn .badge { position: absolute; top: 0; right: 0; }
.search-wrap { position: relative; }
#search-drop { position: absolute; top: 100%; left: 0; right: 0; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; z-index: 30;
  max-height: 300px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 4px; }
