:root {
  --ink: #1d2433; --muted: #6b7280; --line: #e3e6ec; --bg: #f5f6f8; --card: #fff;
  --brand: #1f4fd1; --red: #c62828; --blue: #0b57d0; --amber: #b86e00; --green: #1a7f37;
  --amber-bg: #fff4e0; --green-bg: #e8f5ec; --red-bg: #fdecec;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0 0 12px; } h2 { font-size: 17px; margin: 0 0 10px; } h3 { font-size: 15px; margin: 18px 0 4px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; } .pad { padding: 12px; }
code { font-size: 12px; background: #eef0f4; padding: 1px 4px; border-radius: 3px; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 20px; height: 52px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; text-decoration: none; color: var(--ink); }
.topbar nav { display: flex; gap: 14px; align-items: center; }
.topbar nav a { text-decoration: none; }
main { padding: 22px; }
.doc-screen main { padding: 0; }
.flash { background: var(--red-bg); color: var(--red); padding: 10px 22px; border-bottom: 1px solid #f3c7c7; }

.btn { display: inline-block; background: var(--brand); color: #fff; border: 0; border-radius: 6px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(1.08); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: var(--red); }
.linkish { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
form.inline { display: inline; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 22px; margin: 0 auto; }
.card.narrow { max-width: 380px; margin-top: 40px; } .card.medium { max-width: 720px; } .card.empty { text-align: center; color: var(--muted); }
label { display: block; margin: 10px 0; font-weight: 600; font-size: 13px; }
input, textarea, select { width: 100%; font: inherit; padding: 7px 9px; border: 1px solid #cfd4dc; border-radius: 6px; margin-top: 4px; background: #fff; }
input[type=radio], input[type=checkbox] { width: auto; margin: 0 6px 0 0; }
label.check { display: flex; align-items: flex-start; font-weight: 400; }
.party-grid { display: grid; grid-template-columns: 1fr 1.3fr 1.6fr 70px; gap: 6px 8px; align-items: center; margin: 8px 0 18px; }
.party-grid input { margin: 0; } .party-grid input[type=radio] { justify-self: center; }

.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
table.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { background: #fafbfc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-left: 6px; }
.pill.warn { background: var(--red-bg); color: var(--red); } .pill.amber { background: var(--amber-bg); color: var(--amber); }

.chain { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.chain.ok { background: var(--green-bg); color: var(--green); } .chain.bad { background: var(--red-bg); color: var(--red); font-weight: 700; }
.audit .details { font-size: 12px; max-width: 520px; word-break: break-word; } .evt { font-family: ui-monospace, monospace; font-size: 12px; }

/* ---- document screen */
.doc-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.doc-title { display: flex; align-items: center; gap: 6px; } .doc-title h1 { margin: 0; font-size: 17px; }
.doc-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.me { font-size: 13px; margin-right: 6px; }
.reg-banner { background: var(--amber-bg); color: #7a4a00; padding: 9px 20px; border-bottom: 1px solid #f1d6a8; font-size: 13px; }
.reg-banner.bad { background: var(--red-bg); color: var(--red); border-color: #f3c7c7; }

.doc-layout { display: grid; grid-template-columns: 1fr 380px; height: calc(100vh - 52px - 55px); }
.pages { overflow: auto; padding: 24px 24px 24px 48px; }
.page { position: relative; max-width: 860px; margin: 0 auto 24px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12); user-select: none; }
.page img { display: block; width: 100%; height: 100%; }
.layer { position: absolute; inset: 0; }
.w { position: absolute; cursor: text; border-radius: 2px; }
.w:hover { background: rgba(31,79,209,.10); }
.w.sel { background: rgba(31,79,209,.28); }
.w.del::after { content: ""; position: absolute; left: 0; right: 0; top: 55%; border-top: 2px solid var(--red); }
.w.del.proposed { background: rgba(198,40,40,.06); }
.ins { position: absolute; transform: translateY(-100%); font-size: 11px; line-height: 1.1; color: var(--blue); background: rgba(255,255,255,.93);
  border-bottom: 1px solid var(--blue); white-space: nowrap; max-width: 46%; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; pointer-events: auto; }
.ins.proposed { border-bottom-style: dashed; }
.tag { position: absolute; left: -42px; width: 34px; font: 700 10px/16px system-ui; text-align: center; border-radius: 4px; cursor: pointer; border: 1px solid; padding: 0; }
.tag.proposed { color: var(--amber); background: var(--amber-bg); border-color: var(--amber); }
.tag.agreed { color: var(--green); background: var(--green-bg); border-color: var(--green); }
.flash { animation: flash 1.2s; } @keyframes flash { 0%,60% { box-shadow: 0 0 0 4px rgba(31,79,209,.35); } }

.sidebar { border-left: 1px solid var(--line); background: #fff; overflow: auto; display: flex; flex-direction: column; }
.hint { padding: 12px 16px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); }
.hint:empty { display: none; }
.composer { padding: 14px 16px; border-bottom: 1px solid var(--line); background: #f8faff; }
.composer-head { display: flex; justify-content: space-between; font-weight: 700; font-size: 13px; }
.composer .x { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); }
.composer blockquote { margin: 6px 0 10px; padding: 6px 10px; background: #fff; border-left: 3px solid var(--brand); font-size: 13px; max-height: 110px; overflow: auto; }
.composer textarea, .composer input { margin: 0 0 8px; }
.seg { display: flex; margin-bottom: 8px; } .seg button { flex: 1; padding: 6px; border: 1px solid #cfd4dc; background: #fff; font: inherit; font-size: 12.5px; cursor: pointer; }
.seg button:first-child { border-radius: 6px 0 0 6px; } .seg button:last-child { border-radius: 0 6px 6px 0; } .seg button + button { border-left: 0; }
.seg button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabs { display: flex; border-bottom: 1px solid var(--line); } .tab { flex: 1; background: none; border: 0; padding: 10px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.on { color: var(--ink); border-bottom-color: var(--brand); } #pending-count { font-weight: 400; font-size: 12px; color: var(--amber); }
.tab-body { padding: 10px 12px; }
.ccard { border: 1px solid var(--line); border-left: 4px solid; border-radius: 8px; padding: 9px 11px; margin-bottom: 9px; cursor: pointer; }
.ccard.proposed { border-left-color: var(--amber); } .ccard.agreed { border-left-color: var(--green); } .ccard.rejected, .ccard.withdrawn { border-left-color: #bbb; opacity: .75; }
.ccard-head { display: flex; gap: 6px; align-items: baseline; font-size: 12.5px; } .ccard-head span:nth-child(2) { color: var(--muted); flex: 1; }
.status { font-size: 11px; font-weight: 700; text-transform: uppercase; } .status.proposed { color: var(--amber); } .status.agreed { color: var(--green); } .status.rejected, .status.withdrawn { color: #888; }
.what { margin: 5px 0; font-size: 13px; } .what s { color: var(--red); } .what u { color: var(--blue); text-decoration-style: dotted; } .arrow { color: var(--muted); }
.note { font-size: 12px; color: var(--muted); font-style: italic; } .note.warn { color: var(--red); }
.chips { display: flex; gap: 5px; margin-top: 6px; } .chip { font-size: 11px; padding: 1px 8px; border-radius: 4px; border: 1px dashed #bbb; color: #999; }
.chip.got { border: 1px solid var(--green); color: var(--green); background: var(--green-bg); font-style: italic; font-weight: 700; } .chip.rej { border-color: #bbb; color: #888; }
.actions { display: flex; gap: 6px; margin-top: 8px; }
.versions { list-style: none; padding: 0; margin: 0; } .versions li { display: grid; grid-template-columns: 1fr auto; padding: 8px 0; border-bottom: 1px solid var(--line); }
.versions li span { grid-column: 1; } .versions li a { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 12.5px; }
.compare { margin-top: 14px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; } .compare > b, .compare button, .compare ul { grid-column: 1 / -1; }
.compare select { margin: 0; } .compare ul { padding-left: 18px; font-size: 12.5px; }
dialog { border: 0; border-radius: 12px; padding: 0; max-width: 520px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,24,35,.45); }
.dlg { padding: 22px; } .dlg h2 { color: var(--red); } .dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 50; }
.toast.bad { background: var(--red); }

.caret { position: absolute; width: 0; height: 0; cursor: pointer; z-index: 2; }
.caret::before { content: ""; position: absolute; left: -5px; top: -7px; border: 5px solid transparent; border-bottom: 7px solid var(--blue); }
.caret.proposed::before { border-bottom-color: var(--amber); }
.caret::after { content: ""; position: absolute; left: -9px; top: -12px; width: 18px; height: 16px; }   /* bigger hover target */
.caret .bubble { position: absolute; top: 3px; left: -6px; display: none; width: max-content; max-width: 300px; white-space: normal;
  font-size: 12px; line-height: 1.3; color: var(--blue); background: #fff; border: 1px solid var(--blue); border-radius: 6px; padding: 5px 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15); z-index: 3; }
.caret.flip .bubble { left: auto; right: -6px; }
.caret:hover .bubble { display: block; }
.caret.proposed .bubble { border-style: dashed; }

/* ---- fill vs redline */
.mode-pick { margin: 14px 0 6px; display: grid; gap: 8px; }
.mode-card { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; cursor: pointer; }
.mode-card:has(input:checked) { border-color: var(--brand); background: #f3f6ff; }
.mode-card input { margin-top: 3px; }
.view-switch { display: inline-flex; margin-left: 10px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.view-switch button { border: 0; background: #fff; padding: 5px 14px; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.view-switch button.on { background: var(--brand); color: #fff; }

.fld { position: absolute; display: none; box-sizing: border-box; border-radius: 3px; z-index: 3; }
.fill-mode .fld { display: flex; align-items: center; }
.fill-mode .w { pointer-events: none; }
.fill-mode .tag, .fill-mode .ins, .fill-mode .caret { opacity: .35; pointer-events: none; }
.fld.mine { background: rgba(255, 214, 10, .28); outline: 1px solid rgba(214, 160, 0, .8); }
.fld.mine.done { background: rgba(26, 127, 55, .08); outline-color: rgba(26, 127, 55, .55); }
.fld.theirs { background: rgba(120, 130, 150, .08); outline: 1px dashed rgba(120, 130, 150, .45); }
.fld input[type=text], .fld input[type=date] { width: 100%; height: 100%; margin: 0; padding: 0 3px; border: 0; background: transparent; font: inherit; color: #0b2a6b; }
.fld input[type=date] { font-size: .85em; }
.fld input:focus { outline: 2px solid var(--brand); background: #fff; }
.fld.t-checkbox { justify-content: center; }
.fld.t-checkbox input { width: 80%; height: 80%; margin: 0; cursor: pointer; }
.fld button { width: 100%; height: 100%; border: 0; background: rgba(31, 79, 209, .9); color: #fff; font: 700 .8em system-ui; border-radius: 3px; cursor: pointer; }
.fld .sig { font: italic 1.25em "Brush Script MT", "Segoe Script", cursive; color: #0b2a6b; padding-left: 4px; white-space: nowrap; }
.fld .val { color: #0b2a6b; padding-left: 3px; white-space: nowrap; overflow: hidden; }
.fld .who { color: #8a93a6; font-size: .7em; padding-left: 3px; text-transform: uppercase; letter-spacing: .03em; }

.fgroup { margin-bottom: 14px; }
.fgroup-head { display: flex; gap: 6px; align-items: baseline; padding: 4px 2px 6px; border-bottom: 1px solid var(--line); }
.fgroup-head .prog { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--amber); } .fgroup-head .prog.all { color: var(--green); }
.fitem { display: flex; gap: 8px; align-items: center; padding: 6px 4px; border-bottom: 1px solid #f0f2f5; cursor: pointer; font-size: 13px; }
.fitem:hover { background: #f8faff; }
.fitem .dot { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--amber); flex: none; }
.fitem.done .dot { background: var(--green); border-color: var(--green); }
.fitem .flabel { flex: 1; min-width: 0; }
.fitem select { width: auto; margin: 0; padding: 2px 4px; font-size: 12px; }
.sig-preview { font: italic 30px "Brush Script MT", "Segoe Script", cursive; color: #0b2a6b; border-bottom: 1px solid #ccd; padding: 6px 4px; margin: 6px 0 12px; }
.dlg h2.neutral { color: var(--ink); }

.parties-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 14px 0 16px; }
.parties-box summary { cursor: pointer; }
.parties-box[open] summary { margin-bottom: 8px; }
.parties-box .party-grid { margin-bottom: 4px; }
.send-rows { display: grid; gap: 8px; margin: 10px 0 4px; }
.send-row { display: grid; grid-template-columns: 80px 1fr 1.3fr; gap: 8px; align-items: center; }
.send-row input { margin: 0; }
.send-role { font-weight: 700; text-transform: capitalize; font-size: 13px; }
