/* =========================================================
   MED-OS — MOBILE ENHANCED LAYER v3.0
   Fusione del vecchio mobile.css (componenti ricchi) con
   selettori corretti per il DOM MED-OS e override !important
   per global.css, agenda.css, modali.css.
   Colore branding: #167D87 (verde PoliMed)
   DEVE essere caricato DOPO tutti i CSS desktop.
   ========================================================= */

/* =========================================================
   1. STRUTTURA BASE — BODY, SIDEBAR, HEADER
   ========================================================= */
@media only screen and (max-width: 1024px) {
    :root {
        --sidebar-width: 220px;
        --slot-height: 70px;
    }
}

@media only screen and (max-width: 768px) {
    :root {
        --sidebar-width: 0;
        --slot-height: 60px;
    }

    /* Body: da flex a block */
    html, body {
        display: block !important;
        height: auto !important;
        min-height: 100vh !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    /* Sidebar off-canvas */
    body > .left-sidebar {
        position: fixed !important;
        left: -100% !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 85% !important;
        max-width: 320px !important;
        height: 100vh !important;
        z-index: 1001 !important;
        transition: left 0.3s ease !important;
        box-shadow: none !important;
        overflow-y: auto !important;
        padding-top: 56px !important;
    }

    body > .left-sidebar.mobile-active {
        left: 0 !important;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3) !important;
    }

    /* Overlay sidebar */
    .mobile-sidebar-overlay {
        display: none;
        position: fixed !important;
        top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
        background: rgba(0,0,0,0.5);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .mobile-sidebar-overlay.active {
        display: block !important;
        opacity: 1;
    }

    /* Pulsante chiusura sidebar */
    .sidebar-close {
        display: block !important;
        position: absolute;
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        background: #f0f0f0;
        border: none;
        border-radius: 50%;
        font-size: 1.3em;
        color: #666;
        cursor: pointer;
        z-index: 1002;
    }

    /* Header desktop nascosto */
    body > .main-container > header,
    body > .main-container > header.header,
    .main-container > header {
        display: none !important;
        height: 0 !important;
        min-height: 0 !important;
        max-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        visibility: hidden !important;
        overflow: hidden !important;
        position: absolute !important;
        left: -9999px !important;
        pointer-events: none !important;
    }

    /* Main container full width */
    body > .main-container,
    .main-container {
        width: 100% !important;
        margin-left: 0 !important;
        margin-top: 0 !important;
        padding-top: 56px !important;
        padding-bottom: 64px !important;
        flex: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        height: auto !important;
        min-height: 100vh !important;
    }

    /* =========================================================
       2. MOBILE HEADER (Fisso in alto)
       ========================================================= */
    .medos-mobile-header {
        display: flex !important;
        position: fixed !important;
        top: 0 !important; left: 0 !important; right: 0 !important;
        height: 56px;
        background: #ffffff;
        z-index: 1000;
        align-items: center;
        padding: 0 16px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    }

    .medos-mobile-header .mh-toggle {
        width: 44px; height: 44px;
        background: rgba(22,125,135,0.1);
        border: none; border-radius: 8px;
        color: #167D87;
        cursor: pointer;
        display: flex; align-items: center; justify-content: center;
        margin-right: 8px;
        flex-shrink: 0;
        transition: background 0.2s;
    }

    .medos-mobile-header .mh-toggle:active {
        background: rgba(22,125,135,0.2);
    }

    .medos-mobile-header .mh-logo-wrap {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 0;
        overflow: hidden;
    }

    .medos-mobile-header .mh-logo-link {
        display: flex;
        align-items: center;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
    }

    .medos-mobile-header .mh-logo {
        height: 30px;
        width: auto;
        object-fit: contain;
        flex-shrink: 0;
    }

    .medos-mobile-header .mh-title {
        display: none !important;
    }

    .medos-mobile-header .mh-actions {
        display: flex;
        gap: 8px;
        flex-shrink: 0;
    }

    .medos-mobile-header .mh-btn {
        width: 40px; height: 40px;
        background: rgba(22,125,135,0.1);
        border: none; border-radius: 8px;
        color: #167D87; font-weight: 700;
        cursor: pointer;
        display: flex; align-items: center; justify-content: center;
    }

    .medos-mobile-header .mh-btn:active {
        background: rgba(22,125,135,0.2);
    }

    .medos-mobile-header .mh-btn-new {
        background: #167D87;
        color: white;
        padding: 0 14px;
        width: auto;
        gap: 4px;
        font-size: 0.8em;
    }

    /* =========================================================
       3. SIDEBAR NAVIGATION MOBILE
       ========================================================= */
    .left-sidebar .logo-container {
        padding: 16px !important;
        border-bottom: 1px solid #eef0f2;
        margin-bottom: 8px;
    }

    .left-sidebar .logo-container img {
        max-width: 140px;
    }

    .nav-sidebar {
        padding: 8px 0 !important;
    }

    .nav-sidebar a,
    .nav-sidebar .nav-group-toggle {
        padding: 16px 20px !important;
        font-size: 1em !important;
        border-bottom: 1px solid #f5f5f5;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .nav-sidebar a.active {
        background: rgba(22, 125, 135, 0.08) !important;
        border-left: 4px solid #167D87 !important;
    }

    .nav-group-items a {
        padding-left: 40px !important;
        font-size: 0.95em !important;
    }

    .mini-calendar-wrapper {
        padding: 12px 16px !important;
        border-bottom: 1px solid #eef0f2;
    }

    .calendar-nav-buttons {
        padding: 12px 16px !important;
    }

    .calendar-nav-buttons button {
        height: 42px !important;
        font-size: 11px !important;
    }

    /* =========================================================
       4. BOTTOM NAVIGATION
       ========================================================= */
    .medos-bottom-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important; left: 0 !important; right: 0 !important;
        height: 64px;
        background: white;
        border-top: 1px solid #e0e0e0;
        z-index: 999;
        justify-content: space-around;
        align-items: center;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    }

    .medos-bottom-nav .bn-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 8px;
        color: #999;
        text-decoration: none;
        font-size: 0.7em;
        font-weight: 600;
        cursor: pointer;
        transition: color 0.2s;
        background: none;
        border: none;
    }

    .medos-bottom-nav .bn-item.active {
        color: #167D87;
    }

    .medos-bottom-nav .bn-item svg {
        width: 24px; height: 24px;
    }

    .medos-bottom-nav .bn-item:active {
        color: #167D87;
    }

    /* =========================================================
       5. AGENDA / PLANNER — Vista lista
       ========================================================= */
    .planner-master,
    .planner-area > .planner-master {
        display: none !important;
    }

    /* Timeline/griglia nascosta */
    .timeline-container,
    .appointments-container,
    .sala-column-v,
    .time-labels,
    .current-time-line {
        display: none !important;
    }

    #agenda-lista-container {
        display: block !important;
        height: auto !important;
        padding: 12px !important;
        padding-bottom: 80px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        background: #f5f5f5 !important;
    }

    /* Topbar agenda nascosta */
    .medos-topbar {
        display: none !important;
    }

    /* Fix #sale scroll */
    #sale {
        max-height: none !important;
        overflow-y: auto !important;
        padding-bottom: 80px !important;
    }

    /* Card appuntamento agenda-lista — classi reali: .al-row */
    .al-row,
    #agenda-lista-container .al-row {
        background: white !important;
        border-radius: 8px !important;
        margin-bottom: 4px !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
        /* Non usare border shorthand: preserva border-left inline (colore sala dinamico) */
        border-top: 1px solid #eef0f2 !important;
        border-right: 1px solid #eef0f2 !important;
        border-bottom: 1px solid #eef0f2 !important;
        border-left-width: 3px !important;
        border-left-style: solid !important;
        padding: 4px 8px !important;
        cursor: pointer;
        transition: transform 0.15s, box-shadow 0.15s;
        min-height: auto !important;
        justify-content: flex-start !important;
        gap: 0 !important;
        line-height: 1.25 !important;
    }

    .al-row:active {
        transform: scale(0.98);
        box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    }

    /* Top section: ora + paziente */
    .al-top {
        flex-direction: row !important;
        align-items: center !important;
        gap: 3px !important;
        margin-bottom: 0 !important;
    }

    .al-title {
        font-weight: 700 !important;
        font-size: 0.8em !important;
        color: #2c3e50 !important;
        flex: 1 !important;
        display: flex !important;
        align-items: center !important;
        gap: 3px !important;
        min-width: 0 !important;
        padding-right: 0 !important;
        flex-wrap: wrap !important;
    }

    /* Icone azione: da absolute a relative per evitare overflow */
    .al-icons-bar {
        position: relative !important;
        right: auto !important;
        top: auto !important;
        transform: none !important;
        justify-content: flex-start !important;
        flex-wrap: wrap !important;
        gap: 2px !important;
        padding: 2px 0 0 !important;
        border-top: none !important;
        margin-top: 0 !important;
    }

    .al-icon-btn {
        width: 28px !important;
        height: 28px !important;
        border-radius: 6px !important;
    }

    .al-icon-btn svg {
        width: 16px !important;
        height: 16px !important;
    }

    /* Bottom section: medico, sala, arrivo */
    .al-bottom {
        flex-direction: row !important;
        gap: 4px !important;
        font-size: 0.7em !important;
        align-items: center !important;
        flex-wrap: wrap !important;
        margin-top: 0 !important;
    }

    .al-bottom > div {
        width: auto !important;
    }

    /* Select medico */
    .al-select-medico {
        max-width: 110px !important;
        width: auto !important;
        font-size: 0.7em !important;
        padding: 2px 4px !important;
        border: 1px solid #e0e0e0 !important;
        border-radius: 4px !important;
        background: #f8f9fa !important;
    }

    /* Bottone arrivo */
    .al-arrivo-btn {
        height: 22px !important;
        min-width: 22px !important;
        padding: 0 4px !important;
        font-size: 0.65em !important;
    }

    /* Group header */
    .al-group-header {
        font-size: 0.82em !important;
        font-weight: 800 !important;
        color: #2c3e50 !important;
        border-bottom: 2px solid #167D87 !important;
        padding: 8px 0 3px !important;
        margin: 8px 0 4px !important;
    }

    /* Filtri bar */
    #al-filtri-bar {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    #al-filtri-bar > div:first-child {
        flex: 1 1 100% !important;
        justify-content: center !important;
    }

    .btn-al-group {
        padding: 8px 14px !important;
        font-size: 0.8em !important;
    }

    /* Riquadri sale */
    #al-sale-wrapper {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
        height: auto !important;
        flex: 1 1 100% !important;
        justify-content: center !important;
        padding: 6px 0 !important;
        pointer-events: auto !important;
        display: flex !important;
    }

    .al-riquadro-sala {
        font-size: 0.68em !important;
        padding: 2px 6px !important;
        gap: 3px !important;
    }

    .al-riq-nome {
        font-size: 0.68em !important;
    }

    .al-riq-badge {
        font-size: 0.72em !important;
    }

    /* Contatori footer */
    .al-contatori-footer {
        padding: 14px 12px 18px !important;
        margin-top: 10px !important;
    }

    .al-cnt-footer-inner {
        flex-direction: column !important;
        gap: 10px !important;
        align-items: flex-start !important;
    }

    .al-cnt-chips {
        gap: 6px !important;
    }

    .al-cnt-chip {
        font-size: 0.72em !important;
    }

    /* Data display */
    #al-data-display {
        flex: 0 0 auto !important;
    }

    /* Header sezione elenco */
    .mobile-list-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        background: #f8f9fa;
        border-radius: 12px;
        margin-bottom: 12px;
        border: 1px solid #e0e0e0;
    }

    .mobile-list-header h3 {
        margin: 0;
        font-size: 1em;
        font-weight: 700;
        color: #2c3e50;
    }

    .mobile-list-count {
        background: #167D87;
        color: white;
        padding: 4px 12px;
        border-radius: 20px;
        font-size: 0.85em;
        font-weight: 700;
    }

    /* Filtri rapidi mobile */
    .mobile-quick-filters {
        display: flex;
        gap: 8px;
        padding: 0 12px 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-filter-chip {
        flex-shrink: 0;
        padding: 8px 16px;
        background: white;
        border: 2px solid #e0e0e0;
        border-radius: 24px;
        font-size: 0.9em;
        font-weight: 600;
        color: #666;
        cursor: pointer;
        transition: all 0.2s;
    }

    .mobile-filter-chip.active {
        background: #167D87;
        border-color: #167D87;
        color: white;
    }

    /* Sezioni per sala */
    .mobile-sala-section {
        margin-bottom: 24px;
    }

    .mobile-sala-title {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 12px 16px;
        margin-bottom: 12px;
        background: #f0f7f8;
        border-radius: 10px;
        font-weight: 700;
        font-size: 1em;
        color: #2c3e50;
    }

    .mobile-sala-title-dot {
        width: 14px;
        height: 14px;
        border-radius: 50%;
        background: var(--sala-color, #167D87);
    }

    /* Messaggio nessun appuntamento */
    .mobile-empty-state {
        text-align: center;
        padding: 60px 20px;
        color: #999;
    }

    .mobile-empty-state svg {
        width: 64px;
        height: 64px;
        margin-bottom: 16px;
        opacity: 0.3;
    }

    .mobile-empty-state p {
        font-size: 1.1em;
        margin: 0;
    }

    /* =========================================================
       6. SIDE PANEL (Full-screen su mobile)
       ========================================================= */
    #side-panel,
    .planner-area > #side-panel {
        position: fixed !important;
        top: 0 !important; right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        z-index: 2000 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    #side-panel.open {
        animation: slideInRight 0.3s ease;
    }

    @keyframes slideInRight {
        from { transform: translateX(100%); }
        to { transform: translateX(0); }
    }

    .panel-header {
        padding: 16px !important;
        flex-wrap: wrap !important;
    }

    .panel-header h2,
    #sp-nome {
        font-size: 1.1em !important;
        max-width: 100% !important;
    }

    .action-icons-container {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    /* =========================================================
       7. MODAL — FULLSCREEN BOTTOM SHEET
       ========================================================= */
    #overlay {
        z-index: 2400 !important;
    }

    .modal,
    #modal-creazione.modal,
    #modal-paziente.modal,
    #modal-fattura.modal,
    #modal-sale.modal,
    #modal-impostazioni.modal,
    #modal-tutore-reg.modal {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        transform: none !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 92vh !important;
        max-height: 92dvh !important;
        border-radius: 20px 20px 0 0 !important;
        margin: 0 !important;
        animation: slideUp 0.3s ease;
    }

    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .modal-header,
    #modal-creazione .modal-header,
    #modal-paziente .modal-header,
    #modal-fattura .modal-header {
        padding: 20px !important;
        position: sticky !important;
        top: 0;
        background: white;
        z-index: 10;
        border-radius: 20px 20px 0 0;
        border-bottom: 2px solid #f0f0f0;
    }

    .modal-header .modal-close,
    .modal-close {
        font-size: 1.8em !important;
        padding: 8px !important;
        position: absolute !important;
        right: 15px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
    }

    .modal-body,
    #modal-creazione .modal-body,
    #modal-paziente .modal-body,
    #modal-fattura .modal-body {
        padding: 20px !important;
        max-height: calc(92vh - 140px) !important;
        max-height: calc(92dvh - 140px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer,
    #modal-creazione .modal-footer,
    #modal-paziente .modal-footer,
    #modal-fattura .modal-footer {
        padding: 16px 20px !important;
        flex-direction: column-reverse !important;
        gap: 10px !important;
        position: sticky !important;
        bottom: 0;
        background: white;
        border-top: 2px solid #f0f0f0;
    }

    .modal-footer button,
    .modal-footer .btn-salva,
    .modal-footer .btn-annulla,
    .modal-footer .btn {
        width: 100% !important;
        padding: 14px !important;
        font-size: 1em !important;
        border-radius: 10px !important;
        text-align: center !important;
    }

    /* Tab buttons nel modal */
    .modal-tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0 12px !important;
    }

    .modal-tabs::-webkit-scrollbar {
        display: none;
    }

    .modal-tabs .tab-btn {
        flex-shrink: 0;
        padding: 12px 16px !important;
        font-size: 0.9em !important;
        white-space: nowrap;
    }

    /* =========================================================
       8. FORM GRID — Stack verticale
       ========================================================= */
    .form-grid,
    .form-grid-prestazione,
    .form-row {
        display: block !important;
        grid-template-columns: none !important;
        flex-direction: column !important;
        gap: 0 !important;
    }

    .form-grid .form-group,
    .form-grid > div,
    .form-grid-prestazione > div,
    .form-grid-prestazione .form-group,
    .form-row .form-group {
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 20px !important;
    }

    .form-group input,
    .form-group select,
    .form-group textarea,
    .input-wrapper input,
    .input-wrapper select,
    .input-wrapper textarea,
    .modal-body input,
    .modal-body select,
    .modal-body textarea,
    .form-input,
    .form-select,
    .form-textarea {
        width: 100% !important;
        font-size: 16px !important;
        padding: 16px !important;
        border-radius: 10px !important;
        box-sizing: border-box !important;
        border: 2px solid #e0e0e0 !important;
        background: white !important;
        transition: border-color 0.2s;
    }

    .form-group input:focus,
    .form-group select:focus,
    .form-group textarea:focus,
    .form-input:focus,
    .form-select:focus,
    .form-textarea:focus {
        border-color: #167D87 !important;
        outline: none !important;
    }

    .form-group label,
    .form-label,
    .modal-body label {
        display: block;
        font-size: 0.95em;
        font-weight: 600;
        color: #2c3e50;
        margin-bottom: 8px;
    }

    /* =========================================================
       9. RICERCA / AUTOCOMPLETE
       ========================================================= */
    #global-search,
    #input-cerca-anagrafica {
        font-size: 16px !important;
        padding: 14px !important;
    }

    .search-results,
    #search-results {
        max-height: 200px !important;
        width: 100% !important;
        font-size: 0.95em;
    }

    .search-results div,
    #search-results .result-item {
        padding: 14px 12px !important;
        font-size: 1em !important;
    }

    #drop-comuni,
    .search-citta-results,
    #risultati-p-comune {
        max-height: 200px !important;
        width: 100% !important;
        font-size: 0.95em;
    }

    #drop-comuni div,
    .search-citta-results div {
        padding: 14px 12px !important;
        font-size: 1em !important;
    }

    /* =========================================================
       10. BUTTONS — Touch friendly
       ========================================================= */
    .btn-header-nuovo,
    .btn-header-azienda,
    .btn-header-import {
        display: none !important;
    }

    .btn,
    button:not(.mh-toggle):not(.mh-btn):not(.bn-item):not(.modal-close):not(.sidebar-close):not(.nav-group-toggle) {
        min-height: 48px;
        min-width: 48px;
        padding: 14px 24px;
        font-size: 1em;
        border-radius: 10px;
        font-weight: 600;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        cursor: pointer;
        transition: transform 0.15s, opacity 0.15s;
    }

    .btn:active {
        transform: scale(0.97);
    }

    .btn-primary {
        background: #167D87;
        color: white;
        border: none;
    }

    .btn-secondary {
        background: #f0f0f0;
        color: #2c3e50;
        border: 2px solid #e0e0e0;
    }

    .btn-danger {
        background: #e74c3c;
        color: white;
        border: none;
    }

    /* =========================================================
       11. TABELLE — Scroll orizzontale + card layout
       ========================================================= */
    .table-container,
    .table-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        margin: 0 -12px;
        padding: 0 12px;
    }

    table,
    .data-table {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        min-width: 600px;
        font-size: 0.85em;
    }

    table th, table td,
    .data-table th, .data-table td {
        padding: 14px 12px;
        white-space: nowrap;
    }

    /* Card layout alternativo per tabelle */
    .mobile-cards .data-table,
    .mobile-cards table {
        display: block;
        min-width: unset;
    }

    .mobile-cards .data-table thead,
    .mobile-cards table thead {
        display: none;
    }

    .mobile-cards .data-table tbody,
    .mobile-cards table tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .mobile-cards .data-table tr,
    .mobile-cards table tr {
        display: block;
        background: white;
        border-radius: 12px;
        padding: 16px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        border: 1px solid #eef0f2;
    }

    .mobile-cards .data-table td,
    .mobile-cards table td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid #f0f0f0;
        white-space: normal;
    }

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

    .mobile-cards .data-table td::before,
    .mobile-cards table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: #167D87;
        font-size: 0.85em;
    }

    /* =========================================================
       12. TOAST
       ========================================================= */
    .toast-container,
    #toast-container {
        top: 60px !important;
        left: 8px !important;
        right: 8px !important;
        max-width: none !important;
    }

    .toast {
        padding: 14px 16px !important;
        font-size: 0.9em !important;
        border-radius: 10px !important;
    }

    /* =========================================================
       13. STATISTICHE / DASHBOARD / KPI
       ========================================================= */
    .stat-card, .stat-box, .kpi-card,
    .sg-kpi, .sp-kpi, .cp-kpi, .ic-kpi {
        width: 100% !important;
        margin: 10px 0 !important;
        padding: 20px !important;
        border-radius: 16px !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.08) !important;
        border: 1px solid #eef0f2 !important;
        background: white !important;
    }

    .stat-value,
    .sg-kpi-value,
    .sp-kpi-value,
    .cp-kpi-value,
    .ic-kpi-value {
        font-size: 2em !important;
        font-weight: 900 !important;
        color: #167D87 !important;
        margin: 10px 0;
    }

    .stat-label,
    .sg-kpi-label,
    .sp-kpi-label,
    .cp-kpi-label,
    .ic-kpi-label {
        font-size: 0.95em;
        color: #666;
        font-weight: 600;
    }

    .chart-container {
        height: 250px !important;
        margin: 16px -12px !important;
    }

    .stats-row, .kpi-row,
    .sg-kpi-grid, .sp-filters, .cp-filters, .ic-filters,
    .gs-bar, .sc-controls {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .sg-container, .sp-container, .cp-container, .ic-container,
    .gs-container, .sc-container {
        padding: 12px !important;
    }

    /* =========================================================
       14. WORKLIST MOBILE
       ========================================================= */
    .worklist-item {
        background: white;
        border-radius: 12px;
        padding: 16px;
        margin: 8px 0;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        border-left: 4px solid var(--status-color, #167D87);
    }

    .worklist-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 10px;
    }

    .worklist-patient {
        font-weight: 700;
        font-size: 1.1em;
        color: #2c3e50;
    }

    .worklist-status {
        padding: 4px 12px;
        border-radius: 20px;
        font-size: 0.75em;
        font-weight: 700;
        background: #e8f4f8;
        color: #167D87;
    }

    .worklist-details {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        font-size: 0.9em;
        color: #666;
        margin-bottom: 12px;
    }

    .worklist-detail-item {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .worklist-actions {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
    }

    .worklist-actions .btn {
        flex: 1;
        min-width: 80px;
        padding: 10px;
        font-size: 0.85em;
    }

    /* =========================================================
       15. ANAGRAFICA MOBILE
       ========================================================= */
    .patient-card,
    .anag-card {
        background: white;
        border-radius: 12px;
        padding: 16px;
        margin: 8px 0;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        border: 1px solid #eef0f2;
    }

    .patient-card-header,
    .anag-card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 12px;
    }

    .patient-name,
    .anag-card-name {
        font-weight: 700;
        font-size: 1.15em;
        color: #2c3e50;
        margin-bottom: 4px;
    }

    .patient-code,
    .anag-card-code {
        font-size: 0.85em;
        color: #167D87;
        font-weight: 600;
    }

    .patient-info-grid,
    .anag-card-info {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        font-size: 0.9em;
        color: #666;
    }

    .anag-table-container,
    .anag-results {
        overflow-x: auto !important;
    }

    /* =========================================================
       16. CONTABILITA MOBILE
       ========================================================= */
    .invoice-card {
        background: white;
        border-radius: 12px;
        padding: 16px;
        margin: 8px 0;
        border-left: 4px solid #167D87;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    }

    .invoice-header {
        display: flex;
        justify-content: space-between;
        margin-bottom: 12px;
    }

    .invoice-number {
        font-weight: 700;
        color: #167D87;
    }

    .invoice-amount {
        font-size: 1.3em;
        font-weight: 700;
        color: #2c3e50;
    }

    .invoice-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
        font-size: 0.85em;
        color: #666;
    }

    .contab-tabs,
    .tab-buttons {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .contab-tabs::-webkit-scrollbar,
    .tab-buttons::-webkit-scrollbar {
        display: none;
    }

    /* =========================================================
       17. IMPOSTAZIONI MOBILE
       ========================================================= */
    .settings-section,
    .imp-section {
        background: white;
        border-radius: 12px;
        padding: 16px;
        margin: 12px 0;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    }

    .settings-section-title,
    .imp-section-title {
        font-size: 1.1em;
        font-weight: 700;
        color: #2c3e50;
        margin-bottom: 16px;
        padding-bottom: 10px;
        border-bottom: 2px solid #eef0f2;
    }

    .palette-container {
        flex-wrap: wrap;
        gap: 6px;
    }

    .color-option {
        width: 32px;
        height: 32px;
    }

    /* =========================================================
       18. PAGINE SECONDARIE
       ========================================================= */
    .page-content, .content-wrapper, .main-content,
    .content-area {
        padding: 12px !important;
        width: 100% !important;
    }

    .section-title {
        font-size: 1.05em !important;
        padding: 12px 0 8px !important;
        margin-top: 16px !important;
    }

    /* =========================================================
       19. UTILITY
       ========================================================= */
    .hide-on-mobile, .hide-mobile {
        display: none !important;
    }

    .show-on-mobile, .show-mobile {
        display: block !important;
    }

    .flex-mobile {
        display: flex !important;
    }

    .text-center-mobile {
        text-align: center !important;
    }

    .scroll-h {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .scroll-h::-webkit-scrollbar {
        display: none;
    }

    .p-0-mobile { padding: 0 !important; }
    .p-2-mobile { padding: 8px !important; }
    .p-3-mobile { padding: 12px !important; }
    .p-4-mobile { padding: 16px !important; }
    .m-0-mobile { margin: 0 !important; }
    .mb-2-mobile { margin-bottom: 8px !important; }
    .mb-3-mobile { margin-bottom: 12px !important; }

    /* Scrollbar nascosta */
    ::-webkit-scrollbar {
        width: 0;
        height: 0;
    }

    /* Impedisci zoom iOS su input focus */
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* =========================================================
   MOBILE PORTRAIT < 480px
   ========================================================= */
@media only screen and (max-width: 480px) {
    :root {
        --slot-height: 50px;
    }

    .medos-mobile-header {
        height: 52px;
    }

    body > .main-container,
    .main-container {
        padding-top: 52px !important;
    }

    .medos-mobile-header .mh-title {
        font-size: 1em;
    }

    .modal,
    #modal-creazione.modal,
    #modal-paziente.modal,
    #modal-fattura.modal {
        max-height: 95vh !important;
        max-height: 95dvh !important;
    }

    .modal-body,
    #modal-creazione .modal-body,
    #modal-paziente .modal-body {
        padding: 12px 16px !important;
    }

    body {
        font-size: 14px;
    }

    /* Tabelle più compatte */
    .data-table {
        min-width: 500px;
        font-size: 0.85em;
    }

    /* Bottoni più piccoli */
    .btn {
        padding: 12px 20px;
        font-size: 0.95em;
    }
}

/* =========================================================
   LANDSCAPE MOBILE
   ========================================================= */
@media only screen and (max-width: 768px) and (orientation: landscape) {
    .medos-mobile-header {
        height: 48px;
    }

    body > .main-container,
    .main-container {
        padding-top: 48px !important;
    }

    body > .left-sidebar {
        width: 70% !important;
    }

    .medos-bottom-nav {
        height: 56px;
    }
}

/* =========================================================
   DESKTOP — Nasconde elementi mobile-only
   ========================================================= */
@media only screen and (min-width: 769px) {
    .medos-mobile-header,
    .medos-bottom-nav,
    .mobile-sidebar-overlay,
    .agenda-mobile-toolbar,
    .sidebar-close,
    .mobile-list-header,
    .mobile-quick-filters,
    .mobile-sala-section,
    .mobile-empty-state {
        display: none !important;
    }

    .hide-desktop {
        display: none !important;
    }
}

/* =========================================================
   STAMPA
   ========================================================= */
@media print {
    .medos-mobile-header,
    .medos-bottom-nav,
    .left-sidebar,
    .mobile-sidebar-overlay,
    .sidebar-close,
    .btn {
        display: none !important;
    }

    .main-container {
        margin: 0 !important;
        padding: 20px !important;
    }
}

/* =========================================================
   WORKLIST.POLIMEDPALMA.IT — ALWAYS VISIBLE HEADER + FOOTER
   Il sottodominio worklist non ha sidebar desktop:
   header mobile e bottom nav sono sempre visibili.
   ========================================================= */
body.page-worklist-mobile .medos-mobile-header {
    display: flex !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 56px;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding: 0 12px;
    z-index: 10000;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

body.page-worklist-mobile .medos-mobile-header .mh-logo-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 4px;
}

body.page-worklist-mobile .medos-mobile-header .mh-logo {
    height: 30px;
    width: auto;
    max-width: 160px;
    object-fit: contain;
}

body.page-worklist-mobile .medos-mobile-header .mh-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

body.page-worklist-mobile .medos-mobile-header .mh-btn-logout {
    background: transparent !important;
    border: 1px solid #e74c3c !important;
    color: #e74c3c !important;
    border-radius: 8px !important;
    padding: 6px 14px !important;
    font-size: 0.82em !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    min-height: 40px !important;
    touch-action: manipulation;
    transition: background 0.15s, color 0.15s;
}

body.page-worklist-mobile .medos-mobile-header .mh-btn-logout:hover,
body.page-worklist-mobile .medos-mobile-header .mh-btn-logout:active {
    background: #e74c3c !important;
    color: white !important;
}

/* Bottom nav sempre visibile su worklist.polimedpalma.it */
body.page-worklist-mobile .medos-bottom-nav {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 56px;
    background: #ffffff;
    border-top: 1px solid var(--border);
    z-index: 10000;
    box-shadow: 0 -1px 4px rgba(0,0,0,0.06);
    padding-bottom: env(safe-area-inset-bottom);
}

body.page-worklist-mobile .medos-bottom-nav .bn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: transparent;
    border: none;
    color: #7f8c8d;
    font-size: 0.68em;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 2px;
    min-height: 48px;
    touch-action: manipulation;
    transition: color 0.15s;
}

body.page-worklist-mobile .medos-bottom-nav .bn-item svg {
    width: 22px;
    height: 22px;
}

body.page-worklist-mobile .medos-bottom-nav .bn-item.active {
    color: var(--accent);
}

body.page-worklist-mobile .medos-bottom-nav .bn-item:active {
    color: var(--accent);
}

/* Padding per non nascondere contenuto sotto header e bottom nav */
body.page-worklist-mobile {
    padding-top: 56px !important;
    padding-bottom: 56px !important;
}

/* Su desktop, nascondi wm-topbar (duplicato del vecchio header) */
body.page-worklist-mobile .wm-topbar {
    display: none !important;
}
