/* ==================== GESTIONE FERIE - VISTA SMARTPHONE ====================
   Pannello a schermo intero (#ferie-mobile) + modali come bottom sheet quando il
   body ha la classe fm-open. Bersagli touch >= 44px, feedback alla pressione,
   rispetto delle safe area del telefono. Usa i token di style.css. */

.fm {
    position: fixed;
    inset: 0;
    z-index: 900;              /* sotto i modali (1000), sopra la dashboard */
    display: flex;
    flex-direction: column;
    background: var(--gray-100);
    color: var(--gray-900);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}
.fm.hidden { display: none !important; }
body.fm-open { overflow: hidden; }

/* Intestazione fissa */
.fm-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 8px 8px;
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow);
}
.fm-header h2 {
    flex: 1;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fm-back, .fm-refresh {
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px;
    border: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}
.fm-back { white-space: nowrap; }
.fm-refresh { font-size: 22px; }
.fm-back:active, .fm-refresh:active { background: rgba(255, 255, 255, 0.32); }

/* Filtri (solo pannello Richieste) */
.fm-filters { background: #fff; border-bottom: 1px solid var(--gray-200); padding: 8px 12px 10px; }
.fm-seg {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 4px;
    background: var(--gray-100);
    border-radius: 12px;
}
.fm-seg button {
    min-height: 44px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--gray-600);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.15;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}
.fm-seg button .fm-count { font-size: 15px; font-weight: 700; color: var(--gray-800); }
.fm-seg button.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.fm-seg button.active .fm-count { color: var(--primary); }
.fm-seg button:active { transform: scale(0.97); }
.fm-month-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.fm-month-row label { font-size: 14px; color: var(--gray-600); white-space: nowrap; }
.fm-month-row input[type="month"] {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 0 10px;
    border: 1px solid var(--gray-300);
    border-radius: 10px;
    font-size: 16px;      /* evita lo zoom automatico di iOS */
    background: #fff;
}
.fm-month-row button {
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--gray-300);
    border-radius: 10px;
    background: #fff;
    color: var(--gray-700);
    font-size: 14px;
    cursor: pointer;
}

/* Corpo scorrevole, con spazio per la barra in basso */
.fm-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px calc(84px + env(safe-area-inset-bottom, 0px));
}
.fm-empty { padding: 40px 16px; text-align: center; color: var(--gray-500); }

