/* =================================
   Variables globales et reset
   ================================= */
:root {
    --primary-color: #007bff;
    --secondary-color: #00c4e9;
    --background-color: #f8f9fa;
    --white: #fff;
    --text-color: #212529;
    --border-color: #dee2e6;
    --success-color: #28a745;
    --error-color: #dc3545;
    --red-counter: #dc3545;
    --numero-a-color: #007bff;  /* Bleu */
    --numero-b-color: #28a745;  /* Vert */
    --numero-e-color: #dc3545;  /* Rouge */
    --numero-c-color: #6f42c1;  /* Violet */
    --numero-d-color: #fd7e14;  /* Orange */
    --numero-commun-ae: #FFA500; /* Orange */
    --numero-commun-be: #FF69B4; /* Rose */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-full: 50%;
}

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

/* =================================
   Styles de base
   ================================= */
body {
    font-family: Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.5;
}

header {
    background-color: #343a40;
    color: var(--white);
    padding: 1rem;
    text-align: center;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
}

h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

h3 {
    color: var(--text-color);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

/* =================================
   Tableaux initiaux et d'affinage
   ================================= */
.tableaux-container, .affinage-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.tableau-pair {
    display: flex;
    gap: 2rem;
}

.tableau {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    flex: 1;
}

.instructions {
    color: var(--primary-color);
    font-weight: bold;
    margin-bottom: 1rem;
}

.decompte {
    margin-bottom: 1rem;
}

.reste {
    color: var(--red-counter);
    font-weight: bold;
}

/* Grille de sélection */
.grille-container {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 0.4rem;
    margin-bottom: 1.5rem;
}

.grille-container .numero {
    aspect-ratio: 1;
    width: 100%;
    min-width: 35px;
    max-width: 45px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    background-color: var(--white);
    color: var(--text-color);
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease-in-out;
    user-select: none;
}

.grille-container .numero:hover:not(:disabled) {
    transform: scale(1.05);
}

/* Styles des numéros sélectionnés par tableau */
#tableau-a .numero.selected {
    background-color: var(--numero-a-color);
    color: var(--white);
}

#tableau-b .numero.selected {
    background-color: var(--numero-b-color);
    color: var(--white);
}

#tableau-e .numero.selected {
    background-color: var(--numero-e-color);
    color: var(--white);
}

#tableau-c .numero.selected {
    background-color: var(--numero-c-color);
    color: var(--white);
}

#tableau-d .numero.selected {
    background-color: var(--numero-d-color);
    color: var(--white);
}

/* Animation d'erreur */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.error-shake {
    animation: shake 0.3s ease-in-out;
}

/* =================================
   Page de génération
   ================================= */
.generation-container {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.generation-header h2 {
    margin-bottom: 1.5rem;
}

.generation-settings {
    margin-top: 2rem;
}

.setting-group {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
}

.setting-group label {
    flex: 0 0 300px;
    font-weight: 500;
}

.setting-group select {
    width: 250px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--white);
    font-size: 0.9rem;
}

/* =================================
   Page des résultats
   ================================= */
.resultats-container {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.resultats-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    justify-content: space-between;
    flex-wrap: wrap;
}

.info-pages {
    font-size: 1rem;
    font-weight: bold;
    color: var(--primary-color);
}

.resultats-controls {
    display: flex;
    gap: 0.5rem;
}

