/* ============================================================
   Archive Sxone — design system (register: product / outil interne)
   « Atelier en couches » : canvas teinté, panneaux surélevés,
   barre latérale ardoise. Thèmes clair + sombre (data-theme).
   Chiffres tabulaires, colonnes numériques alignées à droite.
   ============================================================ */

/* ---------- Thème CLAIR (par défaut) ---------- */
:root {
  /* Surfaces — canvas nettement teinté (jamais blanc), panneaux qui lèvent */
  --canvas:      oklch(0.952 0.009 256);
  --surface:     oklch(0.996 0.0025 256);
  --surface-2:   oklch(0.972 0.006 256);
  --surface-3:   oklch(0.954 0.009 256);
  --hover:       oklch(0.945 0.016 256);
  --selected:    oklch(0.940 0.032 256);
  --border:      oklch(0.872 0.010 256);
  --border-soft: oklch(0.905 0.008 256);
  --thead-bg:    oklch(0.935 0.013 256);  /* entête de table nettement détachée */
  --zebra:       oklch(0.963 0.008 256);  /* lignes alternées (un cran plus visible) */

  /* Texte — encré, contraste relevé */
  --fg:        oklch(0.25 0.022 262);
  --fg-muted:  oklch(0.44 0.018 262);
  --fg-subtle: oklch(0.53 0.015 262);  /* AA: 4.87:1 sur surface-2 (texte petit) */

  /* Accent + sémantiques */
  --accent:        oklch(0.55 0.155 256);
  --accent-hover:  oklch(0.47 0.165 256);
  --accent-weak:   oklch(0.945 0.042 256);
  --on-accent:     oklch(0.99 0.005 256);
  --success:       oklch(0.55 0.12 150);
  --success-weak:  oklch(0.955 0.040 150);
  --warning:       oklch(0.56 0.13 70);
  --warning-weak:  oklch(0.955 0.050 75);
  --danger:        oklch(0.53 0.18 27);
  --danger-weak:   oklch(0.955 0.045 27);

  /* Barre latérale — 2e neutre ardoise, la profondeur de l'atelier */
  --side-bg:        oklch(0.295 0.028 264);
  --side-surface:   oklch(0.335 0.028 264);
  --side-fg:        oklch(0.92 0.012 264);
  --side-fg-muted:  oklch(0.70 0.016 264);
  --side-hover:     oklch(0.355 0.030 264);
  --side-active-bg: oklch(0.42 0.078 258);
  --side-active-fg: oklch(0.985 0.010 258);
  --side-border:    oklch(0.385 0.022 264);

  --radius:    9px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px oklch(0.30 0.03 264 / 0.09);
  --shadow:    0 1px 2px oklch(0.30 0.03 264 / 0.07), 0 8px 22px oklch(0.30 0.03 264 / 0.11);
  --ring:      0 0 0 3px var(--accent-weak);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, monospace;

  color-scheme: light;
}

/* ---------- Thème SOMBRE ---------- */
[data-theme="dark"] {
  --canvas:      oklch(0.195 0.016 264);
  --surface:     oklch(0.246 0.020 264);
  --surface-2:   oklch(0.286 0.022 264);
  --surface-3:   oklch(0.320 0.024 264);
  --hover:       oklch(0.300 0.024 264);
  --selected:    oklch(0.345 0.052 258);
  --border:      oklch(0.375 0.020 264);
  --border-soft: oklch(0.330 0.018 264);
  --thead-bg:    oklch(0.312 0.024 264);
  --zebra:       oklch(0.268 0.021 264);

  --fg:        oklch(0.935 0.012 264);
  --fg-muted:  oklch(0.745 0.016 264);
  --fg-subtle: oklch(0.670 0.016 264);  /* AA: 4.78:1 sur surface-2 (texte petit) */

  --accent:        oklch(0.72 0.14 256);
  --accent-hover:  oklch(0.80 0.135 256);
  --accent-weak:   oklch(0.34 0.060 256);
  --on-accent:     oklch(0.16 0.020 256);
  --success:       oklch(0.72 0.13 152);
  --success-weak:  oklch(0.32 0.050 152);
  --warning:       oklch(0.78 0.13 75);
  --warning-weak:  oklch(0.34 0.050 75);
  --danger:        oklch(0.68 0.17 27);
  --danger-weak:   oklch(0.33 0.070 27);

  --side-bg:        oklch(0.165 0.014 264);
  --side-surface:   oklch(0.226 0.020 264);
  --side-fg:        oklch(0.905 0.012 264);
  --side-fg-muted:  oklch(0.625 0.016 264);
  --side-hover:     oklch(0.266 0.022 264);
  --side-active-bg: oklch(0.345 0.068 256);
  --side-active-fg: oklch(0.975 0.010 256);
  --side-border:    oklch(0.278 0.018 264);

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.40);
  --shadow:    0 1px 2px oklch(0 0 0 / 0.40), 0 6px 20px oklch(0 0 0 / 0.42);

  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Typographie ---------- */
