:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 16px;
    --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    --nav-h: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }

/* Layout admin */
.admin-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
    color: #fff;
    padding: 1.5rem 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    transition: transform .3s;
}
.sidebar-brand {
    padding: 0 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
    margin-bottom: 1rem;
}
.sidebar-brand h2 { font-size: 1.1rem; font-weight: 700; }
.sidebar-brand small { opacity: .7; font-size: .75rem; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1.25rem;
    color: rgba(255,255,255,.85);
    transition: background .2s;
    font-size: .9rem;
}
.sidebar nav a:hover, .sidebar nav a.active {
    background: rgba(255,255,255,.12);
    color: #fff;
}
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 1.5rem;
    min-height: 100vh;
}
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.topbar h1 { font-size: 1.5rem; font-weight: 700; }

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid #e2e8f0;
}
.card-header h3 { font-size: 1rem; font-weight: 600; }

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.stat-card .label { font-size: .8rem; color: var(--text-muted); margin-bottom: .25rem; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-card.success .value { color: var(--success); }
.stat-card.warning .value { color: var(--warning); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .35rem; color: var(--text-muted); }
.form-control {
    width: 100%;
    padding: .65rem .85rem;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: .95rem;
    transition: border-color .2s, box-shadow .2s;
    background: #fff;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .65rem 1.25rem;
    border: none;
    border-radius: 10px;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline {
    background: transparent;
    border: 1px solid #e2e8f0;
    color: var(--text);
}
.btn-sm { padding: .4rem .75rem; font-size: .8rem; }
.btn-block { width: 100%; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th, td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid #f1f5f9; }
th { font-weight: 600; color: var(--text-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
tr:hover td { background: #f8fafc; }

/* Badges */
.badge {
    display: inline-block;
    padding: .25rem .6rem;
    border-radius: 20px;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0e7ff; color: #3730a3; }

/* Auth pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 25px 50px rgba(0,0,0,.2);
}
.auth-card .logo { text-align: center; margin-bottom: 1.5rem; }
.auth-card .logo h1 { font-size: 1.5rem; color: var(--primary); }
.auth-card .logo p { color: var(--text-muted); font-size: .85rem; }

/* Mobile app layout (membre) */
.app-shell {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 1rem);
}
.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: 1.25rem 1rem 2rem;
    border-radius: 0 0 24px 24px;
}
.app-header .greeting { font-size: .85rem; opacity: .9; }
.app-header .name { font-size: 1.35rem; font-weight: 700; }
.app-header .balance {
    margin-top: 1rem;
    background: rgba(255,255,255,.15);
    border-radius: 14px;
    padding: 1rem;
    backdrop-filter: blur(10px);
}
.app-header .balance .amount { font-size: 1.75rem; font-weight: 700; }
.app-body { padding: 1rem; margin-top: -1rem; }

.quick-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .75rem;
    margin-bottom: 1rem;
}
.quick-action {
    background: var(--card);
    border-radius: 14px;
    padding: .85rem .5rem;
    text-align: center;
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: .7rem;
}
.quick-action .icon {
    width: 40px; height: 40px;
    border-radius: 12px;
    background: #eef2ff;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto .4rem;
    font-size: 1.2rem;
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: calc(var(--nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--card);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 20px rgba(0,0,0,.08);
    z-index: 200;
    border-radius: 20px 20px 0 0;
}
.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    color: var(--text-muted);
    font-size: .65rem;
    padding: .5rem;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a .nav-icon { font-size: 1.25rem; }

/* Binary tree */
.tree-container { overflow-x: auto; padding: 1rem 0; }
.tree-node {
    text-align: center;
    display: inline-block;
    min-width: 100px;
}
.tree-node .avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto .35rem;
    font-weight: 700;
    font-size: .85rem;
}
.tree-node .name { font-size: .75rem; font-weight: 600; }
.tree-node .code { font-size: .65rem; color: var(--text-muted); }
.tree-level { display: flex; justify-content: center; gap: 2rem; margin: 1.5rem 0; }
.tree-empty {
    width: 48px; height: 48px;
    border-radius: 50%;
    border: 2px dashed #cbd5e1;
    display: flex; align-items: center; justify-content: center;
    color: #94a3b8;
    font-size: .7rem;
    margin: 0 auto;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 1rem; right: 1rem;
    z-index: 9999;
}
.toast {
    padding: .85rem 1.25rem;
    border-radius: 10px;
    color: #fff;
    margin-bottom: .5rem;
    animation: slideIn .3s ease;
    box-shadow: var(--shadow);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Menu toggle mobile admin */
.menu-toggle { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; }

/* Responsive */
/* === RESPONSIVE MEMBRE & GLOBAL === */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 1rem; }
    .menu-toggle { display: block; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .65rem; }
    .auth-card { padding: 1.5rem 1.25rem; border-radius: 16px; }
    .app-body { padding: .85rem; }
    .card { padding: 1rem; border-radius: 12px; }
    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
        gap: .5rem;
    }
    .quick-action { font-size: .65rem; padding: .75rem .4rem; }
    .quick-action .icon {
        width: 36px;
        height: 36px;
    }
    .bottom-nav a { font-size: .6rem; }
    .app-header .name { font-size: 1.15rem; }
    .app-header .balance .amount { font-size: 1.5rem; }
}

@media (max-width: 380px) {
    .quick-actions { grid-template-columns: repeat(2, 1fr); }
    .bottom-nav a span:not(.nav-icon) { font-size: .55rem; }
    .stats-grid { grid-template-columns: 1fr; }
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
}
.overlay.show { display: block; }

.hidden { display: none !important; }

/* Bootstrap Icons */
.bi { display: inline-block; vertical-align: -0.125em; line-height: 1; }
.bottom-nav .nav-icon .bi { font-size: 1.2rem; }
.quick-action .icon .bi { font-size: 1.45rem; color: var(--primary); }
.menu-toggle .bi { font-size: 1.35rem; color: #334155; }
.btn-ico .bi { font-size: 1rem; }
.modal-close .bi { font-size: 1.1rem; }

/* Bouton actualiser (espace membre) */
.membre-refresh-btn {
    position: fixed;
    top: .65rem;
    right: .65rem;
    z-index: 180;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .95);
    color: var(--primary);
    box-shadow: 0 2px 12px rgba(15, 23, 42, .12);
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
}
.membre-refresh-btn .bi { font-size: 1.1rem; transition: transform .35s ease; }
.membre-refresh-btn:hover { box-shadow: 0 4px 16px rgba(99, 102, 241, .25); }
.membre-refresh-btn:hover .bi { transform: rotate(-30deg); }
.membre-refresh-btn.is-refreshing .bi { animation: refresh-spin .6s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
