:root {
  --bg: #f7f7f5;
  --bg-elev: #ffffff;
  /* Couleurs modale (adaptables en dark mode plus bas) */
  --modal-body-bg: #f3f3f3;
  --modal-field-bg: #ffffff;
  --ai-panel-bg: #ede1ef;
  --border: #e3e3df;
  --text: #1b1b1a;
  --text-muted: #6b6b66;
  --accent: #5b4ec9;
  --accent-soft: #ece9fa;
  --danger: #c6373a;
  --success: #2a8a4a;
  --warning: #c68a2e;
  --info: #3d8bcd;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  --radius: 8px;
  --row-pad-y: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  /* Sticky stack offsets (cumulés si plusieurs barres sticky) */
  --sticky-topbar-h: 56px;
  --sticky-filters-h: 0px;
  --sticky-ai-h: 0px;
  --sticky-batch-h: 0px;
}
body.density-compact { --row-pad-y: 6px; }

[data-theme="dark"] {
  --bg: #1a1a1c;
  --bg-elev: #232326;
  --border: #37373b;
  --text: #eaeae8;
  --text-muted: #9a9a94;
  --accent: #9b8efa;
  --accent-soft: #2b2750;
  --danger: #e5615f;
  --success: #68c389;
  --warning: #e8b768;
  --modal-body-bg: #1f1f22;
  --modal-field-bg: #28282c;
  --ai-panel-bg: #2b2338;
  --info: #6bb0ea;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
}

/* ═══ TOPBAR ═══ */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  z-index: 40;
}
body.sticky-topbar-on .topbar { position: sticky; top: 0; }
.brand strong { font-size: 16px; letter-spacing: -0.2px; }
.brand .subtitle { color: var(--text-muted); margin-left: 8px; font-size: 13px; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab {
  background: transparent; border: none; color: var(--text-muted);
  padding: 8px 14px; border-radius: var(--radius);
  font: inherit; cursor: pointer; font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.tab:hover { background: var(--accent-soft); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* Dropdown menu (Affichage) */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); right: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px; min-width: 240px;
  z-index: 100;
  display: flex; flex-direction: column; gap: 4px;
}
.dropdown-menu[hidden] { display: none !important; }
.dropdown-menu .dropdown-section { border-top: 1px solid var(--border); padding-top: 6px; margin-top: 4px; }
.dropdown-menu .dropdown-section:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.dropdown-menu .dropdown-title { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; padding: 4px 8px; }
.dropdown-menu label {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
.dropdown-menu label:hover { background: var(--accent-soft); }
.dropdown-menu input[type="checkbox"],
.dropdown-menu input[type="radio"] { accent-color: var(--accent); }

/* ═══ BUTTONS ═══ */
button {
  font: inherit; cursor: pointer;
  border-radius: var(--radius);
  padding: 8px 14px;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.ghost:hover { background: var(--accent-soft); border-color: var(--accent-soft); }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
button.danger { background: transparent; color: var(--danger); border-color: var(--border); }
button.danger:hover { background: rgba(198, 55, 58, 0.08); border-color: var(--danger); }

/* ═══ MAIN (full width) ═══ */
main { padding: 16px 20px; max-width: none; }
.view { display: none; }
.view.active { display: block; }

/* ═══ CARDS / KPI ═══ */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 16px; font-size: 14px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi-grid.small-kpi { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 0; }
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.kpi .label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -0.5px; }

.row { display: grid; gap: 16px; margin-bottom: 16px; }
.row.two-col { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .row.two-col { grid-template-columns: 1fr; } }

/* ═══ BARS ═══ */
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 160px 1fr 50px; gap: 8px; align-items: center; font-size: 13px; }
.bar-row .name { color: var(--text-muted); font-family: var(--font-mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar-outer { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; height: 16px; overflow: hidden; }
.bar-row .bar-inner { background: var(--accent); height: 100%; transition: width 0.3s; border-radius: 4px 0 0 4px; }
.bar-row .count { text-align: right; font-family: var(--font-mono); color: var(--text-muted); font-size: 12px; }

/* ═══ FILTERS ═══ */
.filters {
  display: flex; gap: 10px; align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  z-index: 20;
}
.filters input[type="search"],
.filters select,
.filters input[type="text"],
.filters input[type="email"],
.filters input[type="number"],
.filters input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text); font: inherit;
}
.filters input[type="search"] { min-width: 260px; flex: 1; }
.filters label { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; user-select: none; }
.filters input[type="checkbox"] { accent-color: var(--accent); }
.muted-inline { color: var(--text-muted); font-size: 12px; margin-left: auto; font-family: var(--font-mono); }

/* ═══ AI TOGGLE BAR ═══ */
.ai-toggle-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  margin-bottom: 10px;
  z-index: 19;
}
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 13px; color: var(--text-muted); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .slider {
  width: 36px; height: 20px;
  background: var(--border); border-radius: 10px;
  position: relative; transition: background 0.15s;
}
.switch .slider::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: white; transition: transform 0.15s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(16px); }

