/* =====================================================================
   XerOCR — coquille. Tokens + chrome de l'app, rendu serveur.
   Polices AUTO-HÉBERGÉES (aucun CDN, CSP font-src 'self') — rôles :
     titres   = Mona Sans (OFL)
     corps/UI = IBM Plex Sans (OFL)
     données  = IBM Plex Mono (OFL)
     accents  = Fluxisch Else (OFL)
     logo     = OCR-A (domaine public)
   Réf. visuelle : design/.
   ===================================================================== */

/* ---- Polices auto-hébergées (servies sous /static/fonts) ---- */
@font-face {
  font-family: 'Mona Sans VF';
  src: url('/static/fonts/MonaSansVF-opsz-wght.woff2') format('woff2');
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: 'Fluxisch Else';
  src: url('/static/fonts/FluxischElse-Light.woff2') format('woff2');
  font-weight: 300;
  font-display: swap;
}
@font-face {
  font-family: 'Fluxisch Else';
  src: url('/static/fonts/FluxischElse-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Fluxisch Else';
  src: url('/static/fonts/FluxischElse-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'OCRA';
  src: url('/static/fonts/OCRA.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/static/fonts/IBMPlexSans-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/static/fonts/IBMPlexSans-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/static/fonts/IBMPlexSans-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/static/fonts/IBMPlexMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/static/fonts/IBMPlexMono-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}

:root {
  /* Greyscale (warm) */
  --paper:    #EBE8E0;
  --surface:  #F4F1EA;
  --raised:   #FBFAF6;
  --raised-2: #FFFFFF;
  --g-50:  #E4E0D7;
  --g-100: #D6D2C8;
  --g-150: #C2BEB3;
  --g-200: #ADA89C;
  --g-300: #8D8879;
  --g-400: #6F6B60;
  --g-500: #54514A;
  --g-600: #3A3833;
  --g-700: #26241F;
  --g-800: #181714;
  --ink:   #1A1917;

  /* Accents */
  --fern:      oklch(0.50 0.07 145);
  --fern-soft: oklch(0.92 0.03 145);
  --fern-deep: oklch(0.36 0.07 145);

  --slate:      oklch(0.50 0.05 240);
  --slate-soft: oklch(0.92 0.02 240);
  --slate-deep: oklch(0.36 0.05 240);

  --clay:      oklch(0.58 0.10 45);
  --clay-soft: oklch(0.92 0.035 45);
  --clay-deep: oklch(0.42 0.10 45);

  --butter:      oklch(0.78 0.09 90);
  --butter-soft: oklch(0.94 0.04 90);
  --butter-deep: oklch(0.52 0.09 90);

  /* Extension à 10 couleurs (classement des moteurs par rang CER, comme le
     Picarones live) — rangs 5-9, daltonien-safe provisoire. */
  --amethyst:      oklch(0.55 0.10 300);
  --amethyst-soft: oklch(0.92 0.03 300);
  --amethyst-deep: oklch(0.40 0.10 300);
  --teal:          oklch(0.55 0.08 195);
  --teal-soft:     oklch(0.92 0.02 195);
  --teal-deep:     oklch(0.40 0.08 195);
  --vermillion:      oklch(0.55 0.12 25);
  --vermillion-soft: oklch(0.92 0.04 25);
  --vermillion-deep: oklch(0.40 0.12 25);
  --olive:      oklch(0.55 0.07 115);
  --olive-soft: oklch(0.92 0.03 115);
  --olive-deep: oklch(0.40 0.07 115);
  --rose:      oklch(0.62 0.08 350);
  --rose-soft: oklch(0.92 0.03 350);
  --rose-deep: oklch(0.45 0.08 350);

  --warn: var(--butter-deep);
  --err:  oklch(0.55 0.14 28);

  /* Familles — rôles : titres Mona Sans, corps IBM Plex Sans,
     données IBM Plex Mono, accents Fluxisch Else, logo OCR-A. */
  --display: 'Mona Sans VF', 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --accent:  'Fluxisch Else', Georgia, serif;
  --ocr:     'OCRA', 'IBM Plex Mono', ui-monospace, monospace;
  --sans:    'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono:    'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;

  /* Ombres légères et feuilletées — valeurs exactes de picarones.css live. */
  --shadow-sm: 0 1px 2px rgba(26, 25, 23, 0.04);
  --shadow:    0 1px 3px rgba(26, 25, 23, 0.05), 0 4px 14px rgba(26, 25, 23, 0.04);
  --ring: 0 0 0 3px rgba(58, 90, 64, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='3' height='3' viewBox='0 0 3 3'><circle cx='0.75' cy='0.75' r='0.6' fill='%231a1917' fill-opacity='0.28'/></svg>");
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--ink); color: var(--paper); }
a { color: inherit; text-decoration: none; }

/* Accessibilité : anneau de focus net et visible au clavier. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--fern-deep);
  outline-offset: 2px;
  box-shadow: var(--ring);
}

/* === App shell === */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

/* === Left rail === */
.rail {
  padding: 22px 18px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}
.wordmark-card {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--r-lg);
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wordmark {
  font-family: var(--ocr);
  font-size: 21px;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.01em;
}
.wordmark .mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: var(--r-pill);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 700;
  font-size: 12px;
}
.wordmark-sub {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: rgba(239, 237, 232, 0.55);
}

/* === Nav (pill items) — tous les emplacements réservés === */
.rail-nav-window {
  background: var(--raised);
  border-radius: var(--r-lg);
  padding: 10px 8px;
  box-shadow: var(--shadow-sm);
}
.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--r-pill);
  color: var(--g-500);
  transition: background 0.15s, color 0.15s;
  min-width: 0;
}
.nav-item:hover {
  background: var(--g-50);
  color: var(--ink);
}
.nav-item.active { background: var(--ink); color: var(--paper); }
.nav-glyph {
  width: 22px; height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-glyph svg { width: 16px; height: 16px; }
.nav-label { font-size: 14px; font-weight: 500; letter-spacing: 0; flex: 1; min-width: 0; }
.nav-meta {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.04em;
  color: var(--g-400);
  text-transform: uppercase;
}
.nav-item.active .nav-meta { color: rgba(239, 237, 232, 0.55); }

/* === System block === */
.rail-system {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 4px 4px 0;
}
.sys-card {
  background: var(--raised);
  border-radius: var(--r-lg);
  padding: 14px 15px;
  box-shadow: var(--shadow-sm);
}
.pipeline-stat {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.pipeline-value {
  font-family: var(--display);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.pipeline-copy {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--g-400);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.pipeline-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.sys-card-title {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--g-400);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px dotted var(--g-100);
  padding-bottom: 8px;
}
.sys-row { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; font-size: 11.5px; min-width: 0; }
.sys-row .k { color: var(--g-400); }
.sys-row .v { color: var(--ink); font-weight: 500; font-family: var(--mono); overflow-wrap: anywhere; text-align: right; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--g-150); }
.dot.on { background: var(--fern); }

/* === Lang toggle (pill) === */
.rail-foot { padding: 8px 4px 0; display: flex; justify-content: space-between; align-items: center; }
.foot-meta { font-family: var(--mono); font-size: 10px; color: var(--g-300); }
.lang-toggle { display: inline-flex; background: var(--raised); border-radius: var(--r-pill); padding: 3px; }
.lang-toggle a {
  padding: 5px 12px;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--g-400);
  border-radius: var(--r-pill);
}
.lang-toggle a.on { background: var(--ink); color: var(--paper); }

/* === Main column === */
.main {
  min-width: 0;
  padding: 22px 28px 64px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* === View hero === */
.view-hero {
  background: var(--raised);
  border-radius: var(--r-lg);
  padding: 24px 28px 22px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.view-hero-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: min(520px, 100%);
}
.view-hero-eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--g-400);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.view-hero-name {
  font-family: var(--display);
  font-size: 36px;
  font-weight: 700;
  font-optical-sizing: auto;
  letter-spacing: -0.03em;
  line-height: 1.02;
  margin-top: 4px;
  overflow-wrap: anywhere;
}
.view-hero-desc { font-family: var(--accent); font-style: italic; font-size: 15px; color: var(--g-500); max-width: 60ch; margin-top: 8px; overflow-wrap: anywhere; }
.hero-stat { text-align: right; }
.view-hero-stats {
  display: flex;
  gap: 22px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.hero-stat .v {
  font-family: var(--display);
  font-size: 28px;
  font-weight: 700;
  font-optical-sizing: auto;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-muted { color: var(--g-300); }
.hero-stat .k {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--g-400);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* === Sections et primitives communes === */
.sec {
  background: var(--raised);
  border-radius: var(--r-lg);
  padding: 22px 26px 24px;
  position: relative;
}
.sec-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.sec-copy {
  flex: 1;
  min-width: 0;
}
.sec-title {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  font-optical-sizing: auto;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.sec-sub {
  font-family: var(--accent);
  font-style: italic;
  font-size: 13px;
  color: var(--g-400);
  margin-top: 2px;
  overflow-wrap: anywhere;
}
.sec-aside {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--g-400);
  padding-top: 4px;
  white-space: nowrap;
}
.sec-body { min-width: 0; }
.panel {
  background: var(--raised-2);
  border-radius: var(--r-md);
  padding: 16px 18px;
  min-width: 0;
  box-shadow: inset 0 0 0 1px rgba(26, 25, 23, 0.03);
}
.label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--g-400);
}
.mono { font-family: var(--mono); }
.empty {
  padding: 30px 16px;
  text-align: center;
  font-family: var(--accent);
  font-style: italic;
  font-size: 13.5px;
  color: var(--g-400);
}

/* === Reports section === */
.report-list { display: flex; flex-direction: column; gap: 8px; }
.report-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  transition: box-shadow 0.15s, transform 0.05s;
}
.report-row:hover { box-shadow: var(--shadow); }
.report-row:active { transform: translateY(1px); }
.report-row .r-name {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.report-row .r-open {
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--g-500);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* === Actions et formulaires === */
.btn {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  padding: 9px 18px;
  border: none;
  background: var(--g-50);
  color: var(--ink);
  cursor: pointer;
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
  text-decoration: none;
  min-height: 34px;
  justify-content: center;
  text-align: center;
  overflow-wrap: anywhere;
}
.btn:hover { background: var(--g-100); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--g-700); }
.btn-sm { padding: 6px 12px; font-size: 11.5px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* === Launcher (Banc d'essai) === */
.corpus-select-card {
  min-height: 150px;
  justify-content: space-between;
}
.corpus-select-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.run-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.stack-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.select,
.input {
  font-family: var(--sans);
  font-size: 13px;
  padding: 9px 14px;
  border: none;
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  max-width: 100%;
}
.select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--g-400) 50%),
    linear-gradient(135deg, var(--g-400) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.input { min-width: 220px; }
.import-fields { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.run-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.run-status {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--ink);
  background: var(--surface);
  padding: 4px 12px;
  border-radius: var(--r-pill);
}
.run-status:empty { display: none; }
.run-result { min-height: 1px; }
.run-result:empty { display: none; }

/* Barre de progression (document × concurrent) — pilotée par le flux SSE. */
.run-progress { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.run-progress .progress { flex: 1; }
.progress {
  background: var(--g-50);
  height: 8px;
  border-radius: var(--r-pill);
  overflow: hidden;
}
.progress-bar {
  width: 0;
  height: 100%;
  background: var(--fern);
  border-radius: var(--r-pill);
  transition: width 0.3s ease;
}
.run-progress-text {
  font-size: 11.5px;
  color: var(--g-500);
  white-space: nowrap;
}
.run-log {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--g-600);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 12px 14px;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
}
.run-log:empty::before { content: "—"; color: var(--g-300); }
.run-log-shell {
  border-top: 1px solid var(--g-100);
  padding-top: 12px;
}
.run-log-shell summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--g-400);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* === Segmentation (canevas SVG des régions) === */
.seg-canvas {
  display: flex;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--g-100);
  border-radius: var(--r-md);
  padding: 16px;
}
.seg-canvas .seg-svg {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-sm);
}

