/* =============================================================
   Recouvrement v3 — Minimaliste, professionnel
   Palette : bleu nuit + sarcelle (vert canard) + neutre
   ============================================================= */

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

:root {
    /* PALETTE PRINCIPALE - simple et pro */
    --primary: #1e40af;          /* Bleu nuit */
    --primary-dark: #1e3a8a;
    --primary-light: #dbeafe;
    --primary-50: #eff6ff;

    --accent: #0f766e;           /* Sarcelle */
    --accent-light: #ccfbf1;
    --accent-50: #f0fdfa;

    --success: #059669;
    --success-light: #d1fae5;

    --warning: #d97706;
    --warning-light: #fef3c7;

    --danger: #dc2626;
    --danger-light: #fee2e2;

    --info: #0891b2;
    --info-light: #cffafe;

    /* NEUTRES */
    --gray-50:  #fafafa;
    --gray-100: #f4f4f5;
    --gray-200: #e4e4e7;
    --gray-300: #d4d4d8;
    --gray-400: #a1a1aa;
    --gray-500: #71717a;
    --gray-600: #52525b;
    --gray-700: #3f3f46;
    --gray-800: #27272a;
    --gray-900: #18181b;

    /* SEMANTIQUES — fond légèrement coloré, plus chaleureux */
    --bg: #f5f7fa;               /* Light blue-gray au lieu de blanc pur */
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;

    --radius-sm: 4px;
    --radius:    6px;
    --radius-lg: 8px;
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
    --shadow:    0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
    --shadow-lg: 0 10px 25px rgba(15,23,42,0.10);

    --sidebar-w: 240px;
    --header-h: 60px;
}

html, body {
    height: 100%;
    /* CRITIQUE: pas de scroll horizontal au niveau page */
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover { color: var(--primary-dark); }

/* SVG Icons - flat pro */
.icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    vertical-align: middle;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }

/* =============================================================
   LAYOUT
   ============================================================= */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar - foncée pro */
.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    border-right: 1px solid #1e293b;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    color: white;
}
.sidebar-brand img {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}
.sidebar-brand .brand-text {
    line-height: 1.2;
}
.sidebar-brand .brand-text small {
    font-size: 10px;
    font-weight: 500;
    color: rgba(255,255,255,0.55);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-top: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
}
.nav-section {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255,255,255,0.4);
    font-weight: 700;
    margin: 12px 12px 6px;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.7);
    font-weight: 500;
    margin-bottom: 1px;
    transition: all 0.12s ease;
    font-size: 13px;
    text-decoration: none;
}
.nav-link:hover {
    background-color: rgba(255,255,255,0.08);
    color: white;
}
.nav-link.active {
    background-color: var(--primary);
    color: white;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(30,64,175,0.4);
}
.nav-link.active .icon { stroke: white; }
.nav-link .icon { stroke: rgba(255,255,255,0.55); }
.nav-link:hover .icon { stroke: white; }

.sidebar-footer {
    padding: 12px 18px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 11px;
    color: rgba(255,255,255,0.4);
}

/* Main */
.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    /* CRITIQUE: empêche le contenu de pousser horizontalement */
    min-width: 0;
    max-width: calc(100vw - var(--sidebar-w));
    overflow-x: hidden;
}

