:root {
            --primary: #00875A;
            --primary-dark: #006747;
            --danger: #DC3545;
            --warning: #FFC107;
            --info: #17A2B8;
            --success: #28A745;
            --light: #F8F9FA;
            --dark: #343A40;
            --gray: #6C757D;
            --light-gray: #E9ECEF;
            --white: #FFFFFF;
            --shadow: 0 2px 8px rgba(0,0,0,0.1);
            --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
            --radius: 12px;
            --font: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            --animation: 0.3s ease;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: var(--font);
            -webkit-tap-highlight-color: transparent;
        }
        
        body {
            background-color: var(--light-gray);
            color: var(--dark);
            line-height: 1.5;
            padding: 0;
            margin: 0;
            overflow-x: hidden;
            touch-action: pan-y;
        }
        
        .container {
            max-width: 100%;
            margin: 0 auto;
            padding: 16px;
            min-height: 100vh;
            padding-bottom: 80px; /* Spazio per la bottom-nav */
        }
        
     /* ===== Bottom Nav (3 items) ===== */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;

  background: #fff;
  display: flex;
  gap: 12px;
  padding: 10px 14px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));

  box-shadow: 0 -8px 22px rgba(0,0,0,0.10);
  border-top: 1px solid rgba(0,0,0,0.06);
}

.bottom-nav--3 {
  /* se vuoi tenerla, ok: ma .bottom-nav già fa il lavoro */
}

.bottom-nav-item {
  flex: 1;
  border: 0 !important;
  outline: 0;
  background: transparent;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  padding: 10px 8px;
  border-radius: 14px;

  color: #8b8f97;          /* grigio come foto 2 */
  font-size: 12px;
  font-weight: 600;

  cursor: pointer;
}

.bottom-nav-item i {
  font-size: 22px;
  margin-bottom: 6px;
  color: inherit;
}

.bottom-nav-item span {
  line-height: 1;
}

/* Stato attivo: pill verde soft */
.bottom-nav-item.active {
  background: rgba(0, 140, 90, 0.12);
  color: #008c5a;
}

/* Optional: feedback tap */
.bottom-nav-item:active {
  transform: translateY(1px);
}

body.keyboard-open .bottom-nav {
  display: none !important;
}

/* quando nav sparisce, non lasciare spazio sotto inutile */
body.keyboard-open #mainContainer {
  padding-bottom: 18px !important;
}