h1 { font-size: 1.5rem;  font-weight: 660; letter-spacing: -0.015em; margin: 0 0 0.9rem; }
h2 { font-size: 1.12rem; font-weight: 640; letter-spacing: -0.008em; margin: 1.9rem 0 0.7rem; }
h3 { font-size: 0.94rem; font-weight: 640; color: var(--fg); margin: 1.4rem 0 0.5rem; }
p  { margin: 0 0 0.7rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* ============================================================
   COQUILLE — barre latérale + contenu
   ============================================================ */
.app { display: flex; align-items: flex-start; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: stretch;
  height: 100vh; width: 220px; flex: 0 0 220px;
  display: flex; flex-direction: column;
  padding: 0.85rem 0.7rem;
  background: var(--side-bg); color: var(--side-fg);
  border-right: 1px solid var(--side-border);
}
.sidebar .brand {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.35rem 0.55rem 1rem;
  font-weight: 680; font-size: 1rem; letter-spacing: -0.015em;
  color: var(--side-fg); text-decoration: none; white-space: nowrap;
}
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand::before {
  content: ""; flex: none; width: 17px; height: 17px;
  border-radius: 5px; background: var(--accent);
  box-shadow: 0 0 0 3px oklch(0.55 0.155 256 / 0.18);
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.12rem; }
.sidebar nav a {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.44rem 0.6rem; border-radius: var(--radius-sm);
  color: var(--side-fg-muted); font-size: 0.88rem; font-weight: 500;
  text-decoration: none; white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar nav a:hover { background: var(--side-hover); color: var(--side-fg); text-decoration: none; }
.sidebar nav a.on { background: var(--side-active-bg); color: var(--side-active-fg); font-weight: 600; }
.sidebar nav a:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--side-active-bg); }

.sidebar .spacer { flex: 1 1 auto; }
.sidebar-foot {
  display: flex; flex-direction: column; gap: 0.1rem;
  margin-top: 0.7rem; padding-top: 0.7rem;
  border-top: 1px solid var(--side-border);
}
.sidebar-foot .who {
  padding: 0.25rem 0.6rem 0.4rem; font-size: 0.78rem;
  color: var(--side-fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-foot a, .theme-toggle {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.42rem 0.6rem; border-radius: var(--radius-sm);
  color: var(--side-fg-muted); font: inherit; font-size: 0.84rem;
  background: none; border: none; text-align: left; width: 100%;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.sidebar-foot a:hover, .theme-toggle:hover { background: var(--side-hover); color: var(--side-fg); text-decoration: none; }
.theme-toggle:focus-visible, .sidebar-foot a:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--side-active-bg); }
.theme-toggle .ico { font-size: 0.95rem; line-height: 1; }

.content { flex: 1 1 auto; min-width: 0; }
main { padding: 1.5rem 1.7rem 4rem; }
main.bare { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1.5rem; }

/* ---------- Boutons / contrôles de formulaire ---------- */
.btn, button.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.8rem; height: 32px;
  background: var(--surface); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font: inherit; font-size: 0.84rem; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--fg-subtle); text-decoration: none; }
.btn:active { background: var(--hover); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }

