        /* ========================================
           STILI PAREGGI PARKING
           ======================================== */
        .pareggi-container {
            padding: 20px;
            max-width: 1400px;
            margin: 0 auto;
        }
        
        .pareggi-pronti-section {
            margin-bottom: 30px;
        }
        
        .pareggi-pronti-section h2 {
            color: var(--text-primary);
            margin-bottom: 10px;
            font-size: 1.8em;
        }

        .pareggi-list {
            margin-top: 20px;
        }

        .pareggi-list h3 {
            color: var(--text-primary);
            margin-bottom: 15px;
        }

        /* PARKING/FASE4 context: flex-column. Il tab PAREGGI usa display:grid da table.css */
        #parkingTab .pareggi-table,
        #fase4Tab .pareggi-table {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        
        .pareggio-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 12px 15px;
            transition: all 0.3s ease;
        }
        
        .pareggio-row:hover {
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        }
        
        .pareggio-row.parking-row {
            border-left: 3px solid #ff9800;
        }
        
        /* PARKING context: neutro (dentro .pareggio-row). Il puzzle usa stili colorati in table.css */
        .pareggio-row .pareggio-dare,
        .pareggio-row .pareggio-avere {
            padding: 10px;
            background: var(--bg-primary);
            border-radius: 6px;
        }

        /* PARKING/FASE4 context: pareggio-header compatto (font-size 0.9em, margin-bottom 8px).
           Il tab PAREGGI usa font-weight:bold, margin-bottom:10px da table.css. */
        #parkingTab .pareggio-header,
        #fase4Tab .pareggio-header {
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 8px;
            font-size: 0.9em;
        }
        
        .pareggio-numero {
            font-size: 0.9em;
            font-weight: 600;
            color: var(--portal-primary);
            margin-left: 6px;
            cursor: pointer;
            transition: all 0.2s ease;
            display: inline-block;
            padding: 2px 4px;
            border-radius: 4px;
        }
        
        .pareggio-numero:hover {
            background: var(--table-hover);
            transform: scale(1.05);
        }
        
        .pareggio-link-icon {
            cursor: pointer;
            font-size: 0.95em;
            color: var(--accent-primary);
            transition: all 0.2s ease;
            padding: 2px 4px;
            border-radius: 4px;
            text-decoration: none;
            font-weight: 600;
            display: inline-block;
            user-select: none;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
        }

        .pareggio-link-icon:hover {
            background: var(--table-hover);
            transform: scale(1.05);
            cursor: pointer;
        }
        
        /* PARKING/FASE4 context: pareggio-item usa text-primary (non secondary) + font-size 0.9em.
           Il tab PAREGGI usa color:var(--text-secondary), margin:5px 0 da table.css. */
        #parkingTab .pareggio-item,
        #fase4Tab .pareggio-item {
            color: var(--text-primary);
            font-size: 0.9em;
            line-height: 1.4;
        }

        #parkingTab .pareggio-item strong,
        #fase4Tab .pareggio-item strong {
            display: block;
            margin-bottom: 5px;
        }

        /* PARKING/FASE4 context: pareggio-amount leggermente piu compatto (1.1em, 600).
           Il tab PAREGGI usa font-size:1.2em, font-weight:bold, margin-top:10px da table.css. */
        #parkingTab .pareggio-amount,
        #fase4Tab .pareggio-amount {
            font-weight: 600;
            font-size: 1.1em;
        }
        
        .pareggio-confidence {
            display: inline-block;
            margin-top: 10px;
            padding: 8px 12px;
            border-radius: 6px;
            font-size: 0.85em;
            font-weight: 500;
            text-align: center;
        }
        
        .pareggio-confidence.parking-confidence {
            background: rgba(255, 152, 0, 0.1);
            color: #ff9800;
            border: 1px solid rgba(255, 152, 0, 0.3);
        }
        
        .parking-actions {
            margin-top: 10px;
            display: flex;
            gap: 8px;
        }
        
        .parking-actions button {
            flex: 1;
            transition: all 0.2s ease;
        }
        
        .parking-actions button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        
        /* PARKING/FASE4 context: status card compatto (1px border, 20px padding, 12px radius).
           Il tab PAREGGI usa stili piu prominenti definiti in table.css (2px, 25px, 15px). */
        #parkingTab .status-card,
        #fase4Tab .status-card {
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 20px;
        }

        #parkingTab .status-header,
        #fase4Tab .status-header {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 15px;
        }

        #parkingTab .status-details,
        #fase4Tab .status-details {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        #parkingTab .status-item,
        #fase4Tab .status-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 0;
            border-bottom: 1px solid var(--border-color);
        }

        #parkingTab .status-item:last-child,
        #fase4Tab .status-item:last-child {
            border-bottom: none;
        }
        
        .badge {
            background: var(--accent-primary);
            color: white;
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 0.85em;
            font-weight: 600;
        }
        
        /* Varianti stato per status-card nel contesto parking/fase4 */
        #parkingTab .status-card.status-in-corso,
        #fase4Tab .status-card.status-in-corso {
            border-color: #ff9800;
            background: rgba(255, 152, 0, 0.05);
        }

        #parkingTab .status-card.status-completato,
        #fase4Tab .status-card.status-completato {
            border-color: #4caf50;
            background: rgba(76, 175, 80, 0.05);
        }

        #parkingTab .status-card.status-errore,
        #fase4Tab .status-card.status-errore {
            border-color: #d32f2f;
            background: rgba(211, 47, 47, 0.05);
        }

        /* btn-refresh nel contesto parking/fase4: bordo 1px leggero.
           Nei tab pareggi/puzzle usa il bordo 2px con rotate(180deg) da table.css. */
        #parkingTab .btn-refresh,
        #fase4Tab .btn-refresh,
        .btn-export {
            background: transparent;
            border: 1px solid var(--border-color);
            padding: 6px 12px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 0.9em;
            transition: all 0.2s ease;
        }

        #parkingTab .btn-refresh:hover,
        #fase4Tab .btn-refresh:hover,
        .btn-export:hover {
            background: var(--table-hover);
        }
        
        /* ========================================
           NOTIFICHE TOAST - USER FRIENDLY
           ======================================== */
        .notification {
            position: fixed;
            top: 80px;
            right: 30px;
            background: white;
            padding: 16px 24px;
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
            display: flex;
            align-items: center;
            gap: 12px;
            z-index: 10000;
            opacity: 0;
            transform: translateX(400px);
            transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
            max-width: 400px;
            border-left: 4px solid #4CAF50;
        }
        
        .notification.show {
            opacity: 1;
            transform: translateX(0);
        }
        
        .notification-content {
            display: flex;
            align-items: center;
            gap: 12px;
        }
        
        .notification-icon {
            font-size: 1.5em;
            flex-shrink: 0;
        }
        
        .notification-message {
            font-size: 0.95em;
            color: #212121;
            line-height: 1.4;
        }
        
        .notification-success {
            border-left-color: #4CAF50;
        }
        
        .notification-info {
            border-left-color: #2196F3;
        }
        
        .notification-warning {
            border-left-color: #FF9800;
        }
        
        /* Dark mode notifiche - Migliorato contrasto */
        [data-theme="dark"] .notification {
            background: rgba(30, 30, 30, 0.98);
            border-left-color: var(--accent-primary, #4CAF50);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 20px rgba(76, 175, 80, 0.2);
        }
        
        [data-theme="dark"] .notification-message {
            color: #f0f0f0;
            font-weight: 500;
        }
        
        /* Migliora contrasto notifiche per tutti i tipi */
        .notification-success {
            background: #e8f5e9;
            border-left-color: #4caf50;
        }
        
        .notification-success .notification-message {
            color: #1b5e20;
            font-weight: 500;
        }
        
        [data-theme="dark"] .notification-success {
            background: rgba(76, 175, 80, 0.25);
            border-left-color: #4caf50;
        }
        
        [data-theme="dark"] .notification-success .notification-message {
            color: #a5d6a7;
        }
        
        .notification-info {
            background: #e3f2fd;
            border-left-color: #2196f3;
        }
        
        .notification-info .notification-message {
            color: #0d47a1;
            font-weight: 500;
        }
        
        [data-theme="dark"] .notification-info {
            background: rgba(33, 150, 243, 0.25);
            border-left-color: #2196f3;
        }
        
        [data-theme="dark"] .notification-info .notification-message {
            color: #90caf9;
        }
        
        .notification-warning {
            background: #fff3e0;
            border-left-color: #ff9800;
        }
        
        .notification-warning .notification-message {
            color: #e65100;
            font-weight: 500;
        }
        
        [data-theme="dark"] .notification-warning {
            background: rgba(255, 152, 0, 0.25);
            border-left-color: #ff9800;
        }
        
        [data-theme="dark"] .notification-warning .notification-message {
            color: #ffcc80;
        }
        
        .notification-error {
            background: #ffebee;
            border-left-color: #f44336;
        }
        
        .notification-error .notification-message {
            color: #b71c1c;
            font-weight: 500;
        }
        
        [data-theme="dark"] .notification-error {
            background: rgba(244, 67, 54, 0.25);
            border-left-color: #f44336;
        }
        
        [data-theme="dark"] .notification-error .notification-message {
            color: #ef9a9a;
        }
        
        /* .btn-header-secondary: definizione unificata in sezione Header Buttons (riga ~323) */
        
        /* ========================================
           CELLE EDITABILI
           ======================================== */

        .editor-input {
            width: 100%;
            font: inherit;
            color: inherit;
            background: rgba(255, 255, 255, 0.15);
            border: 1px solid rgba(76, 175, 80, 0.4);
            border-radius: 6px;
            padding: 6px 8px;
            box-sizing: border-box;
        }
        
        [data-theme="dark"] .editor-input {
            background: rgba(40, 60, 40, 0.6);
            border-color: rgba(184, 212, 184, 0.5);
        }
        
        .editor-input:focus {
            outline: 2px solid rgba(76, 175, 80, 0.6);
        }
        
        .editor-input.input-error {
            border-color: #d9534f;
            outline-color: #d9534f;
        }
        
        .editable.saving::after {
            content: '';
            position: absolute;
            top: 50%;
            right: 10px;
            width: 12px;
            height: 12px;
            border: 2px solid rgba(76, 175, 80, 0.6);
            border-top-color: transparent;
            border-radius: 50%;
            animation: editor-spin 0.8s linear infinite;
            transform: translateY(-50%);
        }
        
        @keyframes editor-spin {
            to {
                transform: translateY(-50%) rotate(360deg);
            }
        }
        
        .edit-success {
            animation: edit-success-pulse 1.2s ease;
        }
        
        .edit-error {
            animation: edit-error-pulse 1.2s ease;
        }
        
        @keyframes edit-success-pulse {
            0% { background: rgba(76, 175, 80, 0.25); }
            100% { background: transparent; }
        }
        
        @keyframes edit-error-pulse {
            0% { background: rgba(217, 83, 79, 0.25); }
            100% { background: transparent; }
        }

        /* Selezione e feedback bulk stile Excel */
        .editable-selected {
            outline: 2px solid #4caf50;
            outline-offset: -2px;
            background: rgba(76, 175, 80, 0.12);
        }
        .bulk-applied {
            animation: edit-success-pulse 0.9s ease;
        }

        /* Modale cronologia */
        .history-modal,
        .modal {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.5);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: 10000;
        }
        
        .modal-content {
            background: var(--bg-secondary, #ffffff);
            color: var(--text-primary, #212121);
            border-radius: 12px;
            box-shadow: var(--shadow-lg);
            max-width: 90vw;
            max-height: 90vh;
            overflow: auto;
            display: flex;
            flex-direction: column;
        }
        
        /* Migliora contrasto per dark mode */
        [data-theme="dark"] .modal-content {
            background: #1e1e1e;
            color: #e0e0e0;
        }
        
        .modal-header {
            padding: 20px;
            border-bottom: 1px solid var(--border-color, #e0e0e0);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .modal-header h2 {
            margin: 0;
            color: var(--portal-primary, #2e7d32);
            font-weight: 600;
        }
        
        /* Migliora contrasto titolo in dark mode */
        [data-theme="dark"] .modal-header h2 {
            color: #4caf50;
        }
        
        .modal-close {
            font-size: 28px;
            font-weight: bold;
            color: var(--text-secondary, #757575);
            cursor: pointer;
            line-height: 1;
            transition: color 0.2s ease;
        }
        
        .modal-close:hover {
            color: var(--text-primary, #212121);
        }
        
        /* Migliora contrasto close button in dark mode */
        [data-theme="dark"] .modal-close {
            color: #b0b0b0;
        }
        
        [data-theme="dark"] .modal-close:hover {
            color: #ffffff;
        }
        
        .modal-body {
            padding: 20px;
            flex: 1;
            overflow-y: auto;
            color: var(--text-primary, #212121);
        }
        
        /* Migliora contrasto body in dark mode */
        [data-theme="dark"] .modal-body {
            color: #e8f5e9; /* Verde chiaro per leggibilità */
            background: #1e1e1e;
        }
        
        .modal-body p {
            color: inherit;
            margin: 0 0 12px 0;
            line-height: 1.6;
        }
        
        /* Migliora contrasto per popup contabilizzazione in dark mode */
        [data-theme="dark"] #contabilizzataConfirmModal .modal-body {
            color: #e8f5e9;
        }
        
        [data-theme="dark"] #contabilizzataConfirmModal .modal-body p {
            color: #e8f5e9;
            font-weight: 500;
        }
        
        [data-theme="dark"] #contabilizzataConfirmModal .modal-body div[style*="background"] {
            background: rgba(255, 193, 7, 0.2) !important;
            border-left-color: #ffc107 !important;
        }
        
        [data-theme="dark"] #contabilizzataConfirmModal .modal-body div[style*="background"] p {
            color: #fff9c4 !important; /* Giallo chiaro per leggibilità */
            font-weight: 600;
        }
        
        .modal-footer {
            padding: 15px 20px;
            border-top: 1px solid var(--border-color, #e0e0e0);
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }
        
        /* Stili bottoni modal */
        .modal-footer .btn {
            padding: 10px 20px;
            border-radius: 6px;
            border: none;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.2s ease;
        }
        
        .modal-footer .btn-primary {
            background: var(--portal-primary, #2e7d32);
            color: white;
        }
        
        .modal-footer .btn-primary:hover {
            background: var(--portal-secondary, #388e3c);
            transform: translateY(-1px);
            box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }
        
        .modal-footer .btn-secondary {
            background: #757575;
            color: white;
        }
        
        .modal-footer .btn-secondary:hover {
            background: #616161;
            transform: translateY(-1px);
            box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }
        .history-modal .panel {
            width: 680px;
            max-height: 80vh;
            overflow: auto;
            background: var(--bg-secondary);
            color: var(--text-primary);
            border-radius: 10px;
            box-shadow: 0 10px 24px rgba(0,0,0,0.35);
            padding: 16px;
        }
        .history-modal .panel h3 {
            margin: 0 0 8px 0;
        }
        .history-list {
            display: grid;
            grid-template-columns: 1fr auto auto;
            gap: 8px;
            align-items: center;
        }
        .history-item {
            padding: 8px;
            border-radius: 8px;
            background: rgba(255,255,255,0.06);
        }
        .btn-restore {
            padding: 6px 10px;
            border-radius: 6px;
            background: #2b8a3e;
            color: white;
            cursor: pointer;
            border: none;
        }
        .btn-restore:hover { filter: brightness(1.05); }
        .btn-close-modal {
            float: right;
            background: transparent;
            border: none;
            color: inherit;
            font-size: 18px;
            cursor: pointer;
        }
        
        /* Stili Modal Suggerimenti */
        .suggestion-item {
            background: var(--bg-secondary);
            border: 2px solid var(--border-color);
            border-radius: 10px;
            padding: 15px;
            transition: all 0.2s ease;
        }
        
        .suggestion-item:hover {
            border-color: var(--accent-primary);
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        
        .suggestion-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 12px;
        }
        
        .suggestion-score {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            padding: 6px 12px;
            border-radius: 20px;
            font-weight: 600;
            font-size: 0.9em;
        }
        
        .score-high {
            background: rgba(76, 175, 80, 0.2);
            color: #4caf50;
        }
        
        .score-medium {
            background: rgba(255, 152, 0, 0.2);
            color: #ff9800;
        }
        
        .score-low {
            background: rgba(244, 67, 54, 0.2);
            color: #f44336;
        }
        
        .suggestion-details {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
            margin-bottom: 12px;
        }
        
        .suggestion-caparra,
        .suggestion-gir {
            padding: 12px;
            background: var(--bg-primary);
            border-radius: 8px;
            border-left: 3px solid var(--accent-primary);
        }
        
        .suggestion-caparra {
            border-left-color: #c62828;
        }
        
        .suggestion-gir {
            border-left-color: var(--portal-primary);
        }
        
        .suggestion-item-name {
            font-weight: 600;
            margin-bottom: 4px;
            color: var(--text-primary);
        }

        .suggestion-item-details {
            font-size: 0.85em;
            color: var(--text-primary);
            margin-top: 4px;
        }

        .suggestion-item-details strong {
            color: var(--text-primary);
        }

        .suggestion-metrics {
            display: flex;
            gap: 12px;
            margin-top: 10px;
            padding-top: 10px;
            border-top: 1px solid var(--border-color);
            font-size: 0.85em;
            color: var(--text-primary);
        }

        .suggestion-metric {
            display: flex;
            align-items: center;
            gap: 4px;
            color: var(--text-primary);
        }

        .suggestion-metric strong {
            color: var(--text-primary);
            font-weight: 600;
        }
        
        .suggestion-actions {
            display: flex;
            gap: 8px;
            justify-content: flex-end;
            margin-top: 12px;
        }

        /* Stili Modal Magic Match - Sovrascrive history-modal per avere sfondo chiaro */
        #magicMatchModal .panel,
        #magicMatchModal .magic-match-panel {
            background: var(--bg-secondary);
            color: var(--text-primary);
        }

        #magicMatchModal .panel h3,
        #magicMatchModal .magic-match-panel h3 {
            color: var(--text-primary);
        }

        #magicMatchModal .btn-close-modal {
            color: var(--text-primary);
        }
        
        .magic-match-item {
            background: var(--bg-secondary);
            border: 2px solid var(--border-color);
            border-radius: 10px;
            padding: 15px;
            margin-bottom: 15px;
            transition: all 0.2s ease;
        }
        
        .magic-match-item:hover {
            border-color: var(--accent-primary);
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        
        .magic-match-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 12px;
        }
        
        .magic-match-pareggio {
            font-weight: 600;
            color: var(--text-primary);
            font-size: 1em;
        }
        
        .magic-match-score {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            padding: 6px 12px;
            border-radius: 20px;
            font-weight: 600;
            font-size: 0.9em;
            background: rgba(76, 175, 80, 0.2);
            color: #2e7d32;
        }
        
        .magic-match-details {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
            margin-bottom: 12px;
        }
        
        .magic-match-caparra,
        .magic-match-gir {
            padding: 12px;
            background: rgba(0,0,0,0.05);
            border-radius: 8px;
            border-left: 3px solid var(--accent-primary);
        }
        
        .magic-match-caparra {
            border-left-color: #c62828;
        }
        
        .magic-match-gir {
            border-left-color: var(--portal-primary);
        }
        
        .magic-match-item-name {
            font-weight: 600;
            margin-bottom: 4px;
            color: var(--text-primary);
        }
        
        .magic-match-item-details {
            font-size: 0.85em;
            color: var(--text-primary);
            margin-top: 4px;
        }
        
        .magic-match-item-details strong {
            color: var(--text-primary);
        }
        
        .magic-match-amount {
            font-weight: 600;
            font-size: 1em;
            color: var(--text-primary);
            margin-top: 8px;
        }
        
        .magic-match-summary {
            color: var(--text-primary);
            font-size: 0.95em;
            line-height: 1.6;
        }
        
        .magic-match-summary strong {
            color: var(--text-primary);
            font-weight: 600;
        }
        
        .magic-match-summary .summary-success {
            color: #2e7d32;
            font-weight: 600;
        }
        
        .magic-match-summary .summary-warning {
            color: #e65100;
            font-weight: 600;
        }
        
        /* Assicura che tutti i testi nel modal Magic Match siano leggibili */
        #magicMatchModal .magic-match-pareggio,
        #magicMatchModal .magic-match-item-name,
        #magicMatchModal .magic-match-item-details,
        #magicMatchModal .magic-match-item-details strong,
        #magicMatchModal .magic-match-amount {
            color: var(--text-primary);
        }

        /* ============================================
           MODAL LOGIN - VERSIONE MINIMALISTA
           Aggiornato: 30 Dicembre 2025
           ============================================ */

        /* Panel principale */
        #loginModal .login-panel {
            width: 420px;
            max-width: 92vw;
            background: var(--bg-secondary);
            color: var(--text-primary);
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
            padding: 0;
            overflow: hidden;
        }

        /* Header */
        #loginModal .login-header {
            padding: 20px 24px 16px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            gap: 12px;
        }

        #loginModal .login-icon {
            font-size: 24px;
        }

        #loginModal .login-title {
            font-size: 1.15em;
            font-weight: 600;
            color: var(--text-primary);
            margin: 0;
        }

        /* Body */
        #loginModal .login-body {
            padding: 24px;
        }

        /* Card portale con colore dinamico */
        #loginModal .portal-card {
            padding: 14px 16px;
            border-radius: 8px;
            margin-bottom: 20px;
            border-left: 4px solid var(--portal-color, var(--accent-primary));
            background: var(--portal-bg, rgba(76, 175, 80, 0.06));
        }

        #loginModal .portal-label {
            font-size: 0.75em;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.04em;
            color: var(--text-primary);
            opacity: 0.6;
            margin-bottom: 4px;
        }

        #loginModal .portal-name {
            font-size: 1.05em;
            font-weight: 600;
            color: var(--text-primary);
        }

        /* Input */
        #loginModal .input-group {
            margin-bottom: 16px;
        }

        #loginModal .input-label {
            display: block;
            font-size: 0.85em;
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 8px;
        }

        #loginModal .code-input {
            width: 100%;
            padding: 12px 14px;
            border: 2px solid var(--border-color);
            border-radius: 8px;
            font-size: 1em;
            color: var(--text-primary);
            background: var(--bg-primary);
            transition: all 0.2s ease;
        }

        #loginModal .code-input:focus {
            outline: none;
            border-color: var(--portal-color, var(--accent-primary));
            box-shadow: 0 0 0 3px var(--portal-shadow, rgba(76, 175, 80, 0.12));
        }

        #loginModal .code-input::placeholder {
            color: var(--text-primary);
            opacity: 0.4;
        }

        /* Errore */
        #loginModal .login-error {
            display: none;
            padding: 10px 14px;
            background: rgba(229, 57, 53, 0.08);
            border-radius: 6px;
            border-left: 3px solid #e53935;
            color: #c62828;
            font-size: 0.9em;
            margin-bottom: 16px;
        }

        /* Footer */
        #loginModal .login-footer {
            padding: 0 24px 24px;
        }

        #loginModal .btn-login {
            width: 100%;
            padding: 12px 20px;
            border: none;
            border-radius: 8px;
            background: var(--portal-color, var(--accent-primary));
            color: white;
            font-size: 0.95em;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        #loginModal .btn-login:hover {
            filter: brightness(0.9);
            transform: translateY(-1px);
            box-shadow: 0 4px 12px var(--portal-shadow, rgba(76, 175, 80, 0.3));
        }

        #loginModal .btn-login:active {
            transform: translateY(0);
        }

        /* Colori per portale */
        #loginModal.portal-nl {
            --portal-color: #4caf50;
            --portal-bg: rgba(76, 175, 80, 0.06);
            --portal-shadow: rgba(76, 175, 80, 0.25);
        }

        #loginModal.portal-she {
            --portal-color: #3876da;
            --portal-bg: rgba(56, 118, 218, 0.06);
            --portal-shadow: rgba(56, 118, 218, 0.25);
        }

        #loginModal.portal-hp {
            --portal-color: #85200c;
            --portal-bg: rgba(133, 32, 12, 0.06);
            --portal-shadow: rgba(133, 32, 12, 0.25);
        }

        /* Dark mode adjustments */
        [data-theme="dark"] #loginModal .code-input {
            background: rgba(255, 255, 255, 0.05);
            border-color: rgba(255, 255, 255, 0.1);
        }

        [data-theme="dark"] #loginModal .portal-card {
            background: rgba(255, 255, 255, 0.03);
        }

        /* Responsive mobile */
        @media (max-width: 480px) {
            #loginModal .login-panel {
                width: 95vw;
                border-radius: 10px;
            }

            #loginModal .login-header {
                padding: 16px 20px 14px;
            }

            #loginModal .login-body {
                padding: 20px;
            }

            #loginModal .login-footer {
                padding: 0 20px 20px;
            }
        }
        
        .btn-suggestion {
            padding: 8px 16px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 500;
            font-size: 0.9em;
            transition: all 0.2s ease;
        }
        
        .btn-approve {
            background: #4caf50;
            color: white;
        }
        
        .btn-approve:hover {
            background: #45a049;
        }
        
        .btn-dismiss {
            background: #666;
            color: white;
        }
        
        .btn-dismiss:hover {
            background: #555;
        }