/* ═══ STICKYABLE BARS (toggle via body.sticky-<zone>-on) ═══ */
/*
 Stack sticky dans l'ordre :
 1. topbar      (top: 0)
 2. filters     (top: --sticky-topbar-h)
 3. ai          (top: --sticky-topbar-h + --sticky-filters-h)
 4. batch       (top: + --sticky-ai-h)
 5. thead       (top: cumul des précédents)
*/
body.sticky-filters-on .filters.stickyable[data-sticky-zone="filters"] {
  position: sticky;
  top: 0;
  --this-h: 58px; z-index: 18;
}
body.sticky-topbar-on.sticky-filters-on .filters.stickyable[data-sticky-zone="filters"] { top: var(--sticky-topbar-h); }
body.sticky-ai-on .ai-toggle-bar.stickyable[data-sticky-zone="ai"] {
  position: sticky; top: 0; z-index: 17;
}
body.sticky-topbar-on.sticky-ai-on .ai-toggle-bar.stickyable[data-sticky-zone="ai"] { top: var(--sticky-topbar-h); }
body.sticky-topbar-on.sticky-filters-on.sticky-ai-on .ai-toggle-bar.stickyable[data-sticky-zone="ai"] {
  top: calc(var(--sticky-topbar-h) + 58px);
}
body.sticky-batch-on .batch-actions.stickyable[data-sticky-zone="batch"] {
  position: sticky; top: 0; z-index: 16;
}
body.sticky-topbar-on.sticky-batch-on .batch-actions.stickyable[data-sticky-zone="batch"] { top: var(--sticky-topbar-h); }
body.sticky-topbar-on.sticky-filters-on.sticky-batch-on .batch-actions.stickyable[data-sticky-zone="batch"] {
  top: calc(var(--sticky-topbar-h) + 58px);
}
body.sticky-topbar-on.sticky-filters-on.sticky-ai-on.sticky-batch-on .batch-actions.stickyable[data-sticky-zone="batch"] {
  top: calc(var(--sticky-topbar-h) + 58px + 46px);
}
body.sticky-thead-on thead.stickyable[data-sticky-zone="thead"] th {
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 15;
  border-bottom: 2px solid var(--border);
}
body.sticky-topbar-on.sticky-thead-on thead.stickyable[data-sticky-zone="thead"] th {
  top: var(--sticky-topbar-h);
}
body.sticky-topbar-on.sticky-filters-on.sticky-thead-on thead.stickyable[data-sticky-zone="thead"] th {
  top: calc(var(--sticky-topbar-h) + 58px);
}
body.sticky-topbar-on.sticky-filters-on.sticky-ai-on.sticky-thead-on thead.stickyable[data-sticky-zone="thead"] th {
  top: calc(var(--sticky-topbar-h) + 58px + 46px);
}
body.sticky-topbar-on.sticky-filters-on.sticky-ai-on.sticky-batch-on.sticky-thead-on thead.stickyable[data-sticky-zone="thead"] th {
  top: calc(var(--sticky-topbar-h) + 58px + 46px + 54px);
}

