/* ============================================================================
   Cahier d'enquête — Outil de revue d'audit (/audit/)
   Importe les tokens partagés et ajoute la mise en page de l'outil
   sidebar + main area + drawer + mini-carte.
============================================================================ */

@import url('../shared/tokens.css');

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light; }
body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow: hidden;
}

a { color: inherit; }
a:hover { color: var(--rust); }
code {
  font-family: var(--font-data);
  font-size: 0.9em;
  background: var(--paper-2);
  padding: 1px 4px;
}
kbd {
  font-family: var(--font-data);
  font-size: 0.85em;
  background: var(--paper-3);
  border: 1px solid var(--rule-soft);
  padding: 1px 6px;
  border-radius: 2px;
  box-shadow: 0 1px 0 var(--rule-soft);
}
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ---------- masthead ---------- */
.masthead {
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--rule);
}
.masthead__topline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}
.masthead__label {
  font-family: var(--font-data);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.masthead__title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  margin: 0;
}
.masthead__home {
  font-family: var(--font-data);
  font-size: 12px;
  color: var(--ink-soft);
  text-decoration: none;
  align-self: flex-start;
}
.masthead__home:hover { color: var(--rust); text-decoration: underline; }

.status-strip {
  font-family: var(--font-data);
  font-size: 12px;
  color: var(--ink);
  margin: 12px 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.refresh-btn {
  font-family: var(--font-data);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  padding: 3px 10px;
  cursor: pointer;
  margin-left: 8px;
}
.refresh-btn:hover { background: var(--paper-3); }

/* ---------- two-column layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  position: relative;
  overflow: hidden;
}
body.sidebar-collapsed .layout { grid-template-columns: 0 1fr; }
body.sidebar-collapsed .sidebar { transform: translateX(-100%); }

.sidebar-toggle {
  position: absolute;
  top: 12px;
  left: 280px;
  z-index: 10;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-left: none;
  width: 24px;
  height: 32px;
  cursor: pointer;
  font-size: 12px;
  transition: left 0.25s ease;
}
body.sidebar-collapsed .sidebar-toggle { left: 0; }
body.sidebar-collapsed .sidebar-toggle__icon { transform: rotate(180deg); display: inline-block; }

.sidebar {
  border-right: 1px solid var(--rule);
  background: var(--paper);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
}
.guide-button {
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--paper-2);
  border: none;
  border-bottom: 1px solid var(--rule);
  padding: 12px 24px;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  flex-shrink: 0;
}
.guide-button:hover { background: var(--paper-3); }
.bucket-nav { flex: 1; padding: 16px 20px 16px 24px; overflow-y: auto; }

.group { margin-bottom: 24px; }
.group__title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
  margin: 0 0 8px;
  padding-left: 8px;
  border-left: 4px solid var(--lead);
}
.group--rust .group__title { border-left-color: var(--rust); }
.group--ochre .group__title { border-left-color: var(--ochre); }
.group--lead .group__title { border-left-color: var(--lead); }
.group__count {
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: normal;
  margin-left: 4px;
}

.bucket-list {
  list-style: none;
  margin: 0;
  padding: 0 0 0 12px;
}
.bucket {
  margin: 2px 0;
}
.bucket__link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-data);
  font-size: 12px;
  text-decoration: none;
  padding: 4px 6px;
  color: var(--ink);
}
.bucket__link:hover { background: var(--paper-2); }
.bucket--current .bucket__link { background: var(--paper-3); font-weight: 500; }
.bucket--done .bucket__icon { color: var(--moss); }
.bucket--done .bucket__label { color: var(--ink-soft); }
.bucket--done .bucket__link { opacity: 0.6; }
.bucket--draft .bucket__icon { color: var(--ochre); }
.bucket--stale .bucket__icon { color: var(--rust); }
.bucket__icon { width: 12px; text-align: center; }
.bucket__label { flex: 1; }
.bucket__reviewer { font-size: 10px; color: var(--ink-soft); }

/* ---------- main content area ---------- */
.main {
  overflow-y: auto;
  background: var(--paper);
  padding: 0;
  position: relative;
}
.empty-state {
  padding: 48px 32px;
  max-width: 720px;
}
.empty-state h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 28px;
  margin: 0 0 16px;
}
.callout {
  border-left: 4px solid var(--rust);
  background: var(--paper-2);
  padding: 16px 20px;
  margin: 24px 0;
}
.callout--rust { border-left-color: var(--rust); }
.callout strong { display: block; margin-bottom: 6px; font-family: var(--font-display); font-size: 18px; }
.empty-hint { color: var(--ink-soft); margin-top: 24px; }