/* ========================================
   CUSTOM MODAL SYSTEM
   Sostituisce alert/confirm/prompt nativi
   @version 1.0.0
   @date 2025-12-29
   ======================================== */

/* Dialog base - usa <dialog> HTML5 nativo */
/* FIX CROSS-BROWSER: inset:0 + margin:auto è più robusto di top/left + transform */
.custom-modal {
    border: none;
    border-radius: 16px;
    padding: 0;
    max-width: 420px;
    width: fit-content;
    min-width: min(90%, 320px);
    height: fit-content;
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    animation: modalFadeIn 0.2s ease-out;
    z-index: 10000; /* Sopra tutto! */
    /* Centramento cross-browser robusto */
    position: fixed;
    inset: 0; /* = top:0; right:0; bottom:0; left:0 */
    margin: auto; /* Centra quando inset:0 */
}

.custom-modal[open] {
    display: flex;
    flex-direction: column;
}

.custom-modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: backdropFadeIn 0.2s ease-out;
    z-index: 9999; /* Sotto il modal ma sopra tutto il resto */
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

/* Contenuto modal */
.custom-modal-content {
    padding: 24px;
    text-align: center;
}

.custom-modal-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

.custom-modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.custom-modal-message {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 24px;
}

/* Input per prompt */
.custom-modal-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin-bottom: 24px;
    transition: border-color 0.2s ease;
}

