* {
    box-sizing: border-box;
}

:root {
    --primary: #003366;
    /* Rotary Royal Blue */
    --accent: #D4AF37;
    /* Gold */
    --bg-light: #f4f7f6;
    --text-main: #333;
    --white: #ffffff;
    --sidebar-bg: #002244;
    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --glass: rgba(255, 255, 255, 0.7);
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-content {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: 1rem;
}

.feature-card {
    background: white;
    padding: 2rem;
    border-radius: 20px;
    box-shadow: var(--card-shadow);
    border: 1px solid #f0f0f0;
}

.feature-icon {
    width: 48px;
    height: 48px;
    background: rgba(0, 51, 102, 0.1);
    color: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-light);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--primary);
    color: white;
    padding: 2rem 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
    box-sizing: border-box;
    overflow-y: auto;
    /* Ensure sidebar is scrollable if items exceed height */
}

.sidebar-header {
    margin-bottom: 3rem;
    text-align: center;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    color: var(--accent);
    letter-spacing: 1px;
}

.nav-item {
    padding: 0.8rem 1.2rem;
    margin-bottom: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-item:hover,
.nav-item.active {
    background-color: rgba(212, 175, 55, 0.2);
    color: var(--accent);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    margin-left: 260px;
    width: calc(100% - 260px);
    /* Prevent horizontal overflow */
    box-sizing: border-box;
}

/* Responsive adjustments for Modal - No scrollbar focus */
#modal-edit>div {
    max-height: 98vh;
    width: 600px;
    overflow-y: visible;
    padding: 1.5rem;
    /* Slightly reduced padding */
}

#modal-edit .form-group {
    margin-bottom: 0.8rem;
    /* Much more compact */
}

#modal-edit hr {
    margin: 1rem 0;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.page-title h1 {
    font-size: 1.8rem;
    margin: 0;
    color: var(--primary);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.card {
    background-color: var(--white);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    transition: transform 0.3s;
}

.card:hover {
    transform: translateY(-5px);
}

.card h3 {
    font-size: 0.9rem;
    color: #666;
    margin: 0 0 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.card .trend {
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.trend.up {
    color: var(--success);
}

.trend.down {
    color: var(--danger);
}

/* Table */
.data-table-container {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    overflow-x: auto;
    /* Handle table width on smaller screens */
    width: 100%;
    box-sizing: border-box;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
    /* Minimum width to keep structure legible */
    margin-top: 1rem;
}

th {
    text-align: left;
    padding: 1rem;
    color: #666;
    font-weight: 600;
    border-bottom: 2px solid #eee;
}

td {
    padding: 1rem;
    border-bottom: 1px solid #f0f0f0;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-paid {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-partial {
    background: #fff3e0;
    color: #ef6c00;
}

.status-unpaid {
    background: #ffebee;
    color: #c62828;
}

.badge-guest {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    background: #e3f2fd;
    color: #1976d2;
    margin-left: 8px;
    font-weight: 600;
}

.guest-info {
    font-size: 0.75rem;
    color: #666;
    display: block;
}

/* Mobile View Mockup (Attendance) */
.mobile-mockup {
    max-width: 375px;
    height: 600px;
    background: #fff;
    border: 8px solid #333;
    border-radius: 32px;
    margin: 0 auto;
    overflow: hidden;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.mobile-header {
    background: var(--primary);
    color: white;
    padding: 1rem;
    text-align: center;
}

.attendance-list {
    padding: 1rem;
}

.attendance-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    margin-bottom: 0.8rem;
    background: #fdfdfd;
    border: 1px solid #eee;
    border-radius: 12px;
    transition: all 0.2s;
    cursor: pointer;
}

.attendance-item.present {
    border-color: var(--primary);
    background: rgba(0, 51, 102, 0.03);
}

.attendance-item.present .status-icon {
    color: var(--success);
}

.member-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.member-name {
    font-weight: 600;
    color: var(--primary);
    font-size: 0.95rem;
}

.attendance-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.counter-group {
    display: flex;
    align-items: center;
    background: #f0f0f0;
    border-radius: 20px;
    padding: 4px;
}

.counter-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary);
    font-weight: bold;
}

.counter-value {
    min-width: 25px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
}

.guest-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #888;
    margin-right: 4px;
    font-weight: 600;
}

/* Login Page Styles */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary) 0%, #001a33 100%);
    display: none;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.login-overlay.active {
    display: flex;
}

.login-card {
    background: white;
    padding: 3rem;
    border-radius: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.login-logo {
    width: 80px;
    height: 80px;
    background: var(--accent);
    color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
}

.form-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 0.5rem;
}

.form-input {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: 10px;
    border: 1px solid #ddd;
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
    background-color: #fff;
    display: block;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.2em;
    padding-right: 3rem;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

.login-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    font-size: 0.85rem;
}

.login-options a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

