:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #1b1f24;
  --muted: #626a73;
  --line: #dfe3e8;
  --line-strong: #c8ced6;
  --accent: #2456d8;
  --accent-hover: #1c46b1;
  --mark: #fff0a6;
  --mark-strong: #ffd95a;
  --review: #ffe2a8;
  --good: #18794e;
  --bad: #b42318;
  --shadow: 0 8px 24px rgba(20, 28, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar {
  min-height: 78px;
  padding: 18px clamp(18px, 4vw, 54px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
}
.topbar h1 { margin: 0 0 4px; font-size: clamp(20px, 2.1vw, 27px); letter-spacing: -.02em; }
.topbar p { margin: 0; color: var(--muted); font-size: 14px; }
.privacy { color: var(--muted); font-size: 13px; white-space: nowrap; }

.app-shell { width: min(1500px, 96vw); margin: 18px auto 42px; }
.toolbar,
.statusbar,
.issues-section,
.sources-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.toolbar {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.toolbar-actions, .bulk-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.switch-row { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; color: var(--text); }
.switch-row input { width: 17px; height: 17px; accent-color: var(--accent); }

.btn {
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 14px;
  font-weight: 650;
  font-size: 14px;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:disabled { cursor: default; opacity: .45; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-small { padding: 7px 10px; font-size: 13px; }

.statusbar {
  margin-top: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: var(--muted);
  font-size: 13px;
}

.comparison-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: stretch;
}
.pane {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.pane-header {
  min-height: 76px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.eyebrow { color: var(--muted); font-size: 11px; letter-spacing: .085em; font-weight: 800; }
.pane h2, .issues-heading h2 { margin: 2px 0 0; font-size: 16px; }
.meta { color: var(--muted); font-size: 12px; }
.editor,
.document-view {
  width: 100%;
  min-height: 58vh;
  max-height: 72vh;
  overflow: auto;
  border: 0;
  outline: 0;
  resize: vertical;
  padding: 18px 20px 28px;
  background: var(--surface);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 4;
}
.editor::placeholder { color: #9aa1aa; }
.document-view.empty-state { display: grid; place-items: center; color: var(--muted); font-family: inherit; }
.empty-message { width: min(430px, 84%); text-align: center; line-height: 1.5; }

.change-mark {
  background: var(--mark);
  box-shadow: inset 0 -2px 0 var(--mark-strong);
  border-radius: 2px;
  cursor: pointer;
  padding: 0 1px;
}
.change-mark.flag { background: var(--review); }
.change-mark.accepted { box-shadow: inset 0 -2px 0 var(--good); }
.change-mark:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

.issues-section, .sources-section { margin-top: 12px; padding: 16px; }
.issues-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 12px; }
.issues-list { display: grid; gap: 9px; }
.issue {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.issue.rejected { opacity: .58; }
.issue.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(36,86,216,.1); }
.issue-main { padding: 12px 13px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: start; }
.issue-title { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-bottom: 6px; }
.badge { display: inline-flex; padding: 3px 7px; border-radius: 999px; background: #eef1f5; color: #4c5560; font-size: 11px; font-weight: 750; }
.badge.severity-error { background: #ffebe9; color: var(--bad); }
.badge.severity-review { background: #fff4d7; color: #7a5300; }
.issue-change { font-family: Georgia, "Times New Roman", serif; font-size: 15px; line-height: 1.45; }
.before { text-decoration: line-through; text-decoration-thickness: 1px; color: #6d3030; }
.after { font-weight: 700; }
.arrow { padding: 0 6px; color: var(--muted); }
.issue-reason { margin-top: 7px; color: var(--muted); font-size: 13px; line-height: 1.42; }
.issue-actions { display: flex; gap: 6px; }
.issue-actions button { white-space: nowrap; }
.status-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.status-label.accepted { color: var(--good); }
.status-label.rejected { color: var(--bad); }

.sources-list { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.source-link {
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 12px;
}
.source-link:hover { text-decoration: underline; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #20242a;
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  z-index: 50;
}

@media (max-width: 900px) {
  .topbar { align-items: flex-start; }
  .comparison-grid { grid-template-columns: 1fr; }
  .editor, .document-view { min-height: 44vh; max-height: 58vh; }
  .issues-heading, .issue-main { grid-template-columns: 1fr; display: grid; }
  .issue-actions { justify-content: flex-start; }
}

@media (max-width: 620px) {
  .topbar { display: block; }
  .privacy { margin-top: 8px; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn { flex: 1; }
  .statusbar { display: block; }
  #countText { display: block; margin-top: 4px; }
  .pane-header { min-height: 68px; }
  .editor, .document-view { font-size: 15px; padding: 15px; }
  .bulk-actions { margin-top: 8px; }
}
