/* ============================================================
   FISS — layout.css  (v2 — navigation 2 niveaux style MyScol)
   ============================================================ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* Verrouiller la hauteur au viewport — chaque panneau scroll indépendamment */
html {
  font-size: 16px;
  height: 100%;
  overflow: hidden;
}
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ══════════════════════════════════════════════════════════
   ÉCRAN DE CONNEXION
══════════════════════════════════════════════════════════ */
#login-screen {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--dark-navy);
  background-image:
    radial-gradient(ellipse at 15% 50%, rgba(212,0,26,.22) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(74,144,217,.18) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 90%, rgba(26,74,138,.25) 0%, transparent 60%);
  padding: 20px;
}
.btn-webmail {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: #0A2352; /* Bleu marine FISS */
    color: #ffffff !important;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: bold;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-webmail:hover {
    background-color: #143678; /* Un peu plus clair au survol */
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(10, 35, 82, 0.25);
}
.login-box {
  background: var(--surface); border-radius: 20px;
  padding: 36px 28px; width: 100%; max-width: 440px;
  box-shadow: 0 32px 96px rgba(0,0,0,.45);
  animation: loginIn .4s ease;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-divider { height: 1px; background: var(--border); margin: 20px 0; }
.login-field { margin-bottom: 12px; }
.login-field label { display: block; font-size: 11px; font-weight: 700; color: var(--ink2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .08em; }
.login-field input {
  width: 100%; padding: 12px 16px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 15px;
  background: var(--bg); color: var(--ink); outline: none;
  transition: border-color var(--transition);
}
.login-field input:focus { border-color: var(--accent); }
.login-btn {
  width: 100%; padding: 14px; background: var(--accent); color: white;
  border: none; border-radius: var(--radius-sm); font-family: inherit;
  font-size: 15px; font-weight: 700; cursor: pointer; margin-top: 10px;
  transition: all var(--transition);
}
.login-btn:hover { background: #a80015; transform: translateY(-1px); box-shadow: 0 6px 20px rgba(212,0,26,.35); }
.login-error { color: var(--accent); font-size: 13px; text-align: center; margin-top: 12px; min-height: 20px; }
.login-logo-img { width: 90px; height: 90px; border-radius: 50%; object-fit: cover; margin: 0 auto 14px; display: block; box-shadow: 0 8px 32px rgba(0,0,0,.45); border: 3px solid rgba(74,144,217,.4); }
.login-school-name { font-family: var(--font-display); font-size: 18px; font-weight: 700; color: var(--ink); line-height: 1.3; margin-bottom: 4px; text-align: center; }
.login-school-name span { color: var(--accent); }
.login-school-sub { font-size: 11px; color: var(--ink3); letter-spacing: .1em; text-transform: uppercase; margin-bottom: 8px; text-align: center; }

/* ══════════════════════════════════════════════════════════
   PREMIER LOGIN
══════════════════════════════════════════════════════════ */
#first-login-screen {
  position: fixed; inset: 0; background: rgba(10,35,82,.92);
  display: none; align-items: center; justify-content: center;
  z-index: 500; backdrop-filter: blur(6px); padding: 20px;
}
#first-login-screen.open { display: flex; }
.first-login-box {
  background: var(--surface); border-radius: 20px; padding: 36px 28px;
  width: 100%; max-width: 440px; box-shadow: 0 32px 96px rgba(0,0,0,.5);
  animation: modalIn .3s ease;
}
.pw-strength { height: 4px; border-radius: 2px; margin-top: 6px; transition: all .3s; background: var(--border); }
.pw-strength.weak   { background: var(--accent); width: 33%; }
.pw-strength.medium { background: #C9860A; width: 66%; }
.pw-strength.strong { background: #1A6B45; width: 100%; }

/* ══════════════════════════════════════════════════════════
   APP SHELL
══════════════════════════════════════════════════════════ */
#app {
  display: none;
  height: 100%;
  flex-direction: column;
}

/* ══════════════════════════════════════════════════════════
   TOPBAR GLOBALE (toujours visible)
══════════════════════════════════════════════════════════ */
.app-topbar {
  min-height: 56px;
  background: var(--dark-navy);
  display: flex; align-items: center;
  padding: env(safe-area-inset-top, 0px) 20px 0;
  gap: 12px;
  position: sticky; top: 0; z-index: var(--z-topbar);
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
  /* La barre de statut iOS (heure, wifi...) est en mode translucide et se
     superpose au contenu — sans cette marge, notre propre barre (logo,
     menu ☰) se retrouvait cachée sous l'heure/l'horloge du téléphone. */
  padding-bottom: 8px;
}
.app-topbar-logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; cursor: pointer;
  flex-shrink: 0;
}
.app-topbar-logo img {
  width: 30px; height: 30px; border-radius: 50%;
  object-fit: cover; border: 2px solid rgba(74,144,217,.4);
}
.app-topbar-logo-text {
  font-family: var(--font-display); font-size: 15px;
  color: #fff; line-height: 1.1;
}
.app-topbar-logo-text span { color: var(--accent); }
.app-topbar-logo-text small {
  display: block; font-family: var(--font-body);
  font-size: 9px; color: rgba(255,255,255,.3);
  font-weight: 600; text-transform: uppercase; letter-spacing: .12em;
}
.app-topbar-spacer { flex: 1; }
.app-topbar-section-title {
  font-size: 13px; font-weight: 600; color: rgba(255,255,255,.7);
  display: none;
}
.app-topbar-section-title.visible { display: block; }
.app-topbar-user {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; padding: 6px 10px; border-radius: 10px;
  transition: background .15s;
  position: relative;
}
.app-topbar-user:hover { background: rgba(255,255,255,.07); }
.app-topbar-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: white;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; position: relative;
}
.app-topbar-avatar .profile-badge {
  position: absolute; bottom: -2px; right: -2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent2); border: 2px solid var(--dark-navy);
  display: flex; align-items: center; justify-content: center;
  font-size: 7px; color: white;
}
.app-topbar-user-info { display: flex; flex-direction: column; }
.app-topbar-username { font-size: 12px; font-weight: 600; color: rgba(255,255,255,.85); }
.app-topbar-role { font-size: 10px; color: var(--accent2); text-transform: uppercase; letter-spacing: .05em; }
.app-topbar-notif {
  position: relative; background: none; border: none;
  font-size: 19px; cursor: pointer; width: 36px; height: 36px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  transition: background var(--transition); flex-shrink: 0; color: rgba(255,255,255,.7);
}
.app-topbar-notif:hover { background: rgba(255,255,255,.07); }
.notif-dot {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; background: var(--accent);
  border-radius: 50%; border: 2px solid var(--dark-navy);
}

