:root {
    --primary:   #1a3a6b;
    --primary-d: #122950;
    --accent:    #f0a500;
    --light-bg:  #f4f6fb;
    --sidebar-w: 280px;
}

/* ── Login ──────────────────────────────────────────────────── */
body.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, #2d5fa3 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Segoe UI', sans-serif;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    width: 420px;
    padding: 48px 40px;
}

.login-logo {
    width: 72px;
    height: 72px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.login-logo svg { color: var(--accent); }

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: .85rem;
    color: #6c757d;
    text-align: center;
    margin-bottom: 32px;
}

.form-label { font-weight: 600; color: #374151; font-size: .875rem; }

.form-control {
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: .95rem;
    transition: border-color .2s, box-shadow .2s;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,58,107,.15);
}

.btn-primary-custom {
    background: var(--primary);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-weight: 600;
    padding: 12px;
    width: 100%;
    font-size: 1rem;
    cursor: pointer;
    transition: background .2s, transform .1s;
}

.btn-primary-custom:hover  { background: var(--primary-d); }
.btn-primary-custom:active { transform: scale(.98); }

.alert-danger-custom {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: .875rem;
    margin-bottom: 20px;
}

/* ── Dashboard layout ───────────────────────────────────────── */
body.dash-page {
    font-family: 'Segoe UI', sans-serif;
    background: var(--light-bg);
    margin: 0;
}

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    padding: 28px 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}

.sidebar-header .app-name {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: .5px;
    color: var(--accent);
}

.sidebar-header .app-sub {
    font-size: .75rem;
    opacity: .7;
    margin-top: 2px;
}

.sidebar-user {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}

.sidebar-user .user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    margin-bottom: 10px;
}

.sidebar-user .user-name  { font-weight: 600; font-size: .9rem; }
.sidebar-user .user-role  { font-size: .75rem; opacity: .7; }
.sidebar-user .user-bureau{ font-size: .72rem; opacity: .6; margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 16px 0; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 24px;
    color: rgba(255,255,255,.8);
    text-decoration: none;
    font-size: .9rem;
    transition: background .15s, color .15s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,.12);
    color: #fff;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,.12);
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: rgba(255,255,255,.1);
    border: none;
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: .875rem;
    cursor: pointer;
    transition: background .2s;
    text-decoration: none;
}

