/* ============================================================================
 * MonÉcole (EduAdmin) — Design System "Academic Atelier" & Modern Web Patterns
 * ============================================================================ */

:root {
  --surface: #f8f9ff;
  --surface-container-lowest: #ffffff;
  --surface-container-low: #eff4ff;
  --surface-container-high: #dce9ff;
  --on-surface: #0b1c30;
  --primary: #131b2e;
  --secondary: #0051d5;
  --tertiary: #009668;
  --error: #ba1a1a;
}

/* Mode Haute Densité ERP (Échelle globale compacte) */
html {
  font-size: 11px;
  line-height: 1.35;
}

body {
  background-color: var(--surface);
  color: var(--on-surface);
  font-size: 0.925rem;
}

.material-symbols-outlined {
  font-size: 1.15rem;
  line-height: 1;
  vertical-align: middle;
}

/* 1. Native <dialog closedby="any"> Modal Styling (Compact) */
dialog.atelier-modal {
  border: 1px solid rgba(19, 27, 46, 0.12);
  border-radius: 0.75rem;
  padding: 0;
  background: var(--surface-container-lowest);
  color: var(--on-surface);
  box-shadow: 0 20px 40px -12px rgba(11, 28, 48, 0.25);
  max-width: min(38rem, calc(100vw - 1.5rem));
  width: 100%;
  margin: auto;
}

dialog.atelier-modal::backdrop {
  background-color: rgba(11, 28, 48, 0.55);
  backdrop-filter: blur(3px);
}

/* Native <details> & <summary> Sidebar Accordion (`search-hidden-content`) */
details.nav-disclosure > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

details.nav-disclosure > summary::-webkit-details-marker {
  display: none;
}

details.nav-disclosure[open] > summary .disclosure-chevron {
  transform: rotate(180deg);
}

/* 2. Modern Form Validation (:user-invalid / :user-valid + Fallback) */
.field-hint {
  display: block;
  color: #4b5563;
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
}

.field-error-msg {
  display: none;
  color: var(--error);
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 0.25rem;
}

input:user-invalid,
select:user-invalid,
input.user-invalid-fallback,
select.user-invalid-fallback {
  border-color: var(--error) !important;
  background-color: #fef2f2 !important;
}

input:user-invalid + .field-error-msg,
input.user-invalid-fallback + .field-error-msg {
  display: block;
}

input:user-valid,
input.user-valid-fallback {
  border-color: var(--tertiary);
}

.field-group:has(input:user-invalid) .rules-list {
  color: var(--error);
  font-weight: 600;
}

/* 3. Responsive Data Table with Sticky Headers & Container Query */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(680px, 78vh);
  container-type: inline-size;
}

.table-wrapper table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

.table-wrapper thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 10;
}

.table-wrapper tbody th {
  position: sticky;
  inset-inline-start: 0;
  background: var(--surface-container-lowest);
  z-index: 5;
}

@container (width < 640px) {
  .table-wrapper.stack-on-mobile table,
  .table-wrapper.stack-on-mobile thead,
  .table-wrapper.stack-on-mobile tbody,
  .table-wrapper.stack-on-mobile tr,
  .table-wrapper.stack-on-mobile th,
  .table-wrapper.stack-on-mobile td {
    display: block;
  }

  .table-wrapper.stack-on-mobile thead {
    display: none;
  }

  .table-wrapper.stack-on-mobile tbody tr {
    margin-block-end: 1rem;
    border: 1px solid #dce9ff;
    border-radius: 0.75rem;
    overflow: hidden;
    background: #ffffff;
  }

  .table-wrapper.stack-on-mobile tbody th {
    position: sticky;
    inset-block-start: 0;
    background: #eff4ff;
  }
}

/* 4. Impression A4 Officielle (Papier Entête MENA / DRENA / IEPP & Listes Filtrées) */
.print-only {
  display: none;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt !important;
  }

  .no-print,
  #app-sidebar,
  header,
  footer,
  dialog {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  .table-wrapper {
    max-block-size: none !important;
    overflow: visible !important;
  }

  .a4-sheet {
    box-shadow: none !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}


/* ==========================================================================
   Personnalisation de la Sidebar (Desktop fixe + Tiroir Mobile Off-Canvas)
   ========================================================================== */
/* 1. Conteneur principal de la sidebar (fond, bordure) */
#app-sidebar {
    background-color: #ffffff !important;
    border-right: 2px solid #e2e8f0 !important;
}

