:root {
  --paper: #faf7f1;
  --card: #fffdf9;
  --ink: #241f1b;
  --muted: #6d645b;
  --line: #e7ddcf;
  --burgundy: #7a1f2b;
  --burgundy-soft: #f3e7e6;
  --ok: #2f6b46;
  --ok-soft: #e8f1ea;
  --warn: #8a5a12;
  --warn-soft: #fbf1de;
  --bad: #8f2b2b;
  --bad-soft: #f8e8e6;
  --shadow: 0 1px 2px rgba(36,31,27,.06), 0 12px 30px rgba(36,31,27,.07);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper); color: var(--ink);
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", Arial, sans-serif;
  font-size: 15px; line-height: 1.65; -webkit-text-size-adjust: 100%;
}
a { color: var(--burgundy); }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; background: rgba(250,247,241,.94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--burgundy); white-space: nowrap; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--burgundy); }
.topbar .doc-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: #efe8dc; color: var(--muted); white-space: nowrap;
}
.chip.open { background: var(--warn-soft); color: var(--warn); }
.chip.sent { background: var(--burgundy-soft); color: var(--burgundy); }
.chip.closed { background: var(--ok-soft); color: var(--ok); }
.chip.expired, .chip.revoked { background: var(--bad-soft); color: var(--bad); }
.chip.test { background: #2b2b2b; color: #fff; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 8px 14px; font-weight: 600; }
.btn:hover { border-color: #d6c8b4; }
.btn.primary { background: var(--burgundy); border-color: var(--burgundy); color: #fff; }
.btn.primary:hover { background: #671a24; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.ok { background: var(--ok-soft); border-color: #c9dccd; color: var(--ok); }
.btn.bad { background: var(--bad-soft); border-color: #eccfca; color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 18px; }
.layout { display: grid; grid-template-columns: minmax(0,1fr) 380px; gap: 18px; align-items: start; }
@media (max-width: 940px) { .layout { grid-template-columns: 1fr; } }

.paper { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px 34px 40px; }
@media (max-width: 640px) { .paper { padding: 20px 18px 26px; } }

.doc-head { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 20px; }
.doc-head h1 { font-size: 22px; margin: 0 0 6px; }
.doc-head .meta { color: var(--muted); font-size: 13px; }

.blk { margin: 0 0 14px; }
.blk .blk-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.blk-text { white-space: pre-wrap; word-break: break-word; }
.blk.t-h1 .blk-text { font-size: 21px; font-weight: 700; }
.blk.t-h2 .blk-text { font-size: 17px; font-weight: 700; }
.blk.t-note .blk-text { color: var(--muted); font-size: 14px; }
.blk.t-li { padding-inline-start: 18px; position: relative; }
.blk.t-li::before { content: "\2022"; position: absolute; inset-inline-start: 4px; color: var(--muted); }
.blk[dir="ltr"] { text-align: left; }
.blk[dir="rtl"] { text-align: right; }

mark.hl { background: #fdf0c8; border-radius: 3px; padding: 0 1px; cursor: pointer; box-shadow: inset 0 -2px 0 #eccf6a; }
mark.hl.accept { background: var(--ok-soft); box-shadow: inset 0 -2px 0 #a9cbb0; }
mark.hl.edit { background: #eef1fb; box-shadow: inset 0 -2px 0 #b9c3e6; }
mark.hl.reject { background: var(--bad-soft); box-shadow: inset 0 -2px 0 #e2b3ad; }
mark.hl.active { outline: 2px solid var(--burgundy); outline-offset: 1px; }

.panel { position: sticky; top: 68px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 90px); }
.panel-head { display: flex; align-items: center; gap: 8px; }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-head .count { color: var(--muted); font-size: 13px; }
.comments { overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 2px; }
@media (max-width: 940px) { .panel { position: static; max-height: none; } .comments { max-height: 420px; } }

.cmt { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: 0 1px 1px rgba(36,31,27,.03); }
.cmt.active { border-color: var(--burgundy); box-shadow: 0 0 0 3px var(--burgundy-soft); }
.cmt-top { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.cmt-num { font-weight: 700; color: var(--burgundy); }
.cmt-quote { border-inline-start: 3px solid #e3d6c2; padding-inline-start: 8px; margin: 8px 0; color: #4a423a; font-size: 13px; line-height: 1.6; max-height: 76px; overflow: hidden; }
.cmt-body { white-space: pre-wrap; font-size: 14px; }
.cmt-actions { display: flex; gap: 6px; margin-top: 8px; }
.cmt-status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.cmt-status.accept { background: var(--ok-soft); color: var(--ok); }
.cmt-status.edit { background: #eef1fb; color: #35407a; }
.cmt-status.reject { background: var(--bad-soft); color: var(--bad); }
.cmt-status.open { background: #efe8dc; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; padding: 14px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }

.sel-btn { position: fixed; z-index: 60; transform: translate(-50%, -120%); background: var(--burgundy); color: #fff; border: 0; border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600; box-shadow: 0 6px 18px rgba(122,31,43,.3); }
.sel-btn::after { content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%); border: 5px solid transparent; border-top-color: var(--burgundy); border-bottom: 0; }

.sheet-mask { position: fixed; inset: 0; background: rgba(36,31,27,.32); z-index: 70; }
.sheet { position: fixed; z-index: 80; left: 50%; bottom: 0; transform: translateX(-50%); width: min(620px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 16px 18px 18px; box-shadow: 0 -10px 40px rgba(36,31,27,.18); }
@media (min-width: 700px) { .sheet { bottom: 24px; border-radius: 16px; } }
.sheet h3 { margin: 0 0 8px; font-size: 15px; }
.sheet .quote { border-inline-start: 3px solid #e3d6c2; padding-inline-start: 8px; color: #4a423a; font-size: 13px; margin-bottom: 10px; max-height: 90px; overflow: auto; }
.sheet textarea { width: 100%; min-height: 96px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical; background: #fff; }
.sheet .row { display: flex; gap: 8px; justify-content: flex-start; margin-top: 10px; flex-wrap: wrap; }
.sheet .err { color: var(--bad); font-size: 13px; margin-top: 8px; }

.gate-wrap { max-width: 560px; margin: 6vh auto; padding: 0 16px 60px; }
.gate { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 26px; }
.gate h1 { font-size: 21px; margin: 0 0 6px; }
.gate .sub { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; }
.field input:focus { outline: 2px solid var(--burgundy-soft); border-color: var(--burgundy); }
.gate .facts { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; font-size: 13px; color: var(--muted); }
.gate .facts div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.otp-input { letter-spacing: 10px; font-size: 22px; text-align: center; direction: ltr; }
.notice { background: var(--warn-soft); border: 1px solid #ecd9b4; color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
.notice.err { background: var(--bad-soft); border-color: #eccfca; color: var(--bad); }
.notice.ok { background: var(--ok-soft); border-color: #c9dccd; color: var(--ok); }
.testcode { font-weight: 700; letter-spacing: 4px; direction: ltr; display: inline-block; }

.q-grid { display: grid; grid-template-columns: minmax(0,1fr) 420px; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .q-grid { grid-template-columns: 1fr; } }
.decide { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.decide .btn { flex: 1 1 auto; }
.editbox { width: 100%; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-height: 64px; background: #fff; }
.summary { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0 0; }
.summary .box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-width: 96px; }
.summary .box b { display: block; font-size: 20px; }
.summary .box span { font-size: 12px; color: var(--muted); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.footnote { color: var(--muted); font-size: 12px; margin-top: 16px; line-height: 1.7; }

mark.hl::after { content: attr(data-n); font-size: 10px; line-height: 0; vertical-align: super; color: #9a7b33; margin-inline-start: 1px; }
