/* ============================================================================
   Tadbir Al Maher — charte graphique
   Marque : vert émeraude profond + accent or (distinct du rouge CATHEDIS).
   Cartes arrondies 18px, Segoe UI (offline), AG Grid quartz.
   ============================================================================ */
:root {
  --primary: #0d6e63;          /* émeraude Tadbir */
  --primary-dark: #0a554c;
  --primary-bg: #e6f3f1;
  --primary-border: #9ecfc9;
  --accent: #b9770a;           /* or */
  --accent-bg: #fdf3e3;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #eef1f4;
  --border: #e2e7ec;
  --text: #1c2733;
  --text-secondary: #5a6473;
  --muted: #98a2b3;
  --success: #0f9d6a;
  --danger: #8a6a16;           /* alerte bronze, sans rouge */
  --warning: #b9770a;
  --header-h: 58px;
  --sidebar-w: 76px; /* rail d'icônes (style Maher ERP) — libellés en infobulle */
  --chart-1: #0d6e63; --chart-2: #b9770a; --chart-3: #2f6bd6;
  --chart-4: #4f6f8f; --chart-5: #7a5cc0; --chart-6: #5a6473;
  --card: #ffffff;             /* fond des champs/recherche (alias de --surface) */
  --surface-2: #f1f3f2;        /* fond des vignettes d'images */
  --app-zoom: 1;               /* zoom d'affichage (js/theme.js pose html{zoom} + cette variable) */
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--primary); }

/* ── Layout ── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--header-h) auto auto minmax(0, 1fr);
  height: calc(100vh / var(--app-zoom, 1)); /* repli pour anciens navigateurs */
  height: calc(100dvh / var(--app-zoom, 1)); /* évite le rognage par les barres mobiles */
}
.app-header {
  grid-column: 1 / 3;
  grid-row: 1;
  background: linear-gradient(120deg, var(--primary-dark), var(--primary));
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  box-shadow: 0 2px 10px rgba(13,110,99,.25);
  z-index: 10;
}
.brand-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 11px; background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.18); flex: 0 0 auto;
}
.brand-logo img { width: 32px; height: 32px; display: block; }
.brand { display: flex; align-items: baseline; gap: 9px; }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: .3px; }
.brand-ar { font-size: 15px; opacity: .85; font-weight: 600; }
.header-spacer { flex: 1; }
.header-societe select {
  background: rgba(255,255,255,.14);
  color: #fff;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
}
.header-societe select option { color: var(--text); }
.header-user { font-size: 13px; opacity: .95; text-align: right; line-height: 1.25; }
.header-user .role-badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: rgba(255,255,255,.18); font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
}
.btn-logout {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.3);
  border-radius: 8px; padding: 7px 13px; cursor: pointer; font-weight: 600;
}
.btn-logout:hover { background: rgba(255,255,255,.26); }

/* ── Sélecteur de langue (header) ── */
.lang-select {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.35);
  border-radius: 8px; padding: 6px 8px; font-size: 13px; font-weight: 600; width: auto;
}
.lang-select option { color: var(--text); }

