/**
 * Cash Point Madagascar — Responsive (mobile, tablette, desktop)
 * Compatible Android, iPhone, iPad, tablettes
 */

:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --bottom-nav-h: 64px;
    --touch-min: 44px;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    overscroll-behavior-y: contain;
}

.btn, .form-control, .tab, .bottom-nav-item, .nav-item a, .sidebar-toggle {
    min-height: var(--touch-min);
}

.btn-lg-touch { min-height: 48px; padding: 0.75rem 1.5rem; font-size: 1rem; }

.form-control {
    font-size: 16px;
    padding: 0.75rem;
    border-radius: 10px;
}

.form-control-search { min-width: 0; width: 100%; max-width: 220px; }

.fab {
    display: none;
    position: fixed;
    right: 1rem;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 1rem);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 20px rgba(13, 110, 253, 0.45);
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    z-index: 900;
    text-decoration: none;
}

.fab:active { transform: scale(0.95); }

.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: #fff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    z-index: 950;
    justify-content: space-around;
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.65rem;
    font-weight: 500;
    padding: 0.35rem 0.15rem;
}

.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-icon { font-size: 1.35rem; }

.show-mobile-only { display: none; }
.hide-mobile-table { display: block; }
.hide-mobile { display: inline-flex; }

.mobile-cards { display: flex; flex-direction: column; gap: 0.75rem; }

.mobile-card {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid var(--border);
}

.mobile-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.mobile-card-header strong { display: block; }
.info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.mobile-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.mini-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.mini-avatar.lg { width: 44px; height: 44px; }

.cell-user { display: flex; align-items: center; gap: 0.5rem; }

.badge-role-admin { background: #cfe2ff; color: #084298; }
.badge-role-superviseur { background: #fff3cd; color: #664d03; }
.badge-role-employe { background: #e2e3e5; color: #41464b; }
.badge-statut-actif { background: #d1e7dd; color: #0f5132; }
.badge-statut-inactif { background: #e2e3e5; color: #41464b; }
.badge-statut-suspendu { background: #f8d7da; color: #842029; }

.card-header-wrap { flex-wrap: wrap; gap: 0.75rem; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.search-form { flex: 1; min-width: 140px; }

.form-card { max-width: 720px; margin: 0 auto; }
.form-section { margin-bottom: 1.5rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.form-section-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 1rem;
    font-weight: 600;
}

.checkbox-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    background: #f0f7ff;
    border-radius: 10px;
    border: 1px solid #b6d4fe;
    cursor: pointer;
    margin-bottom: 1rem;
}

.nav-link-accent {
    background: rgba(13, 110, 253, 0.2) !important;
    border-radius: 8px;
    margin: 0 0.75rem;
}

.nav-link-sidebar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
}

@media (max-width: 1024px) {
    .main-content { padding: 1.25rem 1.5rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .comptes-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar-toggle {
        display: flex;
        top: calc(0.75rem + var(--safe-top));
    }

    .sidebar {
        width: min(280px, 85vw);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
        padding-top: var(--safe-top);
    }

    .sidebar.open { transform: translateX(0); }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }

    .sidebar-overlay.show { display: block; }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: calc(3.5rem + var(--safe-top));
        padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 1.5rem);
    }

    .topbar { flex-direction: row; flex-wrap: wrap; position: relative; }
    .topbar-title { padding-left: 2.75rem; flex: 1; }

    .user-info {
        position: absolute;
        top: 0;
        right: 0;
    }

    .hide-mobile { display: none !important; }
    .show-mobile-only { display: flex; }
    .hide-mobile-table { display: none !important; }

    .bottom-nav { display: flex; }
    .fab { display: flex; }

    .card { border-radius: 14px; }
    .header-actions { width: 100%; }
    .form-control-search { max-width: none; }

    .stats-grid { grid-template-columns: 1fr 1fr; }
    .comptes-grid { grid-template-columns: 1fr; }

    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .tab { flex-shrink: 0; white-space: nowrap; }

    .btn-group { flex-direction: column; }
    .btn-group .btn { width: 100%; justify-content: center; }

    .form-actions-sticky {
        position: sticky;
        bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
        background: var(--bg);
        padding: 0.75rem 0;
        z-index: 10;
    }

    .grid-2, .grid-tx { grid-template-columns: 1fr; }

    .login-card { margin: 1rem; padding: 1.5rem; }
}

@media (max-width: 380px) {
    .stats-grid { grid-template-columns: 1fr; }
    .mobile-card-actions { grid-template-columns: 1fr; }
}

@media (min-width: 769px) {
    .bottom-nav { display: none !important; }
    .fab { display: none !important; }
    .show-mobile-only-fab { display: none !important; }
}

@media (max-width: 768px) {
    .show-mobile-only-fab { display: flex !important; }
}

.chart-wrap { height: 260px; position: relative; }
.chart-wrap-pie { height: 280px; }

.alert-chip {
    display: inline-block;
    background: rgba(0,0,0,0.06);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin: 0.15rem;
    font-size: 0.85rem;
}

.filter-bar { align-items: end; margin-bottom: 0; }
.form-actions-inline { display: flex; gap: 0.5rem; flex-wrap: wrap; align-self: end; }

.employes-rapport-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
}

.employe-rapport-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.9rem;
}

.employe-rapport-link:hover { background: #e9ecef; text-decoration: none; }

.profile-info {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.agence-switcher {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.agence-switch-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.agence-switch-form label { font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
.agence-switch-form select { max-width: 280px; flex: 1; min-width: 160px; }

@media (max-width: 768px) {
    .agence-switch-form { flex-direction: column; align-items: stretch; }
    .agence-switch-form select { max-width: none; }
}