/* ═══ TABLES ═══ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: visible;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  table-layout: fixed;
}
.data-table th, .data-table td {
  padding: var(--row-pad-y) 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
  word-break: break-word;
  overflow: hidden;
}
.data-table.compact th, .data-table.compact td { padding: 7px 10px; font-size: 12.5px; }
.data-table th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { position: relative; }
.data-table tbody tr:hover td { background: var(--accent-soft); }
.data-table tr.excluded td { opacity: 0.45; text-decoration: line-through; }
.data-table tr.archived td { opacity: 0.7; }
.data-table tr.trashed > td:first-child { border-left: 3px solid var(--danger); }
.data-table tr.trashed td { opacity: 0.55; }
.data-table tr.selected td { background: var(--accent-soft) !important; }
.data-table tr.conflict td { border-left: 3px solid var(--warning); }
.data-table tr.val-verified > td:first-child { border-left: 3px solid var(--success); }
.data-table tr.val-needs_correction > td:first-child { border-left: 3px solid var(--warning); }
.data-table tr.val-false > td:first-child { border-left: 3px solid var(--danger); }
.data-table input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }

/* Largeurs colonnes */
.units-table th.col-sel, .units-table td.col-sel-cell { width: 34px; min-width: 34px; }
.units-table th.col-section, .units-table td.col-section-cell { width: 88px; min-width: 80px; }
.units-table th.col-niveau, .units-table td.col-niveau-cell { width: 66px; min-width: 60px; }
.units-table th.col-reo, .units-table td.col-reo-cell { width: 20%; min-width: 160px; }
.units-table th.col-fr, .units-table td.col-fr-cell { width: 20%; min-width: 160px; }
.units-table th.col-contenu, .units-table td.col-contenu-cell { width: 22%; min-width: 180px; }
.units-table th.col-source, .units-table td.col-source-cell { width: 124px; min-width: 100px; }
.units-table th.col-etat, .units-table td.col-etat-cell { width: 130px; min-width: 110px; }
.units-table th.col-validation, .units-table td.col-validation-cell { width: 120px; min-width: 100px; }
.units-table th.col-ai, .units-table td.col-ai-cell { width: 94px; min-width: 80px; }
.units-table th.col-editor, .units-table td.col-editor-cell { width: 140px; min-width: 120px; }
.units-table th.col-actions, .units-table td.col-actions-cell { width: 220px; min-width: 200px; text-align: right; position: relative; }

/* Permet le scroll horizontal quand le zoom / colonnes actives dépassent la largeur */
.view[data-view="units"],
.view[data-view="contributions"] { overflow-x: auto; }
.data-table { min-width: 780px; }

.contrib-table th.col-section, .contrib-table td.col-section-cell { width: 80px; }
.contrib-table th.col-niveau, .contrib-table td.col-niveau-cell { width: 60px; }
.contrib-table th.col-reo, .contrib-table td.col-reo-cell { width: 24%; }
.contrib-table th.col-fr, .contrib-table td.col-fr-cell { width: 24%; }
.contrib-table th.col-kind, .contrib-table td.col-kind-cell { width: 90px; }
.contrib-table th.col-validation, .contrib-table td.col-validation-cell { width: 110px; }
.contrib-table th.col-updated, .contrib-table td.col-updated-cell { width: 130px; }
.contrib-table th.col-actions, .contrib-table td.col-actions-cell { width: 220px; text-align: right; position: relative; }

/* Column hiding (body classes) */
body.col-sel-off .col-sel,     body.col-sel-off .col-sel-cell     { display: none !important; }
body.col-section-off .col-section, body.col-section-off .col-section-cell { display: none !important; }
body.col-niveau-off .col-niveau, body.col-niveau-off .col-niveau-cell { display: none !important; }
body.col-reo-off .col-reo,     body.col-reo-off .col-reo-cell     { display: none !important; }
body.col-fr-off .col-fr,       body.col-fr-off .col-fr-cell       { display: none !important; }
body.col-contenu-off .col-contenu, body.col-contenu-off .col-contenu-cell { display: none !important; }
body.col-source-off .col-source, body.col-source-off .col-source-cell { display: none !important; }
body.col-etat-off .col-etat,   body.col-etat-off .col-etat-cell   { display: none !important; }
body.col-validation-off .col-validation, body.col-validation-off .col-validation-cell { display: none !important; }
body.col-ai-off .col-ai,       body.col-ai-off .col-ai-cell       { display: none !important; }
body.col-editor-off .col-editor, body.col-editor-off .col-editor-cell { display: none !important; }
body.col-actions-off .col-actions, body.col-actions-off .col-actions-cell { display: none !important; }