input[type="search"], input[type="text"], input[type="password"], select {
  height: 32px; padding: 0 0.6rem; font: inherit; font-size: 0.84rem;
  color: var(--fg); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
input[type="search"] { min-width: 240px; }
select { padding-right: 1.6rem; }
input::placeholder { color: var(--fg-subtle); }
input:focus-visible, select:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--accent); }

.filters { display: flex; gap: 0.5rem; margin-bottom: 1.1rem; flex-wrap: wrap; align-items: center; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 0.06rem 0.5rem; margin-left: 0.4rem;
  border-radius: 999px; font-size: 0.72rem; font-weight: 600;
  color: var(--fg-muted); background: var(--surface-3); vertical-align: middle;
}

/* ---------- Tables ---------- */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
}
.table-scroll table { border: none; box-shadow: none; }

table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; font-size: 0.86rem; box-shadow: var(--shadow);
}
thead th {
  text-align: left; font-weight: 650; font-size: 0.72rem; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--fg-muted); background: var(--thead-bg);
  padding: 0.55rem 0.7rem; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.table-scroll thead th { position: sticky; top: 0; z-index: 2; }
tbody td { padding: 0.48rem 0.7rem; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
/* En-tête de ligne (scope="row") : apparence d'une cellule normale */
tbody th { font-weight: inherit; text-align: left; color: inherit; }
/* Séparateurs de colonnes (filet vertical entre cellules) */
tr > * + * { border-left: 1px solid var(--border-soft); }
/* Zebra léger — faible spécificité (:where) pour que l'arbre/CRA gardent leur coloration */
tbody tr:nth-child(even) > :where(td, th) { background: var(--zebra); }
/* Survol prioritaire (défini après le zebra) */
tbody tr:hover td, tbody tr:hover th { background: var(--hover); }
tfoot th, tfoot td {
  padding: 0.55rem 0.7rem; border-top: 2px solid var(--border);
  background: var(--surface-2); font-weight: 650; font-size: 0.84rem; text-align: left;
}

/* Colonnes numériques : alignées à droite, chiffres tabulaires */
.num, .num-j, td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
}
tbody td.num, tbody td.num-j { color: var(--fg); font-weight: 550; }

/* ---------- Détail clé/valeur ---------- */
.kv {
  display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.5rem;
  max-width: 780px; margin: 0.5rem 0; padding: 1rem 1.2rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.kv dt { color: var(--fg-subtle); font-size: 0.82rem; }
.kv dd { margin: 0; font-weight: 550; }
/* Entête sur deux colonnes (paire libellé/valeur ×2 par ligne) */
.kv-2col { grid-template-columns: max-content 1fr max-content 1fr; max-width: 1080px; column-gap: 2.4rem; }
@media (max-width: 880px) {
  .kv-2col { grid-template-columns: max-content 1fr; max-width: 780px; }
}

/* ---------- Arbre Phase / Activité / Ligne ---------- */
.tree td:first-child, .tree th:first-child { width: 50%; }
.tree .lvl-phase td { background: var(--surface-3); font-weight: 650; color: var(--fg); }
.tree .lvl-act td   { background: var(--surface-2); font-weight: 600; }
.tree .lvl-line td:first-child { color: var(--fg); font-weight: 400; }
.tree tbody tr:hover td { background: var(--hover); }
.tree td:not(:first-child), .tree th:not(:first-child),
.tree tfoot th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Matrice CRA (feuille de temps) ---------- */
.cra { font-size: 0.82rem; }
.cra th, .cra td { white-space: nowrap; padding: 0.42rem 0.6rem; }
.cra thead th { text-align: right; }
.cra thead th:first-child { text-align: left; }
.cra .imp { font-size: 0.8rem; color: var(--fg-muted); max-width: 460px; overflow: hidden; text-overflow: ellipsis; }
.cra td.num, .cra th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cra td.num:empty::after { content: "·"; color: var(--border); }
/* 1re colonne (imputation) figée à gauche */
.cra th:first-child, .cra td:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--surface);
  border-right: 1px solid var(--border);
}
.cra tbody tr:nth-child(even) th:first-child,
.cra tbody tr:nth-child(even) td:first-child { background: var(--zebra); }
.cra thead th:first-child { z-index: 3; background: var(--thead-bg); }
.cra tbody tr:hover td:first-child,
.cra tbody tr:hover th:first-child { background: var(--hover); }
.cra tfoot th { background: var(--surface-2); }
.cra tfoot th:first-child { z-index: 1; }