/* ---------- review article ---------- */
.review {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}
.review__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.review__breadcrumb {
  margin: 0;
  font-family: var(--font-data);
  font-size: 12px;
  color: var(--ink-soft);
}
.review__nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.review__progress {
  font-family: var(--font-data);
  font-size: 12px;
  color: var(--ink);
  margin: 0 8px;
}

.btn {
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  padding: 6px 14px;
  cursor: pointer;
  color: var(--ink);
}
.btn:hover { background: var(--paper-3); }
.btn--save {
  background: var(--rust);
  color: var(--paper);
  border-color: var(--rust);
}
.btn--save:hover { background: var(--rust-deep); }
.btn--exit { font-size: 11px; color: var(--ink-soft); border-style: dashed; }
.btn--prev, .btn--next { padding: 6px 10px; font-size: 16px; }
.btn--export {
  background: var(--moss);
  color: var(--paper);
  border-color: var(--moss);
  font-size: 14px;
}
.btn--close-drawer, .btn--close-guide {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

.review__body {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 24px;
  padding: 20px 24px;
  overflow-y: auto;
  min-height: 0;
}

/* ---------- mini-map ---------- */
.review__map-pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.minimap {
  height: 100%;
  min-height: 480px;
  border: 1px solid var(--rule);
}
.minimap__hint {
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--ochre);
  margin: 0;
  padding: 4px 8px;
  background: var(--paper-3);
  border-left: 3px solid var(--ochre);
}
.distance-label span {
  display: inline-block;
  background: var(--paper);
  border: 1px solid var(--ink);
  font-family: var(--font-data);
  font-size: 10px;
  padding: 1px 5px;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

/* ---------- info panels ---------- */
.review__info-pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 13px;
  overflow-y: auto;
  min-height: 0;
}
.info-block {
  border-top: 1px solid var(--rule-soft);
  padding-top: 12px;
}
.info-block:first-child { border-top: none; padding-top: 0; }
.info-block h3 {
  font-family: var(--font-data);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin: 0 0 6px;
}
.identity__name {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  margin: 0 0 6px;
}
.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 2px 12px;
  margin: 0;
  font-family: var(--font-data);
  font-size: 11px;
}
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; }
.address { margin: 4px 0; }
.coords {
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--ink-soft);
  margin: 2px 0;
}
.distance {
  font-size: 12px;
  margin: 4px 0 0;
  color: var(--ink);
}
.signals {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--font-data);
  font-size: 11px;
}
.signals li { margin: 2px 0; }
.signal--rust { color: var(--rust); font-weight: 500; }
.signal--ochre { color: var(--ochre); font-weight: 500; }
.signal__label { color: var(--ink-soft); margin-right: 4px; }

/* ---------- decision form ---------- */
/* Lives at the TOP of the info pane so the reviewer sees verdict
   buttons immediately without scrolling past 5 info blocks. */
.decision-form {
  border-bottom: 2px solid var(--rule);
  padding-bottom: 12px;
  margin-bottom: 4px;
}

/* 2×2 compact color-coded verdict grid. Each button is identifiable
   by its accent color at a glance — no need to read the text. The
   full explanation lives in the guide drawer + the title tooltip. */
