/**
 * CPO-Planner - Global Mobile Styles
 *
 * Questo file contiene tutti gli stili responsive per dispositivi mobile.
 * Incluso in base.html per applicazione globale.
 *
 * Breakpoint Bootstrap 4:
 * - xs: < 576px (portrait phones)
 * - sm: >= 576px (landscape phones)
 * - md: >= 768px (tablets)
 * - lg: >= 992px (desktops)
 * - xl: >= 1200px (large desktops)
 */

/* ===========================================
   T1: BOTTOM STEP NAVIGATION - MOBILE
   Barra fissa in basso con 5 step sempre visibili
   =========================================== */

/* Base style - nascosto di default */
.mobile-step-nav {
    display: none;
}

/* Nascondi accordion su tutte le viewport (usiamo bottom nav su mobile) */
.mobile-accordion {
    display: none !important;
}

@media (max-width: 767.98px) {
    /* Nascondi le tab originali */
    .nav-tabs.mobile-accordion-tabs {
        display: none !important;
    }

    /* Bottom Navigation Bar Fissa */
    .mobile-step-nav {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        border-top: 1px solid #e3e6f0;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
        z-index: 1050;
        justify-content: space-around;
        align-items: center;
        padding: 8px 4px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    .mobile-step-nav .step-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        padding: 6px 2px;
        text-decoration: none;
        color: #858796;
        font-size: 0.65rem;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
        border-radius: 8px;
        margin: 0 2px;
    }

    .mobile-step-nav .step-item:hover {
        background: #f8f9fc;
    }

    .mobile-step-nav .step-item.active {
        color: #4e73df;
    }

    .mobile-step-nav .step-item.active .step-icon {
        background: #4e73df;
        color: #fff;
        transform: scale(1.1);
    }

    .mobile-step-nav .step-item.completed .step-icon {
        background: #1cc88a;
        color: #fff;
    }

    .mobile-step-nav .step-icon {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: #e3e6f0;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 4px;
        font-size: 0.9rem;
        transition: all 0.2s ease;
    }

    .mobile-step-nav .step-label {
        text-align: center;
        line-height: 1.2;
        max-width: 60px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Progress bar sopra la bottom nav */
    .mobile-step-nav::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        height: 3px;
        background: #4e73df;
        width: var(--step-progress, 20%);
        transition: width 0.3s ease;
    }

    /* Spazio per il contenuto per non essere coperto dalla bottom nav */
    body.has-mobile-step-nav {
        padding-bottom: 90px;
    }

    /* Indicatore step corrente (pallino sopra) */
    .mobile-step-nav .step-item.active::after {
        content: '';
        position: absolute;
        top: -1px;
        left: 50%;
        transform: translateX(-50%);
        width: 24px;
        height: 3px;
        background: #4e73df;
        border-radius: 0 0 3px 3px;
    }

    .mobile-step-nav .step-item {
        position: relative;
    }
}

/* Su desktop: nascondi bottom nav */
@media (min-width: 768px) {
    .mobile-step-nav {
        display: none !important;
    }
}


/* Su desktop: mostra tab normalmente */
@media (min-width: 768px) {
    .nav-tabs.mobile-accordion-tabs {
        display: flex !important;
    }
}


/* ===========================================
   T7.2: MOBILE PROGRESS HEADER
   Barra sticky che mostra progresso step
   =========================================== */

/* Base: nascosto su desktop */
.mobile-progress-header {
    display: none;
}

