:root {
    --primary: #1a3a5c;
    --primary-light: #2563a8;
    --secondary: #e8f0fe;
    --accent: #f0a500;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #0891b2;
    --dark: #1e293b;
    --light: #f8fafc;
    --border: #e2e8f0;
    --shadow: 0 4px 24px rgba(26,58,92,.12);
    --radius: 12px;
    --transition: all .25s cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f0f4f8;
    color: var(--dark);
    font-size: 13px;
    line-height: 1.6;
}

/* SIDEBAR */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, var(--primary) 0%, #0f2847 100%);
    height: 100vh;
    position: fixed;
    left: 0; top: 0;
    display: flex; flex-direction: column;
    z-index: 1000;
    transition: var(--transition);
    box-shadow: 4px 0 20px rgba(0,0,0,.15);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.2) transparent;
}

.sidebar-logo {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    display: flex; align-items: center; gap: 12px;
}

.sidebar-logo img { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; }

.sidebar-logo-text h2 {
    color: #fff;
    font-size: 13px; font-weight: 700;
    line-height: 1.2;
}

.sidebar-logo-text span {
    color: rgba(255,255,255,.5);
    font-size: 11px;
}

.sidebar-user {
    padding: 16px 24px;
    display: flex; align-items: center; gap: 12px;
    background: rgba(255,255,255,.05);
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-user-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent);
}

.sidebar-user-avatar-placeholder {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: #fff; font-size: 16px;
    border: 2px solid rgba(255,255,255,.3);
    flex-shrink: 0;
}

.sidebar-user-info .name { color: #fff; font-weight: 600; font-size: 13px; }
.sidebar-user-info .role-badge {
    display: inline-block;
    background: var(--accent);
    color: #fff; font-size: 10px;
    padding: 2px 8px; border-radius: 20px;
    font-weight: 600; text-transform: uppercase;
}

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

.nav-section-title {
    color: rgba(255,255,255,.35);
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1.5px;
    padding: 12px 24px 4px;
}

.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 24px;
    color: rgba(255,255,255,.72);
    text-decoration: none;
    font-size: 13px; font-weight: 500;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,.1);
    color: #fff;
    border-left-color: var(--accent);
}

.sidebar-nav a .nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-nav a .badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff; font-size: 10px;
    padding: 2px 6px; border-radius: 10px; font-weight: 700;
}

/* MAIN CONTENT */
.main-content {
    margin-left: 260px;
    min-height: 100vh;
    display: flex; flex-direction: column;
}

.topbar {
    background: #fff;
    padding: 0 28px;
    height: 64px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: 0 1px 8px rgba(0,0,0,.07);
    position: sticky; top: 0; z-index: 100;
}

.topbar-title { font-size: 16px; font-weight: 700; color: var(--primary); }
.topbar-subtitle { font-size: 12px; color: #94a3b8; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.topbar-user {
    display: flex; align-items: center; gap: 10px;
    background: var(--secondary); border-radius: 50px;
    padding: 6px 16px 6px 6px;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.topbar-user:hover { background: #d1dafe; }

.topbar-user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%; object-fit: cover;
    border: 2px solid var(--primary-light);
}

.topbar-user-name { font-weight: 600; color: var(--primary); font-size: 13px; }

.page-content { padding: 18px 22px; flex: 1; }

/* CARDS */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: visible;
}

.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    display: flex; align-items: center; justify-content: space-between;
    background: linear-gradient(135deg, var(--secondary) 0%, #fff 100%);
}

.card-title { font-weight: 700; font-size: 14px; color: var(--primary); display: flex; align-items: center; gap: 8px; }
.card-body { padding: 18px; }