@media (min-width: 1024px) {
    #app-sidebar {
        width: 20rem !important;
        position: sticky !important;
        top: 0 !important;
        height: 100vh;
        height: 100dvh;
        overflow-y: auto;
        transform: none !important;
    }
}

@media (max-width: 1023px) {
    #app-sidebar {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        inset-block: 0 !important;
        inset-inline-start: 0 !important;
        z-index: 50 !important;
        width: min(20rem, 84vw) !important;
        width: min(20rem, 84dvw) !important;
        height: 100vh !important;
        height: 100svh !important;
        overflow-y: auto !important;
        transform: translateX(-105%) !important;
        transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1) !important;
        box-shadow: 0 20px 40px rgba(15, 23, 42, 0.35) !important;
    }

    #app-sidebar.mobile-open {
        transform: translateX(0) !important;
    }
}

#app-sidebar .truncate {
   font-weight: 600 !important;
}
/* 2. Titres de menu déroulants (<summary>) et liens simples */
#app-sidebar summary,
#app-sidebar nav a {
    font-size: 11px !important;          /* Taille du texte des menus */
	font-weight: 500 !important; 
    color: #1e293b !important;           /* Couleur du texte */
    border-radius: 0.5rem !important;    /* Arrondi des boutons */
	line-height: 1.55 !important;
}
/* 3. Effet au survol (hover) */
#app-sidebar summary:hover,
#app-sidebar nav a:hover {
    background-color: #eff4ff !important; /* Fond au survol */
    color: #0051d5 !important;           /* Couleur du texte au survol */
}
/* 4. Sous-menus (liens à l'intérieur des menus déroulants) */
#app-sidebar details nav a {
    font-size: 10px !important;          /* Taille plus petite pour les sous-menus */
    font-weight: 400 !important;         /* Poids de police normal/moyen */
    padding-left: 2rem !important;       /* Indentation */
}
/* 5. Menu actuellement actif / sélectionné */
#app-sidebar a[class*="bg-primary-container"],
#app-sidebar a[class*="text-on-primary-container"] {
    background-color: #131b2e !important;
    color: #ffffff !important;
}
/* 6. Taille et couleur des icônes de la sidebar */
#app-sidebar .material-symbols-outlined {
    font-size: 13px !important;
    color: #64748b;
}
#app-sidebar a:hover .material-symbols-outlined,
#app-sidebar summary:hover .material-symbols-outlined {
    color: #0051d5;
}

/* ==========================================================================
   Adaptation Globale Responsive Mobile & Tablette (Tous Modules ERP)
   ========================================================================== */
.table-wrapper,
.fin-table-wrapper,
.fin-table-wrap,
.ped-table-wrap,
.sl-table-wrap,
.tch-table-wrap {
    max-inline-size: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
    html {
        font-size: clamp(11.5px, 3.1vw, 12.5px);
    }

    /* Empilement automatique en 1 colonne des grilles inline multi-colonnes (hors feuilles d'impression A4) */
    #app-main [style*="grid-template-columns"]:not(.no-mobile-stack):not(.bulletin-sheet):not(.bulletin-sheet *):not(.a4-sheet):not(.a4-sheet *) {
        grid-template-columns: 1fr !important;
    }

    /* Barres de filtres et formulaires multi-colonnes des modules */
    .fin-filter-bar,
    .fin-filter-form .fin-filter-grid,
    .fin-form-row.cols-2,
    .fin-form-row.cols-3,
    .fin-form-row.cols-4,
    .ped-filter-bar {
        grid-template-columns: 1fr !important;
    }

    .ped-filter-group {
        min-width: 100% !important;
        width: 100% !important;
    }

    /* Grilles KPI responsives sur mobile */
    .fin-kpi-grid,
    .ped-kpi-grid,
    .sl-kpi-grid,
    .tt-kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 155px), 1fr)) !important;
        gap: 0.65rem !important;
    }

    /* Barres d'onglets défilables horizontalement au doigt */
    .fin-tabs,
    .tch-tabs-bar {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.35rem;
        scrollbar-width: thin;
    }

    .fin-tab,
    .tch-tab-link {
        flex-shrink: 0;
    }

    /* Modales et boîtes de dialogue adaptées à l'écran mobile (dvh / dvw) */
    dialog,
    .ped-modal-box,
    .tch-modal-card,
    .sl-modal-card {
        max-width: calc(100dvw - 1.25rem) !important;
        max-height: 90dvh !important;
    }

    .tch-hero {
        padding: 1rem 1.15rem !important;
    }
}
