/* =========================================================================
   Archive — feuille de style
   Palette : neutres légèrement chauds (papier) + un seul accent encre-vert.
   Densité : confortable (44 px de hauteur de ligne au doigt, 40 px à la souris).
   Tous les espacements sont pris sur l'échelle 4 px.
   ========================================================================= */

:root {
  color-scheme: light dark;

  /* échelle d'espacement */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px; --s5: 20px;
  --s6: 24px; --s7: 32px; --s8: 40px; --s9: 48px; --s10: 64px;

  /* rayons — varient avec la taille de l'élément */
  --r-sm: 4px; --r-md: 7px; --r-lg: 11px; --r-full: 999px;

  /* couleurs */
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-sunken: #f1efea;
  --border: #e2ded5;
  --border-strong: #cbc5b9;
  --text: #1b1917;
  --text-muted: #5c5750;
  --text-subtle: #726b61;
  --accent: #0f6b6b;
  --accent-hover: #0b5555;
  --accent-fg: #ffffff;
  --accent-wash: #e6f0ef;
  --danger: #a4352b;
  --warning: #8a5a10;
  --warning-wash: #fbf2e0;
  --success: #2b6a44;

  --shadow-sm: 0 1px 2px rgba(27, 25, 23, .06);
  --shadow-md: 0 4px 14px -4px rgba(27, 25, 23, .13);
  --shadow-lg: 0 18px 40px -12px rgba(27, 25, 23, .22);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --ease-in: cubic-bezier(.4, 0, 1, 1);
  --ease-out: cubic-bezier(.2, 0, 0, 1);

  --sidebar-w: 264px;
  --header-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131211;
    --surface: #1c1a18;
    --surface-sunken: #100f0e;
    --border: #33302b;
    --border-strong: #4a463f;
    --text: #ece8e1;
    --text-muted: #a69f93;
    --text-subtle: #8f887c;
    --accent: #5cbcb0;
    --accent-hover: #7bcfc4;
    --accent-fg: #0b2320;
    --accent-wash: #1d2e2c;
    --danger: #e8867a;
    --warning: #d9a64a;
    --warning-wash: #2b2418;
    --success: #79c795;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 14px -4px rgba(0, 0, 0, .55);
    --shadow-lg: 0 18px 40px -12px rgba(0, 0, 0, .7);
  }
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: 24px; letter-spacing: -.015em; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p  { margin: 0; }
a  { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent-wash); }

.tnum { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- layout */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100dvh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s5) var(--s5) var(--s4);
}
.brand-mark {
  width: 30px; height: 30px; flex: none;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-fg);
  display: grid; place-items: center;
  font-weight: 600; font-size: 13px;
}
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.brand-sub  { font-size: 12px; color: var(--text-subtle); }

.nav { padding: 0 var(--s3); display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: 9px var(--s3);
  border: 0; border-radius: var(--r-md);
  background: none; color: var(--text-muted);
  font: inherit; font-size: 14px; text-align: left;
  cursor: pointer; width: 100%;
  transition: background 130ms var(--ease-out), color 130ms var(--ease-out);
}
.nav-item:hover { background: var(--surface-sunken); color: var(--text); }
.nav-item[aria-current="page"] {
  background: var(--accent-wash); color: var(--accent); font-weight: 550;
}
.nav-item .count {
  margin-left: auto; font-size: 12px; color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}
.nav-item[aria-current="page"] .count { color: var(--accent); }

.facets { padding: var(--s6) var(--s3) var(--s8); }
.facet-group + .facet-group { margin-top: var(--s6); }
.facet-title {
  font-size: 11px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-subtle);
  padding: 0 var(--s3) var(--s2);
}
.facet-item {
  display: flex; align-items: center; gap: var(--s2);
  width: 100%; padding: 6px var(--s3);
  border: 0; border-radius: var(--r-sm); background: none;
  font: inherit; font-size: 13.5px; color: var(--text-muted);
  cursor: pointer; text-align: left;
}
.facet-item:hover { background: var(--surface-sunken); color: var(--text); }
.facet-item.on { background: var(--accent-wash); color: var(--accent); font-weight: 550; }
.facet-item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet-item .count { margin-left: auto; font-size: 12px; color: var(--text-subtle); font-variant-numeric: tabular-nums; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s6);
  min-height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.content { padding: var(--s6); flex: 1; }
