/* =============================================================================
   WIDGET CALENDRIER
   =============================================================================
   À inclure dans header.php après widgets.css :
     <link rel="stylesheet" href="assets/css/calendar.css">
   ============================================================================= */


/* -----------------------------------------------------------------------------
   TOOLBAR
   ----------------------------------------------------------------------------- */

.cal-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
    background: #fff;
    flex-wrap: wrap;
}

.cal-nav {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.cal-nav-btn {
    height: 32px;
    min-width: 32px;
    padding: 0 10px;
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border, rgba(0, 0, 0, 0.12));
    border-radius: 6px;
    font-size: 13px;
    color: var(--color-text, #1a1a1a);
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.cal-nav-btn:hover {
    background: var(--color-bg-soft, #fafafa);
    border-color: var(--color-border, rgba(0, 0, 0, 0.20));
}

.cal-nav-btn.is-primary {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
    font-weight: 500;
}

.cal-nav-btn.is-primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.cal-date-picker {
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--color-border, rgba(0, 0, 0, 0.12));
    border-radius: 6px;
    font-size: 13px;
    color: var(--color-text, #1a1a1a);
    background: var(--color-bg, #fff);
    outline: none;
}

.cal-date-picker:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.10);
}

.cal-toolbar-spacer {
    flex: 1;
    min-width: 0;
}

/* Switch "Terminés" */
.cal-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.cal-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.cal-switch-track {
    width: 34px;
    height: 20px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    position: relative;
    transition: background 0.18s ease;
}

.cal-switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.18s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.cal-switch input:checked + .cal-switch-track {
    background: #0F6E56;
}

.cal-switch input:checked + .cal-switch-track::after {
    transform: translateX(14px);
}

.cal-switch-label {
    font-size: 13px;
    color: var(--color-text, #1a1a1a);
}

/* Filtre Titulaire (style boutons toolbar factures) */
.cal-popover-wrap {
    position: relative;
}

.cal-filter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border, rgba(0, 0, 0, 0.12));
    border-radius: 6px;
    font-size: 13px;
    color: var(--color-text, #1a1a1a);
    cursor: pointer;
}

.cal-filter:hover {
    background: var(--color-bg-soft, #fafafa);
}

.cal-popover {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 50;
    min-width: 200px;
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border, rgba(0, 0, 0, 0.10));
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10);
    padding: 4px;
    display: flex;
    flex-direction: column;
}

.cal-popover[hidden] {
    display: none;
}

.cal-popover-item {
    text-align: left;
    background: transparent;
    border: none;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--color-text, #1a1a1a);
    border-radius: 4px;
    cursor: pointer;
}

.cal-popover-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.cal-popover-item.is-active {
    background: rgba(37, 99, 235, 0.10);
    color: #1d4ed8;
    font-weight: 600;
}


/* -----------------------------------------------------------------------------
   BODY — Layout 2 colonnes × 3 lignes (header / multiday / corps)
   -----------------------------------------------------------------------------
   Lignes :
     row 1 = header jour
     row 2 = bandeau multi-jour (peut être vide)
     row 3 = corps (liste Prioritaire | grille horaire)

   Le header Prioritaire span sur les 2 premières lignes pour s'aligner
   visuellement avec header jour + bandeau multi-jour.
   ----------------------------------------------------------------------------- */

.cal-body {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: auto auto 1fr;
    background: #fff;
}


/* -----------------------------------------------------------------------------
   COLONNE PRIORITAIRE (gauche)
   ----------------------------------------------------------------------------- */

.cal-col-priority {
    grid-column: 1;
    grid-row: 1 / 4;             /* span sur toute la hauteur */
    display: grid;
    grid-template-rows: subgrid; /* aligne ses lignes sur le parent */
    border-right: 1px solid var(--color-border, rgba(0, 0, 0, 0.10));
    background: #fff;
}

/* Fallback si subgrid pas supporté (Safari < 16, anciens navigateurs) */
@supports not (grid-template-rows: subgrid) {
    .cal-col-priority {
        display: flex;
        flex-direction: column;
    }
}

.cal-col-head {
    grid-row: 1 / 3;             /* couvre header + multiday */
    padding: 14px 14px 12px;
    border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;   /* texte aligné en bas, comme header jours */
}

.cal-col-head-sub {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--color-text-muted, #6b7280);
    margin-bottom: 2px;
}

.cal-col-head-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-text, #1a1a1a);
}