/* Bilingual content cells */
.bi-content {
  max-height: 3.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}
.col-reo-cell .bi-content { font-style: italic; color: var(--accent); font-weight: 500; }
.col-fr-cell .bi-content { color: var(--text); }
.col-contenu-cell .bi-content { color: var(--text-muted); font-size: 12px; }

/* ═══ BATCH ACTIONS BAR ═══ */
.batch-actions {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 13px;
  gap: 12px;
}
.batch-actions[hidden] { display: none !important; }
.batch-actions #batch-info { font-weight: 600; }
.batch-actions .flex-right { display: flex; gap: 6px; flex-wrap: wrap; }
.batch-actions .ghost { background: var(--bg-elev); border-color: var(--border); padding: 6px 10px; }

/* ═══ HOVER ACTIONS (overlay boutons raccourcis) ═══ */
.hover-actions {
  display: inline-flex; gap: 2px;
  opacity: 0; transition: opacity 0.15s;
  margin-right: 4px; vertical-align: middle;
}
.data-table tbody tr:hover .hover-actions { opacity: 1; }
.hover-btn {
  padding: 4px 8px; min-width: 28px;
  font-weight: 700; font-size: 13px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}
.hover-btn.validate:hover  { border-color: var(--success); color: var(--success); background: rgba(42, 138, 74, 0.08); }
.hover-btn.needs:hover     { border-color: var(--warning); color: var(--warning); background: rgba(198, 138, 46, 0.08); }
.hover-btn.falsebtn:hover  { border-color: var(--danger);  color: var(--danger);  background: rgba(198, 55, 58, 0.08); }
.hover-btn.trashbtn:hover  { border-color: var(--danger);  color: var(--danger);  background: rgba(198, 55, 58, 0.08); }
.hover-btn.restore:hover   { border-color: var(--success); color: var(--success); background: rgba(42, 138, 74, 0.08); }

/* ═══ BADGES ═══ */
.data-table .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
  margin-right: 2px;
}
.data-table .badge.excluded { background: rgba(198, 55, 58, 0.1); color: var(--danger); }
.data-table .badge.archived { background: rgba(198, 138, 46, 0.15); color: var(--warning); }
.data-table .badge.pair    { background: rgba(42, 138, 74, 0.12); color: var(--success); }
.data-table .badge.dialog  { background: rgba(198, 138, 46, 0.12); color: var(--warning); }
.data-table .badge.conflict{ background: rgba(198, 138, 46, 0.18); color: var(--warning); }
.data-table .badge.val-verified         { background: rgba(42, 138, 74, 0.15); color: var(--success); }
.data-table .badge.val-needs_correction { background: rgba(198, 138, 46, 0.18); color: var(--warning); }
.data-table .badge.val-false            { background: rgba(198, 55, 58, 0.12); color: var(--danger); }
.data-table code { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

/* AI dots */
.ai-dots { display: inline-flex; gap: 4px; }
.ai-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  font-size: 11px; font-weight: 700; cursor: help;
}
.ai-dot.claude  { background: rgba(212, 121, 76, 0.15); color: #d4794c; }
.ai-dot.gemini  { background: rgba(61, 139, 205, 0.15); color: var(--info); }
.ai-dot.chatgpt { background: rgba(16, 163, 127, 0.15); color: #10a37f; }

/* Scroll sentinel (infinite) */
.scroll-sentinel { height: 1px; }
.muted.center { text-align: center; padding: 16px; color: var(--text-muted); font-size: 13px; }

/* ═══ GALLERY ═══ */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.gallery-item {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg);
  cursor: pointer; transition: transform 0.12s, box-shadow 0.12s;
}
.gallery-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.gallery-item img { width: 100%; height: 140px; object-fit: cover; object-position: top center; display: block; background: white; }
.gallery-item .caption { padding: 8px 12px; font-size: 12px; font-family: var(--font-mono); color: var(--text-muted); }

/* ═══ MODAL ═══ */
.modal-backdrop[hidden] { display: none !important; }
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px;
  z-index: 100;
  overflow-y: auto;
}
.modal {
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  width: 80vw; max-width: 1400px;
  padding: 0;
  animation: pop 0.18s ease-out;
}
.modal.large { width: 80vw; max-width: 1400px; }
@keyframes pop { from { transform: scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; border-bottom: 1px solid var(--border); }
.modal h3 { margin: 0; font-size: 15px; }
.modal h4 { margin: 0 0 12px; font-size: 14px; }
.modal h5 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; }
.modal .close { background: transparent; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-muted); padding: 4px 10px; }
.modal .close:hover { color: var(--danger); }
.modal form { padding: 20px 24px; }
.modal .field { margin-bottom: 14px; }
.modal .field label { display: block; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; font-weight: 600; }
.modal input[type="text"],
.modal input[type="email"],
.modal input[type="number"],
.modal input[type="password"],
.modal input[type="search"],
.modal textarea,
.modal select {
  width: 100%;
  background: var(--modal-field-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text); font: inherit;
}
.modal textarea { resize: vertical; font-family: var(--font-sans); min-height: 60px; }
.modal #m-contenu { min-height: 80px; }
.modal input[readonly] { color: var(--text-muted); background: transparent; }
.modal .field.checkbox label { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); font-weight: 400; }
.modal .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal footer { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; border-top: 1px solid var(--border); }
.modal footer .flex-right { display: flex; gap: 8px; }