.content-narrow { max-width: 760px; }

/* --------------------------------------------------------------- recherche */
.searchbox { position: relative; flex: 1; min-width: 0; }
.searchbox svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-subtle); pointer-events: none;
}
.searchbox input {
  width: 100%; height: 40px;
  padding: 0 var(--s8) 0 38px;
  font: inherit; font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color 130ms var(--ease-out), box-shadow 130ms var(--ease-out);
}
.searchbox input::placeholder { color: var(--text-subtle); }
.searchbox input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent);
}
.searchbox kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font: 500 11px/1 var(--mono); color: var(--text-subtle);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 4px 6px; background: var(--surface-sunken);
}

/* --------------------------------------------------------------- boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s2);
  height: 36px; padding: 0 var(--s4);
  font: inherit; font-size: 14px; font-weight: 550;
  border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background 130ms var(--ease-out), border-color 130ms var(--ease-out),
              transform 90ms var(--ease-out);
}
.btn:hover  { background: var(--surface-sunken); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-fg);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { border-color: transparent; background: none; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-sunken); color: var(--text); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.btn-sm { height: 30px; padding: 0 var(--s3); font-size: 13px; }
.btn-icon { width: 36px; padding: 0; }

/* --------------------------------------------------------------- résultats */
.results { display: flex; flex-direction: column; }

.result {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: var(--s3);
  align-items: start;
  width: 100%;
  padding: var(--s3) var(--s3);
  border: 0; border-bottom: 1px solid var(--border);
  border-radius: 0; background: none;
  font: inherit; text-align: left; color: inherit;
  cursor: pointer;
  transition: background 110ms var(--ease-out);
}
.result:hover { background: var(--surface); }
.result[aria-selected="true"] { background: var(--accent-wash); }

.result-icon {
  width: 34px; height: 42px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface);
  display: grid; place-items: center;
  color: var(--text-subtle); font-size: 10px; font-weight: 600;
  letter-spacing: .02em;
}

.result-title {
  /* display:block est indispensable : overflow/ellipsis n'a aucun effet sur un
     élément inline, et le titre chevauchait la colonne de droite. */
  display: block;
  font-weight: 550; font-size: 14.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.result-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2);
  margin-top: 3px;
  font-size: 12.5px; color: var(--text-muted);
}
.result-meta .dot { color: var(--border-strong); }
.result-tags { display: inline-flex; flex-wrap: wrap; gap: var(--s2); }
.result-side {
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  font-size: 12.5px; color: var(--text-muted); white-space: nowrap;
}
.result-amount { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit;
       border-radius: 2px; padding: 0 1px; }

/* ------------------------------------------------------------------ tags */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px;
  font-size: 11.5px; font-weight: 500; line-height: 18px;
  border-radius: var(--r-full);
  background: var(--surface-sunken); color: var(--text-muted);
  border: 1px solid var(--border);
}
.tag-sphere { background: var(--accent-wash); color: var(--accent); border-color: transparent; }
.tag-cycle  { background: var(--warning-wash); color: var(--warning); border-color: transparent; }
.tag button { all: unset; cursor: pointer; opacity: .6; padding-left: 2px; }
.tag button:hover { opacity: 1; }

.pill-review {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600;
  color: var(--warning);
}
.pill-review::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--warning);
}

/* ----------------------------------------------------------------- cartes */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s5);
}
.card + .card { margin-top: var(--s4); }
.card-title { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: var(--s3); }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); }
.stat { padding: var(--s4) var(--s5); background: var(--surface);
        border: 1px solid var(--border); border-radius: var(--r-lg); }
.stat-value { font-size: 28px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--text-subtle); margin-top: 2px; }
.stat.is-warning .stat-value { color: var(--warning); }

