:root {
    --grc-primary: #0d6efd;
    --grc-vert: #28a745;
    --grc-rouge: #dc3545;
    --grc-orange: #fd7e14;
    --grc-gris: #6c757d;

    /* Sidebar */
    --sb-width: 240px;
    --sb-width-sm: 70px;
    --sb-bg: #0f172a;
    --sb-text: rgba(255,255,255,0.82);
    --sb-text-muted: rgba(255,255,255,0.35);
    --sb-active: #0d6efd;
    --sb-hover: rgba(255,255,255,0.07);
    --sb-border: rgba(255,255,255,0.07);
    --topbar-h: 56px;
    --sb-transition: 0.25s ease;
}

/* ============ LAYOUT ============ */
body { background: #f5f6fa; overflow-x: hidden; }

#appPage { display: flex; min-height: 100vh; }

/* ============ SIDEBAR ============ */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: var(--sb-width);
    background: var(--sb-bg);
    display: flex;
    flex-direction: column;
    transition: width var(--sb-transition);
    z-index: 1040;
    overflow: hidden;
    flex-shrink: 0;
}
.sidebar.collapsed { width: var(--sb-width-sm); }

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px 0 16px;
    height: 64px;
    border-bottom: 1px solid var(--sb-border);
    flex-shrink: 0;
    gap: 8px;
}
.sidebar-brand-link { flex: 1; overflow: hidden; display: flex; align-items: center; }
.sidebar-logo {
    max-height: 38px;
    max-width: 155px;
    object-fit: contain;
    transition: max-width var(--sb-transition), opacity var(--sb-transition);
}
.sidebar.collapsed .sidebar-logo { max-width: 0; opacity: 0; }

.sidebar-toggle {
    background: none; border: none;
    color: var(--sb-text);
    width: 28px; height: 28px;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0;
    opacity: 0.55;
    transition: opacity 0.15s, background 0.15s, transform var(--sb-transition);
}
.sidebar-toggle:hover { opacity: 1; background: var(--sb-hover); }
.sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }

/* Nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto; overflow-x: hidden;
    padding: 6px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.sidebar-section { margin-bottom: 2px; }

.sidebar-section-label {
    display: block;
    font-size: 0.62rem; font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--sb-text-muted);
    padding: 14px 20px 3px;
    white-space: nowrap;
    transition: opacity var(--sb-transition), max-height var(--sb-transition), padding var(--sb-transition);
    max-height: 40px; overflow: hidden;
}
.sidebar.collapsed .sidebar-section-label { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; }

.sidebar-link {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 20px;
    color: var(--sb-text);
    text-decoration: none;
    font-size: 0.86rem;
    white-space: nowrap;
    border: none; background: none;
    cursor: pointer; width: 100%; text-align: left;
    position: relative;
    transition: background var(--sb-transition), color var(--sb-transition), padding var(--sb-transition);
}
.sidebar-link i {
    font-size: 1.1rem; width: 22px; text-align: center;
    flex-shrink: 0;
    transition: width var(--sb-transition), font-size var(--sb-transition);
}
.sidebar-link span {
    transition: opacity var(--sb-transition); overflow: hidden;
}
.sidebar-link:hover { background: var(--sb-hover); color: #fff; }
.sidebar-link.active {
    background: var(--sb-active); color: #fff; font-weight: 600;
}
.sidebar-link.active::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0;
    width: 3px; background: rgba(255,255,255,0.55); border-radius: 0 2px 2px 0;
}

/* Collapsed: icône centrée, texte invisible */
.sidebar.collapsed .sidebar-link { padding: 11px 0; justify-content: center; gap: 0; }
.sidebar.collapsed .sidebar-link span { opacity: 0; width: 0; }
.sidebar.collapsed .sidebar-link i { font-size: 1.2rem; width: auto; }

/* Sidebar footer */
.sidebar-footer {
    border-top: 1px solid var(--sb-border);
    padding: 6px 0 6px;
    flex-shrink: 0;
}
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 20px;
    color: var(--sb-text-muted);
    font-size: 0.78rem; white-space: nowrap; overflow: hidden;
    transition: padding var(--sb-transition);
}
.sidebar-user i { font-size: 1.05rem; width: 22px; text-align: center; flex-shrink: 0; }
.sidebar-user span { overflow: hidden; text-overflow: ellipsis; transition: opacity var(--sb-transition); }
.sidebar.collapsed .sidebar-user { padding: 7px 0; justify-content: center; }
.sidebar.collapsed .sidebar-user span { opacity: 0; width: 0; }