/* Panneau IA rétractable dans la modal */
.ai-panel {
  background: var(--ai-panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
}
.ai-panel summary { cursor: pointer; font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; padding: 4px 0; }
.ai-panel summary::marker { color: var(--accent); }
.ai-panel[open] summary { margin-bottom: 10px; }
.ai-panel .field:last-child { margin-bottom: 0; }

/* Grille 3 IA × 3 tâches dans la modal édition */
.ai-grid {
  display: grid;
  grid-template-columns: 110px 1fr 1fr 1fr;
  gap: 8px 10px;
  align-items: stretch;
  margin-bottom: 12px;
}
.ai-grid-header {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); font-weight: 600;
  padding-bottom: 4px; border-bottom: 1px solid var(--border);
  text-align: center;
}
.ai-grid-header:first-child { border-bottom: none; }
.ai-grid-row-label {
  font-size: 12px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
  padding: 4px 0;
}
.ai-grid .field { margin-bottom: 0; display: flex; flex-direction: column; }
.ai-grid .field textarea {
  flex: 1;
  min-height: 90px;
  font-size: 12px;
  resize: vertical;
}
.ai-dot sub { font-size: 8px; font-weight: 700; margin-left: 1px; }

/* Validation bar in modal */
.validation-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px;
}
.validation-bar .validation-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.validation-bar label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }

.validation-badge-wrap { margin-bottom: 14px; }
.validation-badge-wrap .badge { display: inline-block; padding: 4px 12px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.validation-badge-wrap .badge.val-verified         { background: rgba(42, 138, 74, 0.15); color: var(--success); }
.validation-badge-wrap .badge.val-needs_correction { background: rgba(198, 138, 46, 0.18); color: var(--warning); }
.validation-badge-wrap .badge.val-false            { background: rgba(198, 55, 58, 0.12); color: var(--danger); }

/* Conflit inline dans modal */
.conflict-inline {
  background: rgba(198, 138, 46, 0.12);
  color: var(--warning);
  border-left: 3px solid var(--warning);
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-size: 13px;
}

/* Bandeau conflits */
.conflict-banner {
  background: rgba(198, 138, 46, 0.12);
  color: var(--warning);
  border: 1px solid var(--warning);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  font-size: 13px;
}
.conflict-banner[hidden] { display: none !important; }

/* ═══ SETTINGS MODAL ═══ */
.settings-layout { display: grid; grid-template-columns: 200px 1fr; min-height: 460px; }
.settings-nav {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
  padding: 16px 8px; gap: 2px;
}
.settings-tab {
  background: transparent; border: none; color: var(--text-muted);
  padding: 8px 14px; border-radius: var(--radius); text-align: left;
  font: inherit; cursor: pointer; font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.settings-tab:hover { background: var(--accent-soft); color: var(--text); }
.settings-tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.settings-content { padding: 24px; }
.settings-pane { display: none; }
.settings-pane.active { display: block; }
.settings-pane h4 { margin: 0 0 14px; font-size: 15px; }

.segment { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.segment button {
  background: transparent; border: none; color: var(--text-muted);
  padding: 7px 16px; border-right: 1px solid var(--border);
  font: inherit; cursor: pointer;
}
.segment button:last-child { border-right: none; }
.segment button.active { background: var(--accent); color: white; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.inline-form input, .inline-form select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; color: var(--text); font: inherit;
}
.apikey-display {
  margin-top: 14px;
  background: rgba(42, 138, 74, 0.08);
  border: 1px solid var(--success);
  padding: 12px 16px; border-radius: var(--radius);
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  font-size: 13px;
}
.apikey-display code { font-family: var(--font-mono); background: var(--bg-elev); padding: 6px 10px; border-radius: 4px; flex: 1; min-width: 280px; word-break: break-all; }

.smtp-info-box {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  margin-bottom: 14px;
  display: grid; gap: 8px;
}
.smtp-info-row { display: grid; grid-template-columns: 160px 1fr auto; gap: 12px; align-items: center; }
.smtp-info-row .smtp-info-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.smtp-info-row code { font-family: var(--font-mono); font-size: 12px; }

/* ═══ SCROLL-TO-TOP ═══ */
.scroll-top-btn {
  position: fixed; bottom: 24px; left: 24px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: white; border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  z-index: 150;
  transition: transform 0.15s, background 0.15s;
}
.scroll-top-btn:hover { filter: brightness(1.08); transform: translateY(-2px); }
.scroll-top-btn[hidden] { display: none !important; }

/* ═══ SCOPE CORBEILLE (filtre) ═══ */
body.scope-trash .filters { background: rgba(198, 55, 58, 0.06); border-color: rgba(198, 55, 58, 0.35); }
button#batch-hard-delete.ghost { color: var(--danger); border-color: var(--danger); }
button#batch-hard-delete.ghost:hover { background: rgba(198, 55, 58, 0.12); }

/* ═══ TOAST ═══ */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  pointer-events: none;
  font-size: 13px; max-width: 400px;
}
#toast.show { opacity: 1; transform: none; }
#toast.success { border-left: 3px solid var(--success); }
#toast.error { border-left: 3px solid var(--danger); }

.muted { color: var(--text-muted); font-size: 13px; margin: 0 0 12px; }

/* ═══ LOGIN ═══ */
.login-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, var(--bg) 0%, var(--accent-soft) 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 40px 20px; z-index: 500;
}
.login-screen[hidden] { display: none !important; }
.login-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  padding: 36px 40px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: -0.5px; }
.login-card h1 span { color: var(--text-muted); font-weight: 400; margin-left: 4px; }
.login-card .muted { margin: -4px 0 8px; }
.login-card .field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.login-card .field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text); font: inherit;
}
.login-card .field input:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent;
}
.login-card button[type="submit"] { margin-top: 6px; padding: 12px; font-weight: 600; }
.login-error {
  background: rgba(198, 55, 58, 0.1);
  border: 1px solid rgba(198, 55, 58, 0.25);
  color: var(--danger);
  padding: 8px 12px; border-radius: 6px; font-size: 13px;
}
.login-error[hidden] { display: none !important; }