/* Barres horizontales : lisibles de 2 à 20 années, sur 375 px comme sur
   1440 px, et restituées comme un tableau par un lecteur d'écran. */
.yearbars { width: 100%; border-collapse: collapse; }
.yearbars th {
  text-align: left; font-weight: 500; font-size: 13px;
  color: var(--text-muted); padding: 3px var(--s3) 3px 0;
  width: 52px; font-variant-numeric: tabular-nums;
}
.yearbars td { padding: 3px 0; }
.yearbar {
  display: block; height: 16px; border-radius: 3px;
  background: var(--accent); opacity: .85; min-width: 3px;
}
.yearbar-n { width: 46px; text-align: right; font-size: 13px; color: var(--text-muted);
             padding-left: var(--s3) !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ fiche */
.detail { display: grid; grid-template-columns: 1fr 380px; gap: 0; min-height: 0; flex: 1; }
.detail-viewer { background: var(--surface-sunken); display: flex; flex-direction: column; min-width: 0; }
.detail-viewer iframe { flex: 1; width: 100%; border: 0; background: var(--surface-sunken); }
.detail-panel { border-left: 1px solid var(--border); background: var(--surface);
                overflow-y: auto; padding: var(--s5); }

.field { margin-bottom: var(--s4); }
.field label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-muted);
  margin-bottom: var(--s1);           /* < écart entre deux champs : var(--s4) */
}
.field input, .field select, .field textarea {
  width: 100%; height: 36px; padding: 0 10px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color 130ms var(--ease-out), box-shadow 130ms var(--ease-out);
}
.field textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.field-hint { font-size: 12px; color: var(--text-subtle); margin-top: var(--s1); }

.kv { display: grid; grid-template-columns: 108px 1fr; gap: var(--s2) var(--s3); font-size: 13.5px; }
.kv dt { color: var(--text-subtle); }
.kv dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }

/* --------------------------------------------------------------- dépôt */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  padding: var(--s10) var(--s6);
  text-align: center;
  background: var(--surface);
  transition: border-color 140ms var(--ease-out), background 140ms var(--ease-out);
}
.dropzone.over { border-color: var(--accent); background: var(--accent-wash); }
.dropzone h2 { margin-bottom: var(--s2); }

.job {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) 0; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.job-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-step { font-size: 12.5px; color: var(--text-subtle); }
.job.err .job-step { color: var(--danger); }
.job.ok  .job-step { color: var(--success); }

.spinner {
  width: 14px; height: 14px; flex: none;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- états */
.empty {
  text-align: center; padding: var(--s10) var(--s6);
  max-width: 420px; margin: 0 auto;
}
.empty-icon { color: var(--text-subtle); margin-bottom: var(--s4); }
.empty h2 { margin-bottom: var(--s2); }
.empty p  { color: var(--text-muted); font-size: 14px; margin-bottom: var(--s5); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-sunken) 25%,
              color-mix(in srgb, var(--surface-sunken) 60%, var(--border)) 50%,
              var(--surface-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-row { display: grid; grid-template-columns: 34px 1fr; gap: var(--s3);
            padding: var(--s3); border-bottom: 1px solid var(--border); }

.banner {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4); border-radius: var(--r-md);
  font-size: 13.5px; margin-bottom: var(--s4);
  border: 1px solid var(--border);
  background: var(--surface);
}
.banner.warn { background: var(--warning-wash); border-color: transparent; color: var(--warning); }
.banner.err  { background: color-mix(in srgb, var(--danger) 10%, transparent);
               border-color: transparent; color: var(--danger); }

/* ------------------------------------------------------------- assistant */
.ask-answer { font-size: 15px; line-height: 1.65; white-space: pre-wrap; }
.ask-answer .cite {
  display: inline-block; min-width: 18px; text-align: center;
  font-size: 11px; font-weight: 600; padding: 0 4px;
  border-radius: var(--r-sm); background: var(--accent-wash); color: var(--accent);
  cursor: pointer; vertical-align: baseline;
}
.source-list { margin-top: var(--s5); display: flex; flex-direction: column; gap: var(--s2); }
.source {
  display: flex; gap: var(--s3); align-items: baseline;
  padding: var(--s2) var(--s3); border-radius: var(--r-md);
  background: var(--surface-sunken); font-size: 13.5px;
  border: 0; width: 100%; text-align: left; cursor: pointer; font-family: inherit;
  color: var(--text);
}
.source:hover { background: var(--accent-wash); }
.source-n { font-weight: 600; color: var(--accent); font-size: 12px; }

/* ------------------------------------------------------------ connexion */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s6); }
.login-card { width: 100%; max-width: 360px; }

