/* ============================================================
   0. CONFIGURATION & VARIABLES (DARK THEME PRO)
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');

:root {
    /* Palette Sombre Profonde */
    --bg-deep: #0b0e14;       /* Fond quasi noir */
    --bg-card: rgba(21, 27, 40, 0.7); /* Verre sombre */
    --bg-hover: rgba(30, 38, 56, 0.9);
    
    /* Accents Néons */
    --accent-primary: #00f2ff; /* Cyan Cyberpunk */
    --accent-secondary: #7000ff; /* Violet Profond */
    --accent-success: #00ff9d;
    --accent-danger: #ff2a6d;
    
    /* Typographie */
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    
    /* Effets */
    --glass-border: 1px solid rgba(255, 255, 255, 0.08);
    --shadow-glow: 0 0 20px rgba(0, 242, 255, 0.15);
    --radius: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-deep);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Fond animé subtil */
    background-image: 
        radial-gradient(circle at 15% 15%, rgba(112, 0, 255, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(0, 242, 255, 0.08) 0%, transparent 40%);
    background-attachment: fixed;
}

/* ============================================================
   1. LAYOUT & CONTAINERS (GLASSMORPHISM)
   ============================================================ */
.main-wrapper {
    width: 100%;
    max-width: 1000px; /* Plus compact et pro */
    min-height: 700px;
    background: var(--bg-card);
    backdrop-filter: blur(20px); /* Effet verre flouté */
    -webkit-backdrop-filter: blur(20px);
    border: var(--glass-border);
    border-radius: var(--radius);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    margin: 40px;
    position: relative;
    overflow: hidden;
    animation: slideUp 0.6s ease-out forwards;
}

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

/* Header Spécifique (Logo Gauche / Logout Droite) */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 40px;
    border-bottom: var(--glass-border);
    background: rgba(11, 14, 20, 0.5);
}

.logo-icon {
    font-weight: 800;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 1.5rem;
}

/* ============================================================
   2. ÉLÉMENTS UI (BOUTONS, LIENS, FORMULAIRES)
   ============================================================ */
a { text-decoration: none; color: inherit; transition: var(--transition); }
h1, h2, h3 { font-weight: 700; color: var(--text-main); margin-top: 0; }

/* Boutons Primaires (Glow effect) */
.btn-primary, button[type="submit"] {
    background: linear-gradient(135deg, var(--accent-secondary) 0%, #5a1cd6 100%);
    color: white;
    padding: 12px 30px;
    border-radius: 50px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(112, 0, 255, 0.3);
    position: relative;
    overflow: hidden;
}

.btn-primary:hover, button[type="submit"]:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 25px rgba(112, 0, 255, 0.5);
}

/* ============================================================
   FIX : BOUTONS PAGE BIENVENUE (Se connecter / S'inscrire)
   ============================================================ */

/* Style de base pour les deux boutons */
.welcome-container a {
    display: inline-block;
    padding: 15px 35px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 1rem;
    margin: 10px;
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-decoration: none;
}

/* 1. Bouton "Se connecter" (Style Plein / Violet) */
/* Cible le premier lien du conteneur */
.welcome-container a:first-child {
    background: linear-gradient(135deg, var(--accent-secondary) 0%, #5a1cd6 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(112, 0, 255, 0.3);
    border: 2px solid transparent; /* Pour éviter le décalage avec l'autre bouton */
}

.welcome-container a:first-child:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(112, 0, 255, 0.5);
    color: white;
}

/* 2. Bouton "Créer un compte" (Style Contour / Cyan) */
/* Cible le deuxième lien */
.welcome-container a:last-child {
    background: transparent;
    border: 2px solid var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.1);
}

.welcome-container a:last-child:hover {
    background: var(--accent-primary);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.4);
    transform: translateY(-3px);
}

/* Boutons Secondaires (Outline) */
.btn-secondary, .btn-logout {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--text-muted);
    padding: 8px 20px;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
}

.btn-secondary:hover, .btn-logout:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(0, 242, 255, 0.05);
}

.btn-logout:hover {
    border-color: var(--accent-danger);
    color: var(--accent-danger);
    background: rgba(255, 42, 109, 0.05);
}

/* Formulaires High-Tech */
input, select, .form-control {
    width: 100%;
    padding: 14px;
    margin: 8px 0 24px 0;
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    box-sizing: border-box;
    transition: var(--transition);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 242, 255, 0.1);
    background: rgba(0,0,0,0.4);
}