@media (max-width: 767.98px) {
    .mobile-progress-header {
        display: block;
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
        z-index: 1040;
        padding: 12px 16px;
        margin: -1rem -1rem 1rem -1rem;
        box-shadow: 0 2px 8px rgba(78, 115, 223, 0.3);
    }

    .progress-header-content {
        max-width: 100%;
    }

    .progress-step-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 8px;
    }

    .progress-step-number {
        font-size: 0.75rem;
        font-weight: 600;
        color: rgba(255, 255, 255, 0.85);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .progress-step-number span {
        color: #fff;
    }

    .progress-step-name {
        font-size: 0.9rem;
        font-weight: 700;
        color: #fff;
        text-align: right;
        max-width: 60%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .progress-bar-container {
        height: 6px;
        background: rgba(255, 255, 255, 0.25);
        border-radius: 3px;
        overflow: hidden;
    }

    .progress-bar-fill {
        height: 100%;
        background: #fff;
        border-radius: 3px;
        transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
        position: relative;
        overflow: hidden;
    }

    /* Animazione shimmer sulla barra */
    .progress-bar-fill::after {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        bottom: 0;
        width: 50%;
        background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
        animation: progressShimmer 2s ease-in-out infinite;
    }

    @keyframes progressShimmer {
        0% { left: -50%; }
        100% { left: 100%; }
    }

    /* Adattamento body quando progress header è presente */
    body.has-mobile-step-nav .mobile-progress-header {
        margin-top: 0;
    }
}


/* ===========================================
   T7.3: VALIDAZIONE STEP-BY-STEP
   Toast notifiche e stati visivi step
   =========================================== */

/* Stati validazione step nella bottom nav */
.mobile-step-nav .step-item.step-valid .step-icon {
    background: #1cc88a !important;
    color: #fff !important;
}

.mobile-step-nav .step-item.step-valid .step-icon::after {
    content: '\f00c';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    background: #fff;
    color: #1cc88a;
    border-radius: 50%;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.mobile-step-nav .step-item.step-invalid .step-icon {
    background: #e74a3b !important;
    color: #fff !important;
    animation: shakeStep 0.5s ease;
}

.mobile-step-nav .step-item.step-invalid .step-icon::after {
    content: '\f00d';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    background: #fff;
    color: #e74a3b;
    border-radius: 50%;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.mobile-step-nav .step-item.step-warning .step-icon {
    background: #f6c23e !important;
    color: #fff !important;
}

.mobile-step-nav .step-item .step-icon {
    position: relative;
}

@keyframes shakeStep {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-3px); }
    40%, 80% { transform: translateX(3px); }
}

/* Toast di validazione */
.validation-toast {
    position: fixed;
    bottom: 100px;
    left: 16px;
    right: 16px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    display: flex;
    align-items: flex-start;
    padding: 12px 16px;
    z-index: 1100;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.validation-toast.show {
    transform: translateY(0);
    opacity: 1;
}

.validation-toast.toast-error {
    border-left: 4px solid #e74a3b;
}

.validation-toast.toast-warning {
    border-left: 4px solid #f6c23e;
}

.toast-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 12px;
}

.toast-error .toast-icon {
    background: rgba(231, 74, 59, 0.1);
    color: #e74a3b;
}

.toast-warning .toast-icon {
    background: rgba(246, 194, 62, 0.1);
    color: #f6c23e;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #333;
    margin-bottom: 4px;
}

.toast-message {
    font-size: 0.8rem;
    color: #666;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    color: #999;
    padding: 4px 8px;
    cursor: pointer;
    margin-left: 8px;
    flex-shrink: 0;
}

.toast-close:hover {
    color: #333;
}

/* Miglioramento campi con errore */
@media (max-width: 767.98px) {
    .form-control.is-invalid {
        border-color: #e74a3b !important;
        background-image: none;
        animation: shakeField 0.4s ease;
    }

    .form-control.is-valid {
        border-color: #1cc88a !important;
        background-image: none;
    }

    .form-control.border-warning {
        border-color: #f6c23e !important;
    }

    @keyframes shakeField {
        0%, 100% { transform: translateX(0); }
        25% { transform: translateX(-5px); }
        75% { transform: translateX(5px); }
    }
}


/* ===========================================
   T7.4: ANIMAZIONI TRANSIZIONE STEP
   Slide fluido tra step del form wizard
   =========================================== */

@media (max-width: 767.98px) {
    /* Container per animazioni */
    .tab-content.step-animated {
        position: relative;
        overflow: hidden;
    }

    /* Override transizione fade di Bootstrap per mobile */
    .step-animated .tab-pane {
        transition: none;
    }

    .step-animated .tab-pane.fade {
        opacity: 1;
        transition: none;
    }

    /* Animazione slide-in da destra (avanti) */
    .step-animated .tab-pane.slide-in-right {
        animation: slideInRight 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    }

    /* Animazione slide-in da sinistra (indietro) */
    .step-animated .tab-pane.slide-in-left {
        animation: slideInLeft 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    }

    /* Animazione slide-out a sinistra (uscita avanti) */
    .step-animated .tab-pane.slide-out-left {
        animation: slideOutLeft 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
    }

    /* Animazione slide-out a destra (uscita indietro) */
    .step-animated .tab-pane.slide-out-right {
        animation: slideOutRight 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
    }

    @keyframes slideInRight {
        0% {
            opacity: 0;
            transform: translateX(30px);
        }
        100% {
            opacity: 1;
            transform: translateX(0);
        }
    }

    @keyframes slideInLeft {
        0% {
            opacity: 0;
            transform: translateX(-30px);
        }
        100% {
            opacity: 1;
            transform: translateX(0);
        }
    }

    @keyframes slideOutLeft {
        0% {
            opacity: 1;
            transform: translateX(0);
        }
        100% {
            opacity: 0;
            transform: translateX(-30px);
        }
    }

    @keyframes slideOutRight {
        0% {
            opacity: 1;
            transform: translateX(0);
        }
        100% {
            opacity: 0;
            transform: translateX(30px);
        }
    }

    /* Effetto pulse sul progress bar durante transizione */
    .mobile-progress-header.transitioning .progress-bar-fill {
        animation: progressPulse 0.35s ease;
    }

    @keyframes progressPulse {
        0% { transform: scaleY(1); }
        50% { transform: scaleY(1.3); }
        100% { transform: scaleY(1); }
    }

    /* Effetto ripple sullo step cliccato */
    .mobile-step-nav .step-item.ripple .step-icon::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        background: rgba(255, 255, 255, 0.4);
        border-radius: 50%;
        transform: translate(-50%, -50%);
        animation: rippleEffect 0.4s ease-out forwards;
    }

    @keyframes rippleEffect {
        0% {
            width: 0;
            height: 0;
            opacity: 1;
        }
        100% {
            width: 60px;
            height: 60px;
            opacity: 0;
        }
    }

    /* Smooth scroll durante transizione */
    html.step-transitioning {
        scroll-behavior: smooth;
    }
}