/* ═══ USER BADGE / DROPDOWN ═══ */
.user-badge {
  padding: 6px 12px; border-radius: 12px;
  font-size: 12px; font-weight: 500;
  background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; gap: 6px;
  border: none; cursor: pointer;
}
.user-badge::before {
  content: ""; display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: currentColor;
}
.user-badge:hover { filter: brightness(1.05); }
.user-badge .caret { font-size: 10px; opacity: 0.7; }
.user-dropdown .dropdown-menu { min-width: 200px; padding: 6px; }
.user-dropdown .menu-item {
  background: transparent; border: none; color: var(--text);
  padding: 8px 12px; border-radius: 4px; text-align: left;
  font: inherit; cursor: pointer; width: 100%;
  transition: background 0.12s;
}
.user-dropdown .menu-item:hover { background: var(--accent-soft); }
.user-dropdown .menu-item.danger { color: var(--danger); }
.user-dropdown .menu-item.danger:hover { background: rgba(198, 55, 58, 0.08); }
.dropdown-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* Icon-only button (reload icon) */
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 34px; height: 34px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; transition: background 0.12s, border-color 0.12s;
}
.icon-btn:hover { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.icon-btn svg { display: block; }

/* ═══ ROLE-BASED HIDING ═══ */
body[data-role="contributeur"] [data-admin-only] { display: none !important; }
body[data-role="contributeur"] .col-source-cell,
body[data-role="contributeur"] th.col-source { display: none !important; }
body[data-role="contributeur"] [data-team-only] { display: none !important; }
body[data-role="team_tureo"] [data-admin-only] { display: none !important; }
body[data-role="team_tureo"] .col-source-cell,
body[data-role="team_tureo"] th.col-source { display: none !important; }

#view[hidden], #topbar[hidden] { display: none !important; }

/* Ligne du tableau cliquable (hors boutons d'action) */
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr.excluded, .data-table tbody tr.trashed { cursor: default; }
.data-table tbody .col-actions-cell,
.data-table tbody .col-sel-cell,
.data-table tbody button,
.data-table tbody input { cursor: auto; }
.data-table tbody button { cursor: pointer; }

/* Contrôle taille de police (topbar) */
.font-size-control {
  display: inline-flex; align-items: stretch;
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg);
}
.font-size-control button {
  background: transparent; border: none; color: var(--text-muted);
  padding: 5px 9px; font: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; border-right: 1px solid var(--border);
  min-width: 30px;
}
.font-size-control button:last-child { border-right: none; }
.font-size-control button:hover { background: var(--accent-soft); color: var(--accent); }
#font-reset { font-size: 11px; color: var(--text); min-width: 44px; }

/* ═══════════════════════════════════════════════════════════════════
   MODALE — mode édition à la chaîne : footer sticky + scroll compact
   ═══════════════════════════════════════════════════════════════════ */
.modal-backdrop { padding: 20px 20px; }
.modal {
  display: flex; flex-direction: column;
  max-height: calc(100vh - 40px);
  overflow: hidden;
}
.modal header { flex: 0 0 auto; }
.modal form {
  display: flex; flex-direction: column;
  flex: 1 1 auto; min-height: 0;
  padding: 0;
}
.modal-body {
  overflow-y: auto; overflow-x: hidden;
  padding: 16px 24px;
  flex: 1 1 auto; min-height: 0;
  background: var(--modal-body-bg);
}
.modal-body .field { margin-bottom: 12px; }
.modal footer {
  flex: 0 0 auto;
  position: sticky; bottom: 0; z-index: 5;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  box-shadow: 0 -6px 14px -8px rgba(0, 0, 0, 0.18);
}

/* ═══════════════════════════════════════════════════════════════════
   BOUTONS VALIDATION — grands, colorés, sélectionnables (travail à la chaîne)
   ═══════════════════════════════════════════════════════════════════ */
.validation-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: transparent;
  border: none;
  padding: 0;
  margin-bottom: 12px;
}
.validation-bar .validation-label {
  grid-column: 1 / -1;
  color: var(--text-muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.5px;
  font-weight: 600; margin-bottom: 2px;
}
.val-tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: 8px 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--modal-field-bg);
  color: var(--text-muted);
  cursor: pointer;
  font: inherit; font-weight: 600; font-size: 13px;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.val-tile:hover { border-color: var(--text-muted); color: var(--text); }
