:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #1b1f24;
  --muted: #626a73;
  --line: #dfe3e8;
  --line-strong: #c8ced6;
  --accent: #2456d8;
  --accent-hover: #1c46b1;
  --good: #18794e;
  --good-bg: #dff4e7;
  --bad: #7a7f87;
  --bad-bg: #eceef1;
  --manual: #7c3aed;
  --manual-bg: #eee7ff;
  --shadow: 0 6px 18px rgba(20, 28, 40, .055);
  --ortho-bg: #ffe4e8;
  --ortho-line: #d92d4f;
  --grammar-bg: #fff0b8;
  --grammar-line: #c87900;
  --content-bg: #dcecff;
  --content-line: #2463c7;
  --compare-height: 43%;
}

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

.topbar {
  min-height: 54px;
  padding: 7px clamp(10px, 1.7vw, 24px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(520px, auto) minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: center;
  position: relative;
  z-index: 20;
}
.brand-line,
.top-actions,
.top-status,
.pane-title-line,
.issues-title-line,
.legend,
.bulk-actions {
  display: flex;
  align-items: center;
}
.brand-line { gap: 9px; min-width: 0; white-space: nowrap; }
.brand-line h1 { margin: 0; font-size: 17px; letter-spacing: -.018em; }
.subtitle { color: var(--muted); font-size: 11px; }
.top-status {
  justify-content: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  white-space: nowrap;
}
#statusText { overflow: hidden; text-overflow: ellipsis; }
#countText { color: var(--text); font-weight: 700; white-space: nowrap; }
.top-actions { justify-content: flex-end; gap: 6px; white-space: nowrap; }
.switch-row { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; }
.switch-row input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }

.legend { gap: 4px; }
.legend-item {
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 750;
  border: 1px solid transparent;
  line-height: 1.35;
}
.legend-ortho { background: var(--ortho-bg); border-color: color-mix(in srgb, var(--ortho-line) 35%, transparent); }
.legend-grammar { background: var(--grammar-bg); border-color: color-mix(in srgb, var(--grammar-line) 35%, transparent); }
.legend-content { background: var(--content-bg); border-color: color-mix(in srgb, var(--content-line) 35%, transparent); }
.legend-manual { background: var(--manual-bg); border-color: color-mix(in srgb, var(--manual) 35%, transparent); }

.workspace {
  width: min(1580px, 98vw);
  height: calc(100dvh - 68px);
  margin: 7px auto 7px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  height: var(--compare-height);
  min-height: 150px;
  flex: 0 0 auto;
  align-items: stretch;
}
.pane {
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.pane-header {
  min-height: 40px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}
.pane-title-line { gap: 7px; }
.eyebrow { color: var(--muted); font-size: 9px; letter-spacing: .075em; font-weight: 800; }
.pane h2,
.issues-heading h2,
.criteria-header h2 { margin: 0; font-size: 13px; }
.meta { color: var(--muted); font-size: 10px; }
.manual-badge { font-size: 10px; color: var(--manual); font-weight: 750; }

.editor,
.document-view {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 0;
  outline: 0;
  resize: none;
  padding: 11px 14px 15px;
  background: var(--surface);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  line-height: 1.46;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 4;
  scroll-behavior: smooth;
}
.editor::placeholder { color: #9aa1aa; }
.document-view.empty-state { display: grid; place-items: center; color: var(--muted); font-family: inherit; }
.empty-message { width: min(410px, 84%); text-align: center; line-height: 1.45; }

.change-mark {
  border-radius: 2px;
  cursor: pointer;
  padding: 0 1px;
  transition: outline .12s ease, opacity .12s ease, filter .12s ease, background .12s ease;
}
.mark-ortho { background: var(--ortho-bg); box-shadow: inset 0 -2px 0 var(--ortho-line); }
.mark-grammar { background: var(--grammar-bg); box-shadow: inset 0 -2px 0 var(--grammar-line); }
.mark-content { background: var(--content-bg); box-shadow: inset 0 -2px 0 var(--content-line); }
.mark-accepted { background: var(--good-bg); box-shadow: inset 0 -2px 0 var(--good); }
.mark-rejected { background: var(--bad-bg); box-shadow: inset 0 -2px 0 #9aa1aa; color: #5d6269; }
.mark-manual { background: var(--manual-bg); box-shadow: inset 0 -2px 0 var(--manual); }
.change-mark.flag { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.18) 0 4px, rgba(255,255,255,0) 4px 8px); }
.change-mark.selected-mark { outline: 2px solid var(--accent); outline-offset: 2px; }
.change-mark:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.manual-deletion-marker {
  display: inline-block;
  width: 8px;
  height: 1.05em;
  vertical-align: -.12em;
  margin: 0 1px;
  border-left: 3px solid var(--manual);
  background: color-mix(in srgb, var(--manual-bg) 72%, transparent);
  border-radius: 2px;
}

.btn {
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 7px 11px;
  font-weight: 650;
  font-size: 12px;
  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: 5px 8px; font-size: 11px; }

.splitter {
  height: 11px;
  flex: 0 0 11px;
  cursor: row-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: none;
  position: relative;
}
.splitter::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 5px;
  border-top: 1px solid var(--line-strong);
}
.splitter-grip {
  width: 78px;
  height: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  position: relative;
  z-index: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.splitter-grip::after {
  content: "······";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -63%);
  color: #8a919a;
  font-size: 10px;
  letter-spacing: 1px;
}
.splitter:focus .splitter-grip { outline: 2px solid var(--accent); outline-offset: 2px; }

