/* ===========================
   Base
=========================== */

:root{
    --text: #3a3f52;
    --link: #53627C;
    --link-hover: #0095f7;

    --border: #ddd;

    /* Largeurs max standard (M057.12) */
    --uer-max-sm: 500px;
    --uer-max-md: 600px;
    --uer-max-narrow: 700px;
    --uer-max-lg: 800px;
    --border-strong: #ccc;

    --row-alt: #f2f2f2;
    --th-bg: #f5f5f5;

    --shadow: 0 2px 4px 0 rgba(0,0,0,.09);

    /* Couleurs sémantiques */
    --color-hep-blue: #00a4e4;
    --color-positive: #198754;
    --color-negative: #c00;
    --color-neutral: #000;
    --color-mat: #696969;
    --color-scn: #800080;
    --color-ces: #C71585;
    --color-muted: #444;

    /* Tailles de police normalisées */
    --fs-sm: 0.78rem;    /* compact tables, badges, chips */
    --fs-base: 0.85rem;  /* texte courant, formulaires, boutons */
    --fs-lg: 1rem;       /* titres de section */
}

body {
    font-family: 'Roboto', sans-serif;
    color: var(--text);
    font-size: 14px;
}

/* ===========================
   Headings — h2 pour titre de page, h3+ pour sous-sections
=========================== */