.btn-logout:hover { background: rgba(255,255,255,.2); color:#fff; }

/* ── Main content ───────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title { font-size: 1.25rem; font-weight: 700; color: var(--primary); }
.topbar-date  { font-size: .8rem; color: #6c757d; }

.page-body { padding: 32px; }

/* ── Stats cards ────────────────────────────────────────────── */
.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon.blue   { background: #eff6ff; color: #2563eb; }
.stat-icon.amber  { background: #fffbeb; color: #d97706; }
.stat-icon.green  { background: #f0fdf4; color: #16a34a; }

.stat-value { font-size: 1.8rem; font-weight: 700; color: #111827; }
.stat-label { font-size: .8rem; color: #6c757d; margin-top: 2px; }

/* ── Table card ─────────────────────────────────────────────── */
.table-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
    overflow: hidden;
}

.table-card-header {
    padding: 20px 24px;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.table-card-title { font-weight: 700; color: #111827; font-size: 1rem; }

.search-box {
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: .875rem;
    width: 260px;
    transition: border-color .2s;
}

.search-box:focus { outline: none; border-color: var(--primary); }

.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table thead th {
    background: #f9fafb;
    padding: 12px 20px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}

.data-table tbody tr { transition: background .1s; }
.data-table tbody tr:hover { background: #f9fafb; }
.data-table tbody td {
    padding: 12px 20px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
}

.badge-profil {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: .75rem;
    font-weight: 600;
}

.badge-admin   { background: #eff6ff; color: #1d4ed8; }
.badge-superadmin { background: #fdf4ff; color: #7e22ce; }
.badge-perc    { background: #f0fdf4; color: #15803d; }
.badge-chef    { background: #fffbeb; color: #b45309; }
.badge-directeur { background: #fff7ed; color: #c2410c; }
.badge-dg      { background: #f0f9ff; color: #0369a1; }

.table-footer {
    padding: 14px 20px;
    color: #6c757d;
    font-size: .8rem;
    border-top: 1px solid #f3f4f6;
}

/* ── Stats grid ─────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-icon.red { background: #fef2f2; color: #dc2626; }

/* ── Filter bar ─────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.filter-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.filter-btn {
    padding: 7px 16px;
    border: 1.5px solid #d1d5db;
    border-radius: 100px;
    background: #fff;
    font-size: .8rem;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}

.filter-btn:hover  { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Count badge ────────────────────────────────────────────── */
.count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 22px;
    padding: 0 7px;
    background: var(--primary);
    color: #fff;
    border-radius: 100px;
    font-size: .72rem;
    font-weight: 700;
    margin-left: 8px;
    vertical-align: middle;
}

/* ── Statut badges ──────────────────────────────────────────── */
.badge-statut {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .3px;
    white-space: nowrap;
}

.badge-ouvert  { background: #f0fdf4; color: #15803d; }
.badge-ferme   { background: #fef2f2; color: #991b1b; }
.badge-reouvert{ background: #fffbeb; color: #b45309; }

/* ── Nature & modalité badges ──────────────────────────────── */
.badge-nature, .badge-modalite {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    background: #f3f4f6;
    color: #374151;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}

/* ── Action buttons (tableau établissements) ────────────────── */
.action-btns { display: flex; gap: 6px; flex-wrap: nowrap; }

.btn-action {
    padding: 5px 11px;
    border: none;
    border-radius: 6px;
    font-size: .75rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s, transform .1s;
    white-space: nowrap;
}
.btn-action:hover  { opacity: .85; }
.btn-action:active { transform: scale(.96); }

.btn-details  { background: #eff6ff; color: #1d4ed8; }
.btn-pay      { background: #f0fdf4; color: #15803d; }
.btn-history  { background: #fffbeb; color: #b45309; }

/* ── Modal overlay ──────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 900;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn .15s ease;
}
.modal-overlay.open { display: flex; }

@keyframes fadeIn { from { opacity:0 } to { opacity:1 } }

.modal-box {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity:0 } to { transform: translateY(0); opacity:1 } }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #f3f4f6;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--primary); }
.modal-close {
    width: 32px; height: 32px;
    border-radius: 8px; border: none;
    background: #f3f4f6; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; color: #6c757d;
    transition: background .15s;
}
.modal-close:hover { background: #e5e7eb; color: #111827; }

.modal-body { padding: 20px 24px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid #f3f4f6;
}

/* ── Detail grid ────────────────────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.detail-item { display: flex; flex-direction: column; gap: 3px; }
.detail-label { font-size: .72rem; font-weight: 700; color: #9ca3af; text-transform: uppercase; letter-spacing: .4px; }
.detail-value { font-size: .9rem; color: #111827; font-weight: 500; }
.detail-full  { grid-column: 1 / -1; }

/* ── Solde bar ──────────────────────────────────────────────── */
.solde-bar-wrap { background: #f3f4f6; border-radius: 8px; height: 10px; overflow: hidden; margin-top: 6px; }
.solde-bar-fill { height: 100%; border-radius: 8px; background: linear-gradient(90deg,#16a34a,#4ade80); }

/* ── Historique table ───────────────────────────────────────── */
.hist-table { width: 100%; border-collapse: collapse; font-size: .82rem; margin-top: 12px; }
.hist-table th { background: #f9fafb; padding: 9px 12px; text-align: left; font-weight: 700; color: #374151; border-bottom: 2px solid #e5e7eb; }
.hist-table td { padding: 9px 12px; border-bottom: 1px solid #f3f4f6; color: #374151; }
.hist-table tr:last-child td { border: none; }
.hist-table .quittance { font-family: monospace; font-size: .78rem; color: #6366f1; }

/* ── Formulaire paiement ────────────────────────────────────── */
.pay-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: .8rem; font-weight: 700; color: #374151; }
.form-group input { border: 1.5px solid #d1d5db; border-radius: 8px; padding: 9px 13px; font-size: .9rem; }
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,58,107,.12); }
.form-group .hint { font-size: .72rem; color: #9ca3af; margin-top: 2px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.btn-primary-modal {
    background: var(--primary); color: #fff; border: none;
    border-radius: 8px; padding: 10px 22px; font-weight: 600;
    font-size: .9rem; cursor: pointer; transition: background .15s;
}
.btn-primary-modal:hover    { background: var(--primary-d); }
.btn-primary-modal:disabled { opacity: .6; cursor: not-allowed; }
.btn-cancel {
    background: #f3f4f6; color: #374151; border: none;
    border-radius: 8px; padding: 10px 18px; font-weight: 600;
    font-size: .9rem; cursor: pointer;
}
.btn-cancel:hover { background: #e5e7eb; }

.alert-success-modal { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; border-radius: 8px; padding: 12px 16px; font-size: .87rem; font-weight: 600; }
.alert-error-modal   { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 8px; padding: 12px 16px; font-size: .87rem; }

/* ── Notification bell (sidebar) ─────────────────────────────── */
.notif-bell-btn {
    position: relative;
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 11px 24px;
    background: none; border: none; cursor: pointer;
    color: rgba(255,255,255,.8); font-size: .9rem;
    transition: background .15s, color .15s;
    text-align: left;
}
.notif-bell-btn:hover { background: rgba(255,255,255,.12); color:#fff; }

.notif-badge {
    position: absolute; top: 6px; left: 34px;
    min-width: 18px; height: 18px;
    background: #dc2626; color: #fff;
    border-radius: 100px; font-size: .65rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px; border: 2px solid var(--primary);
    pointer-events: none;
}

/* ── Notification drawer ─────────────────────────────────────── */
.notif-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.3); z-index: 700;
    animation: nfadeIn .15s ease;
}
.notif-overlay.open { display: block; }
@keyframes nfadeIn { from { opacity:0 } to { opacity:1 } }

.notif-drawer {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 380px; max-width: 100vw;
    background: #fff; z-index: 750;
    display: flex; flex-direction: column;
    box-shadow: -4px 0 24px rgba(0,0,0,.15);
    transform: translateX(100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.notif-drawer.open { transform: translateX(0); }

.notif-drawer-head {
    background: var(--primary); color: #fff;
    padding: 18px 20px;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.notif-drawer-head h3 { margin: 0; font-size: .95rem; font-weight: 700; }
.notif-drawer-head .nd-actions { display: flex; gap: 8px; }
.nd-btn {
    background: rgba(255,255,255,.15); border: none; color: #fff;
    padding: 5px 12px; border-radius: 6px; font-size: .75rem;
    font-weight: 600; cursor: pointer; transition: background .15s;
    white-space: nowrap;
}
.nd-btn:hover { background: rgba(255,255,255,.28); }
.nd-close {
    background: rgba(255,255,255,.15); border: none; color: #fff;
    width: 30px; height: 30px; border-radius: 8px; font-size: 1rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background .15s;
}
.nd-close:hover { background: rgba(255,255,255,.3); }

.notif-list {
    flex: 1; overflow-y: auto;
    padding: 8px 0;
}

.notif-item {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 13px 18px; border-bottom: 1px solid #f3f4f6;
    transition: background .1s; position: relative;
}
.notif-item:hover { background: #f9fafb; }
.notif-item.unread { background: #eff6ff; }
.notif-item.unread:hover { background: #dbeafe; }

.notif-icon {
    width: 38px; height: 38px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; flex-shrink: 0; margin-top: 1px;
}
.ni-paiement    { background: #f0fdf4; }
.ni-echeance    { background: #fffbeb; }
.ni-statut_ferme{ background: #fef2f2; }
.ni-statut_ouvert{ background: #f0fdf4; }
.ni-solde_solde { background: #eff6ff; }
.ni-system      { background: #f3f4f6; }

.notif-content { flex: 1; min-width: 0; }
.notif-title   { font-size: .84rem; font-weight: 700; color: #111827; margin-bottom: 3px; line-height: 1.3; }
.notif-msg     { font-size: .76rem; color: #6c757d; line-height: 1.4; }
.notif-time    { font-size: .7rem; color: #9ca3af; margin-top: 4px; }
.notif-unread-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #2563eb; flex-shrink: 0; margin-top: 5px;
}

.notif-actions { display: flex; gap: 4px; flex-shrink: 0; opacity: 0; transition: opacity .15s; }
.notif-item:hover .notif-actions { opacity: 1; }
.na-btn {
    width: 28px; height: 28px; border: none; border-radius: 6px;
    background: #f3f4f6; cursor: pointer; display: flex;
    align-items: center; justify-content: center; color: #6c757d;
    transition: background .1s, color .1s; font-size: .8rem;
}
.na-btn:hover { background: #e5e7eb; color: #111827; }
.na-btn.del:hover { background: #fef2f2; color: #dc2626; }

.notif-empty {
    text-align: center; padding: 48px 20px; color: #9ca3af;
}
.notif-empty .ne-icon { font-size: 2.5rem; display: block; margin-bottom: 10px; }
.notif-empty p { font-size: .87rem; }

.notif-footer {
    padding: 12px 18px; border-top: 1px solid #f3f4f6;
    font-size: .75rem; color: #9ca3af; text-align: center;
    flex-shrink: 0;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .main-content { margin-left: 0; }
    .login-card { width: 94vw; padding: 32px 24px; }
    .detail-grid { grid-template-columns: 1fr; }
    .form-grid   { grid-template-columns: 1fr; }
    .notif-drawer { width: 100vw; }
}