/* ---------- Suivi de consommation ---------- */
.suivi { margin-top: 2.3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.suivi-bandeau { display: flex; flex-wrap: wrap; gap: 0.7rem; margin: 0.9rem 0 1.4rem; }
.suivi-kpi {
  flex: 0 1 auto; min-width: 132px; padding: 0.65rem 0.95rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.suivi-kpi-val { display: block; font-size: 1.22rem; font-weight: 680; letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums; color: var(--fg); }
.suivi-kpi-lbl { display: block; font-size: 0.72rem; color: var(--fg-subtle); margin-top: 0.2rem;
  text-transform: uppercase; letter-spacing: 0.03em; }
.suivi-kpi-neg  { border-color: var(--danger);  background: var(--danger-weak); }
.suivi-kpi-neg  .suivi-kpi-val { color: var(--danger); }
.suivi-kpi-warn { border-color: var(--warning); background: var(--warning-weak); }
.suivi-kpi-warn .suivi-kpi-val { color: var(--warning); }

.suivi-periode-selector { display: inline-flex; gap: 0.2rem; margin-bottom: 1rem;
  padding: 0.22rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.btn-periode { padding: 0.32rem 0.78rem; border-radius: var(--radius-sm); text-decoration: none;
  color: var(--fg-muted); font-size: 0.83rem; font-weight: 500; }
.btn-periode:hover { background: var(--hover); text-decoration: none; }
.btn-periode.active { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: var(--shadow-sm); }

.suivi-table { margin-bottom: 1.1rem; }
.reste-neg { color: var(--danger); font-weight: 650; }

.suivi-line-detail { margin-bottom: 0.5rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.suivi-line-detail summary { padding: 0.55rem 0.8rem; cursor: pointer; font-size: 0.86rem; color: var(--fg);
  background: var(--surface-2); list-style: none; }
.suivi-line-detail summary::-webkit-details-marker { display: none; }
.suivi-line-detail summary::before { content: "▸"; color: var(--fg-subtle); margin-right: 0.5rem; font-size: 0.75rem; }
.suivi-line-detail[open] summary::before { content: "▾"; }
.suivi-line-detail summary strong { font-weight: 640; }
.suivi-line-detail table { border: none; border-radius: 0; box-shadow: none; }
.suivi-interv { font-size: 0.84rem; }

.export-row { margin: 0.2rem 0 1.3rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; gap: 1rem; margin-top: 1.1rem; font-size: 0.85rem; color: var(--fg-subtle); }

/* ---------- Login (rendu centré, sans coquille) ---------- */
.login-card { width: 100%; max-width: 420px; padding: 2.2rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.login-card h1 { margin-bottom: 1.2rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.8rem; }
.login-card select { height: 36px; }

/* ---------- États utilitaires ---------- */
.muted { color: var(--fg-subtle); }
.empty { padding: 1.6rem; text-align: center; color: var(--fg-subtle); }

/* Masqué visuellement mais lu par les lecteurs d'écran */
.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;
}

/* ---------- Responsive : sidebar horizontale sur écran étroit ---------- */
@media (max-width: 820px) {
  .app { flex-direction: column; align-items: stretch; }
  .sidebar {
    position: static; width: auto; height: auto; flex: none;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.3rem;
    border-right: none; border-bottom: 1px solid var(--side-border);
  }
  .sidebar .brand { padding: 0.35rem 0.55rem; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar .spacer { display: none; }
  .sidebar-foot { flex-direction: row; flex-wrap: wrap; align-items: center;
    margin: 0; padding: 0; border-top: none; margin-left: auto; }
  .sidebar-foot a, .theme-toggle { width: auto; }
  .sidebar-foot .who { display: none; }
  main { padding: 1.2rem 1.1rem 3rem; }
}
