:root {
  --fond: #0f172a;
  --fond2: #111c33;
  --carte: #18233d;
  --carte2: #1f2c4a;
  --bord: #2a3a5c;
  --texte: #e5e9f2;
  --texte2: #9aa7c0;
  --accent: #f59e0b;
  --vert: #22c55e;
  --rouge: #ef4444;
  --bleu: #38bdf8;
  --violet: #a78bfa;
  --rayon: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--fond); color: var(--texte);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; overscroll-behavior-y: contain; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ---------- ecrans plein ---------- */
.ecran.plein { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.carte-centre { width: 100%; max-width: 380px; background: var(--carte); border: 1px solid var(--bord);
  border-radius: 20px; padding: 28px 22px; text-align: center; }
.logo { color: var(--accent); font-size: 30px; letter-spacing: -6px; margin-bottom: 4px; }
h1 { margin: 4px 0 6px; font-size: 22px; }
.aide { color: var(--texte2); margin: 6px 0 16px; }
.aide.petit { font-size: 12px; margin-top: 18px; }
.champ { display: block; text-align: left; margin: 12px 0; }
.champ span { display: block; font-size: 12px; color: var(--texte2); margin-bottom: 6px; }
.champ input, .champ select { width: 100%; padding: 13px 12px; border-radius: 10px; border: 1px solid var(--bord);
  background: var(--fond2); color: var(--texte); outline: none; }
.champ input:focus, .champ select:focus { border-color: var(--accent); }
.btn { border: 0; border-radius: 10px; padding: 13px 16px; width: 100%; margin-top: 8px; font-weight: 600; }
.btn.principal { background: var(--accent); color: #1a1205; }
.btn.lien { background: none; color: var(--texte2); text-decoration: underline; font-weight: 400; }
.btn.petit { width: auto; padding: 8px 14px; margin: 0; }
.msg { min-height: 20px; color: var(--rouge); margin: 10px 0 0; font-size: 14px; }
.msg.ok { color: var(--vert); }

/* ---------- entete ---------- */
.entete { position: sticky; top: 0; z-index: 10; background: rgba(15, 23, 42, .97);
  border-bottom: 1px solid var(--bord); padding: 10px 16px 8px; }
.entete-ligne { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.titre { font-size: 20px; font-weight: 700; }
.sous-titre { font-size: 12px; color: var(--texte2); }
.entete-actions { display: flex; gap: 6px; }
.icone { background: var(--carte); border: 1px solid var(--bord); border-radius: 10px; width: 40px; height: 40px;
  font-size: 18px; display: grid; place-items: center; }
.icone.tourne { animation: tourne 0.8s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }
.periodes { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.periodes::-webkit-scrollbar { display: none; }
.periodes button, .segments button, .puces button { flex: 0 0 auto; background: var(--carte); border: 1px solid var(--bord);
  border-radius: 999px; padding: 6px 13px; font-size: 13px; color: var(--texte2); white-space: nowrap; }
.periodes button.actif, .segments button.actif, .puces button.actif { background: var(--accent); color: #1a1205;
  border-color: var(--accent); font-weight: 600; }
.choix-dates { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.choix-dates input { flex: 1; min-width: 0; padding: 7px; border-radius: 8px; border: 1px solid var(--bord);
  background: var(--fond2); color: var(--texte); color-scheme: dark; }

/* ---------- contenu ---------- */
main { padding: 12px 16px 96px; max-width: 900px; margin: 0 auto; }
.grille { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .grille { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--carte); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 12px; min-width: 0; }
.kpi .lib { font-size: 12px; color: var(--texte2); }
.kpi .val { font-size: 20px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 12px; color: var(--texte2); margin-top: 2px; }
.kpi.grand { grid-column: span 2; }
.kpi.grand .val { font-size: 28px; color: var(--accent); }
.kpi.alerte { border-color: rgba(239, 68, 68, .5); }
.kpi.alerte .val { color: var(--rouge); }
.kpi.cliquable { cursor: pointer; }

.bloc { background: var(--carte); border: 1px solid var(--bord); border-radius: var(--rayon); margin-top: 12px; overflow: hidden; }
.bloc h3 { margin: 0; padding: 12px 14px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--texte2); font-weight: 600;
  display: flex; justify-content: space-between; gap: 8px; }
.bloc h3 small { text-transform: none; letter-spacing: 0; }
.ligne { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--bord); min-width: 0; }
.ligne:first-of-type { border-top: 0; }
.ligne.cliquable { cursor: pointer; }
.ligne.cliquable:active { background: var(--carte2); }
.ligne .g { flex: 1; min-width: 0; }
.ligne .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne .d { font-size: 12px; color: var(--texte2); overflow: hidden; text-overflow: ellipsis; }
.ligne .m { font-weight: 700; white-space: nowrap; text-align: right; }
.ligne .m small { display: block; font-weight: 400; font-size: 12px; color: var(--texte2); }
.rang { width: 26px; height: 26px; border-radius: 8px; background: var(--carte2); display: grid; place-items: center;
  font-size: 12px; color: var(--texte2); flex: 0 0 auto; }
.barre { height: 6px; background: var(--fond2); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.barre i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.vide { padding: 22px 14px; text-align: center; color: var(--texte2); }
.erreur { margin-top: 12px; padding: 14px; border-radius: var(--rayon); background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .4); color: #fecaca; }
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--carte2);
  color: var(--texte2); margin-left: 4px; vertical-align: middle; }
.badge.rouge { background: rgba(239, 68, 68, .18); color: #fca5a5; }
.badge.vert { background: rgba(34, 197, 94, .18); color: #86efac; }
.badge.orange { background: rgba(245, 158, 11, .18); color: #fcd34d; }
.badge.bleu { background: rgba(56, 189, 248, .18); color: #7dd3fc; }

.heures { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding: 10px 14px 4px; }
.heures div { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .9; position: relative; }
.heures-lib { display: flex; gap: 3px; padding: 0 14px 10px; font-size: 10px; color: var(--texte2); }
.heures-lib span { flex: 1; text-align: center; }

.segments, .puces { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.segments::-webkit-scrollbar, .puces::-webkit-scrollbar { display: none; }
.puces { margin-top: 10px; }
.puces button { font-size: 12px; padding: 5px 10px; }
.recherche { width: 100%; margin-top: 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--bord);
  background: var(--carte); color: var(--texte); outline: none; }

/* salle */
.tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; padding: 12px; }
.table { border-radius: 12px; padding: 9px 8px; background: var(--fond2); border: 1px solid var(--bord); min-height: 74px; cursor: pointer; min-width: 0; }
.table .tn { font-weight: 700; }
.table .ts { font-size: 11px; color: var(--texte2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table.occ { background: rgba(245, 158, 11, .14); border-color: rgba(245, 158, 11, .55); }
.table.occ .tt { color: var(--accent); font-weight: 700; font-size: 13px; }
.table.add { background: rgba(56, 189, 248, .12); border-color: rgba(56, 189, 248, .5); }
.table.add .tt { color: var(--bleu); }

/* barre d'onglets */
.onglets { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: rgba(17, 28, 51, .98);
  border-top: 1px solid var(--bord); padding-bottom: env(safe-area-inset-bottom); }
.onglets button { flex: 1; background: none; border: 0; padding: 8px 0 9px; color: var(--texte2); display: flex;
  flex-direction: column; align-items: center; gap: 2px; font-size: 11px; }
.onglets button i { font-style: normal; font-size: 18px; line-height: 1.1; }
.onglets button.actif { color: var(--accent); }

/* feuille de detail */
#voile { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 30; }
#feuille { position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; background: var(--fond2); border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--bord); max-height: 88vh; display: flex; flex-direction: column; max-width: 900px; margin: 0 auto;
  animation: monte .18s ease-out; }
@keyframes monte { from { transform: translateY(40px); opacity: .4; } }
.feuille-poignee { width: 40px; height: 4px; border-radius: 2px; background: var(--bord); margin: 8px auto 0; }
.feuille-entete { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; gap: 8px; }
.feuille-titre { font-weight: 700; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#feuille-corps { overflow-y: auto; padding: 0 16px 24px; }
.detail-grille { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.detail-grille div { background: var(--carte); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.detail-grille b { display: block; font-size: 11px; color: var(--texte2); font-weight: 400; }
.detail-grille span { overflow-wrap: anywhere; }

/* menu */
#menu { position: fixed; top: 60px; right: 12px; z-index: 40; background: var(--carte2); border: 1px solid var(--bord);
  border-radius: 12px; min-width: 220px; overflow: hidden; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }
#menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 13px 16px; border-top: 1px solid var(--bord); }
.menu-info { padding: 12px 16px; font-size: 13px; color: var(--texte2); }
.menu-info b { color: var(--texte); display: block; }

#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 50; background: var(--carte2);
  border: 1px solid var(--bord); padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw; }