/* ── Horaires de prière (chip en-tête + menu, méthode Habous) ── */
.header-dropdown { position: relative; display: inline-flex; }
.header-btn {
  font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.header-btn:hover { background: rgba(255,255,255,.24); }
.header-btn.prayer-now { background: var(--accent); border-color: var(--accent); animation: prayerPulse 1.6s ease infinite; }
@keyframes prayerPulse { 50% { opacity: .75; } }
.header-dropdown-menu {
  display: none; position: absolute; top: calc(100% + 8px); right: 0; z-index: 200;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 12px 34px rgba(0,0,0,.18); min-width: 240px; padding: 10px 12px;
}
.header-dropdown.open .header-dropdown-menu { display: block; }
.prayer-menu-head { font-weight: 700; display: flex; align-items: center; gap: 8px; justify-content: space-between; margin-bottom: 8px; }
.prayer-menu-head select { width: auto; font-size: 12.5px; padding: 4px 6px; }
.prayer-row { display: flex; justify-content: space-between; padding: 5px 2px; font-size: 13.5px; border-bottom: 1px dashed var(--border); }
.prayer-row:last-of-type { border-bottom: none; }
.prayer-row.next { color: var(--primary); font-weight: 700; }
.prayer-menu-foot { font-size: 11px; color: var(--muted); margin-top: 8px; }
@media (max-width: 860px) { #prayer-dd .hdr-label { display: none; } } /* mobile : juste 🕌 */

/* ── Sidebar ── */
.app-sidebar {
  grid-column: 1; grid-row: 2 / 5;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden;
  padding: 12px 0 24px;
  width: var(--sidebar-w);
  transition: width .18s ease;
  z-index: 95; /* au survol, le panneau étendu passe PAR-DESSUS le contenu */
}
/* Survol (desktop) : le rail s'étend en surcouche avec les libellés complets */
@media (min-width: 861px) {
  .app-sidebar:hover { width: 248px; box-shadow: 6px 0 24px rgba(0,0,0,.14); }
  .app-sidebar:hover .side-nav a {
    width: auto; height: auto; justify-content: flex-start; gap: 10px;
    padding: 9px 14px; margin: 1px 10px; border-radius: 999px; font-size: 13.5px;
    white-space: nowrap;
  }
  .app-sidebar:hover .nav-group-title {
    font-size: 10.5px; height: auto; border-top: none; overflow: visible;
    font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
    color: var(--muted); padding: 12px 18px 4px; margin: 4px 0 0;
  }
}
.side-title { display: none; } /* rail : pas de titre */
.side-nav { list-style: none; }
/* Rail : les titres de groupe deviennent de fins séparateurs */
.nav-group-title {
  font-size: 0; height: 0; overflow: hidden;
  border-top: 1px solid var(--border); margin: 10px 16px 8px; padding: 0;
}
.side-nav > li:first-child.nav-group-title { border-top: none; margin-top: 0; }

/* ── Barre d'onglets de travail ── */
.tab-bar {
  grid-column: 2; grid-row: 2;
  display: flex; gap: 4px; align-items: flex-end;
  background: var(--surface-alt); border-bottom: 1px solid var(--border);
  padding: 6px 12px 0; overflow-x: auto; min-width: 0; min-height: 40px;
}
.tab-item {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 12px; border-radius: 10px 10px 0 0; cursor: pointer;
  background: transparent; color: var(--text-secondary); font-size: 13px; font-weight: 500;
  white-space: nowrap; border: 1px solid transparent; border-bottom: none;
}
.tab-item:hover { background: var(--surface); color: var(--text); }
.tab-item.active { background: var(--surface); color: var(--primary); font-weight: 600; border-color: var(--border); }
/* Icônes monoline : signature verte, or sur l'onglet actif */
.tab-item .tab-ico { display: inline-flex; color: var(--primary); }
.tab-item.active .tab-ico { color: var(--accent); }
.tab-ico svg, .side-nav .ico svg { display: block; }
.tab-close { opacity: .5; font-size: 11px; padding: 0 3px; border-radius: 4px; }
.tab-close:hover { opacity: 1; background: var(--primary-bg); color: var(--primary); }
.app-content { grid-column: 2; grid-row: 4; min-width: 0; min-height: 0; }
#onboarding-zone { grid-column: 2; grid-row: 3; min-width: 0; }
.tab-pane { }
.side-nav a {
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; padding: 0; margin: 3px auto;
  border-radius: 14px; text-decoration: none;
  color: var(--text-secondary); font-weight: 500; font-size: 0; /* rail : libellé masqué (infobulle) */
}
.side-nav a:hover { background: var(--primary-bg); color: var(--text); }
.side-nav a.active { background: var(--primary); color: #fff; font-weight: 600; }
.side-nav .ico { width: 24px; display: inline-flex; align-items: center; justify-content: center; color: var(--primary); }
.side-nav .ico svg { width: 22px; height: 22px; }
.side-nav a:hover .ico { color: var(--accent); }        /* survol → or */
.side-nav a.active .ico { color: #fff; }                 /* actif → blanc sur fond vert */

/* ── Contenu ── */
.app-content { overflow-y: auto; padding: 20px 24px 60px; }
.page-title { font-size: 21px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--text-secondary); margin-bottom: 18px; font-size: 13px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(28,39,51,.05);
  margin-bottom: 16px;
}
.card h3 { font-size: 15px; margin-bottom: 12px; }
.cards-row { display: grid; gap: 14px; margin-bottom: 16px; }
.cards-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat-card { text-align: left; }
.stat-label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-value.pos { color: var(--success); }
.stat-value.neg { color: var(--danger); }

/* ── Formulaires ── */
label.fld { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin: 8px 0 3px; }
input, select, textarea {
  font: inherit; padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-border); border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 14px; align-items: end; }
.form-grid .full { grid-column: 1 / -1; }

.btn {
  font: inherit; font-weight: 600; border: none; border-radius: 8px;
  padding: 9px 16px; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-alt); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-gold { background: var(--accent); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ── Bannière d'onboarding (auto-inscription) ── */
.onboarding-banner {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin: 12px 20px 0; padding: 12px 16px;
  background: var(--primary-bg, #e6f4f1); border: 1px solid var(--primary, #0d6e63);
  border-left-width: 4px; border-radius: 10px;
}
.onboarding-banner .ob-txt { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 2px; }
.onboarding-banner .ob-txt strong { font-size: 14px; }
.onboarding-banner .ob-txt span { font-size: 13px; color: var(--text-secondary); }
.onboarding-banner .ob-actions { display: flex; gap: 8px; }

/* ── Mini-tuto par volet ── */
.tuto-card {
  position: relative; margin: 0 0 16px; padding: 14px 16px 12px;
  background: var(--accent-bg, #fdf3e3); border: 1px solid var(--accent, #b9770a);
  border-left-width: 4px; border-radius: 10px;
}
.tuto-card .tuto-title { font-weight: 700; font-size: 14.5px; margin-bottom: 4px; }
.tuto-card .tuto-intro { margin: 0 0 8px; font-size: 13px; color: var(--text-secondary); }
.tuto-card .tuto-points { margin: 0 0 10px; padding-left: 20px; font-size: 13px; line-height: 1.65; }
.tuto-card .tuto-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tuto-card .tuto-off { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); font-weight: 400; cursor: pointer; }
.tuto-card .tuto-off input { width: auto; }
.tuto-card .tuto-x {
  position: absolute; top: 8px; right: 10px; border: 0; background: transparent;
  font-size: 20px; line-height: 1; cursor: pointer; color: var(--text-secondary); padding: 2px 6px;
}
.tuto-card .tuto-x:hover { color: var(--text); }
.btn-help {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface, #fff); color: var(--primary); font-weight: 700; font-size: 15px;
  cursor: pointer; flex: none; margin-right: 4px;
}
.btn-help:hover { background: var(--primary-bg); border-color: var(--primary-border, var(--primary)); }

/* ── Tableaux (repli sans AG Grid) ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; padding: 8px 10px; background: var(--surface-alt); font-weight: 600; }
.data-table td { padding: 7px 10px; border-top: 1px solid var(--border); }
.grid-box { height: 480px; }
.grid-box.small { height: 340px; }

/* ── Badges / divers ── */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge-matiere { background: var(--surface-alt); color: var(--text-secondary); }
.badge-produit { background: var(--primary-bg); color: var(--primary-dark); }
.badge-pack { background: var(--accent-bg); color: var(--accent); }
.badge-ok { background: #e4f5ee; color: var(--success); }
.badge-off { background: #f6f0dc; color: var(--danger); }
.badge-err { background: var(--danger); color: #fff; }
.badge-pack { background: var(--accent); color: #fff; } /* Gold */
.txt-pos { color: var(--success); font-weight: 600; }
.txt-neg { color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); }

/* ── Toast ── */
#toast-zone { position: fixed; bottom: 22px; right: 22px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: #fff; padding: 11px 17px; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); font-size: 13.5px; animation: toastIn .25s ease;
}
.toast.err { background: var(--danger); }
.toast.okk { background: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ── Modale ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,25,35,.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity .18s ease;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--surface); border-radius: 16px; padding: 22px; box-sizing: border-box;
  /* Le cadre s'adapte au contenu (jusqu'à un max) → plus de div interne qui dépasse
     un cadre fixe. Les contenus larges (fiche élève, tableaux) tiennent aussi. */
  width: fit-content; min-width: min(340px, 90vw);
  max-width: min(940px, calc(94vw / var(--app-zoom, 1)));
  max-height: calc(88vh / var(--app-zoom, 1)); overflow-x: hidden; overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
/* Aucun enfant de modale ne déborde du cadre : fini le scroll horizontal et le
   bouton « Enregistrer » coupé (les tableaux gèrent leur propre overflow-x:auto). */
#modal-body, #modal-body > * { max-width: 100%; box-sizing: border-box; }
.modal h3 { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ── POS ── */
.pos-layout { display: grid; grid-template-columns: 1fr 340px; gap: 16px; height: calc((100vh - var(--header-h) - 130px) / var(--app-zoom, 1)); } /* hauteur affinée par fitPos() */
.pos-produits { overflow-y: auto; }
.pos-panier { overflow-y: auto; }

/* Mode caisse immersif : sidebar masquée quand le volet POS est actif */
body.pos-mode .app-sidebar { display: none; }
body.pos-mode .app-layout { grid-template-columns: 0 1fr; }
body.pos-mode .tab-bar, body.pos-mode .app-content { grid-column: 1 / 3; }
body.pos-mode #onboarding-zone { grid-column: 1 / 3; }

/* Familles en onglets sélectionnables (bande permanente au-dessus du menu) */
.pos-fam-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pos-fam-chips.nowrap { flex-wrap: nowrap; overflow-x: auto; margin-bottom: 0; padding-bottom: 4px; scrollbar-width: thin; }
.pos-fam-chip {
  padding: 11px 20px; border-radius: 999px; cursor: pointer; user-select: none;
  background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.pos-fam-chip:hover { border-color: var(--primary-border, var(--primary)); }
.pos-fam-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pos-famille-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--primary-dark); margin: 10px 2px 6px; }
.pos-famille-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 6px; }
.pos-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 10px; cursor: pointer; text-align: center; font-weight: 600; font-size: 13.5px;
  transition: transform .08s ease, box-shadow .12s ease;
}
.pos-btn:hover { box-shadow: 0 3px 12px rgba(13,110,99,.18); transform: translateY(-1px); border-color: var(--primary-border); }
.pos-btn .prix { display: block; color: var(--primary); font-size: 15px; margin-top: 5px; }
.pos-btn .pos-img { display: block; width: 56px; height: 56px; margin: 0 auto 7px; border-radius: 11px; object-fit: cover; background: var(--surface-2, #f1f3f2); }

/* Cellule « Famille » éditable en un clic (grille Articles) */
.ag-theme-quartz .fam-cell { cursor: pointer; }
.ag-theme-quartz .fam-cell:hover { background: rgba(13,110,99,.07); box-shadow: inset 0 0 0 1px var(--primary-border, rgba(13,110,99,.3)); }

/* Vignettes d'articles (grille Articles, Catalogue type) */
.art-vignette { width: 26px; height: 26px; border-radius: 7px; vertical-align: middle; margin-right: 8px; flex: none; object-fit: cover; background: var(--surface-2, #f1f3f2); }
.pos-panier { display: flex; flex-direction: column; }
.pos-lignes { flex: 1; overflow-y: auto; }
.pos-ligne { display: flex; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.pos-ligne .nom { flex: 1; }
.pos-total { font-size: 26px; font-weight: 700; text-align: right; padding: 12px 4px; color: var(--primary-dark); }

/* ── Ticket 80mm (impression) ── */
#ticket-print { display: none; }
@media print {
  body * { visibility: hidden; }
  #ticket-print, #ticket-print * { visibility: visible; }
  #ticket-print {
    display: block; position: absolute; left: 0; top: 0; width: 72mm;
    font-family: 'Courier New', monospace; font-size: 11px; color: #000;
  }
}

/* ── Login ── */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0a554c 0%, #0d6e63 55%, #14877a 100%);
}
.login-card {
  background: #fff; border-radius: 20px; padding: 38px 34px; width: min(400px, 92vw);
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .logo-mark { width: 104px; height: 104px; margin: 0 auto 10px; display: block; }
.login-brand .logo {
  width: 66px; height: 66px; margin: 0 auto 12px; border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800;
}
.login-brand h1 { font-size: 21px; }
.login-brand .ar { color: var(--accent); font-size: 15px; font-weight: 700; margin-top: 2px; }
.login-brand .tag { color: var(--text-secondary); font-size: 12.5px; margin-top: 6px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; text-align: center; }

/* ── Responsive ── */
.burger { display: none; align-items: center; justify-content: center; min-width: 48px; min-height: 48px; background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }
.sidebar-backdrop { display: none; }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }

/* Tablette : sidebar en tiroir, burger visible */
@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--header-h) auto auto minmax(0, 1fr);
  }
  .app-header { grid-column: 1; }
  .tab-bar { grid-column: 1; grid-row: 2; }
  #onboarding-zone { grid-column: 1; grid-row: 3; }
  .app-content { grid-column: 1; grid-row: 4; }
  .app-sidebar { display: none; }
  .app-sidebar.open {
    display: block; position: fixed; top: var(--header-h); bottom: 0; left: 0;
    width: min(86vw, 320px); z-index: 90; box-shadow: 4px 0 18px rgba(0,0,0,.2);
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .app-sidebar.open + .sidebar-backdrop {
    display: block; position: fixed; inset: var(--header-h) 0 0; z-index: 89;
    width: 100%; min-height: 48px; border: 0; background: rgba(9,45,41,.38);
  }
  /* Menu mobile ouvert : on RÉTABLIT les libellés complets (le rail icônes est desktop) */
  .app-sidebar.open .side-nav a {
    width: auto; height: auto; min-height: 48px; justify-content: flex-start; gap: 10px;
    padding: 9px 14px; margin: 1px 10px; border-radius: 999px; font-size: 13.5px;
  }
  .app-sidebar.open .nav-group-title {
    font-size: 10.5px; height: auto; border-top: none;
    font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
    color: var(--muted); padding: 12px 18px 4px; margin: 4px 0 0;
  }
  .burger { display: inline-flex !important; align-items: center; }
  .pos-layout { grid-template-columns: 1fr; height: auto; }
  .app-content { padding: 16px 14px 50px; }
  .header-user { display: none; }          /* nom/rôle non essentiels sur petit écran */
  .brand-ar { display: none; }
  body.pos-mode .app-layout { grid-template-columns: minmax(0, 1fr); }
  body.pos-mode .tab-bar,
  body.pos-mode #onboarding-zone,
  body.pos-mode .app-content { grid-column: 1; }
}

/* Téléphone : véritable en-tête sur deux rangées, cartes/grilles tactiles. */
@media (max-width: 600px) {
  :root { --header-h: calc(112px + env(safe-area-inset-top)); }
  html, body { overflow-x: hidden; }        /* jamais de scroll horizontal de page */
  .app-header {
    display: grid;
    grid-template-columns: 48px 42px minmax(0, 1fr) 48px 48px;
    grid-template-rows: 48px 48px;
    align-content: end; gap: 4px;
    padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  }
  .burger { grid-column: 1; grid-row: 1; }
  .brand-logo { grid-column: 2; grid-row: 1; width: 40px; height: 40px; justify-self: center; }
  .brand, .header-spacer, .header-user { display: none; }
  .header-societe {
    grid-column: 3; grid-row: 1; min-width: 0; overflow: hidden;
    align-self: stretch; display: flex !important; align-items: center;
  }
  .header-societe > span {
    display: block; min-width: 0; max-width: 100%; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
  }
  .header-societe select, #exercice-select, #lang-select {
    min-width: 0; max-width: none; width: 100%; min-height: 48px;
    padding: 7px 8px; font-size: 16px; text-overflow: ellipsis;
  }
  #exercice-select { grid-column: 1 / 3; grid-row: 2; }
  #lang-select { grid-column: 3; grid-row: 2; }
  #prayer-dd { grid-column: 4; grid-row: 2; width: 48px; height: 48px; }
  #prayer-dd .header-btn { width: 48px; height: 48px; padding: 0; justify-content: center; font-size: 18px; }
  #btn-help { grid-column: 4; grid-row: 1; }
  .hdr-tools { grid-column: 5; grid-row: 2; width: 48px; height: 48px; margin: 0; }
  .hdr-tools .hdr-tool { min-width: 48px; min-height: 48px; }
  #btn-volets, #btn-premium { display: none !important; } /* burger = menu ; premium reste disponible sur grand écran */
  .btn-logout {
    grid-column: 5; grid-row: 1; width: 48px; min-width: 48px; height: 48px;
    padding: 0; font-size: 0;
  }
  .btn-logout::before { content: '⎋'; font-size: 23px; line-height: 1; }

  .app-content { padding: 12px 10px calc(46px + env(safe-area-inset-bottom)); }
  .card { padding: 14px 13px; border-radius: 14px; margin-bottom: 12px; }
  .card h3 { font-size: 14px; }
  .cards-row, .cards-4, .mg-kpis, .db-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
  .stat-card { min-width: 0; overflow-wrap: anywhere; }
  .stat-value { font-size: 19px; }
  .stat-label { font-size: 11px; }
  .grid-box { height: calc(62vh / var(--app-zoom, 1)); min-height: 320px; }
  .grid-box.small { height: calc(52vh / var(--app-zoom, 1)); min-height: 300px; }
  .tab-bar { min-height: 52px; padding: 3px 6px 0; gap: 3px; scrollbar-width: thin; }
  .tab-item { min-height: 48px; padding: 0 8px; font-size: 12.5px; }
  .tab-close {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 48px; height: 48px; margin-right: -8px; font-size: 12px;
  }
  .page-title { font-size: 20px; }
  h1.page-title { font-size: 20px; }
  .page-sub { line-height: 1.45; margin-bottom: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  input:not([type="checkbox"]):not([type="radio"]), select, textarea,
  .app-content .btn, .modal .btn { min-height: 48px; font-size: 16px; }
  .app-content .btn-sm, .modal .btn-sm { padding: 8px 12px; font-size: 14px; }
  .modal-overlay { align-items: flex-end; padding-top: env(safe-area-inset-top); }
  .modal {
    width: 100%; max-width: none;
    max-height: calc(100dvh - env(safe-area-inset-top));
    padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0; overscroll-behavior: contain;
  }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions > .btn { flex: 1 1 140px; }
  .tuto-card .tuto-x { width: 48px; height: 48px; top: 2px; right: 2px; }
  .tuto-card .tuto-title { padding-right: 40px; }
  .tuto-card .tuto-off { min-height: 48px; }
  .tuto-card .tuto-off input { width: 24px; height: 24px; }
  .onboarding-banner { margin: 8px 10px 0; padding: 12px; }
  .onboarding-banner .ob-txt { min-width: 0; }
  .onboarding-banner .ob-actions { width: 100%; flex-wrap: wrap; }
  .onboarding-banner .ob-actions .btn { flex: 1 1 140px; min-height: 48px; }
  #toast-zone {
    left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .toast { width: 100%; overflow-wrap: anywhere; }

  /* Pagination AG Grid compacte : la taille de page n'est pas une action utile au téléphone. */
  .ag-paging-page-size, .ag-paging-row-summary-panel { display: none !important; }
  .ag-paging-panel { min-height: 56px; padding: 4px; justify-content: center; }
  .ag-paging-button { min-width: 48px; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; }
}

@media (max-width: 370px) {
  .cards-row, .cards-4, .mg-kpis, .db-kpis { grid-template-columns: minmax(0, 1fr) !important; }
}

/* ── Recherche rapide des grilles (posée par makeGrid) : mobile uniquement ── */
.grid-search { display: none; }
@media (max-width: 860px) {
  .grid-search {
    display: block; width: 100%; margin: 0 0 8px;
    padding: 11px 14px; font-size: 16px; /* 16px = pas de zoom auto iOS */
    border: 1px solid var(--border); border-radius: 10px; background: var(--card, #fff);
  }
  .grid-search:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   Outils d'en-tête : thème (🌙/☀) + zoom (A− / A+) — posés par js/theme.js
   ══════════════════════════════════════════════════════════════════════════ */
.hdr-tools { display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; }
.hdr-tool { margin-right: 0; font-size: 17px; line-height: 1; }
.hdr-zoom { font-size: 13px; font-weight: 800; letter-spacing: -.3px; border-radius: 12px; }
.hdr-tool:disabled { opacity: .45; cursor: default; }
.brand-name { white-space: nowrap; }
@media (max-width: 900px) { .hdr-zoom { display: none; } } /* tablette/téléphone : le pinch-zoom natif suffit, l'en-tête reste sur une ligne */

/* ══════════════════════════════════════════════════════════════════════════
   THÈME SOMBRE — html[data-theme="dark"] (js/theme.js : clair / sombre / auto)
   Toutes les variables de couleur sont redéfinies ; les éléments à couleurs
   codées en dur (champs, badges, toasts, calendriers, AG Grid) sont ajustés.
   ══════════════════════════════════════════════════════════════════════════ */
html[data-theme="dark"] {
  color-scheme: dark;
  --primary: #23a08f;          /* émeraude éclaircie (lisible sur fond sombre) */
  --primary-dark: #1b8477;
  --primary-bg: #123a36;
  --primary-border: #2f6f66;
  --accent: #d9952a;           /* or éclairci */
  --accent-bg: #3a2c10;
  --bg: #0f1517;
  --surface: #16201f;
  --surface-alt: #1c2827;
  --border: #27363a;
  --text: #e6edf0;
  --text-secondary: #a9b7bd;
  --muted: #6f7f86;
  --success: #34c48d;
  --danger: #d6a84b;
  --warning: #d9952a;
  --card: #121b1a;
  --surface-2: #1f2c2b;
  --chart-3: #5b8ee6; --chart-4: #7394b5; --chart-5: #9d84d8; --chart-6: #8b97a3;
}
html[data-theme="dark"] body { background: var(--bg); color: var(--text); }
html[data-theme="dark"] .app-header {
  background: linear-gradient(120deg, #083a34, #0b5248);
  box-shadow: 0 2px 12px rgba(0,0,0,.45);
}
html[data-theme="dark"] .app-sidebar { box-shadow: none; }
@media (min-width: 861px) { html[data-theme="dark"] .app-sidebar:hover { box-shadow: 6px 0 24px rgba(0,0,0,.5); } }
html[data-theme="dark"] .card { box-shadow: 0 1px 4px rgba(0,0,0,.35); }
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea {
  background: var(--card); color: var(--text); border-color: var(--border);
}
html[data-theme="dark"] input::placeholder, html[data-theme="dark"] textarea::placeholder { color: var(--muted); }
html[data-theme="dark"] input:disabled, html[data-theme="dark"] select:disabled { opacity: .6; }
html[data-theme="dark"] .btn-help { background: rgba(255,255,255,.10); color: #fff; border-color: rgba(255,255,255,.28); }
html[data-theme="dark"] .btn-help:hover { background: rgba(255,255,255,.22); }
html[data-theme="dark"] .btn-secondary { background: var(--surface-alt); color: var(--text); }
html[data-theme="dark"] .btn-secondary:hover { background: var(--border); }
html[data-theme="dark"] .tab-bar { background: #131c1b; }
html[data-theme="dark"] .tab-item.active { background: var(--surface); }
html[data-theme="dark"] .badge-ok { background: rgba(52,196,141,.16); color: var(--success); }
html[data-theme="dark"] .badge-off { background: rgba(214,168,75,.16); color: var(--danger); }
html[data-theme="dark"] .badge-produit { color: #8fdccf; }
html[data-theme="dark"] .toast { background: #2a3a3e; color: #e6edf0; box-shadow: 0 4px 16px rgba(0,0,0,.5); }
html[data-theme="dark"] .toast.err { background: #6f5520; color: #fff; }
html[data-theme="dark"] .toast.okk { background: #176b4c; color: #fff; }
html[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.65); }
html[data-theme="dark"] .modal { box-shadow: 0 12px 40px rgba(0,0,0,.6); }
html[data-theme="dark"] .header-dropdown-menu { box-shadow: 0 12px 34px rgba(0,0,0,.55); }
html[data-theme="dark"] .pos-famille-title, html[data-theme="dark"] .pos-total { color: #8fdccf; }
html[data-theme="dark"] .pos-btn:hover { box-shadow: 0 3px 12px rgba(0,0,0,.45); }
html[data-theme="dark"] .grid-search { background: var(--card); color: var(--text); }
html[data-theme="dark"] .onboarding-banner { background: var(--primary-bg); }
html[data-theme="dark"] .tuto-card { background: var(--accent-bg); }
html[data-theme="dark"] .data-table th { background: var(--surface-alt); }
/* Éléments de volets à fond clair codé en dur (calendriers pointage / shifts, aperçu étiquettes) */
html[data-theme="dark"] .pt-cal .pt-we, html[data-theme="dark"] .shift-cal .sh-we { background: #1a2423; }
html[data-theme="dark"] .ax-et-apercu { background: var(--surface-alt); }
/* Les aperçus de documents (iframes / étiquettes) restent BLANCS volontairement : ce sont des documents imprimables. */

/* AG Grid en sombre : mêmes variables que .ag-theme-quartz-dark (CSS vendoré),
   appliquées à TOUTES les grilles .ag-theme-quartz existantes ou futures sans
   bascule de classe (couleurs alignées sur la charte). */
html[data-theme="dark"] .ag-theme-quartz {
  --ag-background-color: #16201f;
  --ag-foreground-color: #e6edf0;
  --ag-border-color: #27363a;
  --ag-secondary-border-color: rgba(230,237,240,.10);
  --ag-header-background-color: #1c2827;
  --ag-tooltip-background-color: #1c2827;
  --ag-control-panel-background-color: #1c2827;
  --ag-input-disabled-background-color: #68686e12;
  --ag-card-shadow: 0 1px 20px 1px black;
  --ag-input-border-color: var(--ag-border-color);
  --ag-input-disabled-border-color: rgba(255,255,255,0.07);
  --ag-checkbox-unchecked-color: color-mix(in srgb, var(--ag-background-color), var(--ag-foreground-color) 40%);
  --ag-active-color: #23a08f;
  --ag-row-hover-color: color-mix(in srgb, transparent, var(--ag-active-color) 20%);
  --ag-selected-row-background-color: var(--ag-row-hover-color);
  --ag-panel-background-color: color-mix(in srgb, var(--ag-background-color), var(--ag-foreground-color) 10%);
  --ag-panel-border-color: color-mix(in srgb, transparent, var(--ag-foreground-color) 10%);
  --ag-menu-background-color: color-mix(in srgb, var(--ag-background-color), var(--ag-foreground-color) 10%);
  --ag-menu-border-color: color-mix(in srgb, transparent, var(--ag-foreground-color) 10%);
  --ag-advanced-filter-join-pill-color: #7a3a37;
  --ag-advanced-filter-column-pill-color: #355f2d;
  --ag-advanced-filter-option-pill-color: #5a3168;
  --ag-advanced-filter-value-pill-color: #374c86;
  --ag-popup-shadow: 0 0px 20px rgba(0, 0, 0, 0.30);
  --ag-row-loading-skeleton-effect-color: rgba(202, 203, 204, 0.4);
  color-scheme: dark;
}

/* Impression : TOUJOURS en clair (tickets, états), quel que soit le thème d'écran */
@media print {
  html[data-theme="dark"] {
    color-scheme: light;
    --primary: #0d6e63; --primary-dark: #0a554c; --primary-bg: #e6f3f1; --primary-border: #9ecfc9;
    --accent: #b9770a; --accent-bg: #fdf3e3; --bg: #ffffff; --surface: #ffffff; --surface-alt: #eef1f4;
    --border: #e2e7ec; --text: #1c2733; --text-secondary: #5a6473; --muted: #98a2b3;
    --success: #0f9d6a; --danger: #8a6a16; --card: #ffffff; --surface-2: #f1f3f2;
  }
  html[data-theme="dark"] body, html[data-theme="dark"] #ticket-print { background: #fff !important; color: #000 !important; }
  html { zoom: 1 !important; } /* le zoom d'affichage ne s'imprime pas */
}
