:root {
  --paper: #EBEFF1;      /* trace paper */
  --sheet: #FFFFFF;
  --ink: #18263A;        /* drafting ink */
  --ink-2: #4E5C6B;
  --ink-3: #7B8794;
  --rule: #CBD3DA;
  --rule-2: #E1E6EA;
  --fire: #C42B1C;       /* removed / non-compliant / objection */
  --fire-bg: #FBEDEB;
  --exit: #12704A;       /* added / fixed — exit-sign green */
  --exit-bg: #E7F3EC;
  --amber: #9A6200;      /* needs review */
  --amber-bg: #FDF3DE;
  --focus: #2457C5;
  --focus-bg: #EEF3FC;
  --r-sm: 4px;
  --r-md: 8px;
  font-family: "IBM Plex Sans Hebrew", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: grid; grid-template-rows: auto 1fr; font-size: 15px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--focus); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num-ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- top bar */
.top {
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px;
  background: var(--sheet); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; color: inherit; text-decoration: none; }
.brand b { font-size: 17px; font-weight: 700; }
.nav { display: flex; height: 100%; gap: 4px; }
.nav a {
  display: grid; place-items: center; padding: 0 14px; height: 100%;
  font-weight: 500; color: var(--ink-2); text-decoration: none; border-bottom: 3px solid transparent;
}
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }
.who { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.who select { min-width: 120px; }

/* ---------------------------------------------------------------- generic */
#app { min-height: 0; overflow: auto; }
.page { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; margin: 0; line-height: 1.2; }
.page-head .sub { color: var(--ink-2); }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 10px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 6px; }
.hint { color: var(--ink-2); font-size: 13px; margin: 0; }
.muted { color: var(--ink-3); }
.panel { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 16px; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

select, input[type="password"], input[type="text"], input[type="date"], textarea {
  border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 6px 8px; background: var(--sheet);
}
textarea { width: 100%; resize: vertical; }
.btn {
  border: 1px solid var(--rule); background: var(--sheet); border-radius: var(--r-sm);
  padding: 6px 12px; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--ink); display: inline-block;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.btn.primary:disabled { background: var(--ink-3); border-color: var(--ink-3); cursor: progress; }
.btn.wide { width: 100%; padding: 10px 16px; }
.btn.danger { color: var(--fire); }
.btn.danger:hover { border-color: var(--fire); }
.btn.small { padding: 2px 8px; font-size: 13px; }
.linkbtn { border: 0; background: none; color: var(--focus); cursor: pointer; padding: 0; text-decoration: underline; }
.error { border-inline-start: 3px solid var(--fire); background: var(--fire-bg); padding: 10px 12px; border-radius: var(--r-sm); font-size: 14px; }
.note { border-inline-start: 3px solid var(--amber); background: var(--amber-bg); padding: 10px 12px; border-radius: var(--r-sm); font-size: 14px; }
.ok-note { border-inline-start: 3px solid var(--exit); background: var(--exit-bg); padding: 10px 12px; border-radius: var(--r-sm); font-size: 14px; }

.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 10px; white-space: nowrap; background: var(--rule-2); color: var(--ink-2); }
.chip.bad { background: var(--fire-bg); color: var(--fire); }
.chip.good { background: var(--exit-bg); color: var(--exit); }
.chip.warn { background: var(--amber-bg); color: var(--amber); }
.chip.info { background: var(--focus-bg); color: var(--focus); }

dl.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
dl.meta dt { color: var(--ink-3); }
dl.meta dd { margin: 0; overflow-wrap: anywhere; }

.empty { text-align: center; padding: 48px 24px; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }

/* file drop */
.drop {
  border: 1.5px dashed var(--rule); border-radius: var(--r-md); padding: 14px; display: grid; gap: 8px;
  grid-template-columns: minmax(0, 1fr); background: var(--sheet); transition: border-color .15s, background .15s;
}
.drop.drag { border-color: var(--focus); background: #F1F5FD; }
.drop.filled { border-style: solid; }
.drop .fname { font-size: 13px; color: var(--ink-2); direction: ltr; text-align: right; overflow-wrap: anywhere; }
.drop .fname:empty { display: none; }

/* deadlines */
.deadlines { display: flex; gap: 10px; flex-wrap: wrap; }
.deadline { border: 1px solid var(--rule); border-radius: var(--r-md); padding: 8px 12px; background: var(--sheet); min-width: 170px; }
.deadline .when { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.deadline .left { font-size: 13px; color: var(--ink-2); }
.deadline.soon { border-color: var(--fire); }
.deadline.soon .left { color: var(--fire); font-weight: 600; }

/* tabs inside a page */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); margin-bottom: 20px; }
.tabs a { padding: 8px 14px; color: var(--ink-2); text-decoration: none; font-weight: 500; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--sheet); }
.tbl { border: 1px solid var(--rule); border-radius: var(--r-md); overflow: auto; background: var(--sheet); }
th, td { text-align: start; vertical-align: top; padding: 10px; border-bottom: 1px solid var(--rule-2); font-size: 14px; }
th { font-size: 13px; font-weight: 600; color: var(--ink-2); background: #F6F8F9; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #F7F9FA; }
tr[aria-selected="true"] td { background: var(--focus-bg); }
.clause { font-variant-numeric: tabular-nums; white-space: nowrap; direction: ltr; unicode-bidi: isolate; font-weight: 600; }
.chapter, .src { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.refs { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.ref { white-space: nowrap; font-size: 12px; border: 1px solid var(--rule); border-radius: 10px; padding: 0 7px; color: var(--ink-2); background: var(--sheet); }
.warns { margin-top: 6px; font-size: 12px; color: var(--amber); }
.uncertain { text-decoration: underline wavy var(--amber); text-underline-offset: 3px; }
.req-long { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
tr[aria-selected="true"] .req-long { -webkit-line-clamp: unset; }

/* projects list */
.plist td:first-child { font-weight: 600; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; inset-inline-start: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--rule); }
.timeline li { position: relative; padding: 0 28px 18px 0; padding-inline-start: 28px; padding-inline-end: 0; }
.timeline li::before {
  content: ""; position: absolute; inset-inline-start: 1px; top: 6px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--sheet); border: 3px solid var(--ink-3);
}
.timeline li.k-version::before { border-color: var(--ink); }
.timeline li.k-diff::before { border-color: var(--exit); }
.timeline li.k-letter::before { border-color: var(--fire); background: var(--fire); }
.timeline li.k-item::before { border-color: var(--focus); }
.timeline li.k-deleted::before { border-color: var(--ink-3); border-style: dashed; }
.timeline .t-when { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.timeline .t-day { list-style: none; font-weight: 700; font-size: 13px; color: var(--ink-2); padding: 6px 0 10px; padding-inline-start: 28px; }
.timeline .t-day::before { display: none; }

/* plans */
.drawing { margin-bottom: 20px; }
.versions { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--sheet); }
.versions > li { padding: 12px 14px; border-bottom: 1px solid var(--rule-2); display: grid; grid-template-columns: 120px 1fr auto; gap: 14px; align-items: center; }
.versions > li:last-child { border-bottom: 0; }
.versions > li.diff-row { background: #F6F8F9; grid-template-columns: 1fr auto; padding: 8px 14px; font-size: 14px; }
.vthumb { width: 120px; height: 60px; object-fit: contain; background: #fff; border: 1px solid var(--rule-2); border-radius: var(--r-sm); }
.vno { font-weight: 700; }
.vmeta { font-size: 13px; color: var(--ink-2); }

/* split layouts */
.split { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
.split > aside { position: sticky; top: 0; display: grid; gap: 16px; }

/* letter review */
.letter-view { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.pages { display: grid; gap: 12px; position: sticky; top: 0; max-height: calc(100vh - 140px); overflow-y: auto; padding: 4px; }
.pageimg { position: relative; background: #fff; box-shadow: 0 0 0 1px var(--rule); margin: 0; }
.pageimg img { width: 100%; display: block; }
.pageimg figcaption { position: absolute; top: 6px; inset-inline-start: 6px; font-size: 12px; background: var(--ink); color: #fff; padding: 1px 8px; border-radius: 10px; }
.pageimg.skipped img { opacity: .45; }
.pageimg.hl { box-shadow: 0 0 0 3px var(--focus); }
.edit-cell input[type="text"] { width: 100%; }
.edit-cell textarea { min-height: 54px; font-size: 14px; }
tr.excluded td { opacity: .45; }

/* ---------------------------------------------------------------- drawing viewer */
.viewer { display: grid; grid-template-rows: auto 1fr; height: calc(100vh - 56px); }
.viewer-body { display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.viewer-body > aside { background: var(--sheet); border-inline-end: 1px solid var(--rule); overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 18px; }
.viewer-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--rule); background: var(--sheet); }
.change-nav { display: inline-flex; align-items: center; gap: 6px; }
.change-nav output { min-width: 62px; text-align: center; color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.change-nav button { min-width: 34px; padding: 4px 8px; font-size: 20px; line-height: 1; }
.change-nav button:disabled { opacity: .4; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: 0; background: var(--sheet); padding: 5px 12px; cursor: pointer; }
.seg button + button { border-inline-start: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 14px; height: 3px; margin-inline-end: 6px; vertical-align: middle; }
.zoom { margin-inline-start: auto; display: flex; gap: 4px; align-items: center; }
.zoom output { min-width: 48px; text-align: center; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.canvas {
  flex: 1; min-height: 0; position: relative; overflow: hidden; cursor: grab;
  background:
    linear-gradient(var(--rule-2) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--rule-2) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--paper);
}
.canvas.panning { cursor: grabbing; }
.canvas.selecting { cursor: crosshair; }
.stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; box-shadow: 0 0 0 1px var(--rule); background: #fff; }
.stage img { display: block; user-select: none; -webkit-user-drag: none; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage svg .ignore-selection { fill: #4477ff33; stroke: #2457C5; stroke-width: 2; stroke-dasharray: 8 5; }
.box { fill: none; stroke-width: 2.5; vector-effect: non-scaling-stroke; stroke-dasharray: 7 4; }
.box.added { stroke: var(--exit); }
.box.removed { stroke: var(--fire); }
.box.modified { stroke: var(--amber); }
.box.linked { stroke-dasharray: none; }
.box.current { stroke-width: 4; stroke-dasharray: none; fill: rgba(36, 87, 197, .06); }
.canvas .empty { position: absolute; inset: 0; display: grid; place-content: center; max-width: 520px; margin: auto; }
.busy { position: absolute; inset: 0; display: grid; place-content: center; background: rgba(235, 239, 241, .82); font-weight: 500; text-align: center; }
.busy small { display: block; color: var(--ink-2); font-weight: 400; margin-top: 4px; }
.bar { width: 220px; height: 3px; background: var(--rule); margin: 12px auto 0; overflow: hidden; border-radius: 2px; }
.bar::after { content: ""; display: block; width: 40%; height: 100%; background: var(--ink); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(260%); } to { transform: translateX(-120%); } }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--rule); border-top-color: var(--ink); border-radius: 50%; animation: rot .8s linear infinite; vertical-align: -1px; }
@keyframes rot { to { transform: rotate(360deg); } }

.regions { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.regions > li { border-radius: var(--r-sm); padding: 6px; }
.regions > li[aria-current="true"] { background: var(--paper); }
.regions .rhead { width: 100%; display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; border: 0; background: none; padding: 0; cursor: pointer; text-align: start; }
.regions .rlinks { margin-top: 6px; margin-inline-start: 40px; display: grid; gap: 4px; font-size: 13px; }
.regions .rlinks select { width: 100%; font-size: 13px; }
.dot-num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-size: 13px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.k-added { background: var(--exit); }
.k-removed { background: var(--fire); }
.k-modified { background: var(--amber); }

@media (max-width: 900px) {
  .split, .letter-view, .viewer-body { grid-template-columns: minmax(0, 1fr); }
  .page { padding: 16px 16px 48px; }
  .page-head .actions { margin-inline-start: 0; }
  .tabs { overflow-x: auto; white-space: nowrap; }
  .top { gap: 12px; padding: 0 12px; }
  .nav a { padding: 0 8px; }
  .brand b { font-size: 15px; }
  .who select { min-width: 0; max-width: 96px; }
  body { grid-template-columns: minmax(0, 1fr); }
  .split > aside { position: static; }
  .pages { display: none; }
  .versions > li { grid-template-columns: 1fr; }
  .vthumb { display: none; }
  .who span, .brand span { display: none; }
  .viewer-body > aside { max-height: 40vh; border-inline-end: 0; border-bottom: 1px solid var(--rule); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
tr.warn td:first-child { box-shadow: inset -3px 0 0 var(--amber); }
