/* Rateb — feuille de style principale (design moderne, v14).
   Charte : vert algérien #006233 = couleur de marque (boutons, liens, accents).
   Le cadre (menu latéral) utilise des verts plus profonds ; le corps de page reste neutre.
   L'or (#c9a227, couleur du logo) n'apparaît qu'en petites touches HORS du corps (menu, connexion).
   Mode sombre : html[data-theme="dark"].  Propriétés logiques partout (RTL pris en charge). */

/* ---------- Variables ---------- */
:root {
  color-scheme: light;
  --green: #006233;
  --green-hover: #00532b;
  --green-dark: #004a26;
  --green-deep: #00331d;
  --green-bright: #17a566;
  --green-soft: #e8f3ed;
  --green-border: #bfd8cc;
  --link: #006233;
  --gold: #c9a227;

  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #f9faf9;
  --surface-glass: rgba(255, 255, 255, 0.86);
  --text: #16201b;
  --muted: #5b6860;
  --border: #e3e8e5;
  --border-strong: #cfd6d2;
  --hover-row: #f1f7f3;

  --success: #067647;
  --success-bg: #ecfdf3;
  --success-border: #bfe3cc;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --danger-border: #fecdca;
  --btn-danger: #b42318;
  --btn-danger-hover: #912018;
  --amber: #b54708;
  --amber-bg: #fffaeb;
  --amber-border: #f0d48a;
  --info: #175cd3;
  --info-bg: #eff8ff;
  --info-border: #bcd7ea;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.04), 0 1px 3px rgba(16, 24, 20, 0.05);
  --shadow-md: 0 10px 28px rgba(16, 24, 20, 0.09);
  --ring: rgba(23, 165, 102, 0.28);

  --sidebar-w: 264px;
  --sidebar-w-c: 76px;
  --topbar-h: 64px;
  --sb-bg: linear-gradient(180deg, #00331d 0%, #003d23 55%, #004a26 100%);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --green: #0a8048;
  --green-hover: #0c9755;
  --green-dark: #0a8048;
  --green-bright: #3ddc97;
  --green-soft: rgba(61, 220, 151, 0.1);
  --green-border: rgba(61, 220, 151, 0.28);
  --link: #4fd698;

  --bg: #0a110e;
  --surface: #121b17;
  --surface-soft: #161f1b;
  --surface-glass: rgba(18, 27, 23, 0.86);
  --text: #e6eee9;
  --muted: #97a79e;
  --border: #22302a;
  --border-strong: #33443c;
  --hover-row: #18241f;

  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.12);
  --success-border: rgba(74, 222, 128, 0.3);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --danger-border: rgba(248, 113, 113, 0.3);
  --btn-danger: #c53a2e;
  --btn-danger-hover: #d9473a;
  --amber: #fbbf24;
  --amber-bg: rgba(251, 191, 36, 0.12);
  --amber-border: rgba(251, 191, 36, 0.3);
  --info: #86b8ff;
  --info-bg: rgba(134, 184, 255, 0.12);
  --info-border: rgba(134, 184, 255, 0.3);

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.5);
  --ring: rgba(61, 220, 151, 0.32);
  --sb-bg: linear-gradient(180deg, #06140d 0%, #08190f 100%);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3 { letter-spacing: 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
hr { border: 0; border-block-start: 1px solid var(--border); margin: 1rem 0; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--green-border); color: var(--text); }
.ico { width: 1.25rem; height: 1.25rem; flex: 0 0 auto; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.center { text-align: center; }
.spacer { flex: 1; }

/* ---------- Structure : menu latéral + zone principale ---------- */
.app-shell { min-height: 100vh; }
.app-main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin-inline-start: var(--sidebar-w);
  transition: margin 0.25s ease;
}
.is-guest .app-main { margin-inline-start: 0; }
html[data-sidebar="collapsed"] .app-main { margin-inline-start: var(--sidebar-w-c); }
html[data-sidebar="collapsed"] .is-guest .app-main { margin-inline-start: 0; }

