/* ============================================================
   Mobile stylesheet — stili dedicati per smartphone (<=768px).
   Caricato dopo tutti gli altri CSS: vince su desktop e pagine.
   Testato su ~360-430px (Samsung A55, Motorola Edge 50).
   ============================================================ */

@media (max-width: 768px) {

    /* ---------- Base ---------- */

    html,
    body {
        overflow-x: hidden;
    }

    /* font >= 16px sugli input: evita lo zoom automatico al focus
       e migliora la leggibilita' su touch */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* tap target comodi */
    .ft-btn {
        min-height: 2.5rem;
    }

    .ft-btn-icon {
        width: 2.5rem;
        height: 2.5rem;
    }

    /* ---------- Header ---------- */

    .ft-header {
        padding: 0 0.75rem;
        min-height: 3.25rem;
    }

    .ft-header-left {
        font-size: 0.95rem;
        min-width: 0;
    }

    .ft-header-left> :last-child {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* chip utente: solo il nome, senza ruolo */
    .ft-user-chip {
        font-size: 0.75rem;
        max-width: 8rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ft-user-chip span:nth-child(2),
    .ft-user-chip span:nth-child(3) {
        display: none;
    }

    .ft-logout-form .ft-btn {
        padding: 0.35rem 0.6rem;
        font-size: 0.8rem;
    }

    /* ---------- Pagine ---------- */

    .ft-content {
        padding: 0.75rem;
    }

    .ft-page-header {
        margin-bottom: 0.9rem;
        padding: 0.5rem 0;
    }

    .ft-page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .ft-page-header .ft-page-title {
        font-size: 1.15rem;
    }

    .ft-page-header .ft-page-subtitle {
        font-size: 0.8rem;
    }

    .ft-page-actions {
        display: flex;
        justify-content: flex-end;
    }

    /* ---------- Card e sezioni ---------- */

    .ft-card,
    .ft-import-card {
        padding: 0.9rem;
    }

    .ft-import-sections {
        grid-template-columns: 1fr;
    }

    /* griglia impostazioni: una scheda per riga */
    .ft-settings-grid {
        grid-template-columns: 1fr;
    }

    /* ---------- Form ---------- */

    .ft-form-grid {
        grid-template-columns: 1fr;
    }

    .ft-form-actions {
        flex-wrap: wrap;
    }

    .ft-form-actions .ft-btn {
        flex: 1 1 auto;
        justify-content: center;
    }

    /* ---------- Dialog ---------- */

    .ft-dialog {
        width: calc(100vw - 1rem);
        max-width: calc(100vw - 1rem);
        min-width: 0;
        max-height: calc(100dvh - 1.5rem);
    }

    .ft-dialog-body {
        padding: 0.9rem;
        overflow-y: auto;
    }

    /* ---------- Tabelle ---------- */

    .ft-table-wrap,
    .fixed-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .bootstrap-table .ft-table,
    .ft-table {
        font-size: 0.78rem;
    }

    .ft-table th,
    .ft-table td {
        padding: 0.4rem 0.35rem;
        white-space: nowrap;
    }

    /* filtri tabella: scrollano con la tabella, restano usabili */
    .bootstrap-table .filter-control input,
    .bootstrap-table .filter-control select {
        min-width: 6rem;
    }

    /* gruppo azioni riga: compatto ma toccabile */
    .ft-btn-group {
        display: inline-flex;
        flex-wrap: nowrap;
        gap: 0.15rem;
    }

    .ft-btn-group .ft-btn-icon {
        width: 2.1rem;
        height: 2.1rem;
    }

    /* ---------- Dashboard ---------- */

    .ft-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .ft-dashboard-row {
        grid-template-columns: 1fr;
    }

    .ft-card-title {
        font-size: 0.95rem;
    }

    .ft-card-subtitle {
        font-size: 0.75rem;
    }

    /* ---------- Avvisi scadenze ---------- */

    .ft-alert-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .ft-alert-main {
        align-items: flex-start;
    }

    .ft-alert-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .ft-alert-actions .ft-btn {
        flex: 1 1 auto;
        text-align: center;
    }

    /* ---------- Calendario ---------- */

    .ft-cal-cell {
        min-height: 3.6rem;
        padding: 2px 3px;
        gap: 2px;
    }

    .ft-cal-daynum {
        font-size: 0.7rem;
    }

    .ft-cal-chip {
        font-size: 0.55rem;
        padding: 1px 3px;
        border-radius: 4px;
    }

    .ft-cal-toolbar {
        padding: 10px;
        gap: 8px;
    }

    .ft-cal-title {
        font-size: 0.95rem;
        order: 3;
        width: 100%;
        text-align: center;
    }

    .ft-cal-legend {
        font-size: 0.65rem;
        gap: 8px;
    }

    .ft-cal-weekdays {
        padding: 6px 8px 0;
    }

    .ft-cal-grid {
        gap: 3px;
        padding: 6px 8px 10px;
    }

    /* ---------- Toast ---------- */

    .ft-toast-container {
        left: 0.75rem !important;
        right: 0.75rem !important;
        max-width: none;
    }

    /* ---------- Login ---------- */

    .ft-login-card {
        margin: 1rem;
        padding: 1.25rem;
    }
}

/* Schermi molto stretti (~360px): KPI a colonna singola */
@media (max-width: 560px) {
    .ft-kpi-grid {
        grid-template-columns: 1fr;
    }
}