label {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Alerts */
.alert { padding: 15px; border-radius: 8px; margin-bottom: 20px; font-size: 0.9rem; }
.alert-danger { background: rgba(255, 42, 109, 0.1); border: 1px solid rgba(255, 42, 109, 0.3); color: #ff8fa3; }
.alert-success { background: rgba(0, 255, 157, 0.1); border: 1px solid rgba(0, 255, 157, 0.3); color: #7affc8; }

/* ============================================================
   3. PAGE : DASHBOARD & GROUPES (Cards animées)
   ============================================================ */
.groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
    padding: 40px;
}

.group-card {
    background: rgba(255,255,255,0.03);
    border: var(--glass-border);
    border-radius: var(--radius);
    padding: 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    height: 140px;
    position: relative;
    transition: var(--transition);
}

.group-card h3 { margin: 0 0 10px 0; font-size: 1.4rem; }

/* Animation Hover Carte */
.group-card:hover {
    background: rgba(255,255,255,0.06);
    transform: translateY(-5px);
    border-color: var(--accent-primary);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

/* Carte "Créer" Spéciale */
a[href*="create_group"].group-card {
    border: 1px dashed var(--text-muted);
}
a[href*="create_group"].group-card:hover {
    border-color: var(--accent-primary);
    border-style: solid;
}

/* ============================================================
   4. PAGE : DÉPENSES (Liste Clean)
   ============================================================ */
.expense-list-container {
    background: rgba(0,0,0,0.2);
    margin: 0 40px 30px 40px;
    border-radius: var(--radius);
    overflow: hidden;
}

.expense-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: var(--transition);
    cursor: default;
}

.expense-item:last-child { border-bottom: none; }

.expense-item:hover {
    background: rgba(255,255,255,0.05);
    padding-left: 35px; /* Petit effet de glissement */
}

.expense-item p:nth-child(1) { color: var(--text-muted); font-size: 0.85rem; width: 60px; } /* Date */
.expense-item p:nth-child(2) { color: var(--text-main); font-weight: 600; flex: 1; font-size: 1.1rem; } /* Titre */
.expense-item p:nth-child(3) { color: var(--accent-success); font-weight: 700; font-size: 1.1rem; margin-right: 20px; text-shadow: 0 0 10px rgba(0,255,157,0.3); } /* Prix */
.expense-item p:nth-child(4) { 
    background: rgba(255,255,255,0.1); 
    padding: 4px 12px; 
    border-radius: 12px; 
    font-size: 0.75rem; 
    color: var(--text-muted);
}

/* ============================================================
   5. PAGE : REMBOURSEMENTS (Transaction Flow)
   ============================================================ */
.reimbursement-container { padding: 40px; }

.transaction-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.transaction-card {
    background: rgba(255,255,255,0.03);
    border: var(--glass-border);
    padding: 20px;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: fadeIn 0.5s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.debtor strong, .creditor strong { color: var(--text-main); font-size: 1.1rem; }
.amount-arrow { color: var(--text-muted); display: flex; flex-direction: column; align-items: center; }
.amount { color: var(--accent-primary); font-weight: bold; font-size: 1.2rem; }
.arrow { color: var(--text-muted); font-size: 1.5rem; }

.btn-pay {
    background: transparent;
    border: 1px solid var(--accent-success);
    color: var(--accent-success);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-pay:hover {
    background: var(--accent-success);
    color: #000;
    box-shadow: 0 0 15px rgba(0, 255, 157, 0.4);
}

/* ============================================================
   6. LOGIN / REGISTER / AUTH
   ============================================================ */
.auth-container, .welcome-container {
    padding: 60px 40px;
    text-align: center;
    max-width: 400px;
    margin: 0 auto;
}

.auth-links {
    color: var(--accent-primary);
    margin-top: 20px;
    display: inline-block;
    font-size: 0.9rem;
}
.auth-links:hover {
    text-decoration: underline;
    text-shadow: 0 0 8px var(--accent-primary);
}

/* ============================================================
   CUSTOM SELECT (Menu déroulant High-Tech)
   ============================================================ */

/* 1. On cible spécifiquement les selects */
select {
    /* Désactive le style moche par défaut du navigateur (gris/biseauté) */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    
    /* On reprend le style "Verre" de tes inputs */
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border-radius: 8px;
    padding: 14px 45px 14px 15px; /* Padding droit plus grand pour laisser place à la flèche */
    font-size: 1rem;
    cursor: pointer;
    
    /* 2. On injecte une flèche personnalisée (SVG encodé) */
    /* C'est une petite flèche Cyan (#00f2ff) pour aller avec ton thème */
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2300f2ff%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 15px top 50%; /* Positionnée à droite et centrée verticalement */
    background-size: 12px auto; /* Taille de la flèche */
    transition: var(--transition);
}

select:hover {
    border-color: var(--accent-primary);
    background-color: rgba(0, 0, 0, 0.5);
}

select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.2); 
}

select option {
    background-color: #0b0e14; 
    color: #fff;
    padding: 10px;
}

select option:disabled {
    color: var(--text-muted);
    font-style: italic;
}

/* Nouveau style pour le bouton "Équilibre" */
.btn-outline {
    background: transparent !important;
    border: 2px solid var(--accent-primary) !important;
    color: var(--accent-primary) !important;
    box-shadow: none !important;
}

.btn-outline:hover {
    background: var(--accent-primary) !important;
    color: #000 !important; /* Texte noir sur fond cyan */
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.4) !important;
}


/* ============================================================
   ETAPE 1 : TABLETTES & ÉCRANS MOYENS (Entre 769px et 1024px)
   ============================================================ */
@media screen and (max-width: 1024px) {

    /* 1. La fenêtre principale s'élargit */
    .main-wrapper {
        width: 95%;      /* On utilise presque toute la largeur */
        margin: 20px auto;
        min-height: auto; /* La hauteur s'adapte au contenu */
    }

    /* 2. Grille des groupes : On passe de 3 à 2 colonnes */
    .groups-grid {
        grid-template-columns: repeat(2, 1fr); /* 2 cartes par ligne */
        gap: 20px;
        padding: 30px;
    }

    /* 3. Les listes de dépenses */
    .expense-list-container {
        margin: 0 20px 20px 20px; /* Marges réduites sur les côtés */
    }
    
    /* 4. Les formulaires (Login / Register / Add Expense) */
    .auth-container, .add-expense-container, .form-card {
        max-width: 80%; /* Le formulaire prend plus de place */
        padding: 40px 20px;
    }

    /* 5. Remboursements : On garde l'alignement mais on réduit l'espace */
    .transaction-card {
        padding: 15px;
        gap: 10px;
    }
    .amount { font-size: 1rem; }
    .arrow { font-size: 1.2rem; }
}


/* ============================================================
   ETAPE 2 : TÉLÉPHONES & MOBILES (Moins de 768px)
   ============================================================ */
@media screen and (max-width: 768px) {

    /* 1. Transformation en "App Native" (Plein écran) */
    body {
        background-image: none; /* On retire les blobs de fond pour la perf */
        background-color: var(--bg-deep);
        align-items: flex-start; /* On colle tout en haut */
        padding: 0;
    }

    .main-wrapper {
        width: 100%;
        margin: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background: transparent; /* On enlève l'effet carte global */
    }

    .reimbursement-container > div:first-child {
        display: flex;
        flex-direction: column !important; /* Force l'empilement vertical */
        align-items: center !important;    /* Centre les éléments */
        gap: 15px;                         /* Espace entre le titre et le bouton */
        margin-bottom: 30px !important;    /* Un peu plus d'espace sous le tout */
    }

    /* On ajuste la taille du titre pour qu'il ne soit pas agressif */
    .reimbursement-container h2 {
        font-size: 1.6rem;
        margin: 0;
        text-align: center;
    }

    /* On s'assure que le bouton "Retour" prend toute la largeur et est centré */
    .reimbursement-container a.btn-secondary {
        width: 100%;
        text-align: center;
        margin: 0; /* Enlève les marges latérales */
        padding: 10px;
    }

    /* 2. Header Mobile Compact */
    .app-header {
        padding: 15px 20px;
        background: rgba(11, 14, 20, 0.95); /* Fond plus opaque */
        position: sticky;
        top: 0;
        z-index: 100;
        backdrop-filter: blur(10px);
    }

    .logo-icon { font-size: 1.2rem; }
    
    .btn-logout {
        padding: 6px 12px;
        font-size: 0.75rem;
    }

    /* 3. Grille des Groupes : 1 seule colonne */
    .groups-grid {
        grid-template-columns: 1fr; /* Une seule carte par ligne */
        padding: 20px;
        gap: 15px;
    }

    .group-card {
        height: auto; /* Hauteur flexible */
        padding: 25px;
        background: rgba(255,255,255,0.05); /* Plus visible sur mobile */
    }

    /* 4. Liste des Dépenses : Transformation radicale en "Cartes" */
    .expense-item {
        flex-direction: column; /* On empile les éléments */
        align-items: flex-start; /* Tout aligné à gauche */
        position: relative;
        background: rgba(30, 38, 56, 0.4);
        margin-bottom: 12px;
        border-radius: 12px;
        border: 1px solid rgba(255,255,255,0.05);
        padding: 15px;
    }

    /* On cache le petit effet de glissement desktop qui gêne sur mobile */
    .expense-item:hover {
        padding-left: 15px; 
        background: rgba(30, 38, 56, 0.4);
    }

    .expense-item p:nth-child(1) { /* Date */
        font-size: 0.75rem;
        margin-bottom: 4px;
        opacity: 0.7;
    }

    .expense-item p:nth-child(2) { /* Titre */
        font-size: 1.1rem;
        margin-bottom: 25px; /* Espace pour le "payé par" */
        width: 100%;
    }

    /* DANS responsive.css (Section Mobile) */

    .expense-item p:nth-child(3) { /* Le Montant */
        position: absolute;
        right: 15px;               /* Reste collé à droite */
        
        /* La formule magique pour centrer verticalement : */
        top: 50%;                  /* On place le haut de l'élément au milieu du conteneur */
        transform: translateY(-50%); /* On le remonte de 50% de sa propre hauteur pour le centrer parfaitement */
        
        margin: 0;
        font-size: 1.2rem;
        font-weight: bold;
        color: var(--accent-success); /* On s'assure qu'il garde sa couleur verte */
    }

    .expense-item p:nth-child(4) { /* Payé par */
        position: absolute;
        bottom: 15px;
        left: 15px;
        background: transparent;
        padding: 0;
        font-size: 0.8rem;
        color: var(--accent-primary);
    }
    
    /* 5. Remboursements : Flux vertical */
    .transaction-list {
        gap: 20px;
    }

    .transaction-card {
        flex-direction: column; /* Vertical */
        text-align: center;
        background: rgba(255,255,255,0.03);
    }

    .amount-arrow {
        flex-direction: row; /* La flèche et le montant restent côte à côte ou empilés */
        margin: 15px 0;
        gap: 10px;
    }

    .arrow {
        transform: rotate(90deg); /* La flèche pointe vers le bas */
        font-size: 1.5rem;
    }

    /* 6. Formulaires et Inputs */
    .auth-container, .reimbursement-container {
        padding: 20px;
        width: 100%;
        box-sizing: border-box;
    }
    
    h1 { font-size: 1.8rem; }
    
    /* Empêche le zoom auto sur iPhone quand on clique sur un input */
    input, select, .btn-primary {
        font-size: 16px !important; 
    }
    
    /* Boutons pleine largeur pour le pouce */
    .btn-primary, button[type="submit"] {
        width: 100%;
        display: block;
        margin-top: 10px;
    }
    
    /* Adaptation des boutons "Retour" */
    .btn-secondary {
        width: 100%;
        display: block;
        text-align: center;
        margin-bottom: 15px;
        box-sizing: border-box;
    }
    /* À mettre DANS le media query @media screen and (max-width: 768px) */

    /* Cible les boutons dans la page de dépenses */
    .btn-primary, .btn-secondary, a[href*="reimbursement"] {
        width: 100% !important;       /* Pleine largeur */
        box-sizing: border-box;       /* Padding inclus */
        white-space: normal !important; /* AUTORISE le texte à passer à la ligne */
        height: auto !important;      /* La hauteur s'adapte au texte (2 lignes si besoin) */
        padding: 12px 15px;           /* Padding confortable */
        line-height: 1.3;             /* Espacement des lignes de texte */
        display: block;               /* Se comporte comme un bloc */
        text-align: center;
        margin-bottom: 10px;
    }

    /* Retouche spécifique pour le bouton "Ajouter une dépense" en bas */
    div[style*="text-align:center"] > .btn-primary {
        margin-top: 20px;
        width: 100%;
    }

    /* À mettre DANS le media query @media screen and (max-width: 768px) */

    /* Force les champs à respecter la largeur du téléphone */
    input, select, .form-control {
        width: 100% !important; /* Force la largeur à 100% du parent */
        max-width: 100vw;       /* Sécurité : ne dépasse jamais la largeur d'écran */
        box-sizing: border-box; /* Inclut le padding dans le calcul de la largeur */
        font-size: 16px !important; /* Taille lisible sur mobile */
        margin-right: 0;
    }

    /* Correction spécifique pour le conteneur des selects */
    form {
        width: 100%;
        overflow-x: hidden; /* Empêche le débordement horizontal */
    }
}