h1 { font-size: 1.6rem; }
h2 { font-size: 1.35rem; margin-bottom: 12px; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
h5, h6 { font-size: 0.9rem; }

/* ===========================
   Buttons — tailles unifiées
=========================== */

.btn { font-size: 0.8rem; padding: 3px 9px; }
.btn-sm { font-size: 0.75rem; padding: 2px 7px; }

.btn-pdf {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 20px;
    padding: 0 14px;
    border: 1px solid #aaa;
    border-radius: 4px;
    background: #f0f0f4;
    color: #000;
    font-size: 0.8rem;
    text-decoration: none;
    cursor: pointer;
}
.btn-pdf:hover { background: #e9e9e9; }

/* ===========================
   Forms — tailles compactes
=========================== */

.form-control, .form-select { font-size: 0.875rem; padding: 3px 7px; }
label { font-size: 0.875rem; }

/* Barre de filtres standard */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.filter-bar label { margin: 0; white-space: nowrap; }

/* Variante avec fond */
.filter-bar-bg {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    background: #f9f9f9;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.filter-bar-bg label { margin: 0; white-space: nowrap; }

/* Légende à droite dans une filter-bar */
.filter-legend {
    margin-left: auto;
    font-size: 0.85rem;
    color: var(--color-muted);
}

/* Groupe label+select dans les barres de filtres */
.filter-group {
    display: flex;
    flex-direction: column;
    min-width: 100px;
}

/* Select auto-width (remplace style="width:auto;" inline) */
.form-select-auto { width: auto; }

/* Selects contenant des noms longs (PI, Collaborateur, Formateur) */
.w-select-name {
    min-width: 140px;
    max-width: 260px;
}

/* ===========================
   Badges et alerts
=========================== */

.badge { font-size: 0.8rem; }
.alert { font-size: 0.875rem; padding: 7px 11px; }

/* ===========================
   Print
=========================== */

@media print {
    .navbar { display: none; }
}

/* ===========================
   Responsive
=========================== */

@media (max-width: 576px) {
    /* Touch targets minimum 44px */
    .btn, .btn-sm, .form-select, .form-control {
        min-height: 44px;
    }
    .btn-sm { padding: 6px 10px; }

    /* Stack filter bars */
    .filter-bar, .filter-bar-bg {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-legend { margin-left: 0; margin-top: 8px; }

    /* Stack flex filter forms on mobile */
    form.d-flex.align-items-end,
    .card-body > form.d-flex {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .filter-group {
        width: 100%;
        min-width: 0;
    }
    .filter-group .form-select,
    .filter-group .form-select-auto {
        width: 100% !important;
    }

    /* KPI cards wrap */
    .kpi-card { padding: 8px 4px; }
    .kpi-value { font-size: 1.2rem; }
}

@media (max-width: 768px) {
    .planning-grid {
        grid-template-columns: 1fr;
    }
    .planning-grid .grid-header:not(:first-child) {
        display: none;
    }
    .grid-cell::before {
        content: attr(data-day);
        display: block;
        font-weight: bold;
        font-size: 0.8rem;
        color: var(--color-muted);
        margin-bottom: 4px;
    }

    /* Modals fullscreen on mobile */
    .modal-dialog {
        max-width: 100%;
        margin: 0;
        min-height: 100vh;
    }
    .modal-content {
        border-radius: 0;
        min-height: 100vh;
    }
}

@media (max-width: 992px) {
    /* Navbar dropdowns stack better */
    .navbar .nav-item.dropdown:hover > .dropdown-menu {
        display: none;
    }
}

/* ===========================
   Navbar
=========================== */

.navbar .nav-link {
    font-size: 0.875rem;
    font-weight: 400;
    letter-spacing: .03em;
}

.navbar .dropdown-item {
    font-size: 0.875rem;
}

/* Hover dropdown */
.navbar .nav-item.dropdown:hover > .dropdown-menu {
    display: block;
    margin-top: 0;
}

/* Module Recap — table compacte */
.module-recap-table {
    font-size: var(--fs-sm);
}
.module-recap-table th, .module-recap-table td {
    padding: 2px 5px;
    white-space: nowrap;
}
.module-prefix-row:hover { background-color: #f0f4f8 !important; }

/* Chevron toggle */
.toggle-icon {
    display: inline-block;
    transition: transform 0.15s;
    font-size: 0.7rem;
    color: #888;
}
.toggle-icon.rotated { transform: rotate(90deg); }

/* Badge CES */
.badge.badge-ces { background-color: var(--color-ces) !important; color: #fff !important; }

/* Puce collaborateur module recap */
.collab-chip {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.75rem;
    background: #f0f0f0;
    color: #444;
    border: 1px solid #ddd;
    margin-right: 3px;
}
.collab-chip.collab-chip-ces {
    background: #fce8f3;
    border-color: #e0a0cc;
    color: #8b1a5e;
}

/* CDC Recap — table compacte */
.cdc-recap-table {
    font-size: var(--fs-sm);
}
.cdc-recap-table th, .cdc-recap-table td {
    padding: 2px 5px;
    white-space: nowrap;
}

/* ===========================
   Layout / helpers
=========================== */

.main-content { margin-top: 12px; }

/* Breadcrumb */
.breadcrumb-nav {
    margin-bottom: 8px;
    font-size: 0.8rem;
}
.breadcrumb-nav .breadcrumb {
    margin-bottom: 0;
    padding: 0;
    background: none;
}
.breadcrumb-nav .breadcrumb-item + .breadcrumb-item::before {
    content: "›";
    color: var(--color-muted);
}

.header-form-container {
    display: flex;
    align-items: center;
}
.header-form-container h2 { margin-right: 10px; }

.collaborateurs-box {
    border: 1px solid #ccc;
    padding: 10px;
    margin-top: 20px;
}

/* Modes */
.mode-saisie { background: linear-gradient(to right, white 80%, lightgreen 80%); }
.mode-consultation { background: linear-gradient(to right, white 80%, lightblue 80%); }
.mode-erreur { background: linear-gradient(to right, white 80%, lightcoral 80%); }

/* Colonnes (tables spécifiques) */
.first-column { width: 115px; }
.second-column { width: 130px; }

/* ===========================
   Couleurs sémantiques (UI-006)
=========================== */

/* Texte */
.text-blue-hep { color: var(--color-hep-blue) !important; }
.text-red { color: red !important; }
.text-dark-gray { color: #737373 !important; }
.text-dark-red { color: var(--color-negative) !important; }
.text-positive { color: var(--color-positive) !important; }
.text-negative { color: var(--color-negative) !important; }
.text-custom-purple { color: #7a2fa0 !important; }
.text-purple { color: #7a2fa0 !important; }
.text-muted-custom { color: var(--color-muted) !important; }
.text-warning { color: orange; }

/* Couleurs didactique */
.color-mat { color: var(--color-mat); }
.color-scn { color: var(--color-scn); }
.color-ces { color: var(--color-ces); }
.color-default { color: var(--color-neutral); }

/* Tags didactique (badges) — classes uniques pour tout le site */
.badge.badge-mat { background-color: var(--color-mat) !important; color: #fff !important; }
.badge.badge-scn { background-color: var(--color-scn) !important; color: #fff !important; }
.badge.badge-other { background-color: #212529 !important; color: #fff !important; }

/* Legacy compat */
.mat { background-color: var(--color-mat); }
.scn { background-color: var(--color-scn); }

/* Toggle visibility */
.d-none { display: none !important; }

/* Hint en petit — min 12px pour WCAG */
.hint { font-size: 85%; }

/* Skip link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-hep-blue);
    color: #fff;
    padding: 8px 16px;
    z-index: 1100;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 0;
}

/* ===========================
   Tables — une seule classe de base
=========================== */

.styled-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background-color: white;
}

.styled-table thead tr {
    background-color: #f1f3f5;
}

.styled-table th,
.styled-table td {
    border: 1px solid var(--border);
    padding: 3px 6px;
    text-align: left;
}

.styled-table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #495057;
}

.styled-table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

.styled-table tbody tr:hover {
    background-color: #eef2f7;
}

.styled-table td {
    vertical-align: middle;
}

/* ===========================
   Table grille horaire
=========================== */

.grille-horaire {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 0.85rem;
}

.grille-horaire th,
.grille-horaire td {
    border: 1px solid var(--border-strong);
    padding: 3px 5px;
    vertical-align: top;
    text-align: center;
}

.grille-horaire th {
    background-color: var(--th-bg);
}

.grille-horaire td {
    min-width: 120px;
    height: 60px;
    position: relative;
}

/* ===========================
   Horaire module — chips & table
=========================== */

.hm-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.hm-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: var(--fs-sm);
    white-space: nowrap;
    border: 1px solid #bbb;
    text-decoration: none;
    color: inherit;
    line-height: 1.4;
}
.hm-chip-unplaced { background: #fff2cc; border-color: #e0c15a; }
.hm-chip-placed   { background: #dff0ff; border-color: #99c9ff; }
.hm-chip-heritage { opacity: 0.5; }
.hm-chip-salle    { background: #e8f5e9; border-color: #8bc34a; cursor: pointer; }

.hm-delete-btn {
    font-size: 0.7em;
    opacity: 0.5;
    text-decoration: none;
    color: inherit;
}
.hm-delete-btn:hover { opacity: 1; color: #c00; }

.hm-add-btn { font-size: 1.1em; }

.cellchips {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 2px 0;
}

/* Grille horaire Bootstrap (horaire_grille) */
.grille-horaire-bs {
    font-size: 0.8rem;
    table-layout: fixed;
}
.grille-horaire-bs th, .grille-horaire-bs td {
    vertical-align: top;
    padding: 3px 5px;
    min-width: 100px;
    height: 52px;
}

.grille-chip {
    background: #dff0ff;
    border: 1px solid #99c9ff;
    color: #004085;
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 0.75rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.grille-chip-heritage {
    background: #f0f0f0;
    border-color: #bbb;
    color: #666;
    font-style: italic;
}

/* ===========================
   CDC layout (vue_cdc_content)
=========================== */

.cdc-empty-msg {
    margin-top: 16px;
    color: var(--color-muted);
}

/* Sections A-D compactes */
.cdc-sections { font-size: var(--fs-base); }

.cdc-section {
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 8px;
    overflow: hidden;
}

.cdc-section-title {
    background: #f1f3f5;
    padding: 4px 8px;
    font-weight: 600;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.cdc-subsection { border-top: 1px solid #eee; }

.cdc-subsection-title {
    background: #f8f9fa;
    padding: 3px 8px 3px 16px;
    font-weight: 500;
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.cdc-item {
    padding: 2px 8px 2px 24px;
    border-top: 1px solid #f0f0f0;
    font-size: var(--fs-sm);
}

.cdc-sous-projet-detail {
    padding-left: 40px;
}

.cdc-empty {
    padding: 2px 8px 2px 24px;
    font-style: italic;
    color: var(--color-muted);
    font-size: var(--fs-sm);
}

.cdc-pct {
    color: var(--color-hep-blue);
    font-weight: 600;
    white-space: nowrap;
    margin-left: 6px;
}

/* Donut image */
.cdc-donut-wrap {
    text-align: center;
    margin-bottom: 20px;
}

.cdc-donut-wrap img {
    max-height: 350px;
    max-width: 100%;
}

/* ===========================
   Mini-planning (vue_cdc)
=========================== */

.mini-planning {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    margin-bottom: 16px;
    font-size: 0.75rem;
    background: white;
}

.mini-planning th,
.mini-planning td {
    border: 1px solid #ccc;
    padding: 2px;
    text-align: center;
    height: 25px;
}

.mini-planning th { background-color: #f0f0f0; }
.mini-planning th:first-child { width: 15%; }
.mini-planning th:not(:first-child) { width: 17%; }

.mini-cell { display: flex; flex-direction: column; gap: 2px; }

.mini-chip {
    border-radius: 3px;
    padding: 1px 3px;
    font-size: 0.9em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.type-cours { background-color: #dff0ff; border: 1px solid #99c9ff; color: #004085; }
.type-indispo { background-color: #c6c6c6; border: 1px solid #858585; color: #000; }

.planning-header {
    text-align: center;
    color: var(--color-muted);
    margin-bottom: 5px;
    border-bottom: 2px solid #eee;
    padding-bottom: 5px;
}

/* ===========================
   Planning salle
=========================== */

.cell-content {
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
    gap: 4px; padding: 4px; box-sizing: border-box;
}

.item-module {
    background: #dff0ff; border: 1px solid #99c9ff;
    border-radius: 4px; padding: 4px; font-size: 0.9em;
}

.item-tag {
    border-radius: 12px; padding: 2px 8px;
    font-size: 0.8em; font-weight: bold;
    color: white; display: inline-block; margin-top: 2px;
}

.tag-prep_tp { background-color: #ff9800; border: 1px solid #e65100; }
.tag-fc { background-color: #9c27b0; border: 1px solid #4a148c; }
.tag-didchi { background-color: #009688; border: 1px solid #004d40; }

.cell-actions {
    position: absolute; bottom: 2px; right: 2px;
    display: none; gap: 4px;
}
td:hover .cell-actions { display: flex; }

.btn-action {
    text-decoration: none; color: #333; font-size: 0.75em;
    background: rgba(255,255,255,0.8); border: 1px solid #999;
    padding: 2px 5px; border-radius: 3px;
}
.btn-action:hover { background: #333; color: #fff; }
.active-tag { background-color: #333; color: white; border-color: black; }

/* ===========================
   Indispo
=========================== */

.indispo-table { border-collapse: collapse; width: 100%; }
.indispo-table th, .indispo-table td { border: 1px solid #ccc; padding: 6px; text-align: center; }
.indispo-table th { background: #f0f0f0; }
.indispo-table td.indispo { background: #e0e0e0; cursor: pointer; }
.indispo-table td.vide { background: #fafafa; cursor: pointer; }
.group-btn { font-size: 0.8em; margin: 2px; }

/* Indispo BS5 */
.indispo-table-bs { font-size: var(--fs-base); }
.indispo-table-bs td, .indispo-table-bs th { height: 44px; }
.indispo-cell { cursor: pointer; }
.indispo-cell:hover { background-color: #f8f0f0 !important; }
.indispo-cell-active { background-color: #fde8e8 !important; }
.indispo-group-btn { font-size: 0.65rem; padding: 1px 4px; line-height: 1.2; }


/* ===========================
   Planning collaborateur (grid)
=========================== */

.planning-grid {
    display: grid;
    grid-template-columns: 100px repeat(5, 1fr);
    gap: 1px;
    background-color: #dee2e6;
    border: 1px solid #dee2e6;
}

.grid-header {
    background-color: #f8f9fa;
    padding: 10px;
    text-align: center;
    font-weight: bold;
    border: 1px solid #dee2e6;
}

.grid-cell {
    background-color: white;
    min-height: 80px;
    padding: 5px;
    border: 1px solid #dee2e6;
    position: relative;
}

.cours-item {
    background-color: #d1ecf1;
    border-left: 4px solid #0dcaf0;
    padding: 4px;
    margin-bottom: 3px;
    font-size: 0.85rem;
    border-radius: 3px;
}

.indispo-item {
    background-color: #f8d7da;
    border-left: 4px solid #dc3545;
    padding: 4px;
    margin-bottom: 3px;
    font-size: 0.85rem;
    border-radius: 3px;
}

.empty-cell {
    color: #adb5bd;
    font-style: italic;
    font-size: 0.8rem;
    text-align: center;
    padding-top: 25px;
}

.filter-card {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 20px;
}

/* ===========================
   HTMX Loading Indicator
=========================== */

.htmx-indicator {
    display: none;
    text-align: center;
    padding: 20px;
    color: #888;
    font-size: 0.85rem;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: block;
}

/* Forcer l'affichage initial sur les lazy-loaded */
.htmx-indicator-visible {
    display: block;
}

/* Fade-in for HTMX-loaded content */
.htmx-added {
    animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #ddd;
    border-top-color: var(--color-hep-blue);
    border-radius: 50%;
    animation: htmx-spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes htmx-spin {
    to { transform: rotate(360deg); }
}

/* ── Auto-save HTMX feedback ── */
.autosave-ok {
    color: var(--bs-success);
    font-weight: 600;
    animation: autosave-fade 3s forwards;
}
.autosave-error {
    color: var(--bs-danger);
    font-size: 0.82em;
}
@keyframes autosave-fade {
    0%, 60% { opacity: 1; }
    100%     { opacity: 0; }
}

/* ── Keyboard focus accessibility (a11y) ── */
:focus-visible {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* ===========================
   Containers — largeurs restreintes (M057.12)
=========================== */

.container-uer-sm     { max-width: var(--uer-max-sm); }
.container-uer-md     { max-width: var(--uer-max-md); }
.container-uer-narrow { max-width: var(--uer-max-narrow); }
.container-uer-lg     { max-width: var(--uer-max-lg); }

/* Boîtes graphiques (remplace inline overflow-x/height) */
.chart-box {
    overflow-x: auto;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 12px;
}
.chart-box-h400 {
    height: 400px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
}

/* Input group compact */
.input-group-narrow { max-width: 280px; }
