/* =============================================================================
   PLANNING V2 — Grille planning (zone principale)
   ============================================================================= */

/* ── Layout général ─────────────────────────────────────────────────────────── */
.p2-layout {
    display: flex;
    height: calc(100vh - 45px - var(--p2-header-height));
    overflow: hidden;
}

.p2-grid-area {
    flex: 1;
    overflow: auto;
    background: var(--bg-body);
}

/* ── Table grille ───────────────────────────────────────────────────────────── */
.p2-grid {
    width: 100%;
    min-width: 900px;   /* évite l'écrasement sur petits écrans */
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
}

/* ── En-têtes colonnes (jours) ──────────────────────────────────────────────── */
.p2-grid-head {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-card);
}

.p2-grid-head tr {
    height: var(--p2-header-height);
}

.p2-grid-head th {
    border-bottom: 1px solid var(--border-panel);
    background: var(--bg-card); /* Ensure background covers behind sticky */
}

.p2-col-member {
    width: var(--p2-member-col) !important;
    min-width: var(--p2-member-col) !important;
    max-width: var(--p2-member-col) !important;
    padding: 10px 12px;
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--text-muted);
    text-align: left;
    border-right: 1px solid var(--border-panel);
    position: sticky;
    left: 0;
    background: var(--bg-card);
    z-index: 11;
}

.p2-col-day {
    /* auto-distribution : les 7 colonnes partagent l'espace restant */
    width: calc((100% - var(--p2-member-col)) / 7);
    min-width: var(--p2-cell-min-width);
    padding: 6px 10px;
    text-align: center;
    border-right: 1px solid var(--border-panel);
    vertical-align: middle;
    box-sizing: border-box;
}

.p2-day-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-bottom: 2px;
}

.p2-day-num {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-main);
    width: 28px;
    height: 28px;
    line-height: 28px;
    border-radius: 50%;
    margin: 0 auto;
}
.p2-day-num.today {
    background: var(--accent);
    color: #fff;
}

.p2-col-day.weekend .p2-day-label,
.p2-col-day.weekend .p2-day-num {
    color: var(--text-muted);
    opacity: .65;
}

.p2-col-day.today {
    background: rgba(var(--accent-rgb, 59,130,246), .04);
}

.p2-col-day.ferie .p2-day-num {
    color: var(--seg-ferie, #F43F5E);
}

/* ── Corps grille ───────────────────────────────────────────────────────────── */
.p2-grid tbody tr {
    transition: background var(--trans-fast);
}
.p2-grid tbody td,
.p2-grid tbody th {
    border-bottom: 1px solid var(--border-panel);
}
.p2-grid tbody tr:hover { background: rgba(255,255,255,.015); }

/* ── Colonne membre ─────────────────────────────────────────────────────────── */
.p2-member-cell {
    position: sticky;
    left: 0;
    background: var(--bg-card);
    z-index: 5;
    border-right: 1px solid var(--border-panel);
    padding: 8px 12px;
    height: var(--p2-row-height);
    vertical-align: middle;
    width: var(--p2-member-col) !important;
    min-width: var(--p2-member-col) !important;
    max-width: var(--p2-member-col) !important;
}

.p2-member-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.p2-member-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}
.p2-avatar-default {
    background: var(--bg-body);
    border: 1px solid var(--border-panel);
    color: var(--text-muted);
}

.p2-member-name {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    display: block;
}

/* ── Cellule journée ────────────────────────────────────────────────────────── */
.p2-day-cell {
    padding: 4px;
    border-right: 1px solid var(--border-panel);
    vertical-align: top;
    height: var(--p2-row-height);
    min-width: var(--p2-cell-min-width);
    position: relative;
    transition: background var(--trans-fast);
}
.p2-day-cell:hover { background: rgba(255,255,255,.02); }
.p2-day-cell.drag-over {
    background: rgba(var(--accent-rgb, 59,130,246), .08);
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}
.p2-day-cell.weekend { background: rgba(0,0,0,.02); }
.p2-day-cell.today-col { background: rgba(var(--accent-rgb, 59,130,246), .03); }

/* ── Contenu de la cellule (shift assigné) ──────────────────────────────────── */
.p2-cell-shift {
    border-radius: var(--radius-md);   /* coins arrondis généreux V1 */
    padding: 5px 8px 4px;
    height: 100%;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: opacity var(--trans-fast), transform var(--trans-fast);
    position: relative;
    overflow: hidden;
    /* Pas de bordure gauche — fond pastel plein, style V1 */
}
/* Survol : léger éclaircissement du bloc par une ombre intérieure, SANS opacity (l'opacité d'un parent s'appliquerait aussi à la
   bulle de détail, qui deviendrait translucide et laisserait voir les cellules voisines à travers). */