/* ===========================================
   T3: TAB DETTAGLIO → SCROLL ORIZZONTALE
   Per le tab nel dettaglio stazione (7 tab)
   =========================================== */

@media (max-width: 767.98px) {
    /* Container scrollabile per tab */
    .nav-tabs-scrollable {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
        padding-bottom: 2px;
        margin-bottom: -1px;
    }

    .nav-tabs-scrollable::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }

    .nav-tabs-scrollable .nav-item {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .nav-tabs-scrollable .nav-link {
        padding: 0.75rem 1rem;
    }

    /* Forza nascondimento testo tab su mobile - solo icone */
    .nav-tabs-scrollable .nav-link span {
        display: none !important;
    }

    /* Indicatore scroll (freccia) */
    .tabs-scroll-indicator {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 40px;
        background: linear-gradient(90deg, transparent, rgba(255,255,255,0.95) 50%);
        display: flex;
        align-items: center;
        justify-content: flex-end;
        padding-right: 8px;
        pointer-events: none;
        z-index: 10;
    }

    .tabs-scroll-indicator i {
        color: #4e73df;
        animation: bounceRight 1s infinite;
    }

    @keyframes bounceRight {
        0%, 100% { transform: translateX(0); }
        50% { transform: translateX(5px); }
    }

    /* Nascondi indicatore se scrollato fino in fondo */
    .tabs-scroll-indicator.hidden {
        display: none;
    }
}