#codeStatus {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}



        
        /* Card */
        .card > .form-group:first-child { margin-top: 0; }

        .card {
            background-color: var(--white);
            border-radius: var(--radius);
            padding: 20px;
            margin-bottom: 16px;
            box-shadow: var(--shadow);
            border-left: 4px solid var(--primary);
            transition: transform var(--animation), box-shadow var(--animation);
        }
        
        .card:hover {
            transform: translateY(-2px);
            box-shadow: var(--shadow-lg);
        }
        
        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
            padding-bottom: 10px;
            border-bottom: 1px solid var(--light-gray);
        }
        
        .card-title {
            font-size: 18px;
            font-weight: 600;
            color: var(--dark);
        }
        
        /* Button */
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 12px 20px;
            border-radius: 8px;
            border: none;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            font-size: 16px;
            text-decoration: none;
            position: relative;
            overflow: hidden;
        }
        
        .btn::after {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 5px;
            height: 5px;
            background: rgba(255, 255, 255, 0.5);
            opacity: 0;
            border-radius: 100%;
            transform: scale(1, 1) translate(-50%);
            transform-origin: 50% 50%;
        }
        
        .btn:focus:not(:active)::after {
            animation: ripple 1s ease-out;
        }
        
        @keyframes ripple {
            0% {
                transform: scale(0, 0);
                opacity: 0.5;
            }
            100% {
                transform: scale(20, 20);
                opacity: 0;
            }
        }
        
        .btn-primary {
            background-color: var(--primary);
            color: var(--white);
        }
        
        .btn-primary:hover {
            background-color: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 135, 90, 0.3);
        }
        
        .btn-secondary {
            background-color: var(--light);
            color: var(--dark);
            border: 1px solid var(--gray);
        }
        
        .btn-danger {
            background-color: var(--danger);
            color: var(--white);
        }
        
        .btn-warning {
            background-color: var(--warning);
            color: var(--dark);
        }
        
        .btn-block {
            width: 100%;
            margin-top: 10px;
        }
        
        .btn-icon {
            width: 40px;
            height: 40px;
            padding: 0;
            border-radius: 50%;
        }
        
        /* FAB - Floating Action Button */
        .fab {
            position: fixed;
            bottom: 80px; /* Sopra la bottom-nav */
            right: 24px;
            width: 56px;
            height: 56px;
            border-radius: 50%;
            background-color: var(--primary);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            box-shadow: 0 4px 12px rgba(0, 135, 90, 0.4);
            cursor: pointer;
            z-index: 1000;
            transition: all 0.3s ease;
            border: none;
        }
        
        .fab:hover {
            transform: scale(1.1) rotate(90deg);
            box-shadow: 0 6px 16px rgba(0, 135, 90, 0.6);
        }
        
        /* Form */
        .form-group {
            margin-bottom: 20px;
            position: relative;
        }
        
        .form-label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--dark);
        }
        
        .form-control {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid var(--light-gray);
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
            background-color: var(--white);
        }
        
        .form-control:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(0, 135, 90, 0.1);
        }
        
        .form-control.valid {
            border-color: var(--success);
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2328A745'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 12px center;
            background-size: 20px;
            padding-right: 40px;
        }
        
        .form-control.invalid {
            border-color: var(--danger);
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23DC3545'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 12px center;
            background-size: 20px;
            padding-right: 40px;
        }
        
        .validation-message {
            margin-top: 5px;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 6px;
            animation: slideDown 0.3s ease;
        }
        
        @keyframes slideDown {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .validation-success {
            color: var(--success);
        }
        
        .validation-error {
            color: var(--danger);
        }
        
        /* Loading Spinner */
        .spinner {
            width: 24px;
            height: 24px;
            border: 3px solid var(--light-gray);
            border-top: 3px solid var(--primary);
            border-radius: 50%;
            animation: spin 1s linear infinite;
            display: inline-block;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        /* Skeleton Loading */
        .skeleton {
            background: linear-gradient(90deg, var(--light-gray) 25%, #e0e0e0 50%, var(--light-gray) 75%);
            background-size: 200% 100%;
            animation: skeleton-loading 1.5s infinite;
            border-radius: 4px;
        }
        
        @keyframes skeleton-loading {
            0% { background-position: 200% 0; }
            100% { background-position: -200% 0; }
        }
        
        .skeleton-card {
            height: 120px;
            margin-bottom: 16px;
            border-radius: var(--radius);
        }
        
        .skeleton-text {
            height: 16px;
            margin-bottom: 8px;
            border-radius: 4px;
        }
        
        .skeleton-text:last-child {
            width: 60%;
        }
        
        /* Toast Notification */
        .toast-container {
            position: fixed;
            bottom: 100px; /* Sopra la bottom-nav */
            left: 50%;
            transform: translateX(-50%);
            z-index: 9999;
            width: 90%;
            max-width: 400px;
        }
        
        .toast {
            background-color: var(--white);
            border-radius: var(--radius);
            padding: 16px;
            margin-bottom: 10px;
            box-shadow: var(--shadow-lg);
            display: flex;
            align-items: center;
            gap: 12px;
            animation: toastSlideUp 0.3s ease;
            border-left: 4px solid;
        }
        
        .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(--info);
        }
        
        @keyframes toastSlideUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        /* List */
        .list {
            list-style: none;
        }
        
        .list-item {
            display: flex;
            align-items: center;
            padding: 16px;
            border-bottom: 1px solid var(--light-gray);
            transition: background-color 0.2s;
            position: relative;
            overflow: hidden;
        }
        
        .list-item:hover {
            background-color: var(--light);
        }
        
        .list-item-content {
            flex-grow: 1;
        }
        
        .list-item-title {
            font-weight: 600;
            margin-bottom: 4px;
        }
        
        .list-item-subtitle {
            color: var(--gray);
            font-size: 14px;
        }
        
        .list-item-badge {
            display: inline-flex;
            align-items: center;
            padding: 4px 10px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
            margin-left: 10px;
        }
        
        .badge-danger {
            background-color: rgba(220, 53, 69, 0.1);
            color: var(--danger);
        }
        
        .badge-warning {
            background-color: rgba(255, 193, 7, 0.1);
            color: #856404;
        }
        
        .badge-success {
            background-color: rgba(40, 167, 69, 0.1);
            color: var(--success);
        }
        
        /* Swipe to Delete */
        .swipe-container {
            position: relative;
            overflow: hidden;
            border-radius: 8px;
            margin-bottom: 8px;
        }
        
        .swipe-content {
            background-color: var(--white);
            padding: 16px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            transition: transform 0.3s ease;
            position: relative;
            z-index: 2;
        }
        
        .swipe-actions {
            position: absolute;
            top: 0;
            right: 0;
            height: 100%;
            display: flex;
            align-items: center;
            z-index: 1;
        }
        
        .swipe-delete {
            background-color: var(--danger);
            color: white;
            height: 100%;
            display: flex;
            align-items: center;
            padding: 0 24px;
            cursor: pointer;
            transform: translateX(100%);
        }
        
        /* Grid */
        .grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 16px;
            margin-top: 20px;
        }
        
        .grid-item {
            background-color: var(--white);
            border-radius: var(--radius);
            padding: 24px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            text-align: center;
            box-shadow: var(--shadow);
            transition: all 0.3s ease;
            text-decoration: none;
            color: var(--dark);
            border: 2px solid transparent;
            cursor: pointer;
        }
        
        .grid-item:hover {
            transform: translateY(-5px);
            border-color: var(--primary);
            box-shadow: var(--shadow-lg);
        }
        
        .grid-item:active {
            transform: translateY(-2px);
        }
        
        .grid-item i {
            font-size: 36px;
            margin-bottom: 12px;
            color: var(--primary);
        }
        
        .grid-item-primary {
            border: 3px solid var(--primary);
            animation: pulse-border 2s infinite;
        }
        
        @keyframes pulse-border {
            0% { border-color: var(--primary); }
            50% { border-color: rgba(0, 135, 90, 0.5); }
            100% { border-color: var(--primary); }
        }
        
        /* Filter bar */
        .filter-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 16px;
            background-color: var(--white);
            border-radius: var(--radius);
            margin-bottom: 16px;
            box-shadow: var(--shadow);
            position: sticky;
            top: 0;
            z-index: 90;
        }
        
        .filter-current {
            padding: 8px 16px;
            background-color: var(--light);
            border-radius: var(--radius);
            margin-bottom: 16px;
            font-size: 14px;
            animation: fadeIn 0.5s ease;
        }
        
        .filter-current strong {
            color: var(--primary);
        }
        
        /* Status indicator */
        .status-indicator {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            display: inline-block;
            margin-right: 8px;
            animation: blink 2s infinite;
        }
        
        @keyframes blink {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }
        
        .status-danger {
            background-color: var(--danger);
        }
        
        .status-warning {
            background-color: var(--warning);
        }
        
        .status-success {
            background-color: var(--success);
        }
        
        /* Draft list */
        .draft-list {
            margin-top: 20px;
        }
        
        .draft-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 16px;
            background-color: var(--light);
            border-radius: 8px;
            margin-bottom: 8px;
            border-left: 4px solid var(--info);
            transition: all 0.3s ease;
        }
        
        /* Modal - Bottom Sheet */
        .modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            display: none;
            align-items: flex-end;
            justify-content: center;
            z-index: 1000;
            animation: fadeIn 0.3s ease;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        
        .bottom-sheet {
            background-color: var(--white);
            border-radius: 20px 20px 0 0;
            width: 100%;
            max-height: 80vh;
            overflow-y: auto;
            animation: slideUp 0.3s ease;
            padding-bottom: env(safe-area-inset-bottom);
        }
        
        @keyframes slideUp {
            from { transform: translateY(100%); }
            to { transform: translateY(0); }
        }
        
        .bottom-sheet-header {
            padding: 20px;
            border-bottom: 1px solid var(--light-gray);
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: sticky;
            top: 0;
            background-color: var(--white);
            z-index: 2;
        }
        
        .bottom-sheet-body {
            padding: 20px;
        }
        
        .bottom-sheet-handle {
            width: 40px;
            height: 4px;
            background-color: var(--light-gray);
            border-radius: 2px;
            margin: 0 auto 16px;
        }
        
        /* Pull to Refresh */
        .pull-to-refresh {
            text-align: center;
            padding: 20px;
            color: var(--gray);
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 10px;
            opacity: 0;
            transform: translateY(-100%);
            transition: all 0.3s ease;
        }
        
        .pull-to-refresh.active {
            opacity: 1;
            transform: translateY(0);
        }
        
        /* Offline Indicator */
        .offline-indicator {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            background-color: var(--danger);
            color: white;
            text-align: center;
            padding: 8px;
            z-index: 9999;
            transform: translateY(-100%);
            transition: transform 0.3s ease;
        }
        
        .offline-indicator.show {
            transform: translateY(0);
        }
        
        /* QR Scanner */
        .qr-scanner {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 200px;
            background: linear-gradient(135deg, var(--primary), var(--primary-dark));
            border-radius: var(--radius);
            margin: 20px 0;
            border: 2px dashed rgba(255, 255, 255, 0.5);
            color: white;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        
        .qr-scanner::before {
            content: '';
            position: absolute;
            width: 200%;
            height: 200%;
            background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
            animation: scanner-beam 3s infinite linear;
        }
        
        @keyframes scanner-beam {
            0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
            100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
        }
        
        .qr-scanner i {
            font-size: 64px;
            color: white;
            margin-bottom: 16px;
            position: relative;
            z-index: 1;
        }
        
        .qr-scanner:hover {
            transform: scale(1.02);
            box-shadow: 0 8px 24px rgba(0, 135, 90, 0.4);
        }
        
        /* Toggle Switch iOS Style */
        .toggle-switch {
            position: relative;
            width: 60px;
            height: 34px;
        }
        
        .toggle-switch input {
            opacity: 0;
            width: 0;
            height: 0;
        }
        
        .toggle-slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            transition: .4s;
            border-radius: 34px;
        }
        
        .toggle-slider:before {
            position: absolute;
            content: "";
            height: 26px;
            width: 26px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
        }
        
        input:checked + .toggle-slider {
            background-color: var(--primary);
        }
        
        input:checked + .toggle-slider:before {
            transform: translateX(26px);
        }
        
        /* Utility */
        .text-center {
            text-align: center;
        }
        
        .text-success {
            color: var(--success);
        }
        
        .text-danger {
            color: var(--danger);
        }
        
        .text-warning {
            color: #856404;
        }
        
        .mt-2 {
            margin-top: 8px;
        }
        
        .mt-3 {
            margin-top: 16px;
        }
        
        .mt-4 {
            margin-top: 24px;
        }
        
        .mb-2 {
            margin-bottom: 8px;
        }
        
        .mb-3 {
            margin-bottom: 16px;
        }
        
        .mb-4 {
            margin-bottom: 24px;
        }
        
        .d-flex {
            display: flex;
        }
        
        .align-center {
            align-items: center;
        }
        
        .justify-between {
            justify-content: space-between;
        }
        
        /* Page specific */
        .page {
            display: none;
            animation: fadeIn 0.3s ease;
        }
        
        .page.active {
            display: block;
        }
        
        /* Navigation */
        .nav-back {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--gray);
            text-decoration: none;
            margin-bottom: 20px;
            padding: 8px 0;
            transition: color 0.3s ease;
            cursor: pointer;
        }
        
        .nav-back:hover {
            color: var(--primary);
        }
        
        /* Haptic Feedback Simulation */
        @keyframes haptic-vibration {
            0% { transform: translateX(0); }
            25% { transform: translateX(-2px); }
            50% { transform: translateX(2px); }
            75% { transform: translateX(-1px); }
            100% { transform: translateX(0); }
        }
        
        .haptic {
            animation: haptic-vibration 0.3s ease;
        }
        
        /* Progress Bar */
        .progress-bar {
            width: 100%;
            height: 4px;
            background-color: var(--light-gray);
            border-radius: 2px;
            overflow: hidden;
            margin: 10px 0;
        }
        
        .progress {
            height: 100%;
            background-color: var(--primary);
            width: 0%;
            transition: width 0.3s ease;
        }
        
        /* Responsive */
        @media (min-width: 768px) {
            .container {
                max-width: 768px;
            }
            
            .grid {
                grid-template-columns: repeat(4, 1fr);
            }
            
            .bottom-sheet {
                max-width: 500px;
                border-radius: var(--radius);
                animation: modalSlideUp 0.3s ease;
            }
            
            @keyframes modalSlideUp {
                from {
                    opacity: 0;
                    transform: translateY(50px);
                }
                to {
                    opacity: 1;
                    transform: translateY(0);
                }
            }
        }

/* --- Compatibility aliases for existing app buttons --- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-secondary { background: var(--light-gray); color: var(--dark); border: 1px solid rgba(0,0,0,0.08); }
.btn-danger { background: var(--danger); color: #fff; }
.btn.btn-secondary:hover { filter: brightness(0.98); }
.btn.btn-danger:hover { filter: brightness(0.98); }

/* Header for SPA pages */
.page-header { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom: 14px; }
.page-title { font-size: 20px; font-weight: 700; }
.icon-btn { width:44px; height:44px; border-radius: 12px; border: none; background: var(--white); box-shadow: var(--shadow); display:flex; align-items:center; justify-content:center; }
.icon-btn:active { transform: scale(0.98); }

/* --- App additions (compat) --- */
.avatar{width:48px;height:48px;border-radius:999px;background:rgba(0,135,90,.12);display:flex;align-items:center;justify-content:center;color:var(--primary)}
.icon-circle{width:40px;height:40px;border-radius:999px;background:rgba(0,135,90,.12);display:flex;align-items:center;justify-content:center;color:var(--primary)}
