/* Interface de la bibliotheque YOUNESS SCHOOL : theme sombre proche du dashboard yesmo.
   La CSP interdit tout style en ligne : toute mise en forme passe par des classes. */
:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #0e1626;
  --card: #111a2b;
  --card-2: #0f1a2c;
  --input: #0c1524;
  --line: #22314a;
  --line-2: #2b3c5a;
  --line-3: #1c2942;
  --text: #e6edf3;
  --text-2: #cbd5e1;
  --muted: #8aa0bd;
  --muted-2: #9fb3d1;
  --dim: #64748b;
  --brand: #60a5fa;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 14px;
}
a { color: var(--brand); }
a:hover { color: #93c5fd; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
code { background: var(--input); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; word-break: break-all; }
pre.json { background: var(--input); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12px; overflow: auto; max-height: 320px; white-space: pre-wrap; word-break: break-word; margin: 6px 0; }
mark { background: #854d0e; color: #fef3c7; border-radius: 3px; padding: 0 2px; }
h2 { font-size: 20px; margin: 0 0 4px; }
h3 { font-size: 16px; margin: 0 0 10px; }
h4 { font-size: 14px; margin: 14px 0 8px; color: var(--muted-2); }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; line-height: 1.5; }

/* ---------- Structure ---------- */
.top {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px;
  border-bottom: 1px solid var(--line-3); background: var(--panel);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; color: var(--brand); letter-spacing: .3px; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--muted-2); font-weight: 600; margin-left: 6px; }