.issues-section {
  flex: 1 1 auto;
  min-height: 150px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 8px 6px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.issues-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  flex: 0 0 auto;
}
.issues-title-line { gap: 7px; min-width: 0; }
.issues-help { color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bulk-actions { gap: 5px; flex-wrap: wrap; justify-content: flex-end; }

/* Las tarjetas conservan su altura natural. El scroll pertenece al panel, no a cada tarjeta. */
.issues-list {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: scroll;
  overflow-x: hidden;
  padding: 1px 6px 4px 1px;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}
.issue {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: visible;
  cursor: pointer;
}
.issue.accepted { border-color: color-mix(in srgb, var(--good) 35%, var(--line)); }
.issue.rejected { border-color: #cfd3d8; background: #fafafa; }
.issue.manual { border-color: color-mix(in srgb, var(--manual) 35%, var(--line)); }
.issue.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(36,86,216,.10); }
.issue-main {
  padding: 8px 9px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}
.issue-main > div:first-child { min-width: 0; }
.issue-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.issue-title strong { font-size: 12px; }
.badge { display: inline-flex; padding: 2px 6px; border-radius: 999px; background: #eef1f5; color: #4c5560; font-size: 9.5px; font-weight: 750; }
.badge.severity-error { background: #ffebe9; color: #b42318; }
.badge.severity-review { background: #fff4d7; color: #7a5300; }
.badge.manual-badge-card { background: var(--manual-bg); color: var(--manual); }
.category-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 8px; }
.category-dot.mark-ortho { background: var(--ortho-line); box-shadow: none; }
.category-dot.mark-grammar { background: var(--grammar-line); box-shadow: none; }
.category-dot.mark-content { background: var(--content-line); box-shadow: none; }
.category-dot.mark-manual { background: var(--manual); box-shadow: none; }
.category-dot.mark-accepted { background: var(--good); box-shadow: none; }
.category-dot.mark-rejected { background: #9aa1aa; box-shadow: none; }
.issue-change {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  line-height: 1.38;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}
.before { text-decoration: line-through; text-decoration-thickness: 1px; color: #6d3030; }
.after { font-weight: 700; }
.arrow { padding: 0 5px; color: var(--muted); }
.issue-reason { margin-top: 4px; color: var(--muted); font-size: 11.5px; line-height: 1.35; white-space: normal; overflow-wrap: anywhere; }
.issue-actions { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; max-width: 280px; }
.issue-actions button { white-space: nowrap; }
.status-label { font-size: 10px; font-weight: 750; color: var(--muted); }
.status-label.accepted { color: var(--good); }
.status-label.rejected { color: #767c84; }
.status-label.manual { color: var(--manual); }
.remembered { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--line-strong)); }

.sources-details {
  flex: 0 0 auto;
  margin-top: 5px;
  border-top: 1px solid var(--line);
  padding-top: 4px;
  font-size: 10px;
  color: var(--muted);
}
.sources-details summary { cursor: pointer; font-weight: 700; }
.sources-list { margin-top: 5px; display: flex; gap: 5px; flex-wrap: wrap; max-height: 70px; overflow: auto; }
.source-link {
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 7px;
  font-size: 10px;
}
.source-link:hover { text-decoration: underline; }

.criteria-dialog {
  width: min(860px, 92vw);
  max-height: 78vh;
  padding: 0;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 24px 70px rgba(0,0,0,.22);
}
.criteria-dialog::backdrop { background: rgba(20,24,32,.35); }
.criteria-box { padding: 14px; display: flex; flex-direction: column; max-height: 78vh; }
.criteria-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.criteria-note { color: var(--muted); font-size: 12px; margin: 8px 0 10px; }
.criteria-list { overflow: auto; display: grid; gap: 6px; min-height: 80px; }
.criteria-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.criteria-row p { margin: 0; font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.criteria-kind { font-weight: 750; color: var(--accent); }
.criteria-empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.criteria-footer { display: flex; justify-content: flex-end; margin-top: 10px; }

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

@media (max-width: 1240px) {
  .topbar { grid-template-columns: 1fr auto; }
  .top-status { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
  .workspace { height: calc(100dvh - 90px); }
  .top-legend { display: none; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .topbar { display: flex; flex-wrap: wrap; }
  .brand-line { width: 100%; }
  .top-actions { flex-wrap: wrap; justify-content: flex-start; }
  .workspace { height: auto; overflow: visible; width: 96vw; }
  .comparison-grid { grid-template-columns: 1fr; height: auto !important; }
  .pane { min-height: 300px; }
  .editor, .document-view { min-height: 250px; }
  .splitter { display: none !important; }
  .issues-section { min-height: 360px; max-height: 62vh; margin-top: 9px; }
  .issues-heading, .issue-main { grid-template-columns: 1fr; display: grid; }
  .issue-actions { justify-content: flex-start; max-width: none; }
}

@media (max-width: 650px) {
  .brand-line { flex-wrap: wrap; white-space: normal; }
  .brand-line h1 { font-size: 16px; }
  .subtitle { font-size: 10px; }
  .issues-help { display: none; }
}