/* === Moteurs (table d'état) === */
table.engines { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 13px; }
table.engines th {
  text-align: left;
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--g-400);
  font-weight: 500;
  padding: 8px 12px;
  border-bottom: 1px solid var(--g-100);
}
table.engines td { padding: 11px 12px; border-bottom: 1px solid var(--g-50); }
table.engines tr:last-child td { border-bottom: none; }
table.engines .eng-name { font-weight: 500; color: var(--ink); }
table.engines .eng-kind {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--g-300);
  margin-left: 6px;
}
table.engines .eng-detail { font-size: 12px; color: var(--g-500); }
.dot.off { background: var(--g-150); }

/* === Tables de données (corpus, catalogues, historique) === */
table.data { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--g-400);
  font-weight: 500;
  padding: 8px 12px;
  border-bottom: 1px solid var(--g-100);
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--g-50); }
table.data tr:last-child td { border-bottom: none; }
table.data a { color: var(--fern-deep); font-weight: 500; }
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* === Badge === */
.badge {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--g-500);
  background: var(--g-50);
  padding: 3px 8px;
  border-radius: var(--r-pill);
  margin-left: 8px;
  vertical-align: middle;
  white-space: nowrap;
}

/* === Cartes corpus (« Mes corpus ») === */
.corpus-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.corpus-card .c-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  word-break: break-word;
  overflow-wrap: anywhere;
}
.corpus-card .c-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--g-400);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.corpus-card .c-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}
.c-del {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--g-400);
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: var(--r-sm);
}
.c-del:hover { color: var(--err); background: var(--g-50); }
.c-del:disabled { opacity: 0.5; cursor: default; }