.grow { flex: 1; }
.pill {
  font-size: 12.5px; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line-2);
  display: inline-flex; align-items: center; gap: 7px; color: var(--text-2); text-decoration: none; white-space: nowrap;
}
a.pill:hover { border-color: #3b82f6; color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; display: inline-block; }
.dot.on { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.off { background: var(--danger); }
.layout { display: flex; min-height: calc(100vh - 51px); }
nav.side { width: 210px; flex: none; border-right: 1px solid var(--line-3); padding: 12px; background: var(--panel); }
nav.side a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted-2);
  padding: 9px 12px; border-radius: 9px; font-size: 14px; margin-bottom: 2px; text-decoration: none;
}
nav.side a:hover { background: #16233b; color: var(--text); }
nav.side a.active { background: var(--primary-2); color: #fff; }
nav.side .count { font-size: 11px; background: #334155; color: #e2e8f0; border-radius: 999px; padding: 1px 7px; }
nav.side a.active .count { background: rgba(255, 255, 255, .2); }
main { flex: 1; padding: 22px; min-width: 0; max-width: 1180px; }
main:focus { outline: none; }
.loading { color: var(--muted); padding: 30px 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head > div:first-child { min-width: 0; flex: 1 1 320px; }

/* ---------- Cartes, grilles ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px; min-width: 0; }
.card.inner { background: var(--card-2); }
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-title .grow { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 14px; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
.stat { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-decoration: none; color: inherit; display: block; }
a.stat:hover { border-color: #3b82f6; }
.stat b { display: block; font-size: 24px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12.5px; }
.stat.warn b { color: #fbbf24; } .stat.bad b { color: #f87171; } .stat.good b { color: #4ade80; }
.kv { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr); gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 170px) minmax(0, 1fr) 54px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .n { text-align: right; color: var(--text-2); }

/* ---------- Boutons, formulaires ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--primary); color: #fff;
  border: 0; padding: 9px 15px; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer; min-height: 38px;
  font-family: inherit; text-decoration: none; line-height: 1.2; white-space: nowrap;
}
.btn:hover { background: var(--primary-2); color: #fff; }
.btn.gray { background: #334155; } .btn.gray:hover { background: #475569; }
.btn.red { background: #dc2626; } .btn.red:hover { background: #b91c1c; }
.btn.green { background: #16a34a; } .btn.green:hover { background: #15803d; }
.btn.ghost { background: transparent; border: 1px solid var(--line-2); color: var(--text-2); }
.btn.ghost:hover { border-color: #3b82f6; color: var(--text); background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; min-height: 30px; }
.btn:disabled, .btn.disabled { opacity: .45; cursor: default; pointer-events: none; }
.linkbtn { background: none; border: 0; color: var(--brand); cursor: pointer; font-size: inherit; padding: 0; text-decoration: underline; font-family: inherit; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.sb { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.btns { margin-top: 14px; gap: 8px; }
label.fld, .fld { display: block; font-size: 12.5px; color: var(--muted-2); margin: 12px 0 5px; }
.fld .opt { color: var(--dim); font-weight: 400; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input[type=url], select, textarea {
  background: var(--input); color: var(--text); border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px;
  font-size: 14px; width: 100%; font-family: inherit; min-width: 0;
}
textarea { min-height: 90px; resize: vertical; line-height: 1.45; }
textarea.code, textarea.big { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
textarea.big { min-height: 220px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: #3b82f6; }
input.invalid, select.invalid, textarea.invalid { border-color: #dc2626; }
select { cursor: pointer; }
.chk { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0; font-size: 13.5px; cursor: pointer; line-height: 1.4; }
.chk input { margin-top: 2px; width: 16px; height: 16px; flex: none; accent-color: var(--primary); }
.chk.inline { display: inline-flex; margin: 4px 14px 4px 0; }
.help { color: var(--muted); font-size: 12.5px; margin-top: 5px; line-height: 1.45; }
.ferr { color: #f87171; font-size: 12.5px; margin-top: 6px; }
.ferr:empty { display: none; }
input[type=checkbox].sel { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; flex: none; margin: 2px 0 0; }

.switch { width: 46px; height: 26px; border-radius: 999px; background: #334155; position: relative; cursor: pointer; transition: background .15s; border: 0; flex: none; padding: 0; }
.switch.on { background: #16a34a; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch.on::after { left: 23px; }
.switch:disabled { opacity: .4; cursor: default; }

/* ---------- Onglets ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 6px 0 16px; overflow-x: auto; }
.tabs a, .tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted-2); padding: 9px 13px; cursor: pointer;
  font-size: 14px; font-family: inherit; text-decoration: none; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center;
}
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs .active { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.tabs .count { font-size: 11px; background: #334155; border-radius: 999px; padding: 1px 7px; color: #e2e8f0; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; vertical-align: middle; white-space: nowrap; line-height: 1.5; }
.badge.vert, .badge.green { background: #14532d; color: #bbf7d0; }
.badge.bleu, .badge.blue { background: #1e3a8a; color: #bfdbfe; }
.badge.orange { background: #78350f; color: #fde68a; }
.badge.gris, .badge.gray { background: #334155; color: #e2e8f0; }
.badge.rouge, .badge.red { background: #7f1d1d; color: #fecaca; }
.badge.violet { background: #4c1d95; color: #ddd6fe; }
.badge.outline { background: transparent; border: 1px solid var(--line-2); color: var(--muted-2); font-weight: 500; }
.badges { display: inline-flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.ok { color: #4ade80; } .bad { color: #f87171; } .warnc { color: #fbbf24; } .muted { color: var(--muted); } .dim { color: var(--dim); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.break { word-break: break-word; overflow-wrap: anywhere; }

/* ---------- Bandeaux ---------- */
.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 11px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 13.5px; line-height: 1.45; }
.banner > div { flex: 1; min-width: 200px; }
.banner.info { background: #0f2a4a; border: 1px solid #1e40af; color: #dbeafe; }
.banner.warn { background: #3a2a0a; border: 1px solid #92400e; color: #fcd34d; }
.banner.bad { background: #3b1620; border: 1px solid #7f1d1d; color: #fecaca; }
.banner.good { background: #0d2b1b; border: 1px solid #166534; color: #bbf7d0; }

/* ---------- Listes ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { border: 1px solid var(--line); border-radius: 11px; padding: 11px 13px; background: var(--card-2); min-width: 0; }
.item.selected { border-color: #3b82f6; background: #0f1f3a; }
.item-head { display: flex; gap: 10px; align-items: flex-start; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; font-size: 14.5px; word-break: break-word; }
.item-title a { color: var(--text); text-decoration: none; }
.item-title a:hover { color: var(--brand); text-decoration: underline; }
.item-meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; word-break: break-word; }
.item-meta .sep { color: var(--dim); margin: 0 5px; }
.item-text { color: var(--text-2); font-size: 13px; margin-top: 6px; white-space: pre-wrap; word-break: break-word; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.snippet { color: var(--text-2); font-size: 12.5px; margin-top: 6px; line-height: 1.5; border-left: 2px solid var(--line-2); padding-left: 9px; word-break: break-word; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line-2); border-radius: 12px; }

/* ---------- Tableaux ---------- */
.tw { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { color: var(--muted-2); font-weight: 600; white-space: nowrap; }
.tbl td.wrap { white-space: normal; word-break: break-word; min-width: 180px; }
.tbl tr.dup td { color: var(--muted); }
.matrix th, .matrix td { text-align: center; white-space: nowrap; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.fcell { display: inline-block; min-width: 30px; font-size: 11px; font-weight: 700; padding: 3px 6px; border-radius: 7px; }
.fcell.active { background: #14532d; color: #bbf7d0; }
.fcell.desactivee { background: #334155; color: #cbd5e1; }
.fcell.interdite { background: #7f1d1d; color: #fecaca; }
.fcell.indisponible_technique { background: #78350f; color: #fde68a; }
.fcell.non_implementee { background: #1e293b; color: #64748b; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- Fonctions des sources ---------- */
.feat { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 4px 12px; align-items: start; padding: 10px 0; border-top: 1px solid var(--line); }
.feat:first-child { border-top: 0; }
.feat .code { font-weight: 700; color: var(--muted-2); padding-top: 2px; }
.feat .label { font-weight: 600; }
.feat .proof { color: var(--muted); font-size: 12.5px; margin-top: 3px; word-break: break-word; }
.feat .live { font-size: 12px; margin-top: 3px; }
.feat .ctrl { display: flex; align-items: center; gap: 8px; }

/* ---------- Progression ---------- */
progress { width: 100%; height: 8px; border: 0; border-radius: 999px; background: #1e293b; overflow: hidden; appearance: none; -webkit-appearance: none; }
progress::-webkit-progress-bar { background: #1e293b; border-radius: 999px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 999px; }
progress.done::-webkit-progress-value { background: #16a34a; }
progress.done::-moz-progress-bar { background: #16a34a; }
.prog { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.prog progress { flex: 1; }

/* ---------- Filtres de la bibliotheque ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.filters .yr { width: 92px; }
.filters select { width: auto; }
details.ms { position: relative; }
details.ms > summary {
  list-style: none; cursor: pointer; border: 1px solid var(--line-2); background: var(--input); border-radius: 9px;
  padding: 8px 11px; font-size: 13px; color: var(--text-2); white-space: nowrap; user-select: none;
}
details.ms > summary::-webkit-details-marker { display: none; }
details.ms > summary::after { content: ' \25BE'; color: var(--dim); }
details.ms.on > summary { border-color: #3b82f6; color: var(--text); }
details.ms .ms-list {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 15; background: var(--card); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 6px 10px; min-width: 220px; max-height: 300px; overflow: auto; box-shadow: 0 16px 40px rgba(0, 0, 0, .45);
}
.searchbar { display: flex; gap: 8px; }
.searchbar input { flex: 1; }
.selbar {
  position: sticky; top: 51px; z-index: 12; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: #10203a; border: 1px solid #1e40af; border-radius: 12px; padding: 9px 12px; margin: 10px 0;
}
.selbar b { margin-right: 4px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }

/* ---------- Depot de fichiers ---------- */
.drop {
  border: 2px dashed var(--line-2); border-radius: 14px; padding: 26px 16px; text-align: center; color: var(--muted-2);
  background: var(--card-2); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: #3b82f6; background: #0f1f3a; color: var(--text); }
.drop b { display: block; font-size: 15px; color: var(--text); margin-bottom: 4px; }
.drop input[type=file] { display: none; }
.filelist { margin-top: 10px; font-size: 13px; }
.filelist li { margin: 3px 0; word-break: break-word; }

/* ---------- Fiche document ---------- */
.doc-head { display: flex; gap: 16px; align-items: flex-start; }
.doc-head .thumb { width: 110px; flex: none; border-radius: 8px; border: 1px solid var(--line); background: var(--input); }
.doc-head .grow { min-width: 0; }
.doc-title { font-size: 21px; margin: 4px 0 6px; word-break: break-word; }
.attrib { background: var(--input); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font-size: 13px; word-break: break-word; }
.rights-box { border-radius: 12px; padding: 12px 14px; border: 1px solid var(--line-2); background: var(--card-2); }
.rights-box.vert { border-color: #166534; } .rights-box.bleu { border-color: #1e40af; } .rights-box.orange { border-color: #92400e; }
.rights-box.gris { border-color: #475569; } .rights-box.rouge { border-color: #991b1b; }

/* ---------- Signet ---------- */
.bookmarklet {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 10px; background: #16a34a; color: #fff;
  font-weight: 700; text-decoration: none; cursor: grab; border: 2px dashed #86efac;
}
.bookmarklet:hover { color: #fff; background: #15803d; }
.steps { margin: 8px 0; padding-left: 20px; line-height: 1.6; }

/* ---------- Modales, notifications ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(2, 6, 16, .72); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal {
  background: var(--card); border: 1px solid var(--line-2); border-radius: 14px; padding: 20px; width: min(560px, 100%);
  max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.modal.wide { width: min(820px, 100%); }
.modal h3 { margin: 0 0 12px; font-size: 17px; }
.modal p { font-size: 14px; line-height: 1.5; margin: 8px 0; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(460px, calc(100vw - 32px)); }
.toast { background: #16a34a; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); font-size: 14px; line-height: 1.4; word-break: break-word; }
.toast.err { background: #b91c1c; } .toast.info { background: #1d4ed8; } .toast.warn { background: #b45309; }

/* ---------- Ecran etroit (telephone) ---------- */
@media (max-width: 860px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .top { position: static; padding: 9px 14px; flex-wrap: wrap; gap: 8px; }
  .top .hide-sm { display: none; }
  .layout { flex-direction: column; min-height: 0; }
  nav.side {
    position: sticky; top: 0; z-index: 20; width: auto; display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px;
    border-right: 0; border-bottom: 1px solid var(--line-3);
  }
  nav.side a { flex: none; white-space: nowrap; margin: 0; padding: 7px 11px; }
  main { padding: 14px; }
  .card { padding: 14px; border-radius: 12px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input[type=url], select, textarea { font-size: 16px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .bar-row { grid-template-columns: minmax(90px, 120px) minmax(0, 1fr) 44px; }
  .item-head { flex-wrap: wrap; }
  .item-side { flex-direction: row; align-items: center; width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .doc-head { flex-direction: column; }
  .selbar { top: 47px; }
  .modal-btns .btn { flex: 1 1 auto; }
  .toasts { left: 14px; right: 14px; bottom: 14px; max-width: none; }
  .feat { grid-template-columns: 36px minmax(0, 1fr); }
  .feat .ctrl { grid-column: 2; }
  .filters .yr { width: 80px; }
  details.ms[open] { flex-basis: 100%; }
  details.ms .ms-list { position: static; min-width: 0; margin-top: 4px; box-shadow: none; max-height: 240px; }
}

/* ---------- Divers ---------- */
.span-all { grid-column: 1 / -1; }
.offscreen { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }
details > summary.fld { cursor: pointer; color: var(--brand); font-weight: 600; }
details.help > summary { cursor: pointer; color: var(--brand); }

/* ---------- Lecteur officiel (page lecteur.html) ---------- */
.viewer-page { max-width: 1100px; margin: 0 auto; padding: 18px; }
.viewer-frame { width: 100%; height: 78vh; min-height: 420px; border: 1px solid var(--line-2); border-radius: 12px; background: #fff; display: block; }
.viewer-ph { display: grid; place-items: center; height: 50vh; min-height: 260px; border: 2px dashed var(--line-2); border-radius: 12px; background: var(--card-2); text-align: center; padding: 16px; }
@media (max-width: 760px) {
  .viewer-page { padding: 12px; }
  .viewer-frame { height: 70vh; min-height: 320px; }
}
details.card > summary { cursor: pointer; list-style: none; margin-bottom: 0; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: 10px; }