/* Topbar */
.topbar {
    height: var(--header-h);
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 0 rgba(0,0,0,0.02);
}
.topbar h1 {
    font-size: 17px;
    font-weight: 600;
    color: var(--gray-900);
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Bell */
.bell {
    position: relative;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    color: var(--gray-600);
}
.bell:hover { background: var(--gray-100); }
.bell .icon { width: 20px; height: 20px; }
.bell .badge-count {
    position: absolute;
    top: 4px; right: 4px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    line-height: 1;
}
.bell-dropdown {
    position: absolute;
    top: 44px;
    right: 0;
    width: 380px;
    max-height: 500px;
    overflow-y: auto;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 200;
}
.bell-dropdown.open { display: block; }
.bell-dropdown .dropdown-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
    color: white;
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
}
.bell-dropdown .item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    display: block;
    color: var(--gray-700);
}
.bell-dropdown .item:hover { background: var(--gray-50); }
.bell-dropdown .item:last-child { border-bottom: none; }
.bell-dropdown .item .item-title { font-weight: 500; font-size: 13px; color: var(--gray-900); }
.bell-dropdown .item .item-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.bell-dropdown .item .item-detail { font-size: 12px; color: var(--gray-600); margin-top: 4px; line-height: 1.4; }
.bell-dropdown .item .item-section { font-size: 10px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; }
.bell-dropdown .empty {
    padding: 30px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* User menu */
.user-menu {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    padding: 5px 10px 5px 5px;
    border-radius: 999px;
    transition: background 0.15s;
    position: relative;
}
.user-menu:hover { background: var(--gray-100); }
.avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
}
.user-info { line-height: 1.3; }
.user-info .u-name { font-weight: 600; font-size: 13px; color: var(--gray-900); }
.user-info .u-role { font-size: 10px; color: var(--text-muted); }

.user-dropdown {
    position: absolute;
    top: 46px;
    right: 0;
    width: 220px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 200;
    overflow: hidden;
}
.user-dropdown.open { display: block; }
.user-dropdown-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    color: white;
}
.user-dropdown-header strong {
    color: white;
}
.user-dropdown-item {
    padding: 11px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 13px;
}
.user-dropdown-item:hover {
    background: var(--gray-50);
    color: var(--danger);
}

/* Burger */
.burger-btn {
    display: none;
    background: transparent;
    border: 1px solid var(--border);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--gray-700);
    align-items: center;
    justify-content: center;
}
.burger-btn:hover { background: var(--gray-100); }

/* Page */
.page {
    padding: 24px;
    flex: 1;
    /* CRITIQUE: empêche les enfants de pousser horizontalement */
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-title::before {
    content: '';
    width: 4px;
    height: 24px;
    background: linear-gradient(180deg, var(--primary), var(--accent));
    border-radius: 2px;
}
.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
    margin-left: 14px;
}

/* =============================================================
   CARDS
   ============================================================= */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}
.card-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-header h3 .icon { color: var(--primary); }
.card-body {
    padding: 18px;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.stat-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    transition: all 0.15s;
    text-decoration: none;
    color: inherit;
    display: block;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.stat-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary);
}
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before  { background: var(--danger); }
.stat-card.accent::before  { background: var(--accent); }
.stat-card.info::before    { background: var(--info); }
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    color: inherit;
    text-decoration: none;
    border-color: var(--gray-300);
}
.stat-card .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
.stat-card .value {
    font-size: 24px;
    font-weight: 700;
    margin-top: 5px;
    color: var(--gray-900);
    letter-spacing: -0.02em;
}
.stat-card .icon-bg {
    width: 34px; height: 34px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 8px;
}
.stat-card .icon-bg .icon { width: 18px; height: 18px; }
.stat-card.primary .icon-bg { background: var(--primary-light); color: var(--primary); }
.stat-card.success .icon-bg { background: var(--success-light); color: var(--success); }
.stat-card.warning .icon-bg { background: var(--warning-light); color: var(--warning); }
.stat-card.danger  .icon-bg { background: var(--danger-light);  color: var(--danger); }
.stat-card.accent  .icon-bg { background: var(--accent-light);  color: var(--accent); }
.stat-card.info    .icon-bg { background: var(--info-light);    color: var(--info); }

