/* ============================================================
   grid.css — Grille horaire principale
   CrèchePlanning v1.0
   ============================================================ */

/* ---- Conteneur grille ---- */
.grid-container {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    overflow: auto;
    box-shadow: var(--shadow);
    position: relative;
    max-height: calc(100vh - 280px);
}

.grid-loading {
    padding: 2rem;
    text-align: center;
    color: var(--color-text-muted);
    font-style: italic;
}

/* ---- Table grille ---- */
.planning-grid {
    border-collapse: collapse;
    min-width: max-content;
    font-size: 0.8rem;
}

/* En-tête sticky */
.planning-grid thead tr {
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Colonne nom sticky */
.planning-grid .col-nom {
    position: sticky;
    left: 0;
    z-index: 5;
    background: white;
    min-width: 140px;
    max-width: 160px;
}

.planning-grid thead .col-nom {
    z-index: 15;
    background: var(--color-primary);
}

/* En-têtes colonnes heures */
.planning-grid th {
    background: var(--color-primary);
    color: white;
    padding: 0.5rem 0.25rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.75rem;
    white-space: nowrap;
    border-right: 1px solid rgba(255,255,255,0.1);
    min-width: 42px;
}

.planning-grid th.th-heure {
    min-width: 42px;
    width: 42px;
    font-size: 0.7rem;
    padding: 0.4rem 0.1rem;
}

.planning-grid th.th-heure-pleine {
    border-left: 2px solid rgba(255,255,255,0.3);
}

/* Lignes employés/enfants */
.planning-grid tbody tr {
    border-bottom: 1px solid var(--color-border);
}

.planning-grid tbody tr:hover .col-nom {
    background: #f8fafc;
}

/* Cellule nom */
.cell-nom {
    padding: 0.375rem 0.625rem;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--color-text);
    background: white;
    border-right: 2px solid var(--color-border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cell-nom .nom-badge {
    display: inline-block;
    font-size: 0.65rem;
    padding: 0.1rem 0.35rem;
    border-radius: 10px;
    margin-left: 0.25rem;
    vertical-align: middle;
}

.badge-cat1-sm { background: #dcfce7; color: #166534; }
.badge-cat2-sm { background: #fef3c7; color: #92400e; }
.badge-bb-sm   { background: #dbeafe; color: #1e40af; }
.badge-g-sm    { background: #f3e8ff; color: #6b21a8; }
.badge-reg-sm  { background: #e0f2fe; color: #0369a1; }
.badge-occ-sm  { background: #fce7f3; color: #9d174d; }

/* ---- Cellules slots ---- */
.cell-slot {
    width: 42px;
    min-width: 42px;
    height: 32px;
    border-right: 1px solid rgba(0,0,0,0.06);
    cursor: pointer;
    transition: filter 0.1s, transform 0.1s;
    position: relative;
    user-select: none;
    vertical-align: middle;
    text-align: center;
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(0,0,0,0.6);
}

.cell-slot:hover {
    filter: brightness(0.9);
    z-index: 1;
}

.cell-slot.heure-pleine {
    border-left: 2px solid rgba(0,0,0,0.1);
}

/* Statuts couleurs */
.cell-slot[data-statut="PRESENT"],
.cell-slot[data-statut="TRAVAIL"]  { background: var(--color-present); }
.cell-slot[data-statut="PAUSE"]    { background: var(--color-pause); }
.cell-slot[data-statut="ABSENT"],
.cell-slot[data-statut="CONGE"]    { background: var(--color-absent); }
.cell-slot[data-statut="SP"]       { background: var(--color-sp); color: white; }
.cell-slot[data-statut="HO"]       { background: var(--color-ho); color: white; }
.cell-slot[data-statut="CG"]       { background: var(--color-cg); color: white; }
.cell-slot[data-statut="REUNION"]  { background: var(--color-reunion); color: white; }
.cell-slot[data-statut="ALERTE"]   { background: var(--color-alerte); color: white; }

/* Sélection en cours */
.cell-slot.selecting { outline: 2px solid var(--color-accent); outline-offset: -1px; }
.cell-slot.selected  { outline: 2px solid var(--color-primary); outline-offset: -1px; }

/* Section indicator (BB/G) */
.cell-slot .section-label {
    font-size: 0.6rem;
    opacity: 0.8;
    display: block;
    line-height: 1;
}

/* ---- Ligne compteur (sticky bas de grille) ---- */
.sticky-counter {
    position: sticky;
    bottom: 0;
    background: var(--color-primary);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    border-top: 2px solid rgba(255,255,255,0.2);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.sticky-counter.alerte {
    background: var(--color-danger);
}

.sticky-counter strong { font-weight: 700; }

/* ---- Compteur global ---- */
.global-counter {
    display: flex;
    gap: 1.5rem;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    padding: 0.625rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    box-shadow: var(--shadow);
}

.global-counter strong { color: var(--color-primary); font-size: 1.1rem; }

/* ---- Ligne de séparation jour ---- */
.grid-day-separator {
    background: var(--color-primary);
    color: white;
    text-align: center;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.4rem;
    letter-spacing: 0.05em;
}

/* ---- Récap heures équipe ---- */
.heures-recap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #f8fafc;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    padding: 0.5rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.8rem;
    overflow-x: auto;
    flex-wrap: wrap;
}

.heures-recap-label {
    font-weight: 600;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.heures-emp-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 0.2rem 0.625rem;
    font-size: 0.75rem;
    white-space: nowrap;
}

.heures-emp-chip .emp-heures {
    font-weight: 700;
    color: var(--color-primary);
}

.heures-emp-chip.over-contract { border-color: var(--color-warning); background: #fefce8; }
.heures-emp-chip.under-contract { border-color: #e5e7eb; }

/* ---- Layout équipe (grille + sidebar alertes) ---- */
.equipe-layout {
    display: grid;
    grid-template-columns: 1fr var(--sidebar-width);
    gap: 1rem;
    align-items: start;
}

.equipe-main { min-width: 0; }

/* ---- Panneau alertes ---- */
.alertes-panel {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: calc(var(--header-height) + 1rem);
    max-height: calc(100vh - var(--header-height) - 2rem);
    overflow-y: auto;
}

.alertes-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.alertes-header h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--color-primary);
}

.alertes-empty {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem 0;
    font-style: italic;
}

/* ---- Menu contextuel ---- */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    min-width: 180px;
    padding: 0.375rem 0;
    font-size: 0.875rem;
}

.context-menu-title {
    padding: 0.375rem 0.875rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ctx-item {
    display: block;
    width: 100%;
    padding: 0.5rem 0.875rem;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--color-text);
    transition: background 0.1s;
}

.ctx-item:hover { background: #f8fafc; }

.context-menu hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 0.25rem 0;
}

/* ---- Responsive grille ---- */
@media (max-width: 1100px) {
    .equipe-layout {
        grid-template-columns: 1fr;
    }
    .alertes-panel {
        position: static;
        max-height: 300px;
    }
}

@media (max-width: 600px) {
    .cell-slot { min-width: 32px; width: 32px; height: 28px; }
    .planning-grid th.th-heure { min-width: 32px; width: 32px; font-size: 0.6rem; }
    .cell-nom { min-width: 100px; }
}

/* ---- Print ---- */
@media print {
    .grid-container { overflow: visible; max-height: none; }
    .sticky-counter { display: none; }
    .planning-grid { font-size: 0.65rem; }
    .cell-slot { height: 20px; min-width: 28px; width: 28px; }
    .planning-grid th.th-heure { min-width: 28px; width: 28px; }
}
