:root {
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #dde3ea;
  --border-strong: #c9d2dc;
  --text: #15212e;
  --muted: #64717f;
  --accent: #0e7490;
  --accent-hover: #0b5f77;
  --accent-soft: #e3f2f6;
  --l1: #2563eb;
  --l1-soft: #eaf1fe;
  --l1-bg: rgba(59, 130, 246, 0.28);
  --l2: #c97a06;
  --l2-soft: #fdf3e2;
  --l2-bg: rgba(245, 158, 11, 0.33);
  --l3: #d6334a;
  --l3-soft: #fdebee;
  --l3-bg: rgba(239, 68, 68, 0.30);
  --ok: #18794e;
  --ok-soft: #e4f4ec;
  --del: #b42318;
  --ins: #137333;
  --shadow-sm: 0 1px 2px rgba(16, 32, 48, .06);
  --shadow: 0 1px 3px rgba(16, 32, 48, .08), 0 4px 14px rgba(16, 32, 48, .06);
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------- top bar */
.topbar {
  height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; flex: none; }
.logo svg { width: 20px; height: 20px; fill: #fff; stroke: none; }
.logo .tick { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.brand .title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand .sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 10px; align-items: center; flex: none; }

.settings {
  display: flex; align-items: center; height: 36px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); padding: 0 4px; box-shadow: var(--shadow-sm);
}
.settings:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14,116,144,.15); }
.settings .field { display: flex; align-items: center; gap: 2px; height: 28px; padding: 0 0 0 8px; border-radius: 6px; cursor: pointer; }
.settings .field:hover { background: var(--surface-2); }
.settings .field span { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.settings select {
  height: 28px; border: 0; outline: none; background: transparent; padding: 0 22px 0 6px; cursor: pointer;
  font-weight: 600; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%2364717f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center; background-size: 12px;
}
.settings .divider { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer;
  white-space: nowrap; text-decoration: none; font-weight: 550; box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; gap: 5px; }
.btn.small .ico { width: 14px; height: 14px; }
.btn.good { color: var(--ok); }
.btn.good.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { color: var(--del); }
.btn.bad.on { background: var(--del); border-color: var(--del); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }

/* ------------------------------------------------------------- layout */
/* fixed-height panes: the PDF and the review list each scroll on their own */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 460px; grid-template-rows: minmax(0, 1fr); height: calc(100% - 60px); }
.viewer-wrap { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.viewer-toolbar {
  height: 50px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.file { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 0 1 auto; }
.file .ico { color: var(--muted); }
.file .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 60px; }
.file-meta { display: flex; gap: 6px; flex: none; }

/* Original | Edited segmented control */
.seg {
  display: inline-grid; grid-template-columns: 1fr 1fr; flex: none; padding: 3px; gap: 2px;
  background: #e7ecf1; border-radius: 9px;
}
.seg button {
  min-width: 84px; height: 28px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer; transition: background .15s, color .15s;
}
.seg button:hover:not(:disabled):not(.on) { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(16, 32, 48, .16); }
.seg button:disabled { opacity: .45; cursor: not-allowed; }

.zoom { display: inline-flex; align-items: center; flex: none; border: 1px solid var(--border); border-radius: 8px; height: 34px; overflow: hidden; }
.zoom button { width: 32px; height: 100%; border: 0; background: var(--surface); cursor: pointer; font-size: 16px; color: var(--muted); }
.zoom button:hover { background: var(--surface-2); color: var(--text); }
.zoom span { min-width: 48px; text-align: center; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; border-inline: 1px solid var(--border); line-height: 32px; }

.viewer { flex: 1; min-height: 0; overflow: auto; padding: 24px; }
.page { position: relative; margin: 0 auto 20px; background: #fff; border-radius: 2px; box-shadow: 0 1px 3px rgba(16,32,48,.12), 0 8px 24px rgba(16,32,48,.08); }
.page canvas { display: block; }
.hl-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.hl { position: absolute; border-radius: 2px; pointer-events: auto; cursor: pointer; mix-blend-mode: multiply; }
.hl.l1 { background: var(--l1-bg); }
.hl.l2 { background: var(--l2-bg); }
.hl.l3 { background: var(--l3-bg); }
.hl.lnew { background: rgba(34, 160, 90, .26); border-bottom: 2px solid rgba(24, 121, 78, .75); border-radius: 2px 2px 0 0; }
.hl.ldel { background: var(--del); opacity: .85; border-radius: 2px; }
.hl.done { opacity: .35; }
.hl.active { outline: 2px solid var(--text); outline-offset: 1px; animation: pulse 1s ease-out 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(14,116,144,.55); } 100% { box-shadow: 0 0 0 10px rgba(14,116,144,0); } }
.locating .hl-layer { display: none; }
.textLayer { z-index: 1; }

/* empty state + drag and drop */
.empty {
  max-width: 520px; margin: 7vh auto 0; padding: 40px 36px; display: flex; flex-direction: column; align-items: center;
  gap: 6px; text-align: center; background: var(--surface); border: 2px dashed var(--border-strong);
  border-radius: 16px; cursor: pointer; transition: border-color .15s, background .15s;
}
.empty:hover { border-color: var(--accent); background: #fbfdfe; }
.empty strong { font-size: 16px; }
.empty-icon { width: 56px; height: 56px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 8px; }
.empty-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.steps { margin: 22px 0 0; padding: 18px 0 0 22px; border-top: 1px solid var(--border); text-align: left; color: var(--muted); line-height: 1.7; font-size: 13.5px; align-self: stretch; }
.steps b { color: var(--text); font-weight: 600; }
.drop-hint {
  position: absolute; inset: 50px 0 0; display: none; place-items: center; font-size: 18px; font-weight: 600; color: var(--accent);
  background: rgba(227, 242, 246, .85); border: 3px dashed var(--accent); border-radius: 12px; margin: 10px; pointer-events: none;
}
.viewer-wrap.dragging .drop-hint { display: grid; }

/* ------------------------------------------------------------- review panel */
.panel { display: flex; flex-direction: column; background: var(--surface-2); border-left: 1px solid var(--border); min-height: 0; }
.panel-head { padding: 14px 18px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.summary { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.summary span { white-space: nowrap; }
.summary b { color: var(--text); font-weight: 600; }
.status { margin: 12px 16px 0; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); color: #0b4a5c; font-size: 13px; line-height: 1.45; }
.status.error { background: var(--l3-soft); color: #8a1c1c; }
.locate-bar { margin: 12px 16px 0; padding: 10px 12px; border-radius: 8px; background: var(--l2-soft); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; }

#groups { flex: 1; min-height: 0; overflow: auto; padding: 0 16px 16px; }
.intro { margin: 40px 8px; text-align: center; color: var(--muted); line-height: 1.6; }

.group { margin-top: 6px; }
.group-head {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 10px;
  margin: 0 -16px; padding: 12px 16px 10px; background: var(--surface-2);
}
.group-head .lvl { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 11.5px; font-weight: 700; flex: none; }
.group-head .lvl.l1 { background: var(--l1-soft); color: var(--l1); }
.group-head .lvl.l2 { background: var(--l2-soft); color: var(--l2); }
.group-head .lvl.l3 { background: var(--l3-soft); color: var(--l3); }
.group-head .titles { min-width: 0; flex: 1; }
.group-head .title-row { display: flex; align-items: center; gap: 8px; }
.group-head h3 { margin: 0; font-size: 14px; font-weight: 650; display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.group-head .hint { font-size: 12px; color: var(--muted); margin-top: 1px; }
.group-head .count { font-size: 11.5px; font-weight: 600; color: var(--muted); background: #e7ecf1; border-radius: 10px; padding: 1px 7px; }
.group-head .bulk { display: flex; gap: 0; flex: none; margin: -4px -8px -4px 0; }
.group-empty { margin: 0 0 6px 38px; font-size: 13px; color: var(--muted); }

.card {
  position: relative; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 12px 16px;
  margin: 0 0 10px; background: var(--surface); cursor: pointer; box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, border-color .15s, opacity .15s;
}
.card::before { content: ""; position: absolute; left: -1px; top: -1px; bottom: -1px; width: 4px; border-radius: var(--radius) 0 0 var(--radius); background: var(--border); }
.card.l1::before { background: var(--l1); } .card.l2::before { background: var(--l2); } .card.l3::before { background: var(--l3); }
.card:hover { box-shadow: var(--shadow); }
.card.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14,116,144,.18), var(--shadow); }
.card.rejected { opacity: .62; }
.card.rejected .diff ins { background: transparent; color: var(--muted); text-decoration: line-through; }
.card.rejected .diff del { background: transparent; color: var(--text); text-decoration: none; }

.card-top { display: flex; align-items: flex-start; gap: 8px; }
.card-top .chips { display: flex; gap: 5px; flex-wrap: wrap; flex: 1; min-width: 0; }
.card-top .state { flex: none; }
.chip { font-size: 11px; font-weight: 550; padding: 2px 7px; border-radius: 6px; background: #eef1f4; color: #3e4a58; white-space: nowrap; }
.chip.warn { background: var(--l2-soft); color: #7a4b00; }
.chip.err { background: var(--l3-soft); color: #8a1c1c; }
.chip.ok { background: var(--ok-soft); color: #155c33; }
.state { font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.state.accepted { background: var(--ok-soft); color: var(--ok); }
.state.rejected { background: #eef1f4; color: var(--muted); }
.state.answered { background: var(--accent-soft); color: var(--accent); }
.state.kept { background: #eef1f4; color: var(--muted); }
.state.waiting { background: var(--l2-soft); color: #7a4b00; }
.state.reverted { background: #efeaf9; color: #5b3fa3; }
.reverted-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding: 8px 10px;
  background: #f6f3fc; border-radius: 8px; font-size: 12.5px; color: #4a3a78;
}
.card.rejected .reverted-bar { opacity: 1; }

.diff { margin: 8px 0 4px; line-height: 1.6; font-size: 14px; }
.diff del { color: var(--del); background: #fde7e7; text-decoration: line-through; text-decoration-color: rgba(180,35,24,.6); border-radius: 3px; padding: 0 2px; }
.diff ins { color: var(--ins); background: #ddf3e4; text-decoration: none; border-radius: 3px; padding: 0 2px; }
.quote { margin: 8px 0; padding: 6px 10px; border-left: 3px solid var(--border-strong); background: var(--surface-2); border-radius: 0 6px 6px 0; color: #2e3a47; font-size: 13px; line-height: 1.5; }
.q { margin: 8px 0 4px; font-weight: 600; line-height: 1.45; font-size: 14px; }
.meta { font-size: 12.5px; color: var(--muted); margin: 4px 0; line-height: 1.45; }
.meta b { color: #3b4655; font-weight: 600; }
.row { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
textarea {
  width: 100%; min-height: 58px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  resize: vertical; margin-top: 8px; line-height: 1.45; background: var(--surface);
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: flex-start; gap: 10px; }
.check input { width: 17px; height: 17px; margin: 11px 0 0; flex: none; cursor: pointer; accent-color: var(--accent); }
.check .diff { cursor: pointer; }
.alt { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); }

/* ------------------------------------------------------------- export + footer */
.export-result { border-top: 1px solid var(--border); padding: 14px 18px; max-height: 42%; overflow: auto; font-size: 13px; background: var(--surface); }
.export-head { display: flex; align-items: center; gap: 10px; }
.export-head .ok-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.export-head .ok-icon.ok { background: var(--ok-soft); color: var(--ok); }
.export-head .ok-icon.bad { background: var(--l3-soft); color: var(--l3); }
.export-head h4 { margin: 0; font-size: 14px; }
.export-head .sub { font-size: 12px; color: var(--muted); }
.export-head .btn { margin-left: auto; }
.export-result details { margin-top: 10px; }
.export-result summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
.export-result ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.55; }
.export-result li .st { color: var(--muted); }
.export-result li .st.fail { color: var(--del); font-weight: 600; }

.panel-footer {
  border-top: 1px solid var(--border); padding: 12px 18px; display: flex; gap: 14px; align-items: center;
  justify-content: space-between; background: var(--surface);
}
.progress { min-width: 0; font-size: 12.5px; color: var(--muted); }
.progress b { color: var(--text); }
.progress .open { color: var(--l3); font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: #155c33; }
.badge.bad { background: var(--l3-soft); color: #8a1c1c; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr) 400px; }
  .brand .sub { display: none; }
  .file-meta { display: none; }
}

/* ------------------------------------------------------------- edited view: change popup, toast */
.updating { display: inline-flex; align-items: center; gap: 2px; font-size: 12.5px; color: var(--accent); white-space: nowrap; }
.pop {
  position: fixed; z-index: 50; width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(16,32,48,.18), 0 2px 6px rgba(16,32,48,.08); padding: 12px 14px;
}
.pop-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.pop-head .lvl { width: 24px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 10.5px; font-weight: 700; }
.pop-head .lvl.l1 { background: var(--l1-soft); color: var(--l1); }
.pop-head .lvl.l2 { background: var(--l2-soft); color: var(--l2); }
.pop-head .lvl.l3 { background: var(--l3-soft); color: var(--l3); }
.pop-head .muted { font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.pop-x { border: 0; background: transparent; font-size: 18px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 2px; }
.pop-row { display: grid; grid-template-columns: 62px 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); font-size: 13.5px; line-height: 1.45; }
.pop-label { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding-top: 2px; }
.pop-was { color: var(--del); text-decoration: line-through; text-decoration-color: rgba(180,35,24,.5); }
.pop-now { color: var(--ins); font-weight: 550; }
.pop-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: 12px;
  background: #15212e; color: #fff; padding: 10px 12px 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13.5px;
}
.toast .btn.ghost { color: #8fd3e6; }
.toast .btn.ghost:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ------------------------------------------------------------- sign in */
body.locked .topbar, body.locked .layout { filter: blur(5px); pointer-events: none; user-select: none; }
.login-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(21, 33, 46, .45); padding: 16px; }
.login {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 16px; padding: 28px 28px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 12px;
}
.login .logo.big { width: 48px; height: 48px; border-radius: 12px; margin: 0 auto 4px; }
.login .logo.big svg { width: 28px; height: 28px; }
.login h1 { margin: 0; font-size: 20px; text-align: center; letter-spacing: -.01em; }
.login p { margin: -8px 0 6px; text-align: center; }
.login label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.login input { height: 38px; border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; font-size: 14px; background: var(--surface); }
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login .btn { height: 40px; margin-top: 4px; }
.login-error { padding: 8px 10px; border-radius: 8px; background: var(--l3-soft); color: #8a1c1c; font-size: 13px; }