/* ===========================================
   FORM - Ottimizzazioni generali mobile
   =========================================== */

@media (max-width: 767.98px) {
    /* Input più grandi per touch */
    .form-control {
        font-size: 16px !important; /* Previene zoom su iOS */
        padding: 0.75rem;
        min-height: 48px;
    }

    /* Select con altezza adeguata */
    select.form-control {
        height: 48px;
    }

    /* Textarea altezza minima */
    textarea.form-control {
        min-height: 100px;
    }

    /* Label più visibili */
    .form-group label {
        font-weight: 600;
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    /* Pulsanti form full-width */
    .form-group .btn,
    .form-actions .btn {
        width: 100%;
        margin-bottom: 0.5rem;
        min-height: 48px;
    }

    /* Input group su mobile - stack verticale */
    .input-group-mobile-stack {
        flex-direction: column;
    }

    .input-group-mobile-stack .form-control {
        border-radius: 0.35rem !important;
        margin-bottom: 0.5rem;
    }

    .input-group-mobile-stack .input-group-text,
    .input-group-mobile-stack .btn {
        border-radius: 0.35rem !important;
        width: 100%;
    }
}


/* ===========================================
   PULSANTI - Touch-friendly
   =========================================== */

@media (max-width: 767.98px) {
    /* Pulsanti standard più grandi */
    .btn {
        padding: 0.625rem 1rem;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Pulsanti small leggermente più grandi su mobile */
    .btn-sm {
        padding: 0.5rem 0.75rem;
        min-height: 40px;
        font-size: 0.875rem;
    }

    /* Gruppo pulsanti - stack verticale su mobile xs */
    .btn-group-mobile-stack {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .btn-group-mobile-stack .btn {
        margin-bottom: 0.5rem;
        border-radius: 0.35rem !important;
    }

    .btn-group-mobile-stack .btn:last-child {
        margin-bottom: 0;
    }
}

@media (max-width: 575.98px) {
    /* Header con pulsanti - stack sempre */
    .page-header-actions {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
        margin-top: 1rem;
    }

    .page-header-actions .btn {
        width: 100%;
    }
}


/* ===========================================
   CARD - Ottimizzazioni mobile
   =========================================== */

@media (max-width: 767.98px) {
    /* Card header più compatto */
    .card-header {
        padding: 0.75rem 1rem;
    }

    .card-header h5,
    .card-header h6 {
        font-size: 0.9rem;
    }

    /* Card body padding ridotto */
    .card-body {
        padding: 1rem;
    }

    /* Card header con flex - NON fare stack automatico */
    .card-header.d-flex.no-mobile-stack {
        flex-direction: row !important;
        align-items: center !important;
    }
}

@media (max-width: 575.98px) {
    .card-body {
        padding: 0.75rem;
    }

    /* Card header con pulsanti - stack solo su xs */
    .card-header.d-flex:not(.no-mobile-stack) {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .card-header.d-flex:not(.no-mobile-stack) > div:last-child {
        width: 100%;
    }
}


/* ===========================================
   TABELLE - Card View Mobile (T2)
   Trasforma tabelle in cards su schermi piccoli
   =========================================== */

/* Nascondi colonne non essenziali su tablet */
@media (max-width: 991.98px) {
    .table-mobile-hide-lg {
        display: none !important;
    }
}

@media (max-width: 767.98px) {
    /* Tabelle base - celle più compatte */
    .table td,
    .table th {
        padding: 0.5rem;
        font-size: 0.85rem;
        vertical-align: middle;
    }

    /* Badge più piccoli in tabelle */
    .table .badge {
        font-size: 0.7rem;
        padding: 0.25em 0.5em;
    }

    /* Pulsanti azioni più piccoli ma touchabili */
    .table .btn-sm {
        padding: 0.375rem 0.5rem;
        min-height: 36px;
        min-width: 36px;
    }

    /* Nascondi colonne non essenziali su mobile */
    .table-mobile-hide-md,
    .d-table-cell-md {
        display: none !important;
    }
}

/* Card View per tabelle su mobile piccolo (< 576px) */
@media (max-width: 575.98px) {
    /* Nascondi più colonne su mobile piccolo */
    .table-mobile-hide-sm,
    .d-table-cell-sm {
        display: none !important;
    }

    /* === CARD VIEW TRANSFORMATION === */
    .table-mobile-cards {
        border: none !important;
    }

    .table-mobile-cards thead {
        display: none !important;
    }

    .table-mobile-cards tbody {
        display: block;
    }

    .table-mobile-cards tbody tr {
        display: block;
        margin-bottom: 1rem;
        background: #fff;
        border: 1px solid #e3e6f0;
        border-radius: 0.5rem;
        box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
        overflow: hidden;
    }

    .table-mobile-cards tbody tr:hover {
        box-shadow: 0 0.25rem 0.5rem rgba(0,0,0,0.1);
    }

    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.625rem 1rem;
        border: none;
        border-bottom: 1px solid #f0f0f0;
        font-size: 0.875rem;
        text-align: right;
    }

    .table-mobile-cards tbody td:last-child {
        border-bottom: none;
    }

    /* Prima cella (titolo) - stile prominente */
    .table-mobile-cards tbody td:first-child {
        background: linear-gradient(135deg, #f8f9fc 0%, #fff 100%);
        font-weight: 600;
        font-size: 0.95rem;
        padding: 0.875rem 1rem;
        border-bottom: 2px solid #e3e6f0;
    }

    .table-mobile-cards tbody td:first-child a {
        font-weight: 700;
    }

    /* Label dalle colonne - usa data-label */
    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.75rem;
        color: #5a5c69;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        text-align: left;
        flex: 0 0 40%;
        padding-right: 0.5rem;
    }

    /* Prima cella senza label (è il titolo) */
    .table-mobile-cards tbody td:first-child::before {
        display: none;
    }

    /* Cella azioni - centrata e full-width */
    .table-mobile-cards tbody td.td-actions,
    .table-mobile-cards tbody td:last-child:has(.btn-group) {
        justify-content: center;
        padding: 0.75rem 1rem;
        background: #f8f9fc;
    }

    .table-mobile-cards tbody td.td-actions::before,
    .table-mobile-cards tbody td:last-child:has(.btn-group)::before {
        display: none;
    }

    /* Btn group nelle card - più spazio */
    .table-mobile-cards .btn-group {
        flex-wrap: wrap;
        gap: 0.375rem;
        justify-content: center;
    }

    .table-mobile-cards .btn-group .btn {
        flex: 0 0 auto;
    }

    /* Nascondere celle vuote */
    .table-mobile-cards tbody td:empty {
        display: none;
    }

    /* Badge nelle card */
    .table-mobile-cards .badge {
        font-size: 0.75rem;
        padding: 0.35em 0.65em;
    }

    /* Link nelle card */
    .table-mobile-cards a:not(.btn) {
        word-break: break-word;
    }

    /* DataTables compatibility */
    .table-mobile-cards.dataTable tbody td {
        display: flex !important;
    }

    /* Nascondi DataTables controls su mobile se card view */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        margin-bottom: 1rem;
    }

    .dataTables_wrapper .dataTables_info {
        font-size: 0.8rem;
        text-align: center;
        padding-top: 0.5rem;
    }

    .dataTables_wrapper .dataTables_paginate {
        text-align: center;
        padding-top: 0.5rem;
    }

    .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 0.5rem 0.75rem;
        min-width: 44px;
        min-height: 44px;
    }
}


/* ===========================================
   TOPBAR - Mobile ottimizzazioni
   =========================================== */

@media (max-width: 767.98px) {
    /* Topbar più compatta */
    .topbar {
        padding: 0.5rem 1rem;
    }

    /* Toggle sidebar più grande */
    #sidebarToggleTop {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #sidebarToggleTop i {
        font-size: 1.25rem;
    }
}


