:root {
    --primary: #002B5C;
    --primary-light: #003D82;
    --bg-main: #F5F7FA;
    --card-bg: #FFFFFF;
    --text-primary: #1A1A1A;
    --text-secondary: #6B7280;
    --border: #E5E7EB;
    --success: #059669;
    --warning: #D97706;
    --danger: #DC2626;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Nasconde scrollbar ma mantiene funzionalità scroll */
* {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

*::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Touch scrolling fluido su iOS */
body {
    -webkit-overflow-scrolling: touch;
}

/* Touch-friendly per mobile */
@media (hover: none) and (pointer: coarse) {
    /* Aumenta area tap per tutti i bottoni */
    button,
    .btn,
    .header-btn,
    a {
        min-height: 44px;
        min-width: 44px;
    }

    /* Rimuovi hover effects su touch devices */
    .header-btn:hover,
    .btn:hover,
    button:hover {
        transform: none;
    }

    /* Feedback visivo al tap */
    button:active,
    .btn:active,
    .header-btn:active {
        opacity: 0.7;
        transform: scale(0.98);
    }
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-main);
    min-height: 100vh;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ========================================
   LOGO
   ======================================== */

.login-screen {
    background: linear-gradient(
        135deg,
        var(--primary) 0%,
        var(--primary-light) 100%
    );
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 32px;
}

.login-logo-hero img {
    width: 180px;
    max-width: 70vw;
    height: auto;
}

.login-box--dark {
    background: rgba(0, 43, 92, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: white;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.login-box--dark h2 {
    color: white;
}

.login-box--dark p {
    color: rgba(255, 255, 255, 0.85);
}

.login-box--dark label {
    color: rgba(255, 255, 255, 0.9);
}

.login-box--dark input {
    background: white;
    color: var(--text-primary);
    text-align: center;
    font-size: 20px;
    letter-spacing: 4px;
}

.btn-login {
    width: 100%;
    background: white;
    color: var(--primary);
}

.btn-login:hover {
    background: #E5E7EB;
}

/* ========================================
   HEADER
   ======================================== */

.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-left img {
    height: 60px;
}

.header-title {
    color: white;
}

.header-title h1 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 2px;
}

.header-title p {
    font-size: 13px;
    opacity: 0.85;
    font-weight: 400;
}

.header-right {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Version Box - Uniforme in tutte le pagine */
.version-box {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-right: 16px;
    gap: 2px;
}

.version-box .version-status {
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.version-box .version-date {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    gap: 4px;
}

.header-btn {
    /* Dimensioni fisse per uniformità */
    min-width: 44px;
    min-height: 44px;
    padding: 10px 12px;

    /* Stile */
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: white;
    border-radius: .2vh;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;

    /* Layout interno centrato */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;

    /* Reset stili button/a */
    line-height: 1;
    vertical-align: middle;
    box-sizing: border-box;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.header-btn:active {
    transform: translateY(0);
    opacity: 0.8;
}

/* Bottone Home - Stile iOS Blu */
.header-btn-home {
    background: #007AFF !important;
    border: none !important;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.header-btn-home:hover {
    background: #0051D5 !important;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4);
}

/* Bottone Esci - Stile iOS Rosso */
.header-btn-danger {
    background: #FF3B30 !important;
    border: none !important;
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3);
}

.header-btn-danger:hover {
    background: #E0241B !important;
    box-shadow: 0 4px 12px rgba(255, 59, 48, 0.4);
}

#userRoleIcon {
    /* Testo USER/ADMIN senza box */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;

    color: white;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;

    /* Allineamento verticale */
    line-height: 1;
    vertical-align: middle;
}

/* ========================================
   CONTAINER E LAYOUT
   ======================================== */

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 32px;
}

.app-container {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
}

.main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px;
    width: 100%;
}

/* ========================================
   CATEGORIE E LINK CARDS
   ======================================== */

.category {
    margin-bottom: 48px;
}

.category-section {
    margin-bottom: 48px;
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.category-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.category-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.category-content {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.link-card {
    position: relative;
    background: white;
    border: 1px solid var(--border);
    border-radius: .2vh;
    padding: 24px 20px;
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Stati Box */
.link-card[data-status="accessible"] {
    border-left: 4px solid var(--success);
}

.link-card[data-status="restricted"] {
    border-left: 4px solid var(--warning);
    opacity: 0.85;
}

.link-card[data-status="in-progress"] {
    border-left: 4px solid var(--danger);
    background: rgba(220, 38, 38, 0.02);
}

/* Badge Status */
.status-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 4px 8px;
    border-radius: .2vh;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.link-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.link-card[draggable="true"] {
    cursor: move;
}

.link-card.drag-over {
    border: 2px dashed var(--primary);
    background: rgba(0, 43, 92, 0.05);
}

.link-icon {
    font-size: 32px;
    color: var(--primary);
    margin-bottom: 12px;
}

.link-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.link-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

.link-card-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.link-card:hover .link-card-actions {
    opacity: 1;
}

.btn-link-action {
    width: 28px;
    height: 28px;
    border-radius: .2vh;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s;
}

.btn-link-edit {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.btn-link-edit:hover {
    background: #3b82f6;
    color: white;
}

.btn-link-delete {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.btn-link-delete:hover {
    background: #ef4444;
    color: white;
}

/* ========================================
   TABS
   ======================================== */

.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 32px;
    background: white;
    border: 1px solid var(--border);
    border-radius: .2vh;
    overflow: hidden;
}

.tab-btn {
    flex: 1;
    padding: 14px 24px;
    border: none;
    background: white;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-right: 1px solid var(--border);
    transition: all 0.2s;
}

.tab-btn:last-child {
    border-right: none;
}

.tab-btn:hover {
    background: #F9FAFB;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ========================================
   STATISTICHE
   ======================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: .2vh;
    padding: 16px;
}

.stat-number {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--primary);
}

.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* ========================================
   DEVICE CARDS
   ======================================== */

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.device-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: .2vh;
    padding: 24px;
    transition: box-shadow 0.2s;
}

.device-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.device-card.working {
    border-left: 4px solid var(--success);
}

.device-card.maintenance {
    border-left: 4px solid var(--warning);
}

.device-icon {
    font-size: 28px;
    margin-bottom: 16px;
    color: var(--primary);
}

.device-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.device-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: .2vh;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 12px;
}

.device-status.working {
    background: #D1FAE5;
    color: var(--success);
}

.device-status.maintenance {
    background: #FEF3C7;
    color: var(--warning);
}

.device-issues {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.5;
}

/* ========================================
   BUTTONS
   ======================================== */

.btn-action {
    width: 100%;
    padding: 10px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: .2vh;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-action:hover {
    background: var(--primary-light);
}

.btn-add-link {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: .2vh;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-add-link:hover {
    background: var(--primary-light);
}

.btn-delete-section {
    padding: 10px 16px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: .2vh;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-delete-section:hover {
    background: #B91C1C;
}

.btn-edit-section {
    padding: 10px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: .2vh;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-edit-section:hover {
    background: var(--primary-light);
}

.btn-section-order {
    width: 32px;
    height: 32px;
    padding: 0;
    background: rgba(0, 43, 92, 0.1);
    color: var(--primary);
    border: 1px solid var(--border);
    border-radius: .2vh;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-section-order:hover:not(:disabled) {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-section-order:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ========================================
   MODAL
   ======================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

.modal.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-30px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* Blocca lo scroll della pagina quando un modal è aperto */
body.modal-open {
    overflow: hidden;
}

.modal-content {
    background: white;
    border-radius: .2vh;
    padding: 2px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-height: 80vh;
    animation: modalSlideIn 0.3s ease-out;
    overflow-y: auto;
}

.modal-header {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 16px 20px;
    margin: -2px -2px 20px -2px;
    border-radius: .2vh .2vh 0 0;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.modal-header .close-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.8);
    transition: color 0.2s;
}

.modal-header .close-btn:hover {
    color: white;
}

/* Modal header varianti colore */
.modal-header-danger {
    background: linear-gradient(135deg, var(--danger) 0%, #b91c1c 100%) !important;
}

.modal-header-secondary {
    background: linear-gradient(135deg, var(--secondary) 0%, #b45309 100%) !important;
}

.modal-header-purple {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%) !important;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: .2vh;
    font-size: 14px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 43, 92, 0.12);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 28px;
}

.btn-modal {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: .2vh;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-confirm {
    background: var(--primary);
    color: white;
}

.btn-confirm:hover {
    background: var(--primary-light);
}

.btn-cancel {
    background: #F3F4F6;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-cancel:hover {
    background: #E5E7EB;
}

.modal-section {
    background: white;
    border-radius: .2vh;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.modal-section-header {
    color: var(--primary);
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 600;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-info-box {
    background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%);
    border-left: 4px solid var(--primary);
    /* border-radius: .2vh; */
    padding: 16px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    display: flex;
    align-items: start;
    gap: 12px;
}

.modal-info-icon {
    background: white;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-info-content {
    flex: 1;
}

.modal-info-title {
    color: #1E40AF;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
}

.modal-info-text {
    color: #1E3A8A;
    font-size: 12px;
    line-height: 1.6;
}

/* Stili specifici per COPE modal */
.cope-modal-content {
    overflow: hidden !important;
}

.cope-scrollable-content {
    -webkit-overflow-scrolling: touch;
}

/* Modal di conferma personalizzato */
#confirmModal .modal-content {
    animation: modalSlideIn 0.3s ease-out;
}

#confirmModalConfirmBtn:hover {
    background: #991B1B !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(185, 28, 28, 0.4);
}

@keyframes modalSlideIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ========================================
   LOGIN SCREEN
   ======================================== */

.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #001a3d 0%, #002B5C 50%, #003D82 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.login-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.login-box {
    background: white;
    border-radius: .2vh;
    padding: 48px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.login-logo {
    width: 100px;
    height: auto;
    margin-bottom: 24px;
}

.login-box h2 {
    color: var(--primary);
    margin-bottom: 8px;
    font-size: 24px;
}

.login-box p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 32px;
}

/* ========================================
   FOOTER
   ======================================== */

.footer {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 16px 20px;
    text-align: center;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
}

.footer p {
    margin: 0;
}

.footer i {
    opacity: 0.7;
}

/* ========================================
   ADMIN BADGE
   ======================================== */

.admin-badge {
    display: inline-block;
    background: var(--warning);
    color: white;
    padding: 3px 8px;
    border-radius: .2vh;
    font-size: 10px;
    font-weight: 700;
    margin-left: 8px;
    letter-spacing: 0.5px;
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    background: white;
    border-left: 4px solid var(--primary);
    border-radius: .2vh;
    padding: 16px 20px;
    min-width: 300px;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: auto;
    animation: slideInRight 0.3s ease-out;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
}

.toast.info {
    border-left-color: var(--primary);
}

.toast-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.toast.success .toast-icon {
    color: var(--success);
}

.toast.error .toast-icon {
    color: var(--danger);
}

.toast.warning .toast-icon {
    color: var(--warning);
}

.toast.info .toast-icon {
    color: var(--primary);
}

.toast-message {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .header-content {
        padding: 16px 20px;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
    }

    .header-left {
        flex-direction: row;
        flex: 1;
        min-width: 200px;
    }

    .header-left img {
        height: 50px;
    }

    .header-right {
        width: 100%;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 8px;
    }

    /* Versione info su mobile - riga intera sopra */
    .header-right > div:first-child {
        width: 100%;
        margin-right: 0 !important;
        padding: 8px 12px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: .2vh;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center;
        gap: 16px !important;
    }

    .header-right > div:first-child > div {
        flex-direction: row !important;
        align-items: center !important;
        gap: 8px !important;
    }

    /* Role icon + bottoni su seconda riga */
    #userRoleIcon {
        font-size: 16px;
        padding: 8px 12px;
    }

    .header-btn {
        flex: 1;
        padding: 10px 12px;
        font-size: 12px;
        text-align: center;
        justify-content: center;
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .links-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .tabs {
        flex-direction: column;
    }

    .tab-btn {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .tab-btn:last-child {
        border-bottom: none;
    }

    .container,
    .main {
        padding: 20px;
    }

    .toast-container {
        right: 10px;
        left: 10px;
    }

    .toast {
        min-width: auto;
        max-width: 100%;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        margin-bottom: 16px;
    }

    .stat-card {
        padding: 10px 8px;
    }

    .stat-number {
        font-size: 20px;
        margin-bottom: 2px;
    }

    .stat-label {
        font-size: 9px;
        letter-spacing: 0.3px;
    }

    .devices-grid {
        grid-template-columns: 1fr;
    }

    /* Modali responsive su mobile per esempio dentro alla richiesta COPE */
    .modal {
        padding: 2vh;
        align-items: flex-end;
    }

    .modal-content {
        max-height: 95vh;
        max-width: 100%;
        width: 100%;
        border-radius: .2vh .2vh 0 0;
        padding: 0;
        margin: 0;
    }

    /* COPE modal specifico per mobile */
    .cope-modal-content {
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .cope-scrollable-content {
        flex: 1 !important;
        overflow-y: auto !important;
        padding: 16px !important;
    }

    .modal-header {
        font-size: 18px;
        margin-bottom: 0;
        padding: 16px !important;
        border-radius: .2vh .2vh 0 0 !important;
    }

    .modal-actions {
        flex-direction: column;
        gap: 10px;
        padding: 16px !important;
        position: sticky;
        bottom: 0;
        background: white;
    }

    .btn-modal {
        width: 100%;
        min-height: 48px;
    }

    .modal-content > div:not(.modal-header):not(.modal-actions):not(.cope-scrollable-content) {
        padding: 16px !important;
        max-height: calc(95vh - 160px);
        overflow-y: auto;
    }

    .modal-section {
        padding: 16px;
        margin-bottom: 12px;
    }

    .modal-section-header {
        font-size: 14px;
        margin-bottom: 12px;
    }

    .modal-info-box {
        padding: 12px 16px;
    }

    .modal-info-icon {
        width: 28px;
        height: 28px;
    }

    .modal-info-title {
        font-size: 12px;
    }

    .modal-info-text {
        font-size: 11px;
    }

    .modal-section > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* Form responsive */
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px;
    }
}

/* ========================================
   TABLET (768px - 1024px)
   ======================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .header-content {
        padding: 18px 28px;
    }

    .header-left img {
        height: 70px;
    }

    .container,
    .main {
        padding: 24px;
    }

    .links-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
    }

    .modal-content {
        max-width: 600px;
    }

    /* Header buttons su tablet - compatti ma leggibili */
    .header-btn {
        min-width: 48px;
        min-height: 48px;
        padding: 12px 14px;
    }

    #versionBox {
        margin-right: 16px !important;
    }
}

/* ========================================
   MOBILE SMALL (<= 480px)
   ======================================== */

@media (max-width: 480px) {
    .header-content {
        padding: 12px 16px;
    }

    .header-left img {
        height: 40px;
    }

    .header-title h1 {
        font-size: 16px;
    }

    .header-title p {
        font-size: 11px;
    }

    /* VersionBox compatto su mobile piccolo */
    #versionBox {
        gap: 8px !important;
        padding: 6px 10px !important;
    }

    #versionBox > div {
        font-size: 10px !important;
    }

    #versionBox i {
        font-size: 10px !important;
    }

    #versionText {
        display: none; /* Nascondi testo versione su schermi piccoli */
    }

    #versionDate span {
        font-size: 9px !important;
    }

    /* Stats grid su 2 colonne per mobile piccolo */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .stat-card {
        padding: 8px 6px;
    }

    .stat-number {
        font-size: 18px;
    }

    .stat-label {
        font-size: 8px;
    }

    .container,
    .main {
        padding: 16px;
    }

    .card {
        padding: 16px;
    }

    /* Bottoni più compatti */
    .header-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px 10px;
        font-size: 14px;
    }

    #userRoleIcon {
        font-size: 12px;
        padding: 6px 10px;
        gap: 4px;
    }

    /* Links grid più stretto */
    .links-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .modal-header {
        font-size: 16px;
        margin-bottom: 16px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    .form-group label {
        font-size: 12px;
    }
}

/* ========================================
   SPINNER ANIMATO
   ======================================== */

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #002B5C;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========================================
   TAG FILTERS
   ======================================== */

.tag-filter {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: .2vh;
    background: white;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tag-filter:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #EFF6FF;
}

.tag-filter.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.tag-filter i {
    font-size: 10px;
}

/* ========================================
   SCROLLBAR PERSONALIZZATA (SIDEBAR)
   ======================================== */

#quickNotesContainer::-webkit-scrollbar,
#checklistContainer::-webkit-scrollbar {
    width: 6px;
}

#quickNotesContainer::-webkit-scrollbar-track,
#checklistContainer::-webkit-scrollbar-track {
    background: #F3F4F6;
    border-radius: .2vh;
}