.sidebar-logout { color: rgba(255,110,110,0.75) !important; }
.sidebar-logout:hover { background: rgba(220,53,69,0.14) !important; color: #ff7b7b !important; }

/* ============ MAIN WRAPPER ============ */
.main-wrapper {
    margin-left: var(--sb-width);
    display: flex; flex-direction: column;
    min-height: 100vh; flex: 1; min-width: 0;
    transition: margin-left var(--sb-transition);
}
.sidebar.collapsed ~ .main-wrapper { margin-left: var(--sb-width-sm); }

/* Topbar */
.topbar {
    position: sticky; top: 0;
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    display: flex; align-items: center;
    padding: 0 1.5rem; gap: 1rem;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.topbar-btn {
    background: none; border: none; color: #374151;
    padding: 4px 8px; border-radius: 6px; cursor: pointer;
}
.topbar-btn:hover { background: #f3f4f6; }
.topbar-page-title { font-weight: 600; font-size: 1rem; color: #1e293b; flex: 1; }

/* Main content */
.main-content { flex: 1; padding: 1.5rem; }
.main-footer { padding: 1rem 1.5rem; }

/* Overlay mobile */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.45); z-index: 1039;
    pointer-events: none;
}
.sidebar-overlay.active { display: block; pointer-events: auto; }

/* ============ MOBILE ============ */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sb-width) !important;
        transition: transform var(--sb-transition);
    }
    .sidebar.mobile-open { transform: translateX(0); }
    .sidebar-toggle { display: none; }
    .main-wrapper { margin-left: 0 !important; }
}

.navbar-brand { font-weight: 700; }

.card-stat {
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: transform 0.2s;
}
.card-stat:hover { transform: translateY(-2px); }

.card-stat .card-body { padding: 1.25rem; }
.card-stat .stat-value { font-size: 2rem; font-weight: 700; }
.card-stat .stat-label { font-size: 0.85rem; color: #6c757d; }
.card-stat .stat-icon { font-size: 2.5rem; opacity: 0.3; }

.badge-vert { background: var(--grc-vert); }
.badge-rouge { background: var(--grc-rouge); }
.badge-orange { background: var(--grc-orange); }
.badge-gris { background: var(--grc-gris); }

.table th { background: #f8f9fa; font-weight: 600; font-size: 0.85rem; text-transform: uppercase; }

#mapContainer { height: 70vh; border-radius: 8px; overflow: hidden; }
#mapAvaries { height: 70vh; border-radius: 8px; overflow: hidden; }

.passage-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin: 0 2px;
}
.passage-dot.vert { background: var(--grc-vert); }
.passage-dot.rouge { background: var(--grc-rouge); }
.passage-dot.gris { background: var(--grc-gris); }

.freq-display {
    font-family: monospace;
    font-size: 0.9rem;
}
.freq-display span {
    display: inline-block;
    width: 22px;
    text-align: center;
    border: 1px solid #dee2e6;
    border-radius: 3px;
    margin: 0 1px;
    padding: 1px 0;
}
.freq-display span.active { background: var(--grc-primary); color: #fff; border-color: var(--grc-primary); }

.nav-link.active { font-weight: 600; }

.leaflet-popup-content { min-width: 200px; }
.leaflet-popup-content h6 { margin-bottom: 5px; font-size: 0.9rem; }
.leaflet-popup-content .info-line { font-size: 0.8rem; color: #555; margin-bottom: 2px; }

.etat-actif { color: var(--grc-vert); font-weight: 600; }
.etat-avarie { color: var(--grc-orange); font-weight: 600; }
.etat-retiree { color: var(--grc-gris); font-weight: 600; }

.loading { text-align: center; padding: 3rem; }
.loading .spinner-border { width: 3rem; height: 3rem; }

@media (max-width: 768px) {
    .card-stat .stat-value { font-size: 1.5rem; }
    #mapContainer, #mapAvaries { height: 50vh; }
}