/* ===========================================
   MAPPA LEAFLET - Responsive
   =========================================== */

@media (max-width: 767.98px) {
    #map,
    .leaflet-container {
        height: 250px !important;
        min-height: 200px;
    }

    /* Pulsante espandi mappa */
    .map-expand-btn {
        position: absolute;
        bottom: 10px;
        right: 10px;
        z-index: 1000;
        background: #fff;
        border: 2px solid rgba(0,0,0,0.2);
        border-radius: 4px;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
        cursor: pointer;
    }

    .map-expanded #map,
    .map-expanded .leaflet-container {
        height: 400px !important;
    }
}


/* ===========================================
   MODAL - Mobile ottimizzazioni
   =========================================== */

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-content {
        border-radius: 0.75rem;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }

    .modal-title {
        font-size: 1.1rem;
    }

    /* Footer pulsanti stack */
    .modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0 !important;
    }
}


/* ===========================================
   CONTAINER E SPACING - Mobile
   =========================================== */

@media (max-width: 575.98px) {
    /* Container padding ridotto */
    .container-fluid {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Riduzione margini verticali */
    .mb-4 {
        margin-bottom: 1rem !important;
    }

    .py-4 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
}


/* ===========================================
   TITOLI E TESTO - Mobile
   =========================================== */

@media (max-width: 767.98px) {
    /* Titoli pagina più piccoli */
    .h3,
    h3 {
        font-size: 1.35rem;
    }

    .h4,
    h4 {
        font-size: 1.15rem;
    }

    .h5,
    h5 {
        font-size: 1rem;
    }

    /* Testo troncato con ellipsis */
    .text-truncate-mobile {
        display: block;
        max-width: 200px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (max-width: 575.98px) {
    .h3,
    h3 {
        font-size: 1.25rem;
    }

    .text-truncate-mobile {
        max-width: 150px;
    }
}


/* ===========================================
   UTILITY CLASSES - Mobile
   =========================================== */

/* Nascondi su mobile */
@media (max-width: 767.98px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Mostra solo su mobile */
@media (min-width: 768px) {
    .show-mobile-only {
        display: none !important;
    }
}

/* Stack verticale su mobile */
@media (max-width: 767.98px) {
    .stack-mobile {
        flex-direction: column !important;
    }

    .stack-mobile > * {
        width: 100%;
    }
}

/* Full width su mobile */
@media (max-width: 767.98px) {
    .w-100-mobile {
        width: 100% !important;
    }
}

/* Testo centrato su mobile */
@media (max-width: 575.98px) {
    .text-center-mobile {
        text-align: center !important;
    }
}

/* ===========================================
   T5: MOBILE BOTTOM NAVIGATION BAR
   Barra fissa in basso con 4 icone principali
   =========================================== */

.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1050;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.7rem;
    padding: 8px 12px;
    transition: all 0.2s ease;
    position: relative;
    min-width: 60px;
}

.mobile-bottom-nav-item i {
    font-size: 1.25rem;
    margin-bottom: 2px;
}

.mobile-bottom-nav-item span {
    font-weight: 500;
}

.mobile-bottom-nav-item:hover,
.mobile-bottom-nav-item:focus {
    color: #fff;
    text-decoration: none;
}

.mobile-bottom-nav-item.active {
    color: #fff;
}

.mobile-bottom-nav-item.active i {
    transform: scale(1.1);
}

.mobile-bottom-nav-item.active::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: #fff;
    border-radius: 2px;
}

/* Badge per notifiche non lette */
.mobile-nav-badge {
    position: absolute;
    top: 2px;
    right: 8px;
    background: #e74a3b;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* Padding bottom per contenuto quando bottom nav è visibile */
@media (max-width: 767.98px) {
    body {
        padding-bottom: 70px;
    }

    /* Evita che footer/elementi fissi si sovrappongano */
    .content-wrapper,
    #content-wrapper {
        padding-bottom: 70px;
    }
}

/* ===========================================
   T5: MOBILE SIDEBAR OVERLAY & OFF-CANVAS
   Sidebar che scorre da sinistra con overlay
   =========================================== */

/* Overlay scuro quando sidebar è aperta */
.mobile-sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Sidebar mobile - nascosta di default, scorre da sinistra */
@media (max-width: 767.98px) {
    #accordionSidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100vh !important;
        width: 250px !important;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1045;
        overflow-y: auto;
    }

    #accordionSidebar.mobile-sidebar-open {
        transform: translateX(0);
    }

    /* Nascondi sidebar toggle button di default (se presente) */
    #sidebarToggle,
    #sidebarToggleTop {
        display: none !important;
    }
}