/* STAT CARDS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 24px; }

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 16px;
    border-left: 4px solid var(--primary);
    transition: var(--transition);
}

.stat-card:hover { transform: translateY(-3px); box-shadow: 0 8px 32px rgba(26,58,92,.18); }
.stat-card.accent { border-left-color: var(--accent); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.danger  { border-left-color: var(--danger); }
.stat-card.info    { border-left-color: var(--info); }

.stat-icon {
    width: 52px; height: 52px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
    background: var(--secondary);
}

.stat-card.accent .stat-icon { background: #fef3c7; }
.stat-card.success .stat-icon { background: #dcfce7; }
.stat-card.danger  .stat-icon { background: #fee2e2; }
.stat-card.info    .stat-icon { background: #e0f2fe; }

.stat-value { font-size: 22px; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-label { font-size: 12px; color: #64748b; margin-top: 2px; }

/* TABLES */
.table-responsive { overflow-x: auto; }

table.data-table {
    width: 100%; border-collapse: collapse;
    font-size: 13px;
}

table.data-table thead th {
    background: var(--secondary);
    color: var(--primary);
    font-weight: 700;
    padding: 12px 16px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

table.data-table tbody tr { transition: var(--transition); }
table.data-table tbody tr:hover { background: #f8faff; }
table.data-table tbody td { padding: 8px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }

/* BADGES */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
}

.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-warning { background: #fef9c3; color: #a16207; }
.badge-info    { background: #e0f2fe; color: #0369a1; }
.badge-primary { background: var(--secondary); color: var(--primary); }
.badge-secondary { background: #f1f5f9; color: #64748b; }

/* BUTTONS */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 18px; border-radius: 8px;
    font-size: 13px; font-weight: 600;
    cursor: pointer; border: none; transition: var(--transition);
    text-decoration: none; white-space: nowrap;
}

.btn-primary { background: var(--primary-light); color: #fff; }
.btn-primary:hover { background: var(--primary); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-danger:hover  { background: #b91c1c; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--dark); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-outline {
    background: transparent; border: 2px solid var(--primary-light); color: var(--primary-light);
}
.btn-outline:hover { background: var(--primary-light); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }
.btn-icon { padding: 7px; border-radius: 8px; }

/* FORMS */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-weight: 600; font-size: 12px; color: var(--dark); margin-bottom: 6px; }
.form-label span.req { color: var(--danger); }

.form-control {
    width: 100%; padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px; font-size: 12px;
    transition: var(--transition);
    background: #fff; color: var(--dark);
    outline: none;
}

.form-control:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(37,99,168,.12); }
.form-control.is-invalid { border-color: var(--danger); }
select.form-control { cursor: pointer; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }

/* ALERTS / TOASTS */
.toast-container {
    position: fixed; top: 80px; right: 24px;
    z-index: 9999; display: flex; flex-direction: column; gap: 10px;
}

.toast {
    display: flex; align-items: flex-start; gap: 12px;
    background: #fff; border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,.15);
    padding: 14px 18px;
    min-width: 300px; max-width: 420px;
    border-left: 4px solid var(--info);
    animation: slideInRight .3s ease;
    position: relative;
}

.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

.toast-icon { font-size: 20px; flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-weight: 700; font-size: 13px; color: var(--dark); }
.toast-message { font-size: 12px; color: #64748b; margin-top: 2px; }
.toast-close {
    background: none; border: none; cursor: pointer;
    color: #94a3b8; font-size: 18px; line-height: 1; padding: 0;
    margin-left: 8px;
}

@keyframes slideInRight {
    from { transform: translateX(100px); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* MODAL */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.6);
    z-index: 5000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
    animation: fadeIn .2s ease;
}

.modal {
    background: #fff;
    border-radius: 16px;
    width: 90%; max-width: 580px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    animation: scaleIn .25s cubic-bezier(.34,1.56,.64,1);
}

.modal-lg { max-width: 850px; }
.modal-xl { max-width: 1100px; }

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    background: linear-gradient(135deg, var(--secondary) 0%, #fff 100%);
    border-radius: 16px 16px 0 0;
}

.modal-title { font-weight: 700; font-size: 14px; color: var(--primary); display: flex; align-items: center; gap: 8px; }

.modal-close {
    width: 32px; height: 32px; border-radius: 8px;
    background: #f1f5f9; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: #64748b;
    transition: var(--transition);
}

.modal-close:hover { background: var(--danger); color: #fff; }
.modal-body { padding: 18px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    background: #f8fafc;
    border-radius: 0 0 16px 16px;
}

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* PAGINATION */
.pagination { display: flex; align-items: center; gap: 6px; justify-content: center; margin-top: 20px; }
.pagination a, .pagination span {
    padding: 7px 12px; border-radius: 7px;
    text-decoration: none; font-weight: 600; font-size: 13px;
    transition: var(--transition);
}
.pagination a { background: #fff; border: 1.5px solid var(--border); color: var(--dark); }
.pagination a:hover { background: var(--secondary); border-color: var(--primary-light); }
.pagination .active { background: var(--primary-light); color: #fff; border-color: var(--primary-light); }

/* SEARCH BAR */
.search-bar {
    display: flex; align-items: center; gap: 12px;
    background: #fff; border: 1.5px solid var(--border);
    border-radius: 10px; padding: 8px 16px;
    transition: var(--transition);
}
.search-bar:focus-within { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(37,99,168,.1); }
.search-bar input { border: none; outline: none; flex: 1; font-size: 13px; background: transparent; }
.search-bar .search-icon { color: #94a3b8; }

/* PRINT / PDF header */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    .print-header { display: block !important; }
}

.print-header { display: none; }

.print-header-content {
    display: flex; align-items: center; gap: 16px;
    border-bottom: 3px double var(--primary);
    padding-bottom: 12px; margin-bottom: 20px;
}

.print-footer {
    margin-top: 24px; padding-top: 12px;
    border-top: 2px solid var(--border);
    font-size: 11px; color: #64748b;
    display: flex; justify-content: space-between;
}

/* UTILITIES */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: #64748b; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.fw-bold { font-weight: 700; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-10 { gap: 10px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.w-100 { width: 100%; }

/* TABLE LIGNES SAISIE */
.saisie-table {
    width: 100%; border-collapse: collapse;
    font-size: 13px;
}
.saisie-table thead th {
    background: var(--primary);
    color: #fff;
    padding: 10px 12px;
    text-align: left;
}
.saisie-table tbody tr { border-bottom: 1px solid var(--border); }
.saisie-table tbody td { padding: 6px 8px; }
.saisie-table .form-control { padding: 6px 10px; border-radius: 6px; }
.saisie-table .btn-icon { padding: 5px; }

/* EMPTY STATE */
.empty-state {
    text-align: center; padding: 60px 24px; color: #94a3b8;
}
.empty-state .empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: #64748b; margin-bottom: 8px; }

/* LOGIN PAGE */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, #0f2847 50%, #1a4a8c 100%);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}

.login-card {
    background: #fff;
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%; max-width: 440px;
    box-shadow: 0 32px 80px rgba(0,0,0,.3);
    animation: scaleIn .3s cubic-bezier(.34,1.56,.64,1);
}

.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo img { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 12px; }
.login-logo h1 { font-size: 20px; font-weight: 800; color: var(--primary); }
.login-logo p  { font-size: 12px; color: #94a3b8; margin-top: 4px; }

.login-input-group { position: relative; }
.login-input-group .form-control { padding-left: 44px; }
.login-input-group .input-icon {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: #94a3b8; font-size: 17px;
}

.alert {
    padding: 12px 16px; border-radius: 10px;
    font-size: 13px; display: flex; align-items: flex-start; gap: 10px;
    margin-bottom: 18px;
}
.alert-danger  { background: #fee2e2; color: #b91c1c; border-left: 4px solid var(--danger); }
.alert-success { background: #dcfce7; color: #15803d; border-left: 4px solid var(--success); }
.alert-info    { background: #e0f2fe; color: #0369a1; border-left: 4px solid var(--info); }
.alert-warning { background: #fef3c7; color: #92400e; border-left: 4px solid var(--warning); }

/* AVATAR GROUP */
.avatar-sm {
    width: 36px; height: 36px; border-radius: 50%;
    object-fit: cover; border: 2px solid var(--border);
}

/* AUTOCOMPLETE */
.autocomplete-dropdown {
    position: absolute; width: 100%; z-index: 9999;
    background: #fff; border: 1.5px solid var(--border);
    border-radius: 8px; box-shadow: var(--shadow);
    max-height: 220px; overflow-y: auto;
    top: calc(100% + 4px);
}
.autocomplete-dropdown li {
    list-style: none;
    padding: 10px 14px; font-size: 13px;
    cursor: pointer; transition: background .15s;
    border-bottom: 1px solid var(--border);
}
.autocomplete-dropdown li:hover { background: var(--secondary); }
/* ═══════════════════════════════════════════════
   GED — Gestion Électronique des Documents (v8)
   ═══════════════════════════════════════════════ */

/* Résultats de recherche */
.ged-result-item {
    display: flex; align-items: flex-start; gap: 14px;
    padding: 14px 18px; cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .15s;
}
.ged-result-item:hover { background: #f8faff; }
.ged-result-item:last-child { border-bottom: none; }

.ged-pdf-icon {
    flex-shrink: 0; width: 44px; height: 52px;
    background: #fee2e2; border-radius: 8px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    font-size: 22px; color: #dc2626;
}
.ged-pages {
    font-size: 9px; font-weight: 700; color: #991b1b;
    background: #fecaca; border-radius: 3px;
    padding: 1px 4px; margin-top: 2px; line-height: 1.2;
}

.ged-result-body { flex: 1; min-width: 0; }
.ged-result-title {
    font-size: 13px; font-weight: 700; color: var(--dark);
    margin-bottom: 4px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ged-result-meta {
    display: flex; flex-wrap: wrap; gap: 12px;
    font-size: 11px; color: #64748b; margin-bottom: 4px;
}
.ged-result-meta span { display: flex; align-items: center; gap: 4px; }
.ged-result-excerpt {
    font-size: 12px; color: #374151; line-height: 1.5;
    margin-top: 4px;
    display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
}
.ged-result-excerpt mark {
    background: #fef08a; border-radius: 2px; padding: 0 2px; font-style: normal;
}
.ged-result-actions {
    flex-shrink: 0; display: flex; flex-direction: column;
    align-items: flex-end; gap: 4px;
}
.ged-ocr-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 99px;
    font-size: 10px; font-weight: 700; white-space: nowrap;
}
.ged-tag {
    display: inline-block; background: #e0e7ff; color: #3730a3;
    font-size: 10px; font-weight: 600; padding: 2px 7px;
    border-radius: 99px; margin: 2px 2px 0 0;
}

/* Widget pièces jointes */
.ged-widget { margin-top: 16px; }
.ged-widget-list { min-height: 40px; }
.ged-widget-loading {
    padding: 14px; text-align: center;
    color: #94a3b8; font-size: 12px;
}
.ged-widget-upload-zone {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}
.ged-meta-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}

/* Drag & Drop */
.ged-dropzone {
    border: 2px dashed var(--border); border-radius: 8px;
    padding: 20px; text-align: center; cursor: pointer;
    transition: all .2s; background: #fff;
}
.ged-dropzone:hover, .ged-dropzone-over {
    border-color: var(--primary-light); background: #eff6ff;
}

/* Items dans le widget */
.ged-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
    transition: background .15s;
}
.ged-item:hover { background: #f8faff; }
.ged-item:last-child { border-bottom: none; }
.ged-item-icon {
    flex-shrink: 0; width: 34px; height: 40px;
    background: #fee2e2; border-radius: 6px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    font-size: 18px; color: #dc2626;
}
.ged-item-body { flex: 1; min-width: 0; }
.ged-item-title {
    font-size: 12px; font-weight: 600; color: var(--dark);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ged-item-meta {
    display: flex; gap: 10px; font-size: 11px;
    color: #94a3b8; margin-top: 2px; flex-wrap: wrap;
}
.ged-item-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Animation spin */
@keyframes ged-spin { to { transform: rotate(360deg); } }
.ged-spin { display: inline-block; animation: ged-spin .8s linear infinite; }

/* Print */
@media print {
    .ged-widget, .ged-widget-upload-zone, .ged-result-actions { display: none !important; }
}