/* =============================================================
   BOUTONS
   ============================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.12s ease;
    background: transparent;
    color: var(--gray-700);
    line-height: 1.4;
    white-space: nowrap;
}
.btn:hover { background: var(--gray-100); }
.btn .icon { width: 14px; height: 14px; }
.btn-primary {
    background: linear-gradient(180deg, #2563eb, var(--primary));
    color: white;
    border-color: var(--primary);
    box-shadow: 0 1px 2px rgba(30, 64, 175, 0.3);
}
.btn-primary:hover {
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 2px 4px rgba(30, 64, 175, 0.4);
}
.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}
.btn-success:hover { background: #047857; color: white; }
.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; color: white; }
.btn-warning {
    background: var(--warning);
    color: white;
    border-color: var(--warning);
}
.btn-outline {
    border-color: var(--border);
    background: white;
    color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-300); }
.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}
.btn-sm .icon { width: 12px; height: 12px; }

/* =============================================================
   TABLES
   ============================================================= */
/* =============================================================
   TABLE WITH SMART SCROLL (largeur 100%, scroll interne seulement)
   ============================================================= */
.table-scroll-container {
    position: relative;
    margin-bottom: 8px;
    /* Largeur 100% de la zone parent (page) */
    width: 100%;
    max-width: 100%;
    /* Empêche le container de s'étendre */
    min-width: 0;
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: white;
    box-shadow: var(--shadow-sm);
    cursor: grab;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    /* Hauteur limitée pour scroll vertical interne */
    max-height: calc(100vh - 220px);
    /* Focus visible pour le clavier */
    outline: none;
}
.table-wrap:focus-within {
    box-shadow: 0 0 0 2px var(--primary-light), var(--shadow-sm);
}
.table-wrap.is-dragging {
    cursor: grabbing;
    user-select: none;
    scroll-behavior: auto;
}
.table-wrap.is-dragging * {
    cursor: grabbing !important;
}

/* Scrollbar TOP (en haut du tableau) — réplique le scroll horizontal */
.table-scroll-top {
    overflow-x: auto;
    overflow-y: hidden;
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: linear-gradient(180deg, #f8fafc, #f1f5f9);
    height: 14px;
    -webkit-overflow-scrolling: touch;
}
.table-scroll-top-inner {
    height: 1px;
}
/* Quand top scroll est actif, lui supprimer le border-bottom-radius du table-wrap */
.has-top-scroll .table-wrap {
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border-top: none;
}

/* Custom scrollbar — visible et stylée */
.table-wrap::-webkit-scrollbar,
.table-scroll-top::-webkit-scrollbar {
    height: 12px;
    width: 10px;
}
.table-wrap::-webkit-scrollbar-track,
.table-scroll-top::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 6px;
    margin: 0 4px;
}
.table-wrap::-webkit-scrollbar-thumb,
.table-scroll-top::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #94a3b8, #64748b);
    border-radius: 6px;
    border: 2px solid #f1f5f9;
    transition: background 0.15s;
}
.table-wrap::-webkit-scrollbar-thumb:hover,
.table-scroll-top::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
}
.table-wrap::-webkit-scrollbar-corner,
.table-scroll-top::-webkit-scrollbar-corner {
    background: #f1f5f9;
}
/* Firefox */
.table-wrap,
.table-scroll-top {
    scrollbar-width: thin;
    scrollbar-color: #64748b #f1f5f9;
}

/* Indicateur visuel quand y a plus à scroller (ombres latérales) */
.table-scroll-container.has-overflow-right .table-wrap {
    background-image: linear-gradient(to right, rgba(15,23,42,0) 95%, rgba(15,23,42,0.08));
    background-attachment: local;
    background-repeat: no-repeat;
    background-position: right center;
    background-size: 30px 100%;
}