.cal-priority-list {
    grid-row: 3;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    min-height: 100px;
}

/* Cards en Prioritaire : hauteur fixe = 1h (2 slots) pour cohérence visuelle */
.cal-priority-list .cal-event {
    height: calc(var(--cal-slot-height, 34px) * 2);
    flex-shrink: 0;
}


/* -----------------------------------------------------------------------------
   ZONE JOURS (droite) — composée de 3 sous-éléments
   ----------------------------------------------------------------------------- */

.cal-days-wrap {
    grid-column: 2;
    grid-row: 1 / 4;
    display: grid;
    grid-template-rows: subgrid;
    overflow-x: hidden;
}

@supports not (grid-template-rows: subgrid) {
    .cal-days-wrap {
        display: flex;
        flex-direction: column;
    }
}

.cal-days-header   { grid-row: 1; }
.cal-allday-strip  { grid-row: 2; }
.cal-grid          { grid-row: 3; }

/* Header des jours (sticky en haut de la grille) */
.cal-days-header {
    display: grid;
    grid-template-columns: 60px repeat(var(--cal-day-count, 5), 1fr);
    border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.10));
    background: var(--color-bg, #fff);
    position: sticky;
    top: 0;
    z-index: 5;
}

.cal-day-head {
    padding: 8px 12px 6px;
    border-left: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
    background: #fff;
    position: relative;
}

.cal-day-head-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

.cal-day-head-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--color-text-muted, #6b7280);
}

.cal-day-head-plus {
    margin-left: auto;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--color-text-muted, #6b7280);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: background 0.12s ease, color 0.12s ease;
}

.cal-day-head-plus:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-text, #1a1a1a);
}

.cal-day-head-date {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-text, #1a1a1a);
}

/* Jour "aujourd'hui" mis en avant */
.cal-day-head.is-today {
    background: #ff8834;
    color: #fff;
}

.cal-day-head.is-today .cal-day-head-label,
.cal-day-head.is-today .cal-day-head-date {
    color: #fff;
}

.cal-day-head.is-today .cal-day-head-plus {
    color: rgba(255, 255, 255, 0.85);
}

.cal-day-head.is-today .cal-day-head-plus:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* Gutter heures (vide dans le header) */
.cal-time-gutter-head {
    border-left: none;
}


/* -----------------------------------------------------------------------------
   BANDEAU MULTI-JOURS (style Google Agenda, max 3 lignes)
   ----------------------------------------------------------------------------- */

.cal-allday-strip {
    display: grid;
    grid-template-columns: 60px 1fr;
    background: #fff;
    border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
    min-height: 28px;
}

/* Quand pas d'events multi-jour : on garde une fine bande (pour alignement) */
.cal-allday-strip.is-empty {
    min-height: 8px;
}

.cal-allday-strip.is-empty .cal-allday-grid {
    display: none;
}

.cal-allday-grid {
    display: grid;
    grid-auto-rows: 22px;
    gap: 2px;
    padding: 3px 0;
    position: relative;
}

.cal-allday-event {
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    background: #1a1a1a;
    color: #fff;
    border-left: 3px solid var(--cal-event-color, #1a1a1a);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0 1px;
    line-height: 18px;
    transition: opacity 0.12s ease;
}

.cal-allday-event:hover {
    opacity: 0.88;
}

.cal-allday-event-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.cal-allday-overflow {
    font-size: 11px;
    color: var(--color-text-muted, #6b7280);
    padding: 2px 8px;
    font-style: italic;
}


/* -----------------------------------------------------------------------------
   GRILLE HORAIRE
   ----------------------------------------------------------------------------- */

.cal-grid {
    display: grid;
    grid-template-columns: 60px repeat(var(--cal-day-count, 5), 1fr);
    position: relative;
}

.cal-time-gutter {
    border-right: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
}

/* 1 cellule par heure = 2 slots de 30min */
.cal-time-cell {
    height: calc(var(--cal-slot-height, 34px) * 2);
    padding: 6px 8px 0 0;
    font-size: 11px;
    color: var(--color-text-muted, #6b7280);
    text-align: right;
    border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.05));
}

.cal-day-col {
    border-left: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
    position: relative;
    min-height: calc(var(--cal-slot-height, 34px) * 22);
}

.cal-day-col.is-today {
    background: rgba(255, 136, 52, 0.04);
}

/* Ligne stylisée marquant l'heure courante (visible uniquement sur today) */
.cal-now-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: #ff8834;
    z-index: 8;
    pointer-events: none;
}