.val-tile .ico { font-size: 18px; line-height: 1; }
.val-tile .label { font-size: 12px; }
.val-tile input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.val-tile.selected { transform: translateY(-1px); box-shadow: 0 3px 10px -3px rgba(0, 0, 0, 0.2); }
.val-tile[data-val="verified"].selected  { background: rgba(42, 138, 74, 0.18); border-color: var(--success); color: var(--success); }
.val-tile[data-val="needs_correction"].selected { background: rgba(198, 138, 46, 0.22); border-color: var(--warning); color: var(--warning); }
.val-tile[data-val="false"].selected  { background: rgba(198, 55, 58, 0.18); border-color: var(--danger); color: var(--danger); }
.val-tile[data-val=""].selected { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.val-tile[data-val="verified"]:hover:not(.selected)  { border-color: var(--success); color: var(--success); }
.val-tile[data-val="needs_correction"]:hover:not(.selected) { border-color: var(--warning); color: var(--warning); }
.val-tile[data-val="false"]:hover:not(.selected)  { border-color: var(--danger); color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════════
   BOUTONS ÉTAT — archiver / exclure / corbeille (remplacent les checkboxes)
   ═══════════════════════════════════════════════════════════════════ */
.state-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.state-bar .state-label {
  grid-column: 1 / -1;
  color: var(--text-muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.5px;
  font-weight: 600; margin-bottom: 2px;
}
.state-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 6px 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--modal-field-bg);
  color: var(--text-muted);
  cursor: pointer;
  font: inherit; font-weight: 600; font-size: 12px;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.state-tile:hover { border-color: var(--text-muted); color: var(--text); }
.state-tile .ico { font-size: 16px; line-height: 1; }
.state-tile input[type="checkbox"] { position: absolute; opacity: 0; pointer-events: none; }
.state-tile[data-state="archived"].active { background: rgba(155, 142, 250, 0.16); border-color: var(--accent); color: var(--accent); }
.state-tile[data-state="excluded"].active { background: rgba(198, 138, 46, 0.2); border-color: var(--warning); color: var(--warning); }
.state-tile[data-state="deleted"].active  { background: rgba(198, 55, 58, 0.18); border-color: var(--danger); color: var(--danger); }
.state-tile[data-state="archived"]:hover:not(.active) { border-color: var(--accent); color: var(--accent); }
.state-tile[data-state="excluded"]:hover:not(.active) { border-color: var(--warning); color: var(--warning); }
.state-tile[data-state="deleted"]:hover:not(.active)  { border-color: var(--danger); color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════════
   GLOBAL IA WIDGET — éditeur visuel pour ai_global_* (verdict / raison / reclass)
   ═══════════════════════════════════════════════════════════════════ */
.global-widget {
  display: flex; flex-direction: column;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--bg);
  font-size: 11px;
}
.global-widget.v-ok              { border-left: 3px solid var(--success); }
.global-widget.v-needs_correction { border-left: 3px solid var(--warning); }
.global-widget.v-false           { border-left: 3px solid var(--danger); }
.gw-verdicts { display: flex; gap: 4px; }
.gw-verdict-btn {
  flex: 1; padding: 5px 4px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg-elev); color: var(--text-muted);
  font: inherit; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.3px;
  cursor: pointer;
  transition: all 0.1s;
}
.gw-verdict-btn:hover { color: var(--text); border-color: var(--text-muted); }
.gw-verdict-btn[data-v="ok"].active              { background: var(--success); border-color: var(--success); color: white; }
.gw-verdict-btn[data-v="needs_correction"].active { background: var(--warning); border-color: var(--warning); color: white; }
.gw-verdict-btn[data-v="false"].active           { background: var(--danger); border-color: var(--danger); color: white; }
.gw-row { display: flex; gap: 4px; align-items: center; }
.gw-row input, .gw-row select, .gw-row textarea {
  flex: 1; font-size: 11px; padding: 4px 6px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg-elev); color: var(--text); font-family: inherit;
  min-width: 0;
}
.gw-row textarea { resize: vertical; min-height: 28px; font-family: inherit; }
.gw-row .gw-lbl { color: var(--text-muted); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.3px; font-weight: 600; min-width: 42px; }
.gw-toolbar { display: flex; justify-content: flex-end; gap: 4px; margin-top: 2px; }
.gw-btn-icon {
  background: transparent; border: 1px solid var(--border); color: var(--text-muted);
  padding: 2px 6px; border-radius: 4px; font-size: 10px; cursor: pointer;
}
.gw-btn-icon:hover { border-color: var(--text-muted); color: var(--text); }
.gw-btn-icon.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.global-widget.mode-json .gw-visual { display: none; }
.global-widget:not(.mode-json) .gw-json { display: none; }
.gw-json textarea {
  width: 100%; min-height: 80px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 4px;
  padding: 6px 8px; font-family: var(--font-mono, monospace); font-size: 11px; color: var(--text);
  resize: vertical;
}
.gw-parse-error {
  color: var(--danger); font-size: 10px; padding: 2px 4px;
  background: rgba(198, 55, 58, 0.08); border-radius: 3px;
}

/* Widget global occupe toute la hauteur de la cellule grille */
.ai-grid .field > .global-widget { height: 100%; }
