/**
 * MatWork - Stili Responsive per Mobile/Tablet
 * Modalità WebApp
 */

/* ===== MOBILE FIRST - Base ===== */

/* Navbar Mobile */
@media (max-width: 991px) {
    .navbar {
        flex-wrap: wrap;
        height: auto !important;
        padding: 0.5rem !important;
        gap: 0.5rem;
    }
    
    .navbar-brand {
        font-size: 1rem !important;
    }
    
    .nav-links {
        order: 3;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0.5rem 0;
        gap: 0.25rem !important;
        justify-content: flex-start;
    }
    
    .nav-links::-webkit-scrollbar {
        display: none;
    }
    
    .nav-link {
        white-space: nowrap;
        font-size: 0.75rem !important;
        padding: 0.4rem 0.6rem !important;
    }
    
    .nav-link span, .nav-link:not([class*="bi-"])::after {
        display: none;
    }
    
    /* User info in navbar */
    .navbar > div:last-child {
        gap: 0.5rem !important;
    }
    
    .navbar #currentUser {
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.8rem;
    }
    
    .navbar #currentRole {
        display: none !important;
    }
    
    .navbar .btn-sm {
        padding: 0.3rem 0.5rem !important;
        font-size: 0.75rem !important;
    }
    
    .navbar .btn-sm span {
        display: none;
    }
}

/* App Container Mobile */
@media (max-width: 991px) {
    .app-container {
        flex-direction: column !important;
        height: auto !important;
        min-height: calc(100vh - 100px);
    }
    
    .sidebar {
        width: 100% !important;
        max-height: none !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border);
        overflow: visible !important;
    }
    
    .main-content {
        padding: 0.75rem !important;
        overflow: auto !important;
    }
}

/* Cards e Form Mobile */
@media (max-width: 767px) {
    .card {
        border-radius: 8px !important;
        margin-bottom: 0.5rem !important;
    }
    
    .card-header {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8rem !important;
    }
    
    .card-body {
        padding: 0.75rem !important;
    }
    
    .form-control, .form-select {
        font-size: 16px !important; /* Previene zoom su iOS */
        padding: 0.5rem !important;
    }
    
    .btn {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.85rem !important;
    }
    
    /* Stats cards */
    .stats-row, .stat-cards {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }
    
    .stat-card {
        flex: 1 1 45% !important;
        min-width: 140px !important;
        padding: 0.5rem !important;
    }
    
    .stat-card .value {
        font-size: 1.25rem !important;
    }
    
    .stat-card .label {
        font-size: 0.65rem !important;
    }
}

/* Tabelle Responsive */
@media (max-width: 767px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        font-size: 0.8rem !important;
    }
    
    table th, table td {
        padding: 0.4rem 0.5rem !important;
        white-space: nowrap;
    }
    
    /* Nascondi colonne meno importanti su mobile */
    table .hide-mobile {
        display: none !important;
    }
}

/* ===== PAGINA RICHIESTE ===== */
@media (max-width: 991px) {
    /* Sidebar filtri collassabile */
    .sidebar {
        position: relative;
    }
    
    .sidebar-content {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .sidebar .card {
        flex: 1 1 200px;
        margin-bottom: 0 !important;
    }
    
    /* Toolbar */
    .toolbar {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        padding: 0.5rem !important;
    }
    
    .toolbar h2 {
        font-size: 1rem !important;
        width: 100%;
    }
    
    #paginationControls {
        width: 100%;
        justify-content: center !important;
        flex-wrap: wrap;
        gap: 0.25rem !important;
    }
    
    #paginationControls select {
        font-size: 0.8rem !important;
    }
    
    /* Request cards invece di tabella */
    .request-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
        padding: 0.75rem !important;
    }
    
    .request-row .checkbox-col {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
    }
    
    .request-row .info-col {
        width: 100%;
    }
    
    .request-row .actions-col {
        width: 100%;
        justify-content: flex-end !important;
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid var(--border);
    }
}