/* === Dropzone (upload ZIP) === */
.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 280px;
  min-height: 84px;
  padding: 16px 20px;
  border: none;
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--g-400);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, color 0.15s;
  max-width: 100%;
}
.dropzone:hover { background: var(--raised-2); color: var(--ink); }
.dropzone.is-dragover {
  background: var(--fern-soft);
  color: var(--fern-deep);
}
.dropzone input[type="file"] { display: none; }
.dropzone-hint { font-size: 12.5px; }
.dropzone-large {
  min-height: 210px;
  flex-direction: column;
  gap: 10px;
}
.dropzone-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--g-300);
}

/* === Bibliothèque : organisation produit === */
.tabs {
  display: inline-flex;
  align-self: flex-start;
  background: var(--surface);
  border-radius: var(--r-pill);
  padding: 4px;
  gap: 2px;
}
.tabs a,
.tabs button {
  border: 0;
  background: transparent;
  color: var(--g-500);
  border-radius: var(--r-pill);
  padding: 8px 18px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.tabs a.on,
.tabs button.on { background: var(--ink); color: var(--paper); }
.tabs a:hover:not(.on),
.tabs button:hover:not(.on) { color: var(--ink); background: var(--g-50); }

.library-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.library-local-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
  gap: 14px;
  align-items: stretch;
}
.stack-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stack-title {
  font-family: var(--display);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.stack-sub {
  font-family: var(--accent);
  font-style: italic;
  font-size: 13px;
  color: var(--g-400);
}
.upload-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.upload-panel-empty {
  max-width: 760px;
}
.empty-panel {
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--g-400);
  border: 1px dashed var(--g-100);
}
.corpus-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.corpus-stack-head {
  padding: 4px 2px 0;
}
.corpus-card .c-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.corpus-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 12px;
}
.corpus-detail {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.corpus-preview,
.result-card-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.preview-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--g-500);
  font-family: var(--mono);
  font-size: 10.5px;
}
.detail-line {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--g-500);
}