.custom-modal-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Bottoni */
.custom-modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.custom-modal-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
}

.custom-modal-btn-primary {
    background: var(--accent-primary);
    color: white;
}

.custom-modal-btn-primary:hover {
    background: var(--accent-secondary);
    transform: translateY(-1px);
}

.custom-modal-btn-secondary {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.custom-modal-btn-secondary:hover {
    background: var(--border-color);
}

/* Varianti per tipo */
.custom-modal-success .custom-modal-icon { color: #4caf50; }
.custom-modal-error .custom-modal-icon { color: #f44336; }
.custom-modal-warning .custom-modal-icon { color: #ff9800; }
.custom-modal-info .custom-modal-icon { color: #2196f3; }
.custom-modal-confirm .custom-modal-icon { color: #9c27b0; }
.custom-modal-prompt .custom-modal-icon { color: #607d8b; }

/* Bordo superiore colorato per tipo */
.custom-modal-success { border-top: 4px solid #4caf50; }
.custom-modal-error { border-top: 4px solid #f44336; }
.custom-modal-warning { border-top: 4px solid #ff9800; }
.custom-modal-info { border-top: 4px solid #2196f3; }
.custom-modal-confirm { border-top: 4px solid #9c27b0; }
.custom-modal-prompt { border-top: 4px solid #607d8b; }

/* Responsive */
@media (max-width: 480px) {
    .custom-modal {
        max-width: 95%;
        margin: 16px;
    }

    .custom-modal-buttons {
        flex-direction: column;
    }

    .custom-modal-btn {
        width: 100%;
    }
}

/* ========================================
   RESP-006: Modali full-screen su mobile
   ======================================== */
@media (max-width: 768px) {
    /* .modal e .history-modal: overlay generici */
    .modal-content {
        width: 95vw;
        max-width: none;
        max-height: 90vh;
        border-radius: 10px;
    }

    .modal-body {
        overflow-y: auto;
    }

    /* history-modal panel (es. cronologia, magic match) */
    .history-modal .panel {
        width: 95vw;
        max-width: none;
        max-height: 85vh;
        overflow-y: auto;
        border-radius: 10px;
    }

    /* custom-modal (alert/confirm/prompt) */
    .custom-modal {
        width: 95vw;
        max-width: none;
        max-height: 90vh;
        overflow-y: auto;
    }

    .custom-modal-buttons {
        flex-direction: column;
    }

    .custom-modal-btn {
        width: 100%;
        min-height: 44px; /* RESP-007: touch target */
    }

    /* Modal footer bottoni: touch target */
    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-footer .btn {
        min-height: 44px;
        flex: 1;
    }

    /* suggestion-details e magic-match-details: stack su mobile */
    .suggestion-details,
    .magic-match-details {
        grid-template-columns: 1fr;
    }

    /* Login panel: gia' gestito a 480px, rinforziamo a 768px */
    #loginModal .login-panel {
        width: 95vw;
        max-width: none;
    }

    /* pareggio-row: stack su mobile */
    .pareggio-row {
        grid-template-columns: 1fr;
    }
}