.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: var(--sidebar-w);
  background: var(--sb-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: width 0.25s ease, transform 0.25s ease;
  border-inline-end: 1px solid rgba(255, 255, 255, 0.06);
}
html[data-sidebar="collapsed"] .sidebar { width: var(--sidebar-w-c); }

.sb-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.05rem;
  height: var(--topbar-h);
  color: #fff;
  overflow: hidden;
  white-space: nowrap;
  flex: 0 0 auto;
}
.sb-brand:hover { text-decoration: none; }
.sb-logo {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 11px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
}
.sb-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sb-logo.has-co-logo { background: #fff; }
.sb-logo.has-co-logo img { object-fit: contain; padding: 3px; }
.sb-name { font-weight: 700; font-size: 1.08rem; overflow: hidden; text-overflow: ellipsis; }

.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0.5rem 0.75rem 1.25rem; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.2) transparent; }
.sb-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-sep { height: 1px; background: rgba(255, 255, 255, 0.1); margin: 0.6rem 0.4rem; }
.sb-nav .nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.sb-nav .nav-link:hover { background: rgba(255, 255, 255, 0.09); color: #fff; text-decoration: none; }
.sb-nav .nav-link.active { background: rgba(255, 255, 255, 0.15); color: #fff; font-weight: 600; }
.sb-nav .nav-link.active::before {
  content: "";
  position: absolute;
  inset-inline-start: -0.75rem;
  inset-block: 22%;
  width: 4px;
  background: var(--gold);
  border-radius: 0 4px 4px 0;
}
[dir="rtl"] .sb-nav .nav-link.active::before { border-radius: 4px 0 0 4px; }
.sb-nav .nav-link:focus-visible { outline-color: rgba(255, 255, 255, 0.6); }

.sidebar-backdrop { display: none; }
.bottom-nav { display: none; }

/* Menu replié (ordinateur) : icônes seules + info-bulles */
@media (min-width: 901px) {
  html[data-sidebar="collapsed"] .sb-name,
  html[data-sidebar="collapsed"] .nav-label { display: none; }
  html[data-sidebar="collapsed"] .sb-brand { padding-inline: 0; justify-content: center; }
  html[data-sidebar="collapsed"] .sb-nav .nav-link { justify-content: center; padding-inline: 0; }
  html[data-sidebar="collapsed"] .sb-nav { overflow: visible; }
  html[data-sidebar="collapsed"] .sb-nav .nav-link[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    inset-inline-start: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--green-deep);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.35rem 0.65rem;
    border-radius: 8px;
    white-space: nowrap;
    box-shadow: var(--shadow-md);
    pointer-events: none;
    z-index: 5;
  }
}

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-inline: 1.25rem;
  background: var(--surface);
  border-block-end: 1px solid var(--border);
}
@supports (backdrop-filter: blur(1px)) {
  .topbar { background: var(--surface-glass); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); }
}
.topbar-title { color: var(--muted); font-size: 0.95rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; margin-inline-start: 0.35rem; }
.topbar-brand { display: flex; align-items: center; gap: 0.6rem; color: var(--text); font-weight: 700; }
.topbar-brand:hover { text-decoration: none; }
.topbar-brand img { width: 36px; height: 36px; border-radius: 10px; }
.is-guest .topbar-title { display: none; }

/* V19 — navigation publique (pages visiteurs) : dans la barre du haut. */
.public-nav { display: flex; align-items: center; gap: 0.15rem; margin-inline-start: 0.5rem; min-width: 0; overflow: hidden; }
.public-nav a { color: var(--muted); font-size: 0.9rem; font-weight: 600; padding: 0.45rem 0.6rem; border-radius: 10px; white-space: nowrap; }
.public-nav a:hover { color: var(--link); background: var(--green-soft); text-decoration: none; }

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--green-soft); color: var(--link); text-decoration: none; }
.theme-toggle .i-sun { display: none; }
html[data-theme="dark"] .theme-toggle .i-sun { display: block; }
html[data-theme="dark"] .theme-toggle .i-moon { display: none; }
.notif-count {
  position: absolute;
  top: 2px;
  inset-inline-end: 0;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #dc2626;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}

.lang-select {
  width: auto;
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--surface-soft);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2397a79e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  height: 40px;
  padding: 0 2rem 0 0.8rem;
  cursor: pointer;
}
[dir="rtl"] .lang-select { background-position: left 0.65rem center; padding: 0 0.8rem 0 2rem; }
.lang-select:hover { border-color: var(--green-border); }