#quickNotesContainer::-webkit-scrollbar-thumb,
#checklistContainer::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: .2vh;
}

#quickNotesContainer::-webkit-scrollbar-thumb:hover,
#checklistContainer::-webkit-scrollbar-thumb:hover {
    background: var(--primary-light);
}

/* ========================================
   DESCRIPTION LINKS
   ======================================== */

/* Stile per link nelle descrizioni */
.description-text a {
    color: var(--primary);
    text-decoration: underline;
    word-break: break-all;
    transition: color 0.2s;
}

.description-text a:hover {
    color: var(--primary-light);
    text-decoration: underline;
}

.description-text a:active {
    color: var(--primary);
}

/* Assicura che i link siano touch-friendly */
@media (hover: none) and (pointer: coarse) {
    .description-text a {
        min-height: 32px;
        display: inline-block;
        padding: 2px 0;
    }
}

/* ========================================
   COPE FLOATING BUTTON
   ======================================== */

.cope-floating-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: linear-gradient(135deg, var(--primary) 0%, #0047AB 100%);
    color: white;
    border: none;
    border-radius: .2vh;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: move;
    box-shadow: 0 4px 16px rgba(0, 71, 171, 0.4);
    transition: all 0.3s ease;
    z-index: 1000;
}

.cope-floating-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 71, 171, 0.5);
}

.cope-floating-btn:active {
    transform: translateY(0);
}

.cope-floating-btn i {
    font-size: 18px;
}

/* ========================================
   DISABLED LINKS
   ======================================== */

.link-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.link-item.disabled::after {
    content: '🔒';
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 16px;
}


.header-btn-danger {
    background: var(--danger) !important;
    border-color: rgba(220, 38, 38, 0.5) !important;
}

/* ========================================
   BOTTONE REFRESH RIUSABILE
   ======================================== */

.btn-refresh {
    background: #FF8C00;
    color: white;
    border: none;
    padding: 12px;
    border-radius: .2vh;
    cursor: pointer;
    min-width: 48px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-refresh:hover {
    background: #e07800;
    box-shadow: 0 2px 8px rgba(255, 140, 0, 0.3);
}

.btn-refresh:active {
    transform: scale(0.95);
}

.btn-refresh i {
    font-size: 18px;
}

/* ========================================
   BOTTONE MODALE DANGER
   ======================================== */

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #b91c1c;
}