table.table {
    /* Width auto pour que les colonnes prennent leur taille naturelle
     * et créent le scroll horizontal DANS .table-wrap */
    width: auto;
    min-width: 100%;
    border-collapse: collapse;
}
table.table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: linear-gradient(180deg, #f1f5f9 0%, #e8eef5 100%);
    color: #334155;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 11px 14px;
    text-align: left;
    border-bottom: 2px solid var(--primary);
    white-space: nowrap;
}
table.table td {
    padding: 11px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--gray-700);
    vertical-align: middle;
    font-size: 13px;
    /* Forcer une seule ligne, max 500px avec ellipsis */
    white-space: nowrap;
    max-width: 500px;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Au survol cellule longue : tooltip natif via title attr ou expand */
table.table td:hover {
    overflow: visible;
    position: relative;
}
/* Pour les cellules contenant des badges/actions/icons, ne pas couper */
table.table td:has(.actions),
table.table td:has(.badge),
table.table td:has(.icon-btn) {
    overflow: visible;
}
/* Fallback pour browsers sans :has() — cells avec action */
table.table td.actions-cell,
table.table .actions {
    overflow: visible;
}
/* Cellules numériques alignées à droite et compactes */
table.table td.num,
table.table td.amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum';
}
table.table tbody tr:hover {
    background: var(--primary-50);
}
table.table tbody tr:last-child td { border-bottom: none; }

.empty-row {
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
}

/* Actions */
.actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}
.icon-btn {
    width: 30px; height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: white;
    color: var(--gray-600);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.12s;
}
.icon-btn .icon { width: 14px; height: 14px; }
.icon-btn:hover { background: var(--gray-100); color: var(--gray-900); border-color: var(--gray-300); }
.icon-btn.danger:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }
.icon-btn.success:hover { background: var(--success-light); color: var(--success); border-color: var(--success); }
.icon-btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.icon-btn.primary:hover { background: var(--primary-dark); color: white; }

/* =============================================================
   FORMULAIRES
   ============================================================= */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }

.form-group { margin-bottom: 0; }
.form-group.full { grid-column: 1 / -1; }

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 5px;
}
.form-label .req { color: var(--danger); }

.form-control {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: white;
    color: var(--gray-900);
    transition: border-color 0.12s, box-shadow 0.12s;
    font-family: inherit;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.12);
}
.form-control:disabled, .form-control[readonly] {
    background: var(--gray-50);
    color: var(--gray-500);
    cursor: not-allowed;
}
textarea.form-control { min-height: 80px; resize: vertical; }
select.form-control { cursor: pointer; }