.verdict-radios {
  border: none;
  padding: 0;
  margin: 0 0 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.verdict {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 7px 10px;
  border: 2px solid var(--rule-soft);
  border-radius: 4px;
  cursor: pointer;
  background: var(--paper);
  transition: border-color 0.1s ease, background 0.1s ease;
}
.verdict:hover { background: var(--paper-2); }
.verdict input[type="radio"] {
  margin: 0;
  accent-color: var(--ink);
  flex-shrink: 0;
}
.verdict__label {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}
.verdict__label kbd {
  display: inline-block;
  font-family: var(--font-data);
  font-size: 10px;
  font-weight: 400;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0 4px;
  margin-left: 4px;
  vertical-align: baseline;
}

/* Color accents per verdict */
.verdict--keep   { border-color: var(--moss); }
.verdict--keep   .verdict__label { color: var(--moss); }
.verdict--geocoded { border-color: var(--azur, #2b5c7e); }
.verdict--geocoded .verdict__label { color: var(--azur, #2b5c7e); }
.verdict--manual { border-color: var(--ochre); }
.verdict--manual .verdict__label { color: var(--ochre); }
.verdict--terrain { border-color: var(--rust); }
.verdict--terrain .verdict__label { color: var(--rust); }

/* Selected state: fill the background with a tint of the accent */
.verdict:has(input:checked) {
  background: var(--paper-3);
  border-width: 2px;
}
.verdict--keep:has(input:checked)    { border-color: var(--moss); background: rgba(74,107,58,0.08); }
.verdict--geocoded:has(input:checked) { border-color: var(--azur, #2b5c7e); background: rgba(43,92,126,0.08); }
.verdict--manual:has(input:checked)  { border-color: var(--ochre); background: rgba(192,135,41,0.08); }
.verdict--terrain:has(input:checked) { border-color: var(--rust); background: rgba(180,80,46,0.08); }

.decision-form__row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.note-field {
  display: block;
  flex: 1;
  min-width: 0;
}
.note-field textarea {
  width: 100%;
  border: 1px solid var(--rule);
  background: var(--paper);
  font-family: var(--font-body);
  font-size: 12px;
  padding: 6px 8px;
  resize: vertical;
}

.enquete-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ---------- export drawer ---------- */
.export-drawer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--paper);
  border-top: 2px solid var(--rust);
  padding: 24px 32px;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.08);
  z-index: 5;
}
.export-drawer h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 18px;
  margin: 0 0 8px;
}
.export-instructions {
  font-family: var(--font-data);
  font-size: 12px;
  color: var(--ink);
  margin: 12px 0;
  padding-left: 20px;
}
.export-instructions li { margin: 4px 0; }
.btn--close-drawer { position: absolute; top: 12px; right: 12px; }

/* ---------- guide drawer ---------- */
/* z-index must be above Leaflet's internal layers (400–1000+).
   The previous z-index:100 was below the Leaflet tile pane, causing
   the guide to be partially hidden behind the map. 2000 clears
   everything including Leaflet controls and popups. */
.guide-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  background: var(--paper);
  border-left: 1px solid var(--rule);
  box-shadow: -4px 0 24px rgba(0,0,0,0.08);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease-out;
}
.guide-drawer:not([hidden]) { transform: translateX(0); }
.guide-drawer__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--rule);
}
.guide-drawer__header h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 20px;
  margin: 0;
}
.guide-drawer__body {
  padding: 16px 24px 32px;
  overflow-y: auto;
  font-size: 14px;
}
.guide-drawer__body h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16px;
  margin: 18px 0 8px;
}
.guide-drawer__body p, .guide-drawer__body ol, .guide-drawer__body ul {
  margin: 0 0 12px;
}
.guide-drawer__body code {
  font-size: 11px;
}
.guide-groups dt {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 14px;
  margin-top: 8px;
}
.guide-group--rust { color: var(--rust); }
.guide-group--ochre { color: var(--ochre); }
.guide-group--lead { color: var(--lead); }
.guide-groups dd { margin: 0 0 8px 0; font-size: 12px; color: var(--ink-soft); }
.guide-verdicts dt { font-weight: 500; margin-top: 8px; font-size: 13px; }
.guide-verdicts dd { font-size: 12px; color: var(--ink-soft); margin: 0 0 8px 0; }
.guide-shortcuts {
  font-size: 12px;
  border-collapse: collapse;
}
.guide-shortcuts td { padding: 4px 12px 4px 0; }
.guide-shortcuts td:first-child { white-space: nowrap; }
.guide-credit {
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--rule-soft);
}

/* ---------- rate-limit color states (#5) ---------- */
/* Contrast: amber and red previously used --ochre / --rust as background
   with --paper text at 11px, giving ratios of ≈2.4:1 and ≈3.0:1 — both
   below WCAG AA 4.5:1 for small text. Using --rust-deep / --ink as the
   text color on tinted backgrounds keeps the visual semantics (warm
   accent → urgent) while passing AA. */
.rate-limit { font-family: var(--font-data); padding: 1px 6px; font-weight: 500; }
.rate-limit--neutral { color: var(--ink-soft); }
.rate-limit--amber {
  color: var(--ink);
  background: rgba(192, 135, 41, 0.22); /* --ochre @ 22% */
  border: 1px solid rgba(192, 135, 41, 0.6);
}
.rate-limit--red {
  color: var(--paper);
  background: var(--rust-deep); /* darker than --rust to clear AA */
}
.rate-limit--exhausted {
  color: var(--paper);
  background: #4a1a0c; /* darker still, signals exhaustion */
  font-weight: 600;
}