/* ===========================================
   T8: FAB - FLOATING ACTION BUTTON
   Pulsante azioni flottante per dettaglio stazione
   =========================================== */

.fab-container {
    position: fixed;
    bottom: 80px; /* Sopra la bottom nav */
    right: 16px;
    z-index: 1030;
}

.fab-main {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
    border: none;
    color: #fff;
    font-size: 1.25rem;
    box-shadow: 0 4px 12px rgba(78, 115, 223, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab-main:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(78, 115, 223, 0.5);
}

.fab-main:focus {
    outline: none;
}

.fab-container.fab-open .fab-main {
    background: linear-gradient(135deg, #e74a3b 0%, #be2617 100%);
    transform: rotate(45deg);
}

.fab-container.fab-open .fab-main i::before {
    content: "\f00d"; /* X icon */
}

/* Menu FAB */
.fab-menu {
    position: absolute;
    bottom: 70px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.fab-container.fab-open .fab-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Item del menu FAB */
.fab-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: #fff;
    border-radius: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    text-decoration: none;
    color: #5a5c69;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.fab-item:hover {
    text-decoration: none;
    transform: translateX(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.fab-item i {
    width: 20px;
    text-align: center;
}

.fab-item.fab-edit {
    color: #4e73df;
}

.fab-item.fab-edit:hover {
    background: #4e73df;
    color: #fff;
}

.fab-item.fab-back {
    color: #858796;
}

.fab-item.fab-back:hover {
    background: #858796;
    color: #fff;
}

.fab-item.fab-report {
    color: #1cc88a;
}

.fab-item.fab-report:hover {
    background: #1cc88a;
    color: #fff;
}



/* ===========================================
   T9: STATS CARD SLIDER
   Slider orizzontale per card statistiche
   =========================================== */

.stats-slider-container {
    margin-bottom: 1.5rem;
    padding: 0;
}

.stats-slider {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    gap: 12px;
    padding: 4px 16px 8px 16px;
    margin: 0 -16px;
}

.stats-slider::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.stats-slide {
    flex: 0 0 85%;
    scroll-snap-align: center;
    min-width: 85%;
}

.stats-slide .card {
    margin-bottom: 0;
    height: 100%;
}

/* Prima card con margine extra a sinistra */
.stats-slide:first-child {
    margin-left: 0;
}

/* Ultima card con margine extra a destra */
.stats-slide:last-child {
    margin-right: 0;
}

/* Dots indicator */
.stats-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 8px 0;
}

.stats-dots .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d3e2;
    cursor: pointer;
    transition: all 0.3s ease;
}

.stats-dots .dot.active {
    background: #4e73df;
    transform: scale(1.2);
}

.stats-dots .dot:hover {
    background: #4e73df;
    opacity: 0.7;
}

/* Animazione swipe feedback */
.stats-slide.swiping {
    transition: transform 0.1s ease-out;
}

/* Card styling migliorato per mobile */
@media (max-width: 767.98px) {
    .stats-slide .card {
        border-radius: 10px;
    }
    
    .stats-slide .card-body {
        padding: 1rem;
    }
    
    .stats-slide .text-xs {
        font-size: 0.7rem;
    }
    
    .stats-slide .h5 {
        font-size: 1.1rem;
    }
    
    .stats-slide .fa-2x {
        font-size: 1.5rem;
    }
}