/* Menu utilisateur */
.user-menu { position: relative; }
.user-menu summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  height: 40px;
  padding: 0 0.5rem 0 0.3rem;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { border-color: var(--green-border); }
.user-menu[open] summary { border-color: var(--green-border); box-shadow: 0 0 0 3px var(--ring); }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  background: linear-gradient(135deg, var(--green), var(--green-bright));
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  flex: 0 0 auto;
}
.avatar-lg { width: 40px; height: 40px; font-size: 0.9rem; }
.user-name { font-size: 0.88rem; font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu .chev { width: 1rem; height: 1rem; color: var(--muted); }
.menu-pop {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 8px);
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 0.4rem;
  z-index: 80;
  animation: pop 0.14s ease-out;
}
.menu-head { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0.6rem 0.75rem; border-block-end: 1px solid var(--border); margin-block-end: 0.35rem; }
.menu-who { display: flex; flex-direction: column; min-width: 0; font-weight: 600; }
.menu-who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-who-sub { font-size: 0.78rem; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-pop a { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0.7rem; border-radius: 10px; color: var(--text); font-size: 0.92rem; font-weight: 500; }
.menu-pop a:hover { background: var(--green-soft); color: var(--link); text-decoration: none; }
.menu-pop a .ico { color: var(--muted); }
/* V17 (E4) — bouton de deconnexion (formulaire POST) dans le menu : meme
   apparence que les liens du menu. */
.menu-logout-form { margin: 0; }
.menu-logout-btn { display: flex; align-items: center; gap: 0.7rem; width: 100%; padding: 0.6rem 0.7rem; border: none; border-radius: 10px; background: none; color: var(--text); font: inherit; font-size: 0.92rem; font-weight: 500; cursor: pointer; text-align: start; }
.menu-logout-btn:hover { background: var(--green-soft); color: var(--link); }
.menu-logout-btn .ico { color: var(--muted); }
/* V17 (M5) — champ piege (honeypot) : invisible pour un humain. */
.honeypot { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.topbar-login .ico { width: 1rem; height: 1rem; margin-inline-end: 0.35rem; vertical-align: -3px; }

@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Mise en page ---------- */
.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 1.75rem 1.5rem 2rem; flex: 1; }
.container > * { animation: rise 0.35s ease both; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-block-end: 1.25rem; }
.page-head h1 { margin: 0; font-size: 1.65rem; font-weight: 700; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem 1.5rem;
  margin-block-end: 1.25rem;
}
.card h1 { margin-block-start: 0; }
.card h2 { margin-block-start: 0; font-size: 1.15rem; font-weight: 650; }
.card h3 { font-size: 1.02rem; font-weight: 600; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-block-end: 1.25rem; }
.grid > .card { margin-block-end: 0; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--green-border); }
.stat.has-icon { display: grid; grid-template-columns: auto 1fr; align-items: center; align-content: start; gap: 0.35rem 0.85rem; }
.stat.has-icon .stat-body { display: contents; }
.stat.has-icon .stat-label { grid-column: 2; grid-row: 1; line-height: 1.3; }
.stat.has-icon .stat-value, .stat.has-icon .small { grid-column: 1 / -1; }
.stat.has-icon .stat-value { margin-block-start: 0.25rem; font-size: clamp(1.4rem, 1.1rem + 0.7vw, 1.75rem); overflow-wrap: anywhere; }
.stat-icon { grid-column: 1; grid-row: 1; width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--green-soft); color: var(--link); }
.stat-icon .ico { width: 1.3rem; height: 1.3rem; }
.stat .stat-label { color: var(--muted); font-size: 0.88rem; font-weight: 500; }
.stat .stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }

.welcome-banner {
  background: linear-gradient(120deg, var(--green-deep) 0%, var(--green) 60%, var(--green-bright) 140%);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.35rem 1.6rem;
  margin-block-end: 1.25rem;
  box-shadow: var(--shadow-md);
}
.welcome-banner p { margin: 0; font-size: 1.1rem; font-weight: 600; }
html[data-theme="dark"] .welcome-banner { background: linear-gradient(120deg, #06140d 0%, #0a3a22 70%, #0d5a35 140%); border: 1px solid var(--border); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.card.table-wrap { padding: 0; }
.card.table-wrap > :not(table):not(.table-wrap) { margin: 1.1rem 1.4rem; }
.card.table-wrap > h2 { margin-block-end: 0.5rem; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table th, .table td { padding: 0.85rem 1rem; border-block-end: 1px solid var(--border); text-align: start; vertical-align: middle; }
.table thead th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
[dir="rtl"] .table thead th { letter-spacing: 0; text-transform: none; font-size: 0.82rem; }
.table tbody tr { transition: background-color 0.12s ease; }
.table tbody tr:hover { background: var(--hover-row); }
.table tbody tr:last-child td { border-block-end: 0; }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }
.table tfoot td, .table tfoot th { font-weight: 700; background: var(--green-soft); border-block-end: 0; }
.table td .btn + .btn { margin-inline-start: 0.25rem; }

dl.kv { display: grid; grid-template-columns: minmax(160px, 220px) 1fr; gap: 0.5rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); font-weight: 600; }
dl.kv dd { margin: 0; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.18rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-open, .badge-trial, .badge-pending, .badge-draft { background: var(--amber-bg); color: var(--amber); }
.badge-validated, .badge-active, .badge-approved, .badge-submitted { background: var(--success-bg); color: var(--success); }
.badge-closed, .badge-ended, .badge-rejected, .badge-suspended { background: var(--danger-bg); color: var(--danger); }
.badge-inactive { background: var(--surface-soft); color: var(--muted); border: 1px solid var(--border); }

/* ---------- Formulaires ---------- */
form .field { margin-block-end: 1rem; }
form label { display: block; font-weight: 600; font-size: 0.88rem; margin-block-end: 0.35rem; }
form .req { color: var(--danger); }
form .hint { font-size: 0.85rem; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="month"], input[type="tel"], input[type="search"], input[type="url"], input[type="time"],
input[type="file"], select, textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.75; }
input:hover, select:hover, textarea:hover { border-color: var(--green-border); }
input:focus, select:focus, textarea:focus { border-color: var(--green-bright); outline: none; box-shadow: 0 0 0 4px var(--ring); }
input[type="checkbox"], input[type="radio"] { width: 1.05rem; height: 1.05rem; accent-color: var(--green); }
.form-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.form-inline { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.form-inline .field { margin-block-end: 0; flex: 1 1 170px; }
.checkbox-line { display: flex; gap: 0.5rem; align-items: center; }
.checkbox-line label { margin: 0; font-weight: normal; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.62rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--green);
  color: #fff;
  font: inherit;
  font-size: 0.93rem;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 60, 30, 0.18);
  transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.btn:hover, .btn:focus { background: var(--green-hover); color: #fff; text-decoration: none; box-shadow: 0 4px 12px rgba(0, 98, 51, 0.25); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, var(--green-bright) -80%, var(--green) 70%); }
html[data-theme="dark"] .btn-primary { background: var(--green); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: none; }
.btn-secondary:hover, .btn-secondary:focus { background: var(--green-soft); color: var(--link); border-color: var(--green-border); box-shadow: none; }
.btn-danger { background: var(--btn-danger); }
.btn-danger:hover, .btn-danger:focus { background: var(--btn-danger-hover); }
.btn-small { padding: 0.32rem 0.75rem; font-size: 0.85rem; border-radius: 8px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
form.inline-form { display: inline; }

/* ---------- Messages ---------- */
.flash { padding: 0.85rem 1.1rem; border-radius: 12px; margin-block-end: 1.1rem; font-weight: 600; border: 1px solid; border-inline-start-width: 4px; transition: opacity 0.4s ease, transform 0.4s ease; }
.flash.is-hiding { opacity: 0; transform: translateY(-6px); }
.flash-success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.errors { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); border-radius: 12px; padding: 0.85rem 1.1rem; margin-block-end: 1rem; }
.errors ul { margin: 0; padding-inline-start: 1.2rem; }
/* V16 — avertissements (anomalies confirmables) : orange, comme les erreurs mais en ambre. */
.warnings { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-border); border-radius: 12px; padding: 0.85rem 1.1rem; margin-block-end: 1rem; }
.warnings p { margin: 0 0 0.35rem; }
.warnings ul { margin: 0; padding-inline-start: 1.2rem; }
/* V16 — message d'erreur / d'avertissement sous la case concernée. */
.field-error { color: var(--danger); font-size: 0.85rem; font-weight: 600; margin-top: 0.3rem; }
.field-warning { color: var(--amber); font-size: 0.85rem; font-weight: 600; margin-top: 0.3rem; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field.has-warning input, .field.has-warning select, .field.has-warning textarea { border-color: var(--amber); }
/* V16 — bouton d'aide flottant + fenêtre modale. */
.help-fab { position: fixed; bottom: 1.2rem; inset-inline-end: 1.2rem; z-index: 60; width: 3.4rem; height: 3.4rem; border-radius: 50%; background: var(--green); color: #fff; border: none; font-size: 1.5rem; font-weight: 700; line-height: 1; cursor: pointer; box-shadow: var(--shadow-md); display: flex; align-items: center; justify-content: center; text-decoration: none; }
.help-fab:hover { background: var(--green-hover); color: #fff; }
.help-modal { position: fixed; inset: 0; z-index: 70; background: rgba(0, 8, 4, 0.5); display: flex; align-items: flex-end; justify-content: center; padding: 1rem; }
.help-modal[hidden] { display: none; }
.help-dialog { background: var(--surface); color: var(--text); border-radius: var(--radius); padding: 1.2rem; width: 100%; max-width: 480px; box-shadow: var(--shadow-md); max-height: 90vh; overflow-y: auto; }
.help-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-block-end: 0.6rem; }
.help-dialog-head h2 { margin: 0; }
.help-close { background: transparent; border: 0; color: var(--muted); font-size: 1.6rem; line-height: 1; cursor: pointer; padding: 0.2rem 0.5rem; }
.help-hint { color: var(--muted); margin-block-end: 1rem; }
.help-fallback { color: var(--muted); margin-block-start: 1rem; }
@media (max-width: 900px) {
  /* Au-dessus de la barre d'onglets du bas sur mobile. */
  .help-fab { bottom: 5rem; }
  .help-modal { align-items: flex-end; }
}
.alert { padding: 0.8rem 1rem; border-radius: 12px; margin-block-end: 0.6rem; border: 1px solid; border-inline-start-width: 4px; }
.alert:last-child { margin-block-end: 0; }
.alert-warning { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: var(--info-border); }
.alert a { font-weight: 600; text-decoration: underline; color: inherit; }

/* ---------- Pages d'accueil / présentation ---------- */
.hero {
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: 3rem 1.5rem 3.25rem;
  margin-block-end: 1.5rem;
  border-radius: 24px;
  color: #fff;
  background: radial-gradient(circle at 15% 10%, rgba(23, 165, 102, 0.55), transparent 45%), linear-gradient(135deg, #00331d 0%, #004a26 55%, #006233 100%);
  box-shadow: var(--shadow-md);
}
.hero::after { content: ""; position: absolute; inset-inline-end: -60px; bottom: -80px; width: 260px; height: 260px; border-radius: 50%; border: 2px solid rgba(201, 162, 39, 0.35); pointer-events: none; }
.hero > * { position: relative; z-index: 1; }
.hero h1 { color: #fff; font-size: 2.2rem; margin: 0.5rem 0; }
.hero .muted { color: rgba(255, 255, 255, 0.82); max-width: 640px; margin-inline: auto; }
/* html[data-theme] : spécificité volontairement plus forte que les boutons du mode sombre */
html[data-theme] .hero .btn-primary { background: #fff; color: #004a26; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }
html[data-theme] .hero .btn-primary:hover, html[data-theme] .hero .btn-primary:focus { background: #eaf6ef; color: #004a26; }
html[data-theme] .hero .btn-secondary { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.45); box-shadow: none; }
html[data-theme] .hero .btn-secondary:hover, html[data-theme] .hero .btn-secondary:focus { background: rgba(255, 255, 255, 0.12); color: #fff; border-color: #fff; }
.hero a:not(.btn) { color: #fff; text-decoration: underline; }
.hero-logo { height: 96px; width: 96px; border-radius: 24px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.2); object-fit: cover; }
.access-cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-block-start: 1.25rem; }
.access-card { background: var(--surface-soft); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem; transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease; }
.access-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--green-border); }
.access-card h2 { margin-block-start: 0; font-size: 1.05rem; color: var(--link); }
.access-card p { margin-block-end: 0; color: var(--muted); }
.narrow { max-width: 560px; margin-inline: auto; }
.faq { border-block-end: 1px solid var(--border); padding: 0.7rem 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq summary:hover { color: var(--link); }
.faq p { margin: 0.5rem 0 0.2rem; color: var(--muted); }

/* Connexion */
.auth-wrap { display: grid; grid-template-columns: 1.05fr 1fr; max-width: 920px; margin: 1rem auto 2rem; border-radius: 24px; overflow: hidden; box-shadow: var(--shadow-md); border: 1px solid var(--border); background: var(--surface); animation: rise 0.4s ease both; }
.auth-aside { position: relative; overflow: hidden; padding: 2.5rem 2rem; color: #fff; display: flex; flex-direction: column; justify-content: center; gap: 1rem; background: radial-gradient(circle at 20% 0%, rgba(23, 165, 102, 0.5), transparent 50%), linear-gradient(160deg, #00331d 0%, #004a26 60%, #006233 100%); }
.auth-aside::after { content: ""; position: absolute; inset-inline-end: -70px; bottom: -70px; width: 220px; height: 220px; border-radius: 50%; border: 2px solid rgba(201, 162, 39, 0.4); }
.auth-aside img { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.2); }
.auth-aside h2 { margin: 0; font-size: 1.5rem; color: #fff; }
.auth-aside p { margin: 0; color: rgba(255, 255, 255, 0.8); }
.auth-form { padding: 2.5rem 2.25rem; }
.auth-form h1 { margin: 0 0 1.25rem; font-size: 1.5rem; }
.auth-form .btn-primary { width: 100%; padding-block: 0.75rem; }
.auth-form form { margin-block-end: 0.5rem; }
.login-logo { text-align: center; margin-block-end: 0.5rem; }
.login-logo img { height: 84px; width: 84px; border-radius: 22px; }

/* ---------- Divers ---------- */
.temp-password {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: var(--amber-bg);
  color: var(--amber);
  border: 2px dashed var(--amber);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  text-align: center;
  direction: ltr;
  unicode-bidi: plaintext;
  margin: 1rem 0;
  word-break: break-all;
}
.logo-img { max-height: 64px; }
.payslip { max-width: 820px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.75rem; box-shadow: var(--shadow); }
.payslip-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; border-block-end: 3px solid var(--green); padding-block-end: 0.8rem; margin-block-end: 1rem; }
.payslip-head h1 { margin: 0; font-size: 1.4rem; }
.payslip .net-box { background: var(--green-soft); border: 1px solid var(--green-border); border-radius: var(--radius); padding: 0.95rem 1.15rem; font-size: 1.15rem; }
.payslip .net-box strong { color: var(--link); }
.signatures { display: flex; justify-content: space-between; gap: 2rem; margin-block-start: 2rem; }
.signatures div { flex: 1; border-block-start: 1px solid var(--border-strong); padding-block-start: 0.4rem; font-size: 0.9rem; color: var(--muted); }
.doc-sheet { max-width: 820px; margin-inline: auto; padding: 2rem 2.25rem; }
.doc-header { text-align: center; }
.doc-signature { margin-block-start: 2.5rem; text-align: end; }
.inline-create { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; }

.notif-unread { background: var(--green-soft); }

.site-footer { text-align: center; color: var(--muted); padding: 1.25rem 1rem 1.5rem; font-size: 0.85rem; border-block-start: 1px solid var(--border); margin-block-start: 1rem; }
.site-footer p { margin: 0.15rem 0; }
.site-footer a { color: var(--link); font-weight: 500; }
.footer-social { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; justify-content: center; align-items: center; margin: 0.5rem 0; }
.footer-social a { display: inline-flex; align-items: center; gap: 0.35rem; }
.footer-social svg { width: 1.05rem; height: 1.05rem; fill: currentColor; }

/* ---------- Tablette / téléphone : menu en tiroir + barre d'onglets ---------- */
@media (max-width: 900px) {
  .app-main, html[data-sidebar="collapsed"] .app-main { margin-inline-start: 0; padding-block-end: calc(68px + env(safe-area-inset-bottom, 0px)); }
  .is-guest .app-main { padding-block-end: 0; }
  .sidebar, html[data-sidebar="collapsed"] .sidebar { width: min(84vw, 300px); transform: translateX(-100%); box-shadow: none; }
  [dir="rtl"] .sidebar, [dir="rtl"][data-sidebar="collapsed"] .sidebar { transform: translateX(100%); }
  html.nav-open .sidebar, html.nav-open[dir="rtl"] .sidebar { transform: none; box-shadow: var(--shadow-md); }
  html.nav-open, html.nav-open body { overflow: hidden; }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 8, 4, 0.55); opacity: 0; pointer-events: none; transition: opacity 0.25s ease; }
  html.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  html[data-sidebar="collapsed"] .sb-name, html[data-sidebar="collapsed"] .nav-label { display: inline; }

  .bottom-nav {
    display: flex;
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 50;
    padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-block-start: 1px solid var(--border);
    box-shadow: 0 -6px 20px rgba(16, 24, 20, 0.06);
  }
  @supports (backdrop-filter: blur(1px)) {
    .bottom-nav { background: var(--surface-glass); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); }
  }
  .tab-link {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.4rem 0.2rem;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
  }
  .tab-link:hover { text-decoration: none; color: var(--link); }
  .tab-link span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tab-link .ico { width: 1.4rem; height: 1.4rem; }
  .tab-link.active { color: var(--link); background: var(--green-soft); }

  .topbar { padding-inline: 0.75rem; gap: 0.35rem; }
  /* V19 — menu public : deuxieme ligne defilante sur mobile. */
  .topbar { flex-wrap: wrap; height: auto; padding-block: 0.5rem; }
  .public-nav { order: 10; flex: 1 1 100%; margin-inline-start: 0; overflow-x: auto; scrollbar-width: none; }
  .public-nav::-webkit-scrollbar { display: none; }
}

/* ---------- Téléphone ---------- */
@media (max-width: 720px) {
  .container { padding: 1rem 0.8rem 1.5rem; }
  .card { padding: 1.05rem; border-radius: 14px; }
  .page-head h1 { font-size: 1.35rem; }
  .page-actions { width: 100%; }
  .page-actions .btn, .page-actions form.inline-form { flex: 1 1 0; min-width: 0; }
  .page-actions form.inline-form .btn { width: 100%; }
  .topbar-title { display: none; }
  .user-name, .user-menu .chev { display: none; }
  .user-menu summary { padding: 0 0.3rem; border-radius: 50%; width: 40px; justify-content: center; }
  .topbar-login span { display: none; }
  .lang-select { padding-inline-end: 1.7rem; height: 38px; }
  .stat .stat-value { font-size: 1.5rem; }
  .btn { min-height: 44px; }
  .btn-small { min-height: 36px; }
  input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="month"],
  input[type="tel"], input[type="search"], input[type="url"], input[type="time"], select, textarea { font-size: 16px; min-height: 46px; }
  .form-inline { flex-direction: column; align-items: stretch; }
  .form-inline .field { flex: 1 1 auto; }
  .form-inline .btn { width: 100%; }
  dl.kv { grid-template-columns: 1fr; gap: 0.1rem; }
  dl.kv dd { margin-block-end: 0.6rem; }
  .payslip { padding: 1rem; }
  .payslip-head { flex-direction: column; gap: 0.6rem; }
  .signatures { flex-direction: column; gap: 1.2rem; }
  .doc-sheet { padding: 1.2rem; }
  .hero { padding: 2rem 1rem 2.25rem; border-radius: 20px; }
  .hero h1 { font-size: 1.6rem; }
  .hero-logo { height: 80px; width: 80px; }
  .temp-password { font-size: 1.2rem; }
  .auth-wrap { grid-template-columns: 1fr; margin-block-start: 0; border-radius: 20px; }
  .auth-aside { padding: 1.5rem 1.25rem; flex-direction: row; align-items: center; }
  .auth-aside img { width: 56px; height: 56px; border-radius: 15px; }
  .auth-aside h2 { font-size: 1.1rem; }
  .auth-aside p, .auth-aside::after { display: none; }
  .auth-form { padding: 1.5rem 1.25rem; }
}

/* Tableaux -> cartes empilées (téléphone) : data-cards est posé par app.js */
@media (max-width: 640px) {
  .card.table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .card.table-wrap > :not(table):not(.table-wrap) { margin: 0.5rem 0.2rem; }
  table.table[data-cards], table.table[data-cards] tbody, table.table[data-cards] tfoot,
  table.table[data-cards] tr, table.table[data-cards] td, table.table[data-cards] th { display: block; width: 100%; }
  table.table[data-cards] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  table.table[data-cards] tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 0.3rem 1rem;
    margin-block-end: 0.8rem;
  }
  table.table[data-cards] tbody tr:hover { background: var(--surface); }
  table.table[data-cards] td, table.table[data-cards] th {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.3rem 1rem;
    padding: 0.55rem 0;
    border-block-end: 1px dashed var(--border);
    text-align: end;
    font-size: 0.92rem;
  }
  table.table[data-cards] td:last-child, table.table[data-cards] th:last-child { border-block-end: 0; }
  table.table[data-cards] td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 auto;
    max-width: 45%;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 650;
    text-align: start;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  [dir="rtl"] table.table[data-cards] td[data-label]::before { text-transform: none; letter-spacing: 0; font-size: 0.82rem; }
  table.table[data-cards] tfoot tr { background: var(--green-soft); }
  table.table[data-cards] .num { text-align: end; }
}

