/* --- RESET E IMPOSTAZIONI GLOBALI --- */
:root {
    --sidebar-bg: #1A5F99;
    --main-bg: #F0F2F5;
    --content-bg: #FFFFFF;
    --primary-text: #333;
    --secondary-text: #555;
    --border-color: #DEE2E6;
    --accent-color: #1ABC9C;
    --active-link-bg: #144B7A;
}

body, html {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--main-bg);
    color: var(--primary-text);
    font-size: 16px;
}

* {
    box-sizing: border-box;
}

/* --- STRUTTURA PRINCIPALE --- */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* --- BARRA LATERALE --- */
.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    color: white;
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header h2 {
    text-align: center;
    margin: 0 0 30px 0;
    font-weight: 600;
}

.main-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.main-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    margin-bottom: 8px;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.main-nav a:hover {
    background-color: var(--active-link-bg);
}

.main-nav a.active {
    background-color: #2980B9;
}

.sidebar-controls {
    margin-top: auto;
}

#update-history-btn {
    width: 100%;
    padding: 12px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#update-history-btn:hover {
    background-color: #16A085;
}

/* --- CONTENUTO PRINCIPALE --- */
.main-content {
    flex-grow: 1;
    padding: 24px 30px;
    overflow-x: auto;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

/* Regola aggiornata per il contenitore principale dei controlli */
.header-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 24px; /* Aumenta lo spazio tra i due menu */
    align-items: center;
}
.header-controls .control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-controls label {
    font-weight: 500;
    color: var(--secondary-text);
    white-space: nowrap; /* Evita che il testo vada a capo */
}

.header-controls select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--content-bg);
    width: 200px; /* Imposta una larghezza fissa */
}

.user-actions {
    display: flex;
    gap: 20px;
    font-size: 1.5rem;
    color: var(--secondary-text);
}

#history-container {
    background-color: var(--content-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 24px;
}

#history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

#history-list a {
    display: block;
    padding: 8px 12px;
    text-decoration: none;
    color: var(--primary-text);
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    transition: all 0.2s ease;
}

#history-list a:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

#history-list a.active {
    background-color: var(--sidebar-bg);
    color: white;
    border-color: var(--sidebar-bg);
    font-weight: bold;
}

#analysis-content {
    background-color: var(--content-bg);
    border-radius: 8px;
    padding: 20px;
    border: 1px solid var(--border-color);
}

.analysis-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 20px;
    align-items: flex-start;
}

.grid-item {
    overflow-x: auto;
}

/* Stile per tabelle */
table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85rem;
    white-space: nowrap;
}

th, td {
    border: 1px solid #ddd;
    padding: 8px 10px;
    text-align: center;
}

/* Stile Matrice Base */
.base-matrix-container th {
    background-color: #fffbe0;
    font-weight: bold;
}

/* Stile Tabella Analisi */
.analysis-table-container th {
    background-color: #f7f7f7;
    text-align: left;
    font-weight: bold;
}
.analysis-table-container tr:nth-child(2) td { /* Riga VALORE */
    font-weight: bold;
    color: #000;
}

/* Loader / Spinner */
#loader {
    display: none; /* Nascondi di default */
    justify-content: center;
    padding: 40px;
}
.spinner {
    border: 4px solid rgba(0,0,0,0.1);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border-left-color: var(--sidebar-bg);
    animation: spin 1s ease infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
/* Stile per la griglia dei codici inattivi */
.inactive-codes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 10px;
    padding: 10px;
}

.inactive-code {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    height: 40px;
    font-weight: bold;
}

/* Stile per i messaggi di errore */
.error {
    color: #e74c3c;
    font-size: 1.2rem;
    text-align: center;
    padding: 20px;
}
/* Stili per la pagina di riepilogo codici */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.summary-card {
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background-color: #f8f9fa;
}

.card-code {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--sidebar-bg);
}

.card-counter {
    font-size: 0.9rem;
    color: var(--secondary-text);
}

.card-body {
    padding: 16px;
    flex-grow: 1;
}
.card-body p {
    margin: 0 0 8px 0;
}