/* ===== PAGINA DIPENDENTE ===== */
@media (max-width: 767px) {
    .page-header {
        flex-direction: column !important;
    }
    
    .user-card {
        width: 100% !important;
        min-width: auto !important;
    }
    
    .nav-tabs-custom {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap !important;
    }
    
    .nav-tabs-custom::-webkit-scrollbar {
        display: none;
    }
    
    .nav-tab {
        white-space: nowrap;
        font-size: 0.8rem !important;
        padding: 0.5rem 0.75rem !important;
    }
    
    .request-form-container {
        margin-top: 0.5rem;
    }
    
    .form-row {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    .form-group {
        width: 100% !important;
    }
    
    /* Request types grid */
    .request-types {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }
    
    .request-type-card {
        padding: 0.75rem !important;
    }
    
    .request-type-card .icon {
        font-size: 1.25rem !important;
    }
    
    .request-type-card .name {
        font-size: 0.75rem !important;
    }
    
    /* Storico richieste */
    .request-item {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }
    
    .request-item .actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ===== PAGINA DASHBOARD (INDEX) ===== */
@media (max-width: 991px) {
    .sidebar {
        max-height: 300px;
        overflow-y: auto;
    }
    
    /* Risultati dipendenti */
    .dipendente-card {
        padding: 0.75rem !important;
    }
    
    .dipendente-card .detail-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .dipendente-card .detail-tab {
        white-space: nowrap;
        font-size: 0.75rem !important;
    }
}

/* ===== PAGINA ANAGRAFICA ===== */
@media (max-width: 991px) {
    .dipendente-item {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }
    
    .dipendente-item .actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    /* Modal form */
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
    
    .modal-body {
        max-height: 70vh;
        overflow-y: auto;
    }
    
    .modal .row {
        flex-direction: column;
    }
    
    .modal .col-md-6, .modal .col-md-4, .modal .col-md-3 {
        width: 100% !important;
    }
}

/* ===== PAGINA PROGRAMMAZIONE TURNI ===== */
@media (max-width: 991px) {
    .turni-grid {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .turni-grid table {
        min-width: 800px;
    }
    
    .turni-grid th, .turni-grid td {
        min-width: 35px !important;
        font-size: 0.7rem !important;
        padding: 0.25rem !important;
    }
    
    .legenda {
        flex-wrap: wrap;
        gap: 0.25rem !important;
    }
    
    .legenda-item {
        font-size: 0.65rem !important;
    }
}

/* ===== PAGINA IMPORT TURNI ===== */
@media (max-width: 767px) {
    .upload-zone {
        padding: 1.5rem !important;
    }
    
    .upload-zone i {
        font-size: 2rem !important;
    }
    
    .steps {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    .step::after {
        display: none !important;
    }
    
    .preview-table {
        font-size: 0.75rem !important;
    }
}

/* ===== MODALS RESPONSIVE ===== */
@media (max-width: 767px) {
    .modal-overlay {
        padding: 0.5rem !important;
    }
    
    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .modal-header {
        padding: 0.75rem 1rem !important;
    }
    
    .modal-body {
        padding: 1rem !important;
    }
    
    .modal-footer {
        padding: 0.75rem 1rem !important;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        flex: 1;
        min-width: 100px;
    }
}

/* ===== TOAST NOTIFICATIONS ===== */
@media (max-width: 767px) {
    .toast-container {
        left: 0.5rem !important;
        right: 0.5rem !important;
        bottom: 0.5rem !important;
    }
    
    .toast {
        width: 100% !important;
    }
}

/* ===== UTILITIES RESPONSIVE ===== */
@media (max-width: 767px) {
    .d-none-mobile {
        display: none !important;
    }
    
    .text-truncate-mobile {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

@media (min-width: 768px) {
    .d-none-desktop {
        display: none !important;
    }
}

/* ===== PWA / WEBAPP STYLES ===== */

/* Safe area per notch iPhone */
@supports (padding: env(safe-area-inset-top)) {
    .navbar {
        padding-top: env(safe-area-inset-top) !important;
    }
    
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Disable pull-to-refresh su webapp */
html, body {
    overscroll-behavior-y: contain;
}

/* Touch feedback */
.btn, .nav-link, .card, .request-type-card, .dipendente-item {
    -webkit-tap-highlight-color: rgba(5, 150, 105, 0.1);
}

/* Smooth scrolling */
* {
    -webkit-overflow-scrolling: touch;
}

/* Prevent text selection on buttons */
.btn, .nav-link, .nav-tab {
    -webkit-user-select: none;
    user-select: none;
}

/* Fix per iOS input zoom */
@media (max-width: 767px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="time"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .navbar {
        padding: 0.25rem 0.5rem !important;
    }
    
    .nav-links {
        padding: 0.25rem 0 !important;
    }
    
    .sidebar {
        max-height: 150px;
    }
}
