:root {
  --green: #0f4c3a;
  --green-2: #176650;
  --green-soft: #e4efe9;
  --gold: #a9853a;
  --gold-soft: #f5ecd8;
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #1d2721;
  --muted: #66716a;
  --line: #e2dccd;
  --red: #a23b2a;
  --red-soft: #f8e6e1;
  --amber: #8a5a00;
  --amber-soft: #fbf0d5;
  --blue: #1f5a8a;
  --blue-soft: #e3eef7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29, 39, 33, .05), 0 4px 14px rgba(29, 39, 33, .05);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
  font-size: 15px; line-height: 1.55;
}
a { color: var(--green-2); }
a:hover { color: var(--green); }
h1, h2 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.55rem; font-weight: 700; }
h2 { font-size: 1.08rem; font-weight: 600; }
small, .small { font-size: .84rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Barre supérieure ---------- */
.topbar { background: var(--green); color: #fff; position: sticky; top: 0; z-index: 20; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; }
.brand img { background: #fff; border-radius: 6px; padding: 2px; object-fit: contain; }
.brand span { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand strong { font-size: 1rem; white-space: nowrap; }
.brand small { opacity: .75; font-size: .76rem; white-space: nowrap; }
.brand:hover { color: #fff; }
.topbar-tools { display: flex; align-items: center; gap: 10px; }
.langs { display: flex; background: rgba(255,255,255,.12); border-radius: 999px; padding: 3px; }
.langs a { color: #fff; text-decoration: none; font-size: .82rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; min-width: 34px; text-align: center; }
.langs a.on { background: #fff; color: var(--green); }
.me { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; }
.me:hover { color: #fff; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--gold); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.me-name { display: flex; flex-direction: column; line-height: 1.15; font-size: .88rem; }
.me-name small { opacity: .75; font-size: .74rem; }
.mainnav { background: #0b3d2e; }
.mainnav-inner { max-width: 1180px; margin: 0 auto; padding: 0 10px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.mainnav-inner::-webkit-scrollbar { display: none; }
.mainnav a { color: rgba(255,255,255,.82); text-decoration: none; padding: 10px 12px; font-size: .9rem; white-space: nowrap; border-bottom: 3px solid transparent; }
.mainnav a:hover { color: #fff; }
.mainnav a.on { color: #fff; border-bottom-color: var(--gold); font-weight: 600; }

main { max-width: 1180px; margin: 0 auto; padding: 22px 16px 40px; }
main.narrow { max-width: 760px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 10px 16px 28px; }

/* ---------- Mise en page ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.eyebrow { margin: 0 0 4px; color: var(--gold); font-weight: 600; font-size: .84rem; }
.eyebrow a { color: inherit; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card > h2 { margin-bottom: 12px; }
.center { text-align: center; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 14px; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; margin: 0; }
.count { display: inline-block; background: var(--gold-soft); color: var(--gold); border-radius: 999px; padding: 0 9px; font-size: .85rem; margin-inline-start: 6px; }

/* ---------- Boutons ---------- */
.btn, .btn-secondary, .btn-ghost, .btn-danger-ghost, button.link {
  font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 9px; padding: 9px 16px;
  font-weight: 600; cursor: pointer; text-decoration: none; border: 1px solid transparent; line-height: 1.3; min-height: 42px;
}
.btn { background: var(--green); color: #fff; }
.btn:hover { background: var(--green-2); color: #fff; }
.btn-secondary { background: #fff; color: var(--green); border-color: #b9cfc4; }
.btn-secondary:hover { background: var(--green-soft); }
.btn-ghost { background: transparent; color: inherit; border-color: transparent; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); white-space: nowrap; }
.btn-danger-ghost { background: #fff; color: var(--red); border-color: #e3b9b0; }
.btn-danger-ghost:hover { background: var(--red-soft); }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--green-2); font-weight: 500; text-decoration: underline; }
.btn-lg { padding: 12px 22px; font-size: 1.02rem; }
.btn-block { width: 100%; }
.small { font-size: .84rem; }
.btn.small, .btn-secondary.small, .btn-ghost.small, .btn-danger-ghost.small { padding: 6px 12px; min-height: 34px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.inline, .inline-form { display: inline-flex; gap: 8px; align-items: center; margin: 0; }
.inline-form input { min-width: 220px; }

/* ---------- Formulaires ---------- */
.form .field { display: block; margin-bottom: 14px; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%; padding: 10px 12px; border: 1px solid #cfc8b8; border-radius: 9px; background: #fff; min-height: 44px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 76, 58, .25); border-color: var(--green-2); }
input:disabled { background: #f3f1ea; color: var(--muted); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--green); }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.check.big { margin: 6px 0 14px; font-weight: 500; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px 14px; }
.radios { display: flex; gap: 10px; flex-wrap: wrap; }
.radio { flex: 1; min-width: 110px; }
.radio input { position: absolute; opacity: 0; }
.radio span { display: block; text-align: center; padding: 10px; border: 1px solid #cfc8b8; border-radius: 9px; cursor: pointer; font-weight: 600; }
.radio input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.radio input:focus-visible + span { outline: 2px solid var(--gold); }

/* ---------- Messages ---------- */
.flash { border-radius: 10px; padding: 11px 14px; margin-bottom: 16px; border: 1px solid; }
.flash a { font-weight: 600; }
.flash-success { background: var(--green-soft); border-color: #b9d6c8; color: #11402f; }
.flash-error { background: var(--red-soft); border-color: #e6bdb3; color: #7d2a1c; }
.flash-warn { background: var(--amber-soft); border-color: #ecd59c; color: #6d4700; }
.flash-info { background: var(--blue-soft); border-color: #bcd3e6; color: #17456b; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge-draft { background: #eeece6; color: #5d625f; }
.badge-submitted { background: var(--blue-soft); color: var(--blue); }
.badge-returned { background: var(--red-soft); color: var(--red); }
.badge-supervisor_reviewed, .badge-gs_reviewed { background: var(--amber-soft); color: var(--amber); }
.badge-approved { background: var(--green-soft); color: var(--green); }
.badge-missing { background: #fff; color: var(--red); border-color: #e6bdb3; }
.role { font-size: .84rem; font-weight: 600; }
.role-admin { color: var(--gold); }
.role-attache { color: var(--green); }

/* ---------- Tableaux ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
.list th { text-align: start; font-weight: 600; color: var(--muted); font-size: .8rem; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.list td { padding: 10px; border-bottom: 1px solid #efeadf; vertical-align: middle; }
.list tbody tr:hover { background: #fbfaf6; }
.list tfoot th { color: var(--ink); border-top: 2px solid var(--line); border-bottom: 0; }
.list.dense td, .list.dense th { padding: 7px 8px; }
.list .num { text-align: center; font-variant-numeric: tabular-nums; }
.row-actions { text-align: end; white-space: nowrap; }
.row-missing td:first-child { box-shadow: inset 3px 0 0 var(--red); }
[dir=rtl] .row-missing td:first-child { box-shadow: inset -3px 0 0 var(--red); }
.row-inactive { opacity: .55; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; }
.filters select, .filters input { width: auto; flex: 1 1 150px; min-height: 40px; padding: 7px 10px; }
.period-picker { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.period-picker select { width: auto; min-height: 38px; padding: 6px 10px; }

/* ---------- Connexion ---------- */
body.bare .mainnav { display: none; }
.auth { max-width: 420px; margin: 18px auto 0; }
.auth-head { text-align: center; margin-bottom: 18px; }
.auth-head img { background: #fff; border-radius: 10px; padding: 4px; border: 1px solid var(--line); }
.auth-head h1 { font-size: 1.3rem; margin: 10px 0 6px; }
.auth-head p { margin: 0; }
.otp { font-size: 1.7rem; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; padding-inline-start: .5em; }
.auth-links { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; }

/* ---------- Tableau de bord ---------- */
.hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-inline-start: 5px solid var(--gold); }
.hero h2 { font-size: 1.5rem; margin-bottom: 6px; }
.hero p { margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { background: #faf8f2; border: 1px solid #eee8da; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat b { font-size: 1.4rem; color: var(--green); font-variant-numeric: tabular-nums; }
.stat span { font-size: .8rem; color: var(--muted); line-height: 1.3; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; color: inherit; text-decoration: none; }
.kpi span { color: var(--muted); font-size: .82rem; }
.kpi b { font-size: 1.9rem; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi small { color: var(--muted); }
.kpi-ok b { color: var(--blue); }
.kpi-warn b { color: var(--red); }
.kpi-warn:hover { border-color: #e6bdb3; }
.kpi-done b { color: var(--green); }
.bar { display: block; height: 6px; background: #edeae1; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: 99px; }
.quick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.quick-link { text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 4px; margin: 0; }
.quick-link b { color: var(--green); }
.quick-link span { color: var(--muted); font-size: .88rem; }
.quick-link:hover { border-color: #b9cfc4; }
.remind { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--amber-soft); border-color: #ecd59c; }
.remind p { margin: 0; font-weight: 600; color: #6d4700; }

/* ---------- Formulaire de rapport ---------- */
.activity-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.activity { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr auto; column-gap: 10px; background: #faf8f2; border: 1px solid #eee8da; border-radius: 10px; padding: 12px; }
.activity:focus-within { border-color: var(--green-2); background: #fff; }
.activity-num { grid-row: 1 / 3; width: 26px; height: 26px; border-radius: 50%; background: var(--green); color: #fff; font-size: .8rem; display: grid; place-items: center; font-weight: 700; }
.activity-label { font-weight: 600; }
.activity-hint { grid-column: 2; color: var(--muted); font-size: .78rem; line-height: 1.35; margin-top: 2px; }
.activity input { grid-column: 1 / 3; margin-top: 10px; font-size: 1.2rem; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 70%, rgba(246,243,236,0)); padding: 14px 0 10px; justify-content: flex-end; }

/* ---------- Fiche (modèle officiel) ---------- */
.sheet-card { padding: 18px 14px; }
.sheet { font-size: .92rem; }
.sheet-title { font-weight: 700; margin: 0 0 10px; }
.sheet-scale { display: inline-block; margin-inline-start: 6px; font-weight: 600; color: var(--muted); }
.sheet-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.sheet-table th, .sheet-table td { border: 1px solid #9aa39d; padding: 6px 4px; text-align: center; }
.sheet-table th { font-weight: 600; font-size: .78rem; background: #f4f2ec; line-height: 1.3; }
.sheet-table td { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.sheet-daiya { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.sig-slot { display: inline-flex; align-items: center; gap: 8px; }
.sig { max-height: 46px; max-width: 150px; vertical-align: middle; }
.sheet-rating { border-collapse: collapse; margin: 6px 0 14px; }
.sheet-rating td { border: 1px solid #9aa39d; padding: 6px 10px; }
.sheet-rating td.lbl { border: 0; padding-inline-end: 14px; font-weight: 600; }
.sheet-rating td.box { width: 30px; text-align: center; font-weight: 700; color: var(--green); }
.sheet-sign { width: 100%; border-collapse: collapse; }
.sheet-sign th, .sheet-sign td { border: 1px solid #9aa39d; padding: 8px; text-align: start; vertical-align: middle; }
.sheet-sign th { font-weight: 600; font-size: .84rem; background: #f4f2ec; white-space: nowrap; }
.sheet-sign .opinion { min-width: 180px; }
.sheet-sign .sigcell { width: 140px; height: 56px; text-align: center; }
.sheet-notes { margin: 12px 0 0; }

/* ---------- Validation / historique ---------- */
.review { border-inline-start: 5px solid var(--green); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px dashed #ebe5d8; }
.timeline li:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--blue); margin-top: 7px; flex: none; }
.dot-returned, .dot-reopened { background: var(--red); }
.dot-approved { background: var(--green); }
.dot-supervisor_reviewed, .dot-gs_reviewed { background: var(--gold); }
.dot-created { background: #b9b5aa; }
.comment { margin: 4px 0 0; background: #faf8f2; border-radius: 8px; padding: 6px 10px; }
.admin-zone { border-style: dashed; }

/* ---------- Profil / réglages ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.kv code { font-size: .82rem; }
.sig-current { min-height: 56px; display: flex; align-items: center; margin-bottom: 8px; }
.sig-current img { max-height: 70px; max-width: 260px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 4px; }
.sig-pad { width: 100%; max-width: 600px; aspect-ratio: 600 / 220; height: auto; border: 2px dashed #cfc8b8; border-radius: 10px; background: #fff; touch-action: none; display: block; cursor: crosshair; }
.small-actions { margin-top: 8px; }
.file-btn { border: 1px solid #cfc8b8; }
.logo-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 8px; }
.logo-slot { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.logo-slot span { font-weight: 600; font-size: .88rem; }
.logo-slot img { height: 60px; object-fit: contain; background: #faf8f2; border-radius: 6px; }
.logo-slot input[type=file] { min-height: 0; padding: 6px; font-size: .8rem; }
.inline-card { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
pre.code { background: #f4f2ec; border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: .82rem; }
.prose li { margin-bottom: 8px; }
.criteria { padding-inline-start: 18px; }
.steps { padding-inline-start: 22px; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis .kpi:first-child { grid-column: 1 / -1; }
  .quick { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) {
  .brand span { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 1.3rem; }
  main { padding: 16px 12px 32px; }
  .card { padding: 14px; }
  .brand small, .me-name { display: none; }
  .brand strong { font-size: .92rem; }
  .brand { flex: 1 1 auto; overflow: hidden; }
  .brand strong { overflow: hidden; text-overflow: ellipsis; }
  .topbar-tools { gap: 6px; flex: none; }
  .langs a { padding: 4px 8px; min-width: 30px; }
  .topbar-inner { padding: 8px 12px; }
  .topbar .btn-ghost.small { padding: 5px 9px; }
  .grid-2 { grid-template-columns: 1fr; }
  .activity-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .activity { padding: 10px; }
  .activity-hint { display: none; }
  .activity-num { width: 22px; height: 22px; font-size: .72rem; }
  .activity-label { font-size: .88rem; line-height: 1.3; }
  .logo-grid { grid-template-columns: 1fr; }
  .sticky-actions .btn, .sticky-actions .btn-secondary { flex: 1; }
  .hero .btn-lg, .hero .btn-secondary { width: 100%; }
  .hero > div { width: 100%; }
  .inline-form input { min-width: 0; }
  .sheet-sign th { white-space: normal; }
  .sheet-sign, .sheet-sign tbody, .sheet-sign tr { display: block; }
  .sheet-sign tr { display: grid; grid-template-columns: auto 1fr; border: 1px solid #9aa39d; border-bottom: 0; }
  .sheet-sign tr:last-child { border-bottom: 1px solid #9aa39d; }
  .sheet-sign th, .sheet-sign td { border: 0; border-bottom: 1px solid #e3e0d8; }
  .sheet-sign td[colspan] { grid-column: auto; }
  .sheet-sign .sigcell { width: auto; text-align: start; }
}