.form-help {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* =============================================================
   BADGES
   ============================================================= */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
}
.badge-success { background: var(--success-light); color: #047857; }
.badge-warning { background: var(--warning-light); color: #b45309; }
.badge-danger  { background: var(--danger-light); color: #b91c1c; }
.badge-info    { background: var(--info-light); color: #0e7490; }
.badge-gray    { background: var(--gray-100); color: var(--gray-700); }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-accent  { background: var(--accent-light); color: var(--accent); }

/* =============================================================
   ALERTS
   ============================================================= */
.alert {
    padding: 11px 14px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    border-left: 3px solid;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
}
.alert-success { background: var(--success-light); border-color: var(--success); color: #065f46; }
.alert-warning { background: var(--warning-light); border-color: var(--warning); color: #92400e; }
.alert-danger  { background: var(--danger-light); border-color: var(--danger); color: #991b1b; }
.alert-info    { background: var(--info-light); border-color: var(--info); color: #155e75; }

/* =============================================================
   PROGRESS
   ============================================================= */
.progress {
    height: 6px;
    background: var(--gray-100);
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    transition: width 0.3s;
}
.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger  { background: var(--danger); }

/* =============================================================
   LOGIN
   ============================================================= */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e40af 0%, #0f766e 100%);
    padding: 20px;
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px rgba(0,0,0,0.2);
    padding: 32px 30px;
}
.login-header {
    text-align: center;
    margin-bottom: 24px;
}
.login-header img {
    width: 60px;
    height: 60px;
    margin: 0 auto 12px;
}
.login-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--gray-900);
}
.login-header p {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
}

/* =============================================================
   PIECES JOINTES
   ============================================================= */
.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: white;
    font-size: 12px;
    max-width: 320px;
}
.attachment .file-icon {
    width: 20px;
    height: 20px;
    color: var(--gray-500);
    flex-shrink: 0;
}
.attachment .file-info {
    flex: 1;
    min-width: 0;
}
.attachment .file-name {
    font-weight: 500;
    color: var(--gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
}
.attachment .file-meta {
    font-size: 10px;
    color: var(--text-muted);
}
.attachment .file-actions {
    display: flex;
    gap: 3px;
}

/* =============================================================
   PAGINATION + TRI
   ============================================================= */
.pagination-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    margin-top: 18px;
    padding: 12px 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.pagination-info {
    font-size: 13px;
    color: var(--gray-600);
}
.pagination-info strong {
    color: var(--primary);
    font-weight: 700;
}

.pagination-size {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--gray-600);
    justify-content: center;
}
.pagination-size select {
    width: auto;
    padding: 5px 8px;
    font-size: 13px;
}
.form-control-sm {
    padding: 5px 10px;
    font-size: 12px;
    min-width: 70px;
}

.pagination {
    display: flex;
    justify-content: flex-end;
    gap: 3px;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.12s;
    min-width: 32px;
    text-align: center;
}
.pagination a:hover {
    background: var(--primary-50);
    border-color: var(--primary);
    color: var(--primary);
}
.pagination .current {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 1px 3px rgba(30,64,175,0.3);
}
.pagination .ellipsis {
    border: none;
    background: transparent;
    color: var(--gray-400);
}
.pagination .disabled {
    color: var(--gray-300);
    background: var(--gray-50);
    border-color: var(--border);
    cursor: not-allowed;
    opacity: 0.5;
}

/* Saut direct à une page */
.pagination-jump-sep {
    color: var(--gray-300);
    font-weight: 700;
    margin: 0 4px;
}
.pagination-jump-input {
    -moz-appearance: textfield;
}
.pagination-jump-input::-webkit-outer-spin-button,
.pagination-jump-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.pagination-jump-input:focus {
    border-color: var(--primary);
    outline: 2px solid rgba(30,64,175,0.15);
    outline-offset: 0;
}

/* Sortable TH */
.sortable-th a {
    display: block;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    transition: color 0.12s;
}
.sortable-th a:hover {
    color: var(--primary);
}
.sortable-th.active a {
    color: var(--primary);
}
.sort-arrow {
    font-size: 10px;
    margin-left: 3px;
    opacity: 0.85;
}

@media (max-width: 800px) {
    .pagination-bar {
        grid-template-columns: 1fr;
        gap: 12px;
        text-align: center;
    }
    .pagination-info, .pagination-size, .pagination {
        justify-content: center;
    }
}

/* =============================================================
   SEARCH BAR + FILTRES
   ============================================================= */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.search-bar .form-control { max-width: 320px; }

.search-bar-top { margin-bottom: 12px; }

.filters-panel {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 18px;
    overflow: hidden;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}
.filters-header {
    padding: 11px 16px;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}
.filters-header h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 7px;
}
.filters-header .count-badge {
    background: var(--primary);
    color: white;
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 700;
}
.filters-toggle-icon {
    transition: transform 0.2s;
    color: var(--gray-500);
}
.filters-panel.collapsed .filters-toggle-icon {
    transform: rotate(-90deg);
}
.filters-body { padding: 16px; }
.filters-panel.collapsed .filters-body { display: none; }

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}
.filter-group label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.filter-group .form-control {
    font-size: 12px;
    padding: 6px 9px;
}
.filter-range {
    display: flex;
    gap: 4px;
    align-items: center;
}
.filter-range input { flex: 1; min-width: 0; }
.filter-range .sep {
    color: var(--text-muted);
    font-size: 11px;
}

.filters-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-100);
    justify-content: flex-end;
}