.card-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background-color: #f8f9fa;
    font-size: 0.85rem;
}
.card-footer details summary {
    cursor: pointer;
    font-weight: 500;
}
.card-footer ul {
    padding-left: 20px;
    margin-top: 10px;
    max-height: 150px;
    overflow-y: auto;
}
/* Stili specifici per la tabella dei codici regolari */
.table-container table {
    width: 100%; /* La tabella occupa tutto lo spazio disponibile */
    table-layout: fixed; /* Forza il rispetto delle larghezze delle colonne */
}

/* Assegnamo le larghezze alle colonne */
.table-container table th:nth-child(1), /* Colonna "Codice" */
.table-container table td:nth-child(1) {
    width: 10%; 
}

.table-container table th:nth-child(2), /* Colonna "Freq. Totale" o "Posizioni" */
.table-container table td:nth-child(2) {
    width: 60%; /* Diamo molto più spazio a questa colonna */
    word-break: break-word; /* Va a capo se necessario (opzionale) */
    text-align: left; /* Allinea a sinistra per leggibilità */
    padding-left: 15px;
}

.table-container table th:nth-child(3), /* Colonna "Riga Mancante" */
.table-container table td:nth-child(3) {
    width: 15%;
}

/* Per le altre tabelle, se hanno 4 colonne */
.table-container table th:nth-child(4),
.table-container table td:nth-child(4) {
    width: 15%;
}
.inactive-codes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px;
    padding: 10px;
}
.inactive-code {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    height: 45px;
    font-weight: bold;
}
.error {
    color: #e74c3c;
    font-size: 1.2rem;
    text-align: center;
    padding: 20px;
    background-color: #fbe NAI;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
}
/* Stili per evidenziare i codici continui */
.table-container tbody tr.streak-2 { background-color: #f0f9ff; }
.table-container tbody tr.streak-3 { background-color: #e0f2fe; }
.table-container tbody tr.streak-4 { background-color: #bae6fd; }
.table-container tbody tr.streak-5 { background-color: #7dd3fc; font-weight: bold; }
}
/* Stile per il messaggio di benvenuto */
.welcome-message {
    text-align: center;
    padding: 60px 20px;
    background: var(--content-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-top: 2rem;
}

.welcome-message h1 {
    margin-top: 0;
    color: var(--sidebar-bg);
}

.welcome-message p {
    font-size: 1.1rem;
    color: var(--secondary-text);
}


/* Stile per lo scheletro di caricamento */
.skeleton-loader {
    width: 100%;
    height: 350px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e9ecef 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 8px;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.full-history-container {
    display: flex;
    flex-direction: column;
    gap: 2rem; /* Spazio tra i blocchi di analisi */
}
.dashboard-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.dashboard-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.dashboard-card h3 {
    margin: 0;
    padding: 12px 15px;
    font-size: 1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: #f8f9fa;
}

.mini-matrix {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 10px;
    gap: 5px;
}

.mini-matrix-cell {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 35px;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 4px;
    background-color: #e9ecef;
    cursor: pointer;
    transition: transform 0.2s;
}
.mini-matrix-cell:hover {
    transform: scale(1.1);
    background-color: var(--sidebar-bg);
    color: white;
}
/* Sfondo oscurato */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Contenitore della finestra */
.modal-container {
    background-color: #fff;
    padding: 25px;
    border-radius: 8px;
    width: 90%;
    max-width: 1200px; /* Larghezza massima della finestra */
    max-height: 90vh; /* Altezza massima */
    overflow-y: auto;
    position: relative;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}
.modal-overlay.active .modal-container {
    transform: scale(1);
}

/* Header della finestra */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 20px;
}
.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}
.modal-close-btn {
    font-size: 2rem;
    font-weight: bold;
    color: var(--secondary-text);
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    line-height: 1;
}
.modal-close-btn:hover {
    color: var(--primary-text);
}

/* Corpo della finestra */
.modal-body {
    min-height: 200px; /* Altezza minima per mostrare il loader */
}
.sidebar-header a {
    text-decoration: none;
    color: white;
}
/* In fondo a css/style.css */
.table-container tbody tr.highlight-row {
    background-color: #fffbe0; /* Un giallo paglierino chiaro */
    font-weight: bold;
}
/* ======================================================= */
/*                 STILI PER LA FINESTRA MODALE              */
/* ======================================================= */

/* Lo sfondo scuro semi-trasparente */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

/* Il contenitore bianco del pop-up */
.modal-content {
    background-color: #ffffff;
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 80%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    text-align: left;
}

/* Il pulsante di chiusura (la 'X') */
.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    border: none;
    background: none;
    font-size: 2.5rem;
    cursor: pointer;
    color: #888;
}

.modal-close:hover {
    color: #000;
}

.modal-body-content {
    margin-top: 20px;
}
/* Stili per la griglia della Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.dashboard-item {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    background-color: #fff;
}

.dashboard-item h3 {
    margin-top: 0;
    font-size: 1.1rem;
    text-align: center;
}

.dashboard-item small {
    display: block;
    text-align: center;
    margin-bottom: 10px;
    color: #666;
}

/* Stili per le mini-matrici */
.mini-matrix {
    width: 100%;
    border-collapse: collapse;
}

.mini-matrix th, .mini-matrix td {
    text-align: center;
    padding: 4px;
    font-size: 0.85rem;
    min-width: 35px;
}

.mini-matrix th {
    background-color: #f2f2f2;
    font-weight: bold;
}

.mini-matrix tbody th {
    background-color: #fff8e1; /* Giallo chiaro per l'header verticale */
}

.mini-matrix thead th {
     background-color: #e3f2fd; /* Azzurro per l'header orizzontale */
}
.mini-matrix-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* 5 colonne uguali */
    gap: 2px;
}

.mini-matrix-cell {
    padding: 5px;
    text-align: center;
    background-color: #f9f9f9;
    border: 1px solid #eee;
}
/* Stili per la Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.dashboard-item {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    background-color: #fff;
    text-align: center;
}

.dashboard-item h3 {
    margin-top: 0;
}

.mini-matrix-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* 5 colonne */
    gap: 1px;
    margin-top: 10px;
    background-color: #ccc;
    border: 1px solid #ccc;
}

