/* ── reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #222;
  background: #fafafa;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }
.muted { color: #999; font-size: 13px; }

/* ── login / session gate ─────────────────────────────────────────── */
#login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: #f5f5f5;
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  width: 460px; max-width: 92vw;
  background: #fff; border: 1px solid #e0e0e0; border-radius: 12px;
  padding: 30px 32px; box-shadow: 0 8px 30px rgba(0,0,0,0.07);
}
.login-box h2 { font-size: 22px; margin-bottom: 6px; }
.login-box p { color: #777; font-size: 13px; margin-bottom: 18px; }
.login-box input[type="text"] {
  width: 100%; padding: 9px 11px; font-size: 14px;
  border: 1px solid #ccc; border-radius: 6px; margin-bottom: 12px;
}
#btn-login {
  width: 100%; padding: 9px; font-size: 14px; font-weight: 700;
  color: #fff; background: #1A85FF; border: none; border-radius: 6px; cursor: pointer;
  transition: background 0.15s;
}
#btn-login:hover { background: #0f6fe0; }
.login-msg { color: #D41159; font-size: 12px; min-height: 16px; margin-top: 8px; }

#existing-sessions { margin-top: 22px; border-top: 1px solid #eee; padding-top: 16px; }
#existing-sessions h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: #999; margin-bottom: 10px; }
.session-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid #ececec; border-radius: 7px;
  margin-bottom: 6px; cursor: pointer; transition: background 0.12s, border-color 0.12s;
}
.session-row:hover { background: #f6faff; border-color: #cfe3ff; }
.session-row .s-name { font-weight: 600; flex: 1; }
.session-row .s-meta { font-size: 11.5px; color: #999; }
.session-row .s-del {
  border: none; background: none; color: #ccc; cursor: pointer; font-size: 14px;
  padding: 2px 4px; border-radius: 4px;
}
.session-row .s-del:hover { color: #D41159; background: #d4115914; }

/* ── toolbar ──────────────────────────────────────────────────────── */
#toolbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 16px; background: #fff; border-bottom: 1px solid #e0e0e0; flex-shrink: 0;
}
.app-title { font-weight: 700; font-size: 16px; }
.back-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 6px;
  background: #f0f0f0; color: #444; text-decoration: none;
  font-size: 16px; font-weight: 700; flex-shrink: 0; transition: background 0.15s;
}
.back-btn:hover { background: #ddd; }
.toolbar-info { font-size: 13px; color: #666; }
#toolbar .chk { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #555; }
#toolbar input[type="search"] {
  padding: 4px 8px; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; width: 150px;
}
.stats { font-size: 12px; color: #888; margin-left: auto; }
.btn-mode, .btn-sm {
  padding: 5px 11px; border: 1px solid #ccc; border-radius: 6px;
  background: #fff; font-size: 13px; cursor: pointer; transition: background 0.12s, border-color 0.12s;
}
.btn-mode:hover, .btn-sm:hover { background: #f2f2f2; }
.btn-mode.active { background: #1A85FF; color: #fff; border-color: #1A85FF; }
#btn-save.saved { color: #07895d; border-color: #00bf7f55; }

/* ── split layout ─────────────────────────────────────────────────── */
#main { flex: 1; display: flex; gap: 0; overflow: hidden; position: relative; }
.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
#right-pane { border-left: 2px solid #ececec; }
.pane-heading {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: #888; padding: 10px 18px 8px; flex-shrink: 0;
}
.pane-heading .count { color: #bbb; }
#mention-list, #result-list { flex: 1; overflow-y: auto; padding: 0 16px 60px; }

/* the SVG sits between the panes, spanning the whole #main, non-interactive */
#links-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ── mention card (left) ──────────────────────────────────────────── */
.mention-card {
  position: relative;
  border: 1px solid #e6e6e6; border-left: 3px solid #e6e6e6;
  border-radius: 6px; margin-bottom: 5px; background: #fff;
  padding: 7px 11px 7px 13px; font-size: 12.5px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s, box-shadow 0.12s;
}
.mention-card:hover { background: #fafafa; }
.mention-card .m-title { font-weight: 600; line-height: 1.35; }
.mention-card .m-meta { color: #999; font-size: 11px; margin-top: 2px; }
.mention-card .m-meta .mid { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.mention-card .m-inst { font-weight: 700; color: #777; }
.mention-card .m-field { color: #555; font-size: 11.5px; line-height: 1.45; margin-top: 3px; }
.mention-card .m-field .m-flabel { font-weight: 700; color: #777; }
.mention-card .m-exc {
  display: none; margin-top: 6px; padding: 6px 8px; border-radius: 4px;
  background: #f7f7f7; color: #555; font-size: 11.5px; line-height: 1.5; white-space: pre-wrap;
  max-height: 150px; overflow-y: auto;
}
.mention-card.show-exc .m-exc { display: block; }
.m-exc-toggle { font-size: 10.5px; color: #1A85FF; cursor: pointer; margin-top: 3px; display: inline-block; }

/* selection checkbox (merge mode) */
.mention-card .m-check { display: none; position: absolute; top: 8px; right: 9px; }
#app.merge-mode .mention-card .m-check { display: inline-block; }
#app.merge-mode .mention-card { padding-right: 28px; }
.mention-card.selected { border-color: #1A85FF; background: #1a85ff10; box-shadow: 0 0 0 1px #1A85FF55; }

/* grouped member: coloured left stripe + faint tint (colour set inline) */
.mention-card.grouped { border-left-width: 4px; }

/* dim non-related cards when a group is hovered */
#mention-list.focusing .mention-card { opacity: 0.3; }
#mention-list.focusing .mention-card.hl { opacity: 1; }

/* erased mention (left): greyed out, struck through, with an "erased" tag */
.mention-card.erased { opacity: 0.6; background: #fbfbfb; border-left-color: #ddd !important; cursor: default; }
.mention-card.erased .m-title { text-decoration: line-through; color: #999; }
.mention-card.erased::after {
  content: "erased"; position: absolute; top: 7px; right: 9px;
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  color: #b00f4e; background: #d4115914; padding: 1px 6px; border-radius: 8px;
}
#app.merge-mode .mention-card.erased { padding-right: 11px; }
#app.merge-mode .mention-card.erased .m-check { display: none; }

/* ── result card (right) ──────────────────────────────────────────── */
.result-card {
  position: relative;
  border: 1px solid #e0e0e0; border-left: 3px solid #cfcfcf;
  border-radius: 8px; margin-bottom: 6px; background: #fff; overflow: hidden;
}
.result-card.singleton { opacity: 0.92; }
.result-card.merged { border-left-width: 4px; }            /* colour set inline */
.result-card.incomplete { border-color: #ffd40088; }
.rc-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; cursor: pointer; user-select: none;
}
.rc-head:hover { background: #fafafa; }
.rc-head .rc-title { flex: 1; font-weight: 600; line-height: 1.35; }
.rc-head .rc-title.placeholder { color: #bbb; font-weight: 500; font-style: italic; }
.rc-badge {
  flex-shrink: 0; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 700; background: #f0f0f0; color: #777;
}
.result-card.merged .rc-badge { background: #00bf7f1f; color: #07895d; }
.rc-flag {
  flex-shrink: 0; font-size: 10.5px; font-weight: 700; color: #8a6d00;
  background: #ffd40033; padding: 2px 7px; border-radius: 10px;
}
.rc-head .rc-caret { flex-shrink: 0; color: #aaa; font-size: 12px; }
.rc-body { display: none; padding: 4px 14px 12px; border-top: 1px solid #f1f1f1; }
.result-card.open .rc-body { display: block; }

/* compact resolved-policy card — same visual format as a left mention card */
.result-card.policy { cursor: pointer; }
.result-card.policy:hover { background: #fafafa; }
.result-card.policy .rc-policy { padding: 7px 11px 7px 13px; }
.result-card.policy .m-title { font-weight: 600; line-height: 1.35; font-size: 12.5px; }
.result-card.policy .m-meta { color: #999; font-size: 11px; margin-top: 2px; line-height: 1.45; }
.result-card.policy .m-meta .m-inst { font-weight: 700; color: #777; }
.result-card.policy .m-meta .rc-badge { font-size: 10px; padding: 1px 7px; }

/* a resolvable field row */
.f-row { margin: 8px 0; }
.f-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: #aaa; margin-bottom: 3px; }
.f-agree { font-size: 12.5px; line-height: 1.5; color: #333; }
.f-conflict { display: flex; flex-direction: column; gap: 4px; }
.f-opt {
  display: flex; align-items: flex-start; gap: 7px; padding: 5px 8px;
  border: 1px solid #ececec; border-radius: 6px; cursor: pointer; font-size: 12px; line-height: 1.45;
  transition: background 0.1s, border-color 0.1s;
}
.f-opt:hover { background: #f6faff; }
.f-opt.chosen { border-color: #1A85FF; background: #1a85ff10; }
.f-opt input { margin-top: 2px; }
.f-opt .fo-val { flex: 1; color: #333; }
.f-opt .fo-src { font-size: 10px; color: #aaa; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.f-conflict.unresolved .f-label::after { content: " · choose one"; color: #c79100; font-weight: 700; }

/* member list inside a merged card */
.rc-members { margin-top: 10px; border-top: 1px dashed #eee; padding-top: 8px; }
.rc-members .m-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: #aaa; margin-bottom: 4px; }
.member-row { display: flex; align-items: baseline; gap: 8px; padding: 3px 4px; border-radius: 4px; font-size: 12px; cursor: pointer; }
.member-row:hover { background: #1a85ff10; }
.member-row .mr-date { flex-shrink: 0; color: #999; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.member-row .mr-inst { flex-shrink: 0; font-weight: 700; color: #777; font-size: 11px; }
.member-row .mr-title { flex: 1; color: #444; }
.member-row .mr-drop { border: none; background: none; color: #ccc; cursor: pointer; font-size: 13px; }
.member-row .mr-drop:hover { color: #D41159; }

.rc-actions { margin-top: 10px; display: flex; gap: 8px; align-items: center; }
.rc-note { flex: 1; padding: 4px 8px; border: 1px solid #e2e2e2; border-radius: 5px; font-size: 12px; }
.btn-unmerge, .btn-erase { padding: 4px 10px; border: 1px solid #d4115955; color: #b00f4e; background: #fff; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-unmerge:hover, .btn-erase:hover { background: #d4115910; }

/* corner erase button on compact policy / singleton cards */
.rc-erase {
  position: absolute; top: 6px; right: 7px; z-index: 2;
  border: none; background: none; color: #cfcfcf; cursor: pointer;
  font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 5px; opacity: 0;
  transition: opacity 0.12s, background 0.12s;
}
.result-card.policy:hover .rc-erase { opacity: 1; }
.rc-erase:hover { color: #D41159; background: #d4115914; }
.result-card.policy .rc-policy { padding-right: 30px; }

/* ── erased policies section (right pane, bottom) ─────────────────── */
.erased-section { margin-top: 18px; border-top: 1px dashed #e2e2e2; padding-top: 8px; }
.erased-head {
  display: flex; align-items: center; gap: 7px; padding: 4px 2px; cursor: pointer; user-select: none;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #b0413a;
}
.erased-head .count { background: #d4115914; color: #b00f4e; border-radius: 8px; padding: 1px 7px; font-size: 10.5px; }
.erased-head .erased-caret { margin-left: auto; color: #ccc; transition: transform 0.15s; }
.erased-section.open .erased-head .erased-caret { transform: rotate(180deg); }
.erased-body { display: none; margin-top: 6px; }
.erased-section.open .erased-body { display: block; }
.erased-card { display: flex; align-items: center; gap: 8px; opacity: 0.8; background: #fcfcfc; border-left-color: #ddd; }
.erased-card .rc-policy { flex: 1; padding: 7px 11px; }
.erased-card .m-title { text-decoration: line-through; color: #888; font-weight: 600; font-size: 12.5px; line-height: 1.35; }
.erased-card .m-meta { color: #aaa; font-size: 11px; margin-top: 2px; }
.erased-card .m-meta .m-inst { font-weight: 700; color: #999; }
.erased-card .rc-badge { background: #f0f0f0; color: #999; font-size: 10px; padding: 1px 7px; }
.rc-restore {
  flex-shrink: 0; margin-right: 10px; padding: 4px 11px;
  border: 1px solid #1A85FF66; color: #1565c0; background: #fff; border-radius: 6px;
  font-size: 12px; cursor: pointer; transition: background 0.12s;
}
.rc-restore:hover { background: #1a85ff10; }

/* ── merge footer ─────────────────────────────────────────────────── */
#merge-footer {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: #1f2733; color: #fff;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.18);
}
#merge-count { font-weight: 600; }
#btn-merge-confirm {
  padding: 6px 14px; border: none; border-radius: 6px; font-weight: 700; cursor: pointer;
  background: #00BF7F; color: #fff;
}
#btn-merge-confirm:disabled { background: #4a5568; color: #98a2b3; cursor: not-allowed; }
#btn-merge-cancel { padding: 6px 12px; border: 1px solid #4a5568; border-radius: 6px; background: transparent; color: #cbd5e0; cursor: pointer; }

.loading { display: flex; align-items: center; justify-content: center; height: 80px; color: #999; font-size: 13px; }