/* Hamburger mobile */
#hamburger {
  display: none;
  background: none; border: none; color: rgba(255,255,255,.7);
  font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
#hamburger:hover { background: rgba(255,255,255,.07); color: #fff; }

/* ══════════════════════════════════════════════════════════
   ÉCRAN D'ACCUEIL (HOME — sans sidebar)
══════════════════════════════════════════════════════════ */
#home-screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}
#home-screen.visible { display: block; }

/* Greeting home */
.home-greeting {
  margin-bottom: 36px;
}
.home-greeting-title {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 800;
  color: var(--ink); margin-bottom: 4px;
}
.home-greeting-sub { font-size: 13px; color: var(--ink3); }

/* Grille des sections home */
.home-sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

/* Carte de section */
.home-section-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 24px 20px;
  cursor: pointer;
  transition: all .2s ease;
  display: flex; flex-direction: column;
  align-items: flex-start; gap: 12px;
  text-align: left;
  position: relative; overflow: hidden;
}
.home-section-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(0,0,0,.1);
  border-color: var(--section-color, var(--accent));
}
.home-section-card::after {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--section-color, var(--accent));
  opacity: 0; transition: opacity .2s;
}
.home-section-card:hover::after { opacity: 1; }
.home-section-card-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  background: color-mix(in srgb, var(--section-color, var(--accent)) 12%, transparent);
}
.home-section-card-title {
  font-weight: 700; font-size: 15px; color: var(--ink);
}
.home-section-card-desc {
  font-size: 12px; color: var(--ink3); line-height: 1.4;
  margin-top: -4px;
}
.home-section-card-count {
  font-size: 11px; font-weight: 700;
  color: var(--section-color, var(--accent));
  background: color-mix(in srgb, var(--section-color, var(--accent)) 10%, transparent);
  padding: 3px 10px; border-radius: 20px;
}