.filters-section-title {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--gray-500);
    margin: 14px 0 8px;
    letter-spacing: 0.04em;
    font-weight: 700;
}
.filters-section-title:first-child { margin-top: 0; }

/* =============================================================
   PERMISSIONS GRID
   ============================================================= */
.perm-table {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.perm-table th, .perm-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-100);
}
.perm-table th { background: var(--gray-50); text-align: left; font-size: 12px; font-weight: 600; }
.perm-table td.center { text-align: center; }
.perm-table input[type="checkbox"] {
    width: 16px; height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* =============================================================
   DETAIL / FICHE
   ============================================================= */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}
.detail-item {
    padding: 10px 12px;
    background: linear-gradient(180deg, #f8fafc, #f1f5f9);
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
}
.detail-item .label {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.04em;
    margin-bottom: 3px;
}
.detail-item .value {
    font-weight: 600;
    color: var(--gray-900);
    word-break: break-word;
    font-size: 13px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--primary-light);
    margin-bottom: 18px;
    overflow-x: auto;
    background: white;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 0 6px;
    box-shadow: var(--shadow-sm);
}
.tab {
    padding: 11px 18px;
    border: none;
    background: transparent;
    color: var(--gray-600);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.15s;
}
.tab:hover {
    color: var(--primary);
    background: var(--primary-50);
}
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 700;
    background: white;
}

/* =============================================================
   MODAL
   ============================================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
    background: white;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.modal.modal-lg { max-width: 800px; }
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    color: white;
}
.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: white;
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal-header h3 .icon { color: white; }
.modal-close {
    background: rgba(255,255,255,0.15);
    border: none;
    cursor: pointer;
    color: white;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}
.modal-close:hover { background: rgba(255,255,255,0.3); color: white; }
.modal-body {
    padding: 18px 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    background: var(--gray-50);
}

/* =============================================================
   SECTIONS COLONNES (créance détail)
   ============================================================= */
.section-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.section-card-header {
    padding: 12px 16px;
    border-bottom: 2px solid var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(180deg, var(--primary-50), white);
}
.section-card-header h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 7px;
}
.section-card-header h4 .icon { color: var(--primary); }
.section-card-header h4 .count {
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}
.section-list {
    list-style: none;
}
.section-list li {
    padding: 11px 16px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.section-list li:last-child { border-bottom: none; }
.section-list li:hover { background: var(--gray-50); }
.section-list .item-main { flex: 1; min-width: 0; }
.section-list .item-title { font-size: 13px; font-weight: 500; color: var(--gray-900); }
.section-list .item-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.section-list .item-detail { font-size: 12px; color: var(--gray-600); margin-top: 4px; line-height: 1.4; }
.section-list .item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.section-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Total summary in section */
.section-summary {
    padding: 12px 16px;
    background: var(--gray-50);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
.section-summary .label { color: var(--text-muted); font-weight: 500; }
.section-summary .value { font-weight: 700; color: var(--gray-900); font-size: 15px; }

/* =============================================================
   RESPONSIVE
   ============================================================= */
@media (max-width: 900px) {
    :root { --sidebar-w: 0; }
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        transition: transform 0.2s;
        width: 240px;
        box-shadow: 2px 0 12px rgba(0,0,0,0.1);
    }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid.cols-3 { grid-template-columns: 1fr; }
    .burger-btn { display: inline-flex; }
    .user-menu .user-info { display: none; }
    .topbar { padding: 0 12px; }
    .page { padding: 14px; }
    .topbar h1 { font-size: 15px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* utilities */
.flex { display: flex; }

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 4px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.btn-loading {
    cursor: not-allowed !important;
    opacity: 0.85;
}
.btn-loading .icon { display: none; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 14px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 14px; }
.mt-3 { margin-top: 22px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 14px; }
.mb-3 { margin-bottom: 22px; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-bold { font-weight: 600; }
.w-full { width: 100%; }
