body {
    font-family: Arial, sans-serif;
    background: #f9f9f9;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

.logo {
    max-width: 320px;
    width: 80%;
    height: auto;
    transition: max-width 0.5s ease-in-out; /* Animation douce sur 0.5s */
}

.logo.logo-reduit {
    max-width: 160px; /* 50% de la taille initiale */
}

.subtitle {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 400;
    font-size: 1.3rem;
    color: #666;
    margin-top: 5px;
    margin-bottom: 20px;
    text-align: center;
}

input {
    padding: 10px;
    margin: 5px;
    border-radius: 8px;
    border: 1px solid #ccc;
    font-size: 16px;
    box-sizing: border-box;
    width: 90%;
    max-width: 300px;
    font-family: 'Barlow Condensed', sans-serif;
}

#resultat table {
    border-collapse: collapse;
    background: white;
    /* La largeur est maintenant naturelle et non plus fixe */
    table-layout: auto; 
    margin: 0;
    width: 100%; /* La table prend la largeur de son parent direct #resultat */
}

td {
    text-align: center;
    font-family: 'Patrick Hand', cursive;
    font-size: clamp(16px, 4vw, 32px);
    padding: clamp(8px, 2vw, 16px);
    border: 1px solid #eee;
    height: clamp(40px, 6vw, 60px);
    white-space: nowrap;
}

.total {
    background-color: #d4edda;
}

.border-bottom td {
    border-bottom: 2px solid black;
}

.error-message {
    color: #D8000C;
    font-size: 0.9rem;
    font-family: sans-serif;
    height: 1.2em;
}

#url-error-message {
    background-color: #fffbe6;
    border: 1px solid #ffe58f;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: sans-serif;
    margin-bottom: 15px;
    max-width: 500px;
    text-align: center;
}

.error-example {
    font-family: 'Courier New', Courier, monospace;
    color: #555;
    font-style: italic;
    display: inline-block;
    margin-top: 5px;
}

#resultat {
    margin-bottom: 50px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.5s ease-out;
}

/* === STYLES DE CALCUL === */

.zero-padding {
    color: #ccc;
}

/* Méthode par Cassage */
.chiffre-barre {
    color: #dc3545;
    position: relative;
    display: inline-block;
    margin-right: 0.3em;
}

.chiffre-barre::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -10%;
    width: 120%;
    height: 1.5px;
    background-color: currentColor;
    transform: rotate(-20deg);
}

.cascade-container {
    position: relative;
    display: inline-block;
    margin-right: 0.2em;
}

.cascade-container::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -10%;
    width: 120%;
    height: 1.5px;
    background-color: #dc3545;
    transform: rotate(-20deg);
}

.cascade-intermediate-1 {
    font-size: 0.8em;
    color: orange;
    vertical-align: baseline;
}

.cascade-intermediate-0 {
    color: #dc3545; /* Rouge */
    vertical-align: baseline;
}

.chiffre-nouveau {
    color: #007bff;
    font-weight: bold;
}

.chiffre-emprunt {
    font-family: 'Patrick Hand', cursive;
    color: #007bff;
    font-size: 0.8em;
    vertical-align: baseline;
    margin-right: 0;
}

/* Méthode par Compensation */
.retenue-compensation-haut {
    font-family: 'Patrick Hand', cursive;
    color: #c200ff;
    font-size: 0.8em;
    vertical-align: baseline;
    margin-right: 0;
}

.retenue-compensation-bas {
    font-family: 'Micro 5', sans-serif;
    font-size: 0.9em;
    vertical-align: middle;
    margin-left: 0.2em;
}

/* === MISE EN PAGE PRINCIPALE (Mobile First) === */

.input-container {
    display: flex;
    flex-direction: column; /* Mobile default */
    align-items: center;
    width: 100%;
    gap: 5px;
}

.multiplier-x {
    font-family: 'Barlow Condensed', sans-serif;
    color: #aaa;
    font-size: 2rem;
    margin: 0 10px;
}

.actions-container {
    display: flex;
    flex-direction: column; /* Mobile par défaut: label au-dessus */
    align-items: center;
    margin-top: 20px;
    gap: 10px;
    border: none;
}

.actions-label {
    color: #28a745;
    font-weight: bold;
    font-size: 1.1rem;
    font-family: 'Barlow Condensed', sans-serif;
}

.method-buttons {
    display: flex;
    flex-direction: column; /* Mobile par défaut: boutons en colonne */
    width: 90%;
    max-width: 300px;
    gap: 10px;
}

.method-btn {
    background-color: white;
    border: 1px solid #e0e0e0;
    color: #333;
    border-radius: 8px;
    padding: 10px 15px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Barlow Condensed', sans-serif;
}

.method-btn:hover {
    border-color: #ccc;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.method-btn.active {
    background-color: #4caf7d; /* Vert pour l'état actif */
    color: white;
    border-color: #3b8a62; /* Vert plus foncé pour la bordure */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* === RÈGLES POUR GRAND ÉCRAN (Desktop) === */
/* Doit être à la fin pour surcharger les styles mobile-first */
@media (min-width: 600px) {
    .input-container {
        flex-direction: row;
        justify-content: center;
    }
    .actions-container {
        flex-direction: row; /* Aligne le label et le bloc de boutons */
    }
    .actions-label {
        margin-bottom: 0;
        margin-right: 15px;
    }
    .method-buttons {
        flex-direction: row; /* Aligne les boutons entre eux */
        width: auto;
        max-width: none;
    }
    input {
        width: auto;
    }
}

/* Style pour la virgule décimale */
.virgule {
    font-weight: bold;
    /* Réduire la largeur et le padding pour une colonne très fine */
    padding: 0 !important;
    width: 0.4em !important;

    /* Enlever les bordures non nécessaires */
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;

    vertical-align: bottom;
    background-color: #de8a001a;
}

/* === MISE EN PAGE DU RESULTAT SCROLLABLE === */

/* Conteneur principal (Mobile-first: pleine largeur par défaut) */
#resultat-container {
    width: 100%;
    margin: 20px 0 50px 0; /* Marges top/bottom */
    transition: width 0.3s ease-in-out, max-width 0.3s ease-in-out;
}

/* Conteneur pour le défilement */
#scroll-container {
    overflow-x: auto;
    overflow-y: hidden;
    direction: rtl;
    -webkit-overflow-scrolling: touch;
}

/* Rétablir la direction pour le contenu et gérer l'affichage */
#scroll-container #resultat {
    direction: ltr;
    display: inline-block;
    min-width: 100%;
}

/* Styles pour la barre de défilement */
#scroll-container::-webkit-scrollbar {
  height: 10px;
}
#scroll-container::-webkit-scrollbar-track {
  background-color: #e0e0e0;
  border-radius: 10px;
}
#scroll-container::-webkit-scrollbar-thumb {
  background-color: #4CAF50;
  border-radius: 10px;
  border: 2px solid #e0e0e0;
}
#scroll-container::-webkit-scrollbar-thumb:hover {
  background-color: #45a049;
}
#scroll-container {
  scrollbar-width: thin;
  scrollbar-color: #4CAF50 #e0e0e0;
}

/* === MEDIA QUERY POUR LE RESULTAT SUR GRAND ECRAN === */
@media (min-width: 820px) {
    /* Pour les petits calculs, on centre et on contraint */
    #resultat-container {
        width: 90%;
        max-width: 800px;
        margin: 20px auto 50px auto; /* Centrage horizontal */
    }

    /* Si le calcul est grand, on force la pleine largeur */
    #resultat-container.is-overflowing {
        width: 100%;
        max-width: none;
    }
}