.cal-now-line::before {
    content: '';
    position: absolute;
    left: -5px;
    top: -4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ff8834;
    box-shadow: 0 0 0 2px rgba(255, 136, 52, 0.20);
}

/* Slot 30min (drop zone + click empty = nouveau) */
.cal-slot {
    height: var(--cal-slot-height, 34px);
    border-bottom: 1px dashed transparent;
    cursor: pointer;
    transition: background 0.10s ease;
}

.cal-slot:nth-child(2n) {
    border-bottom-color: var(--color-border, rgba(0, 0, 0, 0.06));
}

.cal-slot:nth-child(2n+1) {
    border-bottom-color: transparent;
}

.cal-slot:hover {
    background: rgba(0, 0, 0, 0.02);
}

.cal-slot.is-drop-target {
    background: rgba(37, 99, 235, 0.10);
}


/* -----------------------------------------------------------------------------
   EVENT CARD (Prioritaire ET Calendrier)
   ----------------------------------------------------------------------------- */

.cal-event-wrap {
    position: absolute;
    padding: 0 4px;
}

.cal-event {
    background: #fff;
    border: 1px solid var(--color-border, rgba(0, 0, 0, 0.10));
    border-left: 3px solid var(--cal-event-color, #1a1a1a);
    border-radius: 4px;
    padding: 5px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: grab;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.12s ease, transform 0.06s ease;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.cal-event:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    z-index: 2;
}

.cal-event.is-dragging {
    cursor: grabbing;
    opacity: 0.5;
}

/* Event très court (≤ 30 min) : on n'affiche QUE la ligne d'en-tête */
.cal-event.is-short {
    padding: 4px 8px;
    justify-content: center;
}

.cal-event.is-short .cal-event-title,
.cal-event.is-short .cal-event-foot {
    display: none;
}

/* Event 1h (≤ 60 min) : on cache la description ET le pied (téléphone + checkbox)
   — la checkbox reste accessible via l'ouverture du drawer au clic */
.cal-event.is-medium .cal-event-title,
.cal-event.is-medium .cal-event-foot {
    display: none;
}

/* Cards en Prioritaire : pas de ligne description (toujours) */
.cal-priority-list .cal-event-title {
    display: none;
}

.cal-event-head {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

/* Cloche colorée selon tag */
.cal-event-bell {
    background: transparent;
    border: none;
    padding: 0;
    color: var(--cal-event-color, #1a1a1a);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    transition: opacity 0.12s ease;
    flex-shrink: 0;
}

.cal-event-bell.is-off {
    opacity: 0.25;
}

.cal-event-bell:hover {
    opacity: 0.7;
}

.cal-event-tiers {
    flex: 1;
    font-size: 12px;
    font-weight: 700;
    color: var(--color-text, #1a1a1a);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Pastille noire à droite avec heure (calendar) ou date (priority) */
.cal-event-badge {
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    background: #1a1a1a;
    padding: 2px 7px;
    border-radius: 10px;
    flex-shrink: 0;
    white-space: nowrap;
}

.cal-event-title {
    font-size: 12px;
    color: var(--color-text-secondary, #4b5563);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-event-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: auto;
}

.cal-event-phone {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--color-text-secondary, #4b5563);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.cal-event-phone.is-empty {
    color: var(--color-text-muted, #6b7280);
    font-style: italic;
}

.cal-event-phone svg {
    color: var(--color-text-muted, #6b7280);
    flex-shrink: 0;
}

.cal-event-check {
    flex-shrink: 0;
    cursor: pointer;
}

.cal-event-check input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: #0F6E56;
}

/* Event marqué terminé : visuel discret */
.cal-event.is-done {
    opacity: 0.5;
}

.cal-event.is-done .cal-event-tiers,
.cal-event.is-done .cal-event-title {
    text-decoration: line-through;
}


/* -----------------------------------------------------------------------------
   RESPONSIVE — masque les colonnes jours, pas de repositionnement
   ----------------------------------------------------------------------------- */

/* > 1200px : 5 jours (par défaut) */

/* 1000-1200px : 4 jours */
@media (max-width: 1200px) {
    .cal-day-head:nth-child(6),
    .cal-day-col:nth-child(6) {
        display: none;
    }
    .cal-days-header { grid-template-columns: 60px repeat(4, 1fr); }
    .cal-grid        { grid-template-columns: 60px repeat(4, 1fr); }
    .cal-allday-grid { grid-template-columns: repeat(4, 1fr) !important; }
}

/* 800-1000px : 3 jours */
@media (max-width: 1000px) {
    .cal-day-head:nth-child(5),
    .cal-day-col:nth-child(5) {
        display: none;
    }
    .cal-days-header { grid-template-columns: 60px repeat(3, 1fr); }
    .cal-grid        { grid-template-columns: 60px repeat(3, 1fr); }
    .cal-allday-grid { grid-template-columns: repeat(3, 1fr) !important; }
}

/* 500-800px : 2 jours */
@media (max-width: 800px) {
    .cal-day-head:nth-child(4),
    .cal-day-col:nth-child(4) {
        display: none;
    }
    .cal-days-header { grid-template-columns: 60px repeat(2, 1fr); }
    .cal-grid        { grid-template-columns: 60px repeat(2, 1fr); }
    .cal-allday-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .cal-body        { grid-template-columns: 200px 1fr; grid-template-rows: auto auto 1fr; }
}

/* < 500px (mobile) : Prioritaire en haut + 1 jour en dessous */
@media (max-width: 500px) {

    .cal-day-head:nth-child(3),
    .cal-day-col:nth-child(3) {
        display: none;
    }
    .cal-days-header { grid-template-columns: 50px 1fr; }
    .cal-grid        { grid-template-columns: 50px 1fr; }
    .cal-allday-grid { grid-template-columns: 1fr !important; }

    /* Mobile : on remet la cal-body en flex column et on désactive le subgrid
       (Prioritaire devient une boîte indépendante en haut) */
    .cal-body {
        display: flex;
        flex-direction: column;
    }
    .cal-col-priority {
        display: flex;
        flex-direction: column;
        border-right: none;
        border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.10));
        grid-column: auto;
        grid-row: auto;
    }
    .cal-col-priority .cal-col-head {
        grid-row: auto;
        padding: 10px 12px 8px;
    }
    .cal-col-priority .cal-priority-list {
        grid-row: auto;
        /* Cards en ligne, scroll horizontal — plus naturel sur mobile */
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        min-height: 0;
        padding: 8px;
        scrollbar-width: thin;
    }
    .cal-priority-list .cal-event {
        flex-shrink: 0;
        width: 220px;
        height: auto;
        min-height: 60px;
    }

    .cal-days-wrap {
        display: flex;
        flex-direction: column;
        grid-column: auto;
        grid-row: auto;
    }
    .cal-days-header,
    .cal-allday-strip,
    .cal-grid {
        grid-row: auto;
    }

    /* Toolbar : on resserre fortement et autorise un wrap propre */
    .cal-toolbar {
        gap: 6px;
        padding: 6px 8px;
    }
    .cal-nav-btn {
        height: 28px;
        min-width: 28px;
        padding: 0 6px;
        font-size: 12px;
    }
    .cal-date-picker {
        height: 28px;
        font-size: 12px;
        max-width: 130px;
    }
    .cal-filter {
        height: 28px;
        font-size: 12px;
        padding: 0 8px;
    }
    .cal-filter strong { display: none; }   /* on ne garde que le nom */

    /* La gutter heures rétrécie pour libérer de la place */
    .cal-time-cell {
        font-size: 10px;
        padding: 4px 4px 0 0;
    }
}

/* < 400px : ajustements supplémentaires pour très petits écrans */
@media (max-width: 400px) {
    .cal-toolbar {
        flex-wrap: wrap;
        row-gap: 6px;
    }
    .cal-nav {
        flex-wrap: wrap;
    }
    /* Cacher les boutons "saut semaine" pour gagner de la place */
    .cal-nav-btn[data-cal-nav="prev-week"],
    .cal-nav-btn[data-cal-nav="next-week"] {
        display: none;
    }
    .cal-toolbar-spacer {
        flex-basis: 100%;
        height: 0;
    }
    .cal-switch-label {
        display: none;   /* juste le switch sans son texte */
    }
    .cal-priority-list .cal-event {
        width: 200px;
    }
}