/* ---------- stale-review reimport button (#2) ---------- */
.bucket__reimport {
  font-family: var(--font-data);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--rust);
  color: var(--paper);
  border: none;
  padding: 1px 6px;
  margin-left: 6px;
  cursor: pointer;
}
.bucket__reimport:hover { background: var(--rust-deep); }

/* ---------- keyboard placement crosshair (#1) ---------- */
.kb-crosshair {
  pointer-events: none;
  border: 2px solid var(--rust);
  background: rgba(180, 80, 46, 0.18);
  width: 28px !important;
  height: 28px !important;
  border-radius: 50%;
}
.kb-crosshair__inner {
  font-family: var(--font-data);
  font-size: 18px;
  color: var(--rust-deep);
  text-align: center;
  line-height: 24px;
  font-weight: 700;
}

/* ---------- toasts (#3) ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  padding: 12px 16px;
  background: var(--paper);
  border-left: 4px solid var(--lead);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast--success { border-left-color: var(--moss); }
.toast--warn { border-left-color: var(--ochre); }
.toast--info { border-left-color: var(--lead); }
.toast--fading { opacity: 0; transform: translateY(8px); }
.toast__cancel {
  font-family: var(--font-data);
  font-size: 10px;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid var(--rule);
  padding: 2px 8px;
  cursor: pointer;
  margin-left: auto;
}
.toast__cancel:hover { background: var(--paper-2); }

/* ---------- masthead table link ---------- */
.masthead__table-link {
  font-family: var(--font-data);
  font-size: 12px;
  color: var(--ink-soft);
  text-decoration: none;
  margin-left: 16px;
}
.masthead__table-link:hover { color: var(--rust); text-decoration: underline; }

/* ---------- table page layout ---------- */
.table-page {
  overflow: auto;
  height: auto;
}
.table-page .masthead { flex-shrink: 0; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 12px 24px;
  border-bottom: 1px solid var(--rule-soft);
  background: var(--paper-2);
}
.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--ink-soft);
}
.filter-bar__label {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.filter-bar select,
.filter-bar input {
  font-family: var(--font-body);
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
}
.filter-bar input { min-width: 180px; }

.export-btn {
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--rust);
  color: var(--paper);
  border: 1px solid var(--rust);
  padding: 6px 14px;
  cursor: pointer;
  align-self: flex-end;
}
.export-btn:hover { background: var(--rust-deep); }

.table-container {
  padding: 0 24px 24px;
  overflow-x: auto;
}

.decisions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 12px;
}
.decisions-table th {
  position: sticky;
  top: 0;
  background: var(--paper-2);
  font-family: var(--font-data);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--rule);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.decisions-table th::after {
  content: '';
  display: inline-block;
  width: 10px;
  margin-left: 4px;
}
.decisions-table th.sort-asc::after { content: '▲'; font-size: 8px; }
.decisions-table th.sort-desc::after { content: '▼'; font-size: 8px; }

.decisions-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--rule-soft);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.decisions-table td.td-num {
  text-align: right;
  font-family: var(--font-data);
}
.decisions-table tbody tr:nth-child(even) { background: var(--paper-2); }
.decisions-table__row { cursor: pointer; }
.decisions-table__row:hover { background: var(--paper-3); }

.verdict-chip {
  display: inline-block;
  font-family: var(--font-data);
  font-size: 10px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}
.verdict-chip--moss  { background: rgba(74,107,58,0.15); color: var(--moss); }
.verdict-chip--azur  { background: rgba(43,92,126,0.15); color: var(--azur); }
.verdict-chip--ochre { background: rgba(192,135,41,0.15); color: var(--ochre); }
.verdict-chip--rust  { background: rgba(180,80,46,0.15); color: var(--rust); }
.verdict-chip--lead  { background: rgba(122,112,101,0.12); color: var(--lead); }

.table-empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 48px 24px;
  font-size: 14px;
}

.table-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--rule-soft);
  font-size: 11px;
  color: var(--ink-soft);
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .review__body { grid-template-columns: 1fr; }
  .minimap { min-height: 360px; }
}

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    z-index: 50;
    transform: translateX(-100%);
  }
  body:not(.sidebar-collapsed) .sidebar { transform: translateX(0); }
  .sidebar-toggle { left: 16px; top: 16px; }
  .guide-drawer { width: 100vw; }
  .review__body { padding: 12px 16px; }
  .review__header { flex-wrap: wrap; }
}

/* ---------- prefers-reduced-motion (WCAG 2.3.3) ---------- */
@media (prefers-reduced-motion: reduce) {
  .sidebar-toggle,
  .sidebar,
  .guide-drawer,
  .toast {
    transition: none;
  }
}