/* Member Portal Specifics */
.member-only {
    border-left: 4px solid var(--accent);
}

.action-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: #f0f0f0;
    color: var(--primary);
    cursor: pointer;
    transition: var(--transition);
}

.action-icon:hover {
    background: var(--primary);
    color: white;
}

/* Utils */
.btn {
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: #004488;
    box-shadow: 0 4px 12px rgba(0, 51, 102, 0.2);
}

.btn-secondary {
    background: #f0f0f0;
    color: #666;
}

.btn-secondary:hover {
    background: #e5e5e5;
}

.btn-accent {
    background: var(--accent);
    color: var(--primary);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #bd2130;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.2);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Specific fix for dashboard if needed */
.main-content .grid-2 {
    grid-template-columns: 2fr 1fr;
}

#modal-edit .grid-2 {
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* --- MOBILE RESPONSIVENESS --- */
.mobile-nav-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--primary);
    color: white;
    padding: 0 1.5rem;
    align-items: center;
    justify-content: space-between;
    z-index: 1001;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.menu-toggle {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media screen and (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        position: fixed;
        padding-top: 70px;
        left: 0;
        top: 0;
        z-index: 1500;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1rem;
        padding-top: 72px;
        box-sizing: border-box;
    }

    .mobile-nav-bar {
        display: flex;
    }

    /* ===== HEADER ===== */
    header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
        margin-bottom: 1.25rem !important;
    }

    .page-title h1 {
        font-size: 1.35rem !important;
    }

    .page-title p {
        font-size: 0.82rem;
        margin: 2px 0 0 0;
    }

    /* Boutons dans le header : pleine largeur */
    header>div:last-child,
    header>button {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    header .btn {
        flex: 1;
        min-width: 120px;
        justify-content: center;
        font-size: 0.85rem;
        padding: 0.6rem 0.75rem;
    }

    /* ===== GRILLES & STATS ===== */
    .grid-2,
    .main-content .grid-2,
    #modal-edit .grid-2,
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }

    .stats-grid {
        margin-bottom: 1.25rem !important;
    }

    .card {
        padding: 1rem !important;
    }

    .card h3 {
        font-size: 0.75rem !important;
        margin-bottom: 4px !important;
    }

    .card .value {
        font-size: 1.5rem !important;
    }

    /* ===== TABLEAUX ===== */
    .data-table-container {
        padding: 0.75rem !important;
        width: 100%;
        border-radius: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 480px;
        font-size: 0.82rem;
    }

    th,
    td {
        padding: 0.6rem 0.5rem !important;
    }

    .hide-mobile {
        display: none !important;
    }

    /* ===== MODALES : bottom-sheet sur mobile ===== */
    .modal-overlay,
    .modal,
    #modal-edit,
    #payMod,
    #feesMod,
    #manMod,
    #actionModal,
    #fluxModal,
    #modal-role,
    #modal-tarif,
    #modal-banque {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    .modal-box,
    #payMod .modal-box,
    #feesMod .modal-box {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }

    #modal-edit>div {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 95vh !important;
        overflow-y: auto !important;
    }

    #modal-role>.card,
    #modal-tarif>.card,
    #modal-banque>.card {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        margin: 0 !important;
    }

    /* ===== ONGLETS (TABS) ===== */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        gap: 0 !important;
        padding-bottom: 2px;
    }

    .tab-btn {
        white-space: nowrap;
        padding: 8px 14px !important;
        font-size: 0.82rem !important;
    }

    /* ===== QUARTER HEADERS (facturation) ===== */
    .quarter-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 4px !important;
        font-size: 0.88rem !important;
        padding: 10px 12px !important;
    }

    /* ===== ACTION CARDS (actions.php) ===== */
    .action-card {
        padding: 1rem !important;
    }

    .action-card>div:first-child {
        flex-direction: column !important;
        gap: 0.75rem !important;
        align-items: flex-start !important;
    }

    .action-card>div:first-child>div:last-child {
        width: 100%;
        flex-wrap: wrap;
    }

    /* ===== FORMULAIRES ===== */
    .form-input {
        font-size: 1rem;
        padding: 0.7rem 0.9rem;
    }

    /* ===== BOUTONS D'ACTION ===== */
    .action-icon {
        width: 38px;
        height: 38px;
        border-radius: 8px;
    }

    /* ===== DASHBOARD : photo profil ===== */
    .user-profile>div:last-child {
        width: 70px !important;
        height: 70px !important;
        font-size: 1.6rem !important;
    }

    /* ===== PAGE CONNEXION ===== */
    .login-card {
        padding: 2rem 1.5rem !important;
        border-radius: 16px !important;
        margin: 1rem;
        width: calc(100% - 2rem) !important;
    }

    /* ===== SETTINGS : onglets ===== */
    #btn-roles,
    #btn-tarifs,
    #btn-banques {
        font-size: 0.8rem !important;
        padding: 0.6rem 0 !important;
    }
}