.mini-matrix-cell {
    background-color: #fff;
    padding: 5px;
    font-size: 0.9em;
    text-align: center;
}
.special-view-table .regolare {
    color: green;
    font-weight: bold;
}

.special-view-table .irregolare {
    color: orange;
}
.movimento-verticale { color: #2e86c1; }
.movimento-orizzontale { color: #f39c12; }
.movimento-diagonale { color: #8e44ad; }
.movimento-cavallo { color: #c0392b; font-weight: bold; }
/* Stili per le Statistiche Avanzate */
.stats-grid {
    display: flex;
    gap: 20px;
    justify-content: center;
    text-align: center;
    margin-top: 20px;
}

.stat-card {
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    flex-grow: 1;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: #333;
}

.stat-label {
    font-size: 1rem;
    color: #666;
    margin-top: 5px;
}
/* Stili per Analisi Regolarità */
.progress-bar-container {
    background-color: #e9ecef;
    border-radius: 5px;
    height: 20px;
    width: 100%;
}

.progress-bar {
    background-color: #198754; /* Verde */
    color: white;
    height: 100%;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    font-weight: bold;
    white-space: nowrap;
}
/* Stili per la nuova matrice principale a griglia */
.base-matrix-container-grid {
    display: grid;
    grid-template-columns: auto repeat(5, 1fr); /* 1 colonna per header, 5 per i dati */
    gap: 1px;
    background-color: #ccc;
    border: 1px solid #ccc;
}

.matrix-header-cell, .matrix-cell {
    background-color: #fff;
    text-align: center;
    padding: 8px;
    font-weight: bold;
}

.matrix-header-cell.horizontal {
    background-color: #e3f2fd; /* Azzurro */
}

.matrix-header-cell.vertical {
    background-color: #fff8e1; /* Giallo */
}

.matrix-cell {
    font-weight: normal;
}
.highlight-link {
    background-color: #0d6efd;
    color: white !important;
    border-radius: 5px;
}
.suggestions-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}
.suggestion-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}
.suggested-numbers {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
}
.suggested-number {
    background-color: #e3f2fd;
    border: 1px solid #bbdefb;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
}
.hidden { display: none; }