/* ---------------------------------------------------------- barre mobile */
.tabbar { display: none; }
.menu-btn { display: none; }
.sort-mobile { display: none; padding: 0 var(--s3) var(--s5); }
.sort-mobile select {
  width: 100%; height: 36px; padding: 0 var(--s2);
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md);
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .detail { grid-template-columns: 1fr; }
  .detail-panel { border-left: 0; border-top: 1px solid var(--border); }
  .detail-viewer { min-height: 52vh; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open {
    display: flex; position: fixed; inset: 0 auto 0 0; z-index: 60;
    width: min(86vw, var(--sidebar-w)); box-shadow: var(--shadow-lg);
  }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; }
  .content { padding: var(--s4); padding-bottom: 88px; }
  .topbar  { padding: var(--s3) var(--s4); }
  .menu-btn { display: inline-flex; flex: none; }
  /* La barre d'onglets couvre la navigation ; le panneau latéral ne sert
     plus qu'aux facettes, d'où le masquage de sa liste de vues. */
  .sidebar.open .nav { display: none; }
  .sidebar.open .facets { padding-top: var(--s2); }

  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 9px 0 7px; min-height: 52px;
    border: 0; background: none; font: inherit; font-size: 10.5px;
    color: var(--text-subtle); cursor: pointer;
  }
  .tab[aria-current="page"] { color: var(--accent); font-weight: 600; }

  .result { padding: var(--s3) var(--s2); min-height: 60px; grid-template-columns: 30px 1fr auto; }
  .result-side { max-width: 108px; }
  /* Au-delà de deux tags, la ligne double de hauteur pour un gain nul :
     les tags restants restent visibles sur la fiche du document. */
  .result-tags .tag:nth-child(n+3) { display: none; }
  .detail-viewer { min-height: 46vh; }
  .searchbox kbd { display: none; }
  /* Le tri passe dans le panneau de filtres : sur 390 px, il volait au champ
     de recherche la moitié de sa largeur. */
  .topbar .sort-select { display: none; }
  .sort-mobile { display: block; }
  .searchbox input { font-size: 16px; }   /* évite le zoom automatique sur iOS */
  .field input, .field select, .field textarea { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  .sidebar, .topbar, .tabbar, .detail-panel { display: none !important; }
  body { background: #fff; color: #000; }
}

/* ------------------------------------------------- ajustements mobiles */
.topbar h1 { font-size: 18px; white-space: nowrap; overflow: hidden;
             text-overflow: ellipsis; min-width: 0; }

@media (max-width: 860px) {
  .hide-sm { display: none; }
  /* La bannière juste en dessous dit déjà combien de documents sont à
     vérifier : garder la tuile ferait doublon et laisserait une carte
     orpheline sur la troisième ligne. */
  .stat-review { display: none; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .stat { padding: var(--s3) var(--s4); }
  .stat-value { font-size: 22px; }
  .banner { flex-direction: column; gap: var(--s3); align-items: stretch; }
  .banner .btn { align-self: flex-start; }
}

/* Jauge d'occupation disque — un simple rail, pas un graphique. */
.meter {
  margin-top: var(--s2);
  height: 4px; border-radius: var(--r-full);
  background: var(--surface-sunken); overflow: hidden;
}
.meter span {
  display: block; height: 100%; border-radius: var(--r-full);
  background: var(--accent);
}
.stat.is-warning .meter span { background: var(--warning); }