@media (max-width: 400px) {
  .container { padding-inline: 0.6rem; }
  .grid, .access-cards { grid-template-columns: 1fr; }
  .lang-select { font-size: 0.78rem; padding-inline-start: 0.55rem; }
}

/* Mouvement réduit */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Barres de défilement discrètes */
@media (hover: hover) {
  * { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
}

/* ---------- Impression (fiche de paie, documents) : toujours clair, sans le cadre ---------- */
@media print {
  :root, html[data-theme="dark"] {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --surface-soft: #fff; --text: #000; --muted: #444;
    --border: #ccc; --border-strong: #bbb; --green-soft: #eee; --link: #000; --success-bg: #fff; --success: #000;
    --amber-bg: #fff; --amber: #000;
  }
  body { background: #fff; color: #000; }
  .sidebar, .sidebar-backdrop, .bottom-nav, .topbar, .site-footer, .no-print, .page-actions, .flash, .help-fab, .help-modal { display: none !important; }
  .app-main, html[data-sidebar="collapsed"] .app-main { margin: 0; padding: 0; }
  .container { max-width: none; padding: 0; }
  .container > * { animation: none; }
  .payslip { border: none; max-width: none; padding: 0; box-shadow: none; }
  .card { box-shadow: none; border: none; padding: 0; }
  table.table { font-size: 11pt; }
  .table thead th { background: #eee !important; color: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A4; margin: 15mm; }
}

/* V22.3 (SEO) — navigation de pied de page : maillage interne des pages publiques. */
.footer-nav { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; justify-content: center; margin: 0 0 0.75rem; }
.footer-nav a { text-decoration: none; }
.footer-nav a:hover { text-decoration: underline; }