/* ══════════════════════════════════════════════════════════
   VUE SECTION (avec sidebar contextuelle)
══════════════════════════════════════════════════════════ */
#section-view {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#section-view.visible {
  display: flex;
  flex-direction: row;
}

/* Sidebar contextuelle */
.section-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #0A2352 0%, #0d2d6e 100%);
  border-right: none;
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform .25s ease;
  box-shadow: 4px 0 20px rgba(10,35,82,0.18);
}
.section-sidebar-header {
  padding: 18px 14px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.section-sidebar-back {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; cursor: pointer;
  font-size: 12px; font-weight: 600; color: rgba(255,255,255,0.5);
  padding: 6px 8px; border-radius: 6px;
  transition: all .15s; margin-bottom: 12px;
  width: 100%; text-align: left; letter-spacing: .02em;
}
.section-sidebar-back:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.9); }
.section-sidebar-title {
  font-size: 13px; font-weight: 700; color: #fff;
  display: flex; align-items: center; gap: 10px;
}
.section-sidebar-title-icon {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.15);
}
.section-sidebar-nav {
  flex: 1; overflow-y: auto; padding: 10px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.section-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  cursor: pointer; color: rgba(255,255,255,0.62); font-size: 13px;
  font-weight: 400; transition: all var(--transition);
  margin-bottom: 2px; white-space: nowrap; user-select: none;
}
.section-nav-item:hover {
  background: rgba(255,255,255,0.09);
  color: rgba(255,255,255,0.92);
}
.section-nav-item.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--light-blue);
}
.section-nav-item .icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.section-nav-badge {
  margin-left: auto; background: var(--accent);
  color: white; font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 20px;
}

/* En-têtes de groupe (contexte élève) */
.section-sidebar-nav [style*="text-transform:uppercase"] {
  color: rgba(255,255,255,0.35) !important;
  border-top-color: rgba(255,255,255,0.08) !important;
}

/* Contenu principal de la section */
.section-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.section-topbar {
  height: 50px; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 10px;
}
.section-topbar-title {
  font-family: var(--font-display); font-size: 16px;
  color: var(--ink); flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.section-topbar-date {
  font-size: 12px; color: var(--ink3); font-family: var(--font-mono); white-space: nowrap;
}
.section-content {
  flex: 1; overflow-y: auto; padding: 22px;
}

/* Overlay sidebar mobile */
#sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: calc(var(--z-sidebar) - 1);
}
#sidebar-overlay.open { display: block; }

/* ══════════════════════════════════════════════════════════
   GRILLES & UTILITAIRES
══════════════════════════════════════════════════════════ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.col-span-2 { grid-column: span 2; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.section-header { margin-bottom: 20px; }
.section-title { font-family: var(--font-display); font-size: 24px; color: var(--ink); line-height: 1.2; }
.section-sub { color: var(--ink3); font-size: 13px; margin-top: 4px; }
.page { display: none; animation: fadeIn .2s ease; }
.page.active { display: block; }
.content { padding: 0; } /* géré par section-content */
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.2); border: none; color: #fff; font-size: 24px; cursor: pointer; border-radius: 50%; width: 40px; height: 40px; }

/* ══════════════════════════════════════════════════════════
   TABLEAU PERMISSIONS — header sticky au scroll de page
══════════════════════════════════════════════════════════ */
#perm-table thead tr th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface2);
}
/* Le conteneur du tableau doit ne pas avoir overflow: auto sur Y
   pour que sticky fonctionne par rapport au scroll de la page */
#perm-container > div[style*="overflow-x"] {
  overflow-x: auto;
  /* overflow-y intentionnellement absent → scroll géré par section-content */
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .home-sections-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 768px) {
  #hamburger { display: block; }
  .section-sidebar {
    position: fixed; left: 0; top: calc(56px + env(safe-area-inset-top, 0px)); bottom: 0;
    z-index: var(--z-sidebar);
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,.15);
  }
  .section-sidebar.open { transform: translateX(0); }
  #sidebar-overlay.open { display: block; }
  .section-topbar { padding-left: 52px; }
  .section-topbar-date { display: none; }
  .section-content { padding: 14px; }
  .home-sections-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  #home-screen { padding: 20px 14px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .section-title { font-size: 20px; }
  .app-topbar-user-info { display: none; }
}

@media (max-width: 400px) {
  .home-sections-grid { grid-template-columns: 1fr; }
  .login-box { padding: 28px 18px; }
}