/* Schede richiesta */
.fm-card {
    background: #fff;
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
}
.fm-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.fm-name { font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.fm-card-mid { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 8px; font-size: 14px; color: var(--gray-700); }
.fm-when { font-variant-numeric: tabular-nums; }
.fm-dur { color: var(--gray-500); }
.fm-card-note { margin-top: 8px; font-size: 13px; color: var(--gray-600); background: var(--gray-50); border-radius: 8px; padding: 6px 8px; overflow-wrap: anywhere; }
.fm-card-actions { display: flex; gap: 8px; margin-top: 10px; }
.fm-btn {
    flex: 1;
    min-height: 46px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 80ms ease, background-color 120ms ease;
}
.fm-btn:active { transform: scale(0.97); }
.fm-btn-success { background: var(--success); color: #fff; }
.fm-btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }

/* Chip tipologia: stessi colori della legenda del calendario desktop */
.fm-chip {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-900);
    background: var(--gray-200);
    border: 1px solid transparent;
    line-height: 1.2;
}
.fm-chip.tipo-ferie { background: #90EE90; }
.fm-chip.tipo-rol { background: #87CEEB; }
.fm-chip.tipo-festivita { background: #FFA500; }
.fm-chip.tipo-malattia { background: #FF6B6B; }
.fm-chip.tipo-altro { background: #B0C4DE; }
.fm-chip.pending { background: #FFF59D; border: 1px dashed #c9a800; }

/* Agenda */
.fm-month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.fm-month-nav button {
    min-width: 48px;
    min-height: 44px;
    border: 1px solid var(--gray-300);
    border-radius: 10px;
    background: #fff;
    font-size: 22px;
    color: var(--gray-700);
    cursor: pointer;
}
.fm-month-nav button:active { background: var(--gray-200); }
.fm-month-nav span { font-size: 17px; font-weight: 600; }
.fm-agenda-summary { font-size: 13px; color: var(--gray-500); text-align: center; margin-bottom: 8px; }
.fm-legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.fm-legend .fm-chip { font-size: 12px; padding: 3px 8px; }
.fm-day { background: #fff; border-radius: 12px; padding: 8px 12px; margin-bottom: 6px; box-shadow: var(--shadow); }
.fm-day.empty { background: transparent; box-shadow: none; padding: 2px 12px; margin-bottom: 2px; }
.fm-day.weekend .fm-day-num, .fm-day.weekend .fm-day-dow { color: var(--gray-400); }
.fm-day.holiday { background: #F3E5F5; }
.fm-day.today { outline: 2px solid var(--primary); }
.fm-day.today.empty { outline: none; }
.fm-day.today .fm-day-num { background: var(--primary); color: #fff; }
.fm-day-head { display: flex; align-items: center; gap: 8px; min-height: 24px; }
.fm-day-num {
    min-width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.fm-day.empty .fm-day-num { font-weight: 500; font-size: 13px; }
.fm-day-dow { font-size: 13px; color: var(--gray-600); }
.fm-day.empty .fm-day-dow { font-size: 12px; }
.fm-day-holiday { font-size: 12px; color: #6A1B9A; font-weight: 600; margin-left: auto; text-align: right; }
.fm-day-items { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.fm-day-items button.fm-chip { cursor: pointer; min-height: 36px; font: inherit; font-size: 13px; font-weight: 600; }
.fm-day-items button.fm-chip:active { transform: scale(0.97); }

/* Barra fissa in basso */
.fm-bottom {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    display: flex;
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-top: 1px solid var(--gray-200);
    box-shadow: 0 -4px 12px rgb(0 0 0 / 0.06);
}
.fm-nav {
    flex: 1;
    min-height: 48px;
    border: 0;
    border-radius: 12px;
    background: var(--gray-100);
    color: var(--gray-600);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.fm-nav.active { background: var(--primary-light); color: var(--primary-dark); }
.fm-nav:active { transform: scale(0.97); }
.fm-primary {
    flex: 1.3;
    min-height: 48px;
    border: 0;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}
.fm-primary:active { background: var(--primary-dark); }

/* Modali esistenti (Gestisci, Cancella, Inserisci) come bottom sheet in modalità mobile */
body.fm-open .modal { align-items: flex-end; }
body.fm-open .modal .modal-content {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 18px 18px 0 0;
    max-height: 92vh;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}
body.fm-open .modal .modal-content::before {
    content: '';
    display: block;
    width: 44px; height: 5px;
    border-radius: 3px;
    background: var(--gray-300);
    margin: -6px auto 10px;
}
body.fm-open .modal .modal-content input,
body.fm-open .modal .modal-content select,
body.fm-open .modal .modal-content textarea { font-size: 16px; min-height: 44px; width: 100%; max-width: 100%; box-sizing: border-box; }
body.fm-open .modal .modal-content .form-group label { display: block; text-align: left; }
body.fm-open .modal .modal-content textarea { min-height: 80px; }
body.fm-open .modal .form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
body.fm-open .modal .form-actions .btn { flex: 1 1 40%; min-height: 48px; font-size: 15px; }
body.fm-open .modal .modal-close { min-width: 44px; min-height: 44px; }
body.fm-open .modal .time-range-inputs { flex-wrap: wrap; gap: 8px; }

@media (prefers-reduced-motion: reduce) {
    .fm-btn, .fm-seg button, .fm-nav, .fm-day-items button.fm-chip { transition: none; }
    .fm-btn:active, .fm-seg button:active, .fm-nav:active, .fm-day-items button.fm-chip:active { transform: none; }
}

/* Pulsante "Versione mobile" nel tab desktop: nascosto sugli schermi stretti (lì parte da sola) */
@media (max-width: 480px) {
    #btn-ferie-mobile { display: none; }
}