.pagination-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Rappel des sélections */
.rappel-selections {
    background: var(--background-color);
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.rappel-selections div {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.numeros {
    font-family: monospace;
    font-size: 1em;
    letter-spacing: 0.05em;
}

/* Grille des résultats */
.resultats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.4rem;
    margin: 1rem 0;
}

.resultat-item {
    background: var(--background-color);
    padding: 0.35rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.85rem;
}

.numero-combinaison {
    font-weight: bold;
    white-space: nowrap;
    min-width: 2.5rem;
}

.numeros-container {
    display: flex;
    gap: 0.2rem;
    flex-wrap: wrap;
}

/* Style des numéros dans les résultats */
.resultat-item .numero {
    font-family: monospace;
    font-weight: bold;
    padding: 0.15rem 0.3rem;
    border-radius: 3px;
    min-width: 1.8rem;
    text-align: center;
    color: var(--white);
}

.resultat-item .numero-a {
    background-color: var(--numero-a-color);
}

.resultat-item .numero-b {
    background-color: var(--numero-b-color);
}

.resultat-item .numero-e {
    background-color: var(--numero-e-color);
}

.resultat-item .numero-commun-ae {
    background-color: var(--numero-commun-ae);
}

.resultat-item .numero-commun-be {
    background-color: var(--numero-commun-be);
}

/* =================================
   Page d'affinage
   ================================= */
.affinage-container {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.affinage-header {
    margin-bottom: 1.5rem;
}

.nb-combinaisons {
    color: var(--primary-color);
    font-weight: bold;
    margin-top: 0.5rem;
}

.affinage-settings {
    margin: 2rem 0;
    padding: 1rem;
    background: var(--background-color);
    border-radius: var(--radius-sm);
}

.contrainte-group {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
}

.contrainte-group label {
    flex: 0 0 250px;
    font-weight: 500;
}

.contrainte-group select {
    width: 200px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--white);
    font-size: 0.9rem;
}

.affinage-controls {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* =================================
   Composants communs
   ================================= */
.btn-control {
    background-color: var(--secondary-color);
    color: var(--white);
    border: none;
    padding: 0.4rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    min-width: 100px;
    font-size: 0.9rem;
    transition: all 0.2s ease-in-out;
}

.btn-control:hover:not(:disabled) {
    background-color: var(--primary-color);
    transform: translateY(-1px);
}

.btn-control:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    opacity: 0.7;
}

.page-info {
    padding: 0.4rem 0.8rem;
    background: var(--background-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

/* Messages d'erreur */
.message-erreur {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
}

.error-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--white);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    min-width: 300px;
}

.error-content.error {
    border-left: 4px solid var(--error-color);
}

.error-content.success {
    border-left: 4px solid var(--success-color);
}

.error-icon {
    font-size: 1.2rem;
}

.error-text {
    flex: 1;
    font-size: 0.9rem;
}

.error-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: #666;
}

/* Barre de progression */
.progress-container {
    margin: 1rem 0;
    padding: 1rem;
    background-color: var(--background-color);
    border-radius: var(--radius-md);
    text-align: center;
}

.progress-label {
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.progress-bar-container {
    height: 20px;
    background-color: #e9ecef;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin: 0.5rem 0;
}

.progress-bar {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.3s ease-in-out;
}

.progress-percent {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Info-bulles */
.label-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.info-bulle {
    display: none;
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    white-space: nowrap;
    margin-left: 0.5rem;
    z-index: 1000;
}

.label-container:hover .info-bulle {
    display: block;
}

/* Animations */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* =================================
   Media Queries
   ================================= */
@media (max-width: 1400px) {
    .resultats-grid {
        grid-template-columns: repeat(5, minmax(100px, 1fr));
    }
}

@media (max-width: 1200px) {
    .resultats-grid {
        grid-template-columns: repeat(4, minmax(100px, 1fr));
    }
    
    .setting-group, .contrainte-group {
        flex-direction: column;
        align-items: flex-start;
    }

    .setting-group label, .contrainte-group label {
        flex: none;
        margin-bottom: 0.5rem;
    }

    .setting-group select, .contrainte-group select {
        width: 100%;
    }
}

@media (max-width: 992px) {
    .resultats-grid {
        grid-template-columns: repeat(3, minmax(100px, 1fr));
    }

    .tableau-pair {
        flex-direction: column;
        gap: 1rem;
    }

    .resultats-header {
        flex-direction: column;
        align-items: stretch;
    }

    .resultats-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .btn-control {
        flex: 1;
    }
}

@media (max-width: 768px) {
    .resultats-grid {
        grid-template-columns: repeat(2, minmax(100px, 1fr));
    }

    .grille-container {
        grid-template-columns: repeat(5, 1fr);
    }

    .rappel-selections {
        font-size: 0.8rem;
    }

    .numeros {
        word-break: break-all;
    }
}

@media (max-width: 576px) {
    .resultats-grid {
        grid-template-columns: 1fr;
    }

    .grille-container {
        grid-template-columns: repeat(5, 1fr);
    }

    .message-erreur {
        width: 90%;
        right: 5%;
        top: 10px;
    }

    .btn-control {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .pagination-container {
        width: 100%;
        justify-content: space-between;
    }

    main {
        padding: 0 0.5rem;
    }
}

/* Accessibilité */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Mode sombre */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1a1a1a;
        --white: #2d2d2d;
        --text-color: #e0e0e0;
        --border-color: #404040;
    }
    
    .grille-container .numero:not(.selected) {
        background-color: #2d2d2d;
        color: #e0e0e0;
    }

    .btn-control:disabled {
        background-color: #404040;
    }
}