.p2-cell-shift:hover { box-shadow: inset 0 0 0 999px rgba(255, 255, 255, .12); }
.p2-cell-shift:active { transform: scale(.98); }

/* Nom du shift : couleur pleine du shift (héritée du parent via color:c dans :style) */
.p2-cell-shift-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 4px;
}

.p2-cell-shift-name {
    font-size: 11px;
    font-weight: 800;
    color: inherit;          /* = couleur saturée du shift, lisible sur fond pastel */
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    letter-spacing: .1px;
}

.p2-cell-shift-hours {
    font-size: 10px;
    color: inherit;
    opacity: .85;
    white-space: nowrap;
    font-weight: 600;
    flex-shrink: 0;
}

.p2-cell-segment-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-bottom: 4px;
    flex: 1;
    overflow: hidden;
}

.p2-cell-segment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 9px;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    gap: 6px;
}

.p2-segment-label {
    font-weight: 800;
    text-overflow: ellipsis;
    overflow: hidden;
    opacity: 0.9;
}

.p2-segment-range {
    font-weight: 600;
    opacity: 0.7;
    flex-shrink: 0;
    font-size: 8.5px;
}

.p2-cell-segment-more {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 9px;
    font-weight: 800;
    font-style: italic;
    opacity: 0.6;
    margin-top: 1px;
}

.p2-segment-until {
    font-weight: 700;
    font-style: normal;
    font-size: 8px;
    opacity: 0.8;
}

/* Popover Premium */
.p2-cell-shift {
    position: relative;
    overflow: hidden; /* Masque les débordements internes par défaut */
}

/* On désactive l'overflow hidden au survol pour laisser sortir la popover */
.p2-cell-shift:hover {
    overflow: visible;
    z-index: 100; /* Passe au dessus des autres cellules */
}

.p2-shift-popover {
    position: fixed; /* par rapport à l'écran : jamais rognée par le conteneur défilant de la grille (position posée par DayCell) */
    top: 0;
    left: 0;
    transform: scale(0.95);
    width: 220px;
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.15), 0 10px 10px -5px rgba(0,0,0,0.1);
    padding: 14px;
    z-index: 1001;
    opacity: 0;
    visibility: hidden; /* masquée : aucun clic ni survol n'est capté, où qu'elle soit posée */
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
    color: #1e293b;
    text-align: left;
}

/* Flèche discrète */
.p2-shift-popover::before {
    content: '';
    position: absolute;
    top: var(--p2-arrow-top, 50%);
    right: 100%;
    margin-top: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: transparent #ffffff transparent transparent;
}

/* Bulle ouverte à gauche de la cellule (pas assez de place à droite) : la flèche passe de l'autre côté */
.p2-shift-popover.is-left::before {
    right: auto;
    left: 100%;
    border-color: transparent transparent transparent #ffffff;
}

.p2-cell-shift:hover .p2-shift-popover {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
    transform: scale(1);
}

.p2-popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    font-size: 13px;
}

.p2-popover-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.p2-popover-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.p2-popover-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 4px;
    flex-shrink: 0;
}

.p2-popover-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.p2-popover-label {
    font-weight: 700;
    font-size: 11px;
}

.p2-popover-time {
    font-size: 10px;
    opacity: 0.6;
}

/* Sombre / Dark Mode adaptation */
[data-theme="dark"] .p2-shift-popover {
    background: #1e293b;
    border-color: rgba(255,255,255,0.1);
    color: #f8fafc;
}
[data-theme="dark"] .p2-shift-popover::before {
    border-right-color: #1e293b;
}
[data-theme="dark"] .p2-day-cell:nth-child(n+6) .p2-shift-popover::before {
    border-right-color: transparent;
    border-left-color: #1e293b;
}

/* Shifts fixes sombres (OFF/CONGÉ/AMÉNAGEMENT) : texte blanc */
.p2-cell-shift.is-fixed .p2-cell-shift-name {
    color: #fff;
    opacity: 1;
}

.p2-cell-shift-fixed-content {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 100%;
}
.p2-cell-shift-fixed-content .p2-cell-shift-name {
    flex: 1;
}

.p2-cell-delete {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    background: rgba(0,0,0,.3);
    border: none;
    color: rgba(255,255,255,.7);
    font-size: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--trans-fast);
    padding: 0;
}
.p2-cell-shift:hover .p2-cell-delete { display: flex; }
.p2-cell-delete:hover { background: rgba(220,38,38,.6); color: #fff; }

/* ── Cellule vide ───────────────────────────────────────────────────────────── */
.p2-cell-empty {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1.5px dashed transparent;
    transition: all var(--trans-fast);
    color: transparent;
    font-size: 18px;
}
.p2-day-cell:hover .p2-cell-empty {
    border-color: var(--border-panel);
    color: var(--text-muted);
    opacity: .4;
}