.source-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  color: var(--g-500);
  border-radius: var(--r-pill);
  padding: 10px 16px 10px 10px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  min-width: 0;
  overflow-wrap: anywhere;
}
.source-chip:hover { background: var(--g-50); color: var(--ink); }
.source-chip.on { background: var(--ink); color: var(--paper); }
.src-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.03em;
}
.source-chip.on .src-glyph {
  background: var(--paper);
  color: var(--ink);
}
.src-count {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--g-300);
  letter-spacing: 0.04em;
}
.source-chip.on .src-count { color: rgba(239, 237, 232, 0.7); }
.source-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 16px;
}
.source-shell,
.import-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.source-headline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.catalog-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.result-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.result-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.result-card-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.result-card-meta {
  margin-top: 4px;
  color: var(--g-400);
  font-size: 12px;
}
.result-card-copy {
  color: var(--g-500);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.result-card-actions,
.import-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.result-card-actions .btn,
.import-actions .btn {
  min-width: 160px;
}
.import-actions {
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--g-100);
}
.input-wide { min-width: min(520px, 100%); }

/* === Recherche (catalogues) === */
.search {
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-input {
  flex: 1;
  min-width: min(280px, 100%);
}
.library-search {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 12px;
}

/* === Composeur (Banc d'essai : file de concurrents) === */
.composer-shell { display: flex; flex-direction: column; gap: 12px; }
.queue-list { display: flex; flex-direction: column; gap: 10px; }
.composer-draft {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
  gap: 12px;
}
.comp-field { display: flex; flex-direction: column; gap: 4px; }
.comp-label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--g-400);
}
.comp-field .select,
.comp-field .input { min-width: 0; width: 100%; }
.comp-field-prompt { grid-column: 1 / -1; }
.comp-prompt {
  border-radius: var(--r-md);
  resize: vertical;
  min-height: 64px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
}
.queue-panel {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 188px;
}
.queue-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--g-100);
}
.queue-row:last-child { border-bottom: none; padding-bottom: 0; }
.queue-id {
  color: var(--g-400);
  font-size: 11px;
}
.queue-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.queue-label {
  font-weight: 600;
  color: var(--ink);
}
.queue-meta {
  color: var(--g-400);
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* === Sparklines / tendances (Historique) === */
.trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.trend-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.trend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.trend-head .t-pipe { font-weight: 600; font-size: 13px; color: var(--ink); overflow-wrap: anywhere; }
.trend-spark { color: var(--fern-deep); }
.trend-spark .spark { width: 100%; height: 30px; display: block; }
.trend-meta { display: flex; gap: 12px; font-size: 10.5px; color: var(--g-400); }

@media (max-width: 900px) {
  .view-hero-stats {
    justify-content: flex-start;
  }
  .library-local-grid {
    grid-template-columns: 1fr;
  }
  .corpus-detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    position: static;
    height: auto;
    overflow: visible;
    padding: 18px 18px 12px;
  }
  .rail-nav-window {
    padding: 8px;
    overflow: hidden;
  }
  .rail-nav {
    flex-direction: row;
    overflow-x: auto;
    scroll-padding: 8px;
  }
  .nav-item {
    flex: 0 0 auto;
    min-width: 136px;
  }
  .rail-system {
    flex: none;
    overflow: visible;
  }
  .main { padding: 0 18px 48px; }
  .view-hero,
  .sec { border-radius: var(--r-md); padding: 20px; }
  .view-hero-name { font-size: 32px; }
  .hero-stat { text-align: left; }
  .sec-head { align-items: flex-start; flex-direction: column; }
  .sec-aside { white-space: normal; }
  .report-row,
  .c-actions,
  .run-line,
  .queue-row {
    align-items: stretch;
    flex-direction: column;
  }
  .btn,
  .select {
    width: 100%;
  }
  .corpus-select-row {
    grid-template-columns: 1fr;
  }
  .search { align-items: stretch; flex-direction: column; }
  .search-input,
  .input,
  .dropzone,
  .comp-field,
  .comp-field .select,
  .comp-field .input {
    min-width: 100%;
  }
  .source-switch {
    display: grid;
    grid-template-columns: 1fr;
  }
  .source-chip {
    width: 100%;
  }
  .import-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
