:root {
  --bg: #fafaf7;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e5e3dc;
  --line-strong: #b8b5a8;
  --conf: #1f7a3e;
  --conf-soft: #d4e9d9;
  --rej: #b8342c;
  --rej-soft: #f3d6d3;
  --doute: #c9821a;
  --doute-soft: #fae7c8;
  --notfound: #5a5a5a;
  --notfound-soft: #e8e6df;
  --accent: #8b6914;
  --hover: #f5f3ec;
  --validated: #1e5db0;
  --validated-soft: #d6e4f5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--ink); }
body {
  font-family: "Iowan Old Style", "Charter", Georgia, "Times New Roman", serif;
  font-size: 15px;
  line-height: 1.55;
}
.ui { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
.mono { font-family: "SF Mono", Menlo, Consolas, monospace; }

/* ---------- Header ---------- */

header {
  border-bottom: 2px solid var(--line-strong);
  padding: 22px 40px 18px;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
header h1 { font-size: 22px; font-weight: 500; letter-spacing: -0.01em; }
header .sub { color: var(--muted); font-size: 13px; font-style: italic; margin-top: 2px; }

.validator-info {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 13px;
  color: var(--muted);
}
.validator-info strong { color: var(--ink); }
.validator-info .progress {
  margin-top: 4px;
  background: var(--hover);
  border-radius: 12px;
  height: 8px;
  width: 200px;
  overflow: hidden;
}
.validator-info .progress > div {
  height: 100%;
  background: var(--validated);
  transition: width 0.3s;
}
.validator-info button {
  background: none; border: 1px solid var(--line-strong);
  padding: 3px 8px; border-radius: 2px; font-size: 11px;
  cursor: pointer; margin-left: 6px;
  font-family: inherit;
}

main { padding: 22px 40px 80px; max-width: 1500px; }

/* ---------- Filters bar ---------- */

.filters {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px 18px;
  margin-bottom: 0;
  display: flex; gap: 18px; flex-wrap: wrap;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 13px; align-items: center;
}
.filters label { color: var(--muted); margin-right: 4px; }
.filters select, .filters input {
  font: inherit; padding: 5px 8px;
  border: 1px solid var(--line-strong);
  background: white; border-radius: 2px;
}
.filters .count { margin-left: auto; color: var(--muted); font-style: italic; }
.filters .refresh {
  background: var(--validated); color: white; border: none;
  padding: 5px 12px; border-radius: 2px; cursor: pointer;
  font-size: 12px;
}
.filters .refresh:hover { background: #164a8a; }

/* ---------- Data table ---------- */

.table-scroll {
  max-height: 75vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-top: none;
}

table.data {
  border-collapse: collapse;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 12px;
  background: var(--panel);
  width: 100%;
}
table.data thead {
  background: #2a2a2a; color: #fafaf7;
  position: sticky; top: 0; z-index: 2;
}
table.data th {
  padding: 8px 10px; text-align: left;
  font-weight: 500;
  cursor: pointer; user-select: none;
  border-bottom: 1px solid #4a4a4a;
  white-space: nowrap;
  font-size: 11.5px;
  line-height: 1.3;
}
table.data th:hover { background: #404040; }
table.data th.sortable::after { content: " ⇅"; opacity: 0.4; font-size: 10px; }
table.data th.sort-asc::after { content: " ↑"; opacity: 1; }
table.data th.sort-desc::after { content: " ↓"; opacity: 1; }
table.data td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}
table.data td.num {
  font-family: "SF Mono", Menlo, monospace;
  text-align: right;
}
table.data td.num.bold { font-weight: 600; }

/* Column-specific widths */
table.data th.col-pourvoi,
table.data td.col-pourvoi {
  max-width: 90px;
  width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.data th.col-status,
table.data td.col-status {
  width: 40px;
  text-align: center;
}
table.data tr.row-approuve td { background: #fafff9; }
table.data tr.row-doute td { background: #fffaf0; }
table.data tr.row-rejete td { background: #fff5f3; }
table.data tr.row-notfound td { background: #f7f6f1; color: var(--muted); font-style: italic; }
table.data tbody tr:hover td { background: var(--hover) !important; cursor: pointer; }

.validation-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.vdot-approuve { background: var(--conf); }
.vdot-doute { background: var(--doute); }
.vdot-rejete { background: var(--rej); }

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge.approuve { background: var(--conf-soft); color: var(--conf); }
.badge.doute { background: var(--doute-soft); color: var(--doute); }
.badge.rejete { background: var(--rej-soft); color: var(--rej); }
.badge.notfound { background: var(--notfound-soft); color: var(--notfound); }
.badge.conf { background: var(--conf-soft); color: var(--conf); }
.badge.rej { background: var(--rej-soft); color: var(--rej); }
.badge.neutral { background: #e8e6df; color: var(--muted); }
.badge.mine { background: var(--validated-soft); color: var(--validated); }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--panel);
  width: 100%; max-width: 1400px;
  max-height: 95vh;
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  font-family: -apple-system, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 18px 24px 12px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: flex-start;
}
.modal-header h3 {
  font-size: 17px; font-weight: 500;
  font-family: "Iowan Old Style", Georgia, serif;
  line-height: 1.4;
}
.modal-header .close {
  background: none; border: 1px solid var(--line-strong);
  padding: 5px 12px; cursor: pointer; font-size: 12px;
  border-radius: 2px;
}
.modal-body { padding: 10px 24px 12px; overflow-y: auto; flex: 1 1 auto; min-height: 200px; }

.context-details {
  background: white;
  border: 1px solid var(--line);
  border-radius: 3px;
}
.context-details > summary {
  cursor: pointer;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
  list-style: none;
}
.context-details > summary::before {
  content: "▸ ";
  display: inline-block;
  margin-right: 4px;
  transition: transform 0.15s;
}
.context-details[open] > summary::before {
  transform: rotate(90deg);
}
.context-details > summary:hover { background: var(--hover); }
.modal-context {
  padding: 4px 12px 10px;
  margin-top: 0;
  border-top: 1px solid var(--line);
}
.modal-context > *:last-child { margin-bottom: 0; }

.meta-block {
  background: var(--bg);
  padding: 12px 14px;
  border-radius: 3px;
  font-size: 13px;
  margin-bottom: 12px;
  color: var(--muted);
}
.modal-context .meta-block {
  background: transparent;
  padding: 0;
  margin-bottom: 6px;
}
.meta-block strong { color: var(--ink); }

.scores-block {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.scores-block .s {
  background: var(--bg);
  padding: 4px 6px;
  border-radius: 2px;
  font-size: 11px;
  text-align: center;
}
.scores-block .s .lbl {
  color: var(--muted); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.scores-block .s .val {
  font-size: 16px; font-family: "SF Mono", Menlo, monospace;
  margin-top: 1px;
}

.vertex-reason {
  background: #fffcf0;
  border-left: 3px solid var(--accent);
  padding: 8px 12px;
  margin-bottom: 0;
  font-size: 13px;
  line-height: 1.5;
  font-family: "Iowan Old Style", Georgia, serif;
}
.vertex-reason .lbl {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 4px;
}

.texts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 0;
}
.text-pane {
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.text-pane .pane-head {
  background: #2a2a2a; color: #fafaf7;
  padding: 8px 12px;
  font-size: 12px; font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.text-pane .pane-head .copy-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fafaf7;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 2px 8px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 2px;
  white-space: nowrap;
  flex-shrink: 0;
}
.text-pane .pane-head .copy-btn:hover { background: rgba(255, 255, 255, 0.2); }
.text-pane .pane-head .copy-btn.copied {
  background: var(--conf);
  border-color: var(--conf);
  color: white;
}
.text-pane .pane-body {
  background: white;
  padding: 14px 16px;
  font-family: "Iowan Old Style", Georgia, serif;
  font-size: 13.5px;
  line-height: 1.6;
  /* No max-height: let the content flow at natural height.
     The modal-body parent has overflow-y:auto and the modal itself
     is capped at 95vh, so the global scroll handles long texts. */
  white-space: pre-wrap;
  word-wrap: break-word;
}
.text-pane .pane-body.empty {
  color: var(--muted); font-style: italic;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 12px;
}

/* ---------- Validation zone ---------- */

.validation-zone {
  border-top: 1px solid var(--line);
  padding: 12px 24px 14px;
  background: var(--bg);
  display: flex; flex-direction: column; gap: 8px;
  flex-shrink: 0;
  max-height: 60vh;
  overflow-y: auto;
}
.validation-zone h4 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
.vote-buttons {
  display: flex; gap: 10px;
}
.vote-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid;
  background: white;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s;
}
.vote-btn.approuve { border-color: var(--conf); color: var(--conf); }
.vote-btn.approuve:hover, .vote-btn.approuve.selected { background: var(--conf); color: white; }
.vote-btn.doute { border-color: var(--doute); color: var(--doute); }
.vote-btn.doute:hover, .vote-btn.doute.selected { background: var(--doute); color: white; }
.vote-btn.rejete { border-color: var(--rej); color: var(--rej); }
.vote-btn.rejete:hover, .vote-btn.rejete.selected { background: var(--rej); color: white; }

.vote-comment {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  font: inherit;
  font-size: 13px;
  min-height: 44px;
  resize: vertical;
}

.existing-validations {
  background: white;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 10px 12px;
  font-size: 12px;
}
.existing-validations .ev-row {
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.existing-validations .ev-row:last-child { border-bottom: none; }
.existing-validations .ev-empty { color: var(--muted); font-style: italic; }

.save-status {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  min-height: 0;
}
.save-status:empty { display: none; }
.save-status.saving { color: var(--accent); }
.save-status.saved { color: var(--conf); }
.save-status.error { color: var(--rej); font-weight: 600; }

/* ---------- Welcome modal ---------- */

.welcome-modal {
  background: var(--panel);
  padding: 36px 40px;
  border-radius: 4px;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.welcome-modal h2 {
  font-size: 22px;
  margin-bottom: 8px;
  font-family: "Iowan Old Style", Georgia, serif;
  font-weight: 500;
}
.welcome-modal p {
  color: var(--muted);
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.welcome-modal input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  font-size: 15px;
  font-family: inherit;
  margin-bottom: 14px;
}
.welcome-modal button {
  width: 100%;
  padding: 12px;
  background: var(--validated);
  color: white;
  border: none;
  border-radius: 2px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.welcome-modal button.secondary-btn {
  background: white;
  color: var(--validated);
  border: 1px solid var(--line-strong);
  margin-top: 8px;
}
.welcome-modal button.secondary-btn:hover {
  background: var(--hover);
}
.welcome-modal form {
  display: flex;
  flex-direction: column;
}
.welcome-modal .login-error {
  color: var(--rej);
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}
.welcome-modal .login-info {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
  min-height: 16px;
  font-style: italic;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
  font-family: -apple-system, system-ui, sans-serif;
}
.loading.error { color: var(--rej); }
