/* ==========================================================
   Variables et reset
   ========================================================== */
:root {
    --color-bg:         #f4f6f9;
    --color-sidebar:    #1e2a3a;
    --color-sidebar-h:  #2c3e50;
    --color-accent:     #3498db;
    --color-accent-d:   #2980b9;
    --color-text:       #2c3e50;
    --color-text-light: #7f8c8d;
    --color-border:     #dde3ec;
    --color-white:      #ffffff;
    --color-success:    #27ae60;
    --color-warning:    #f39c12;
    --color-danger:     #e74c3c;
    --color-info:       #3498db;
    --sidebar-w:        240px;
    --header-h:         60px;
    --radius:           8px;
    --shadow:           0 2px 8px rgba(0,0,0,.08);
    --shadow-lg:        0 4px 20px rgba(0,0,0,.12);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-d); text-decoration: underline; }

/* ==========================================================
   Layout : sidebar + contenu
   ========================================================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--color-sidebar);
    color: #ecf0f1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 200;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand .brand-icon {
    width: 32px; height: 32px;
    background: var(--color-accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-brand .brand-name {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
}

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

.nav-section {
    padding: 8px 18px 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255,255,255,.35);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: rgba(255,255,255,.75);
    font-size: 13.5px;
    transition: background .15s, color .15s;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.nav-item:hover, .nav-item.active {
    background: var(--color-sidebar-h);
    color: #fff;
    text-decoration: none;
    border-left-color: var(--color-accent);
}

.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

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

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,.08);
}

/* Contenu principal */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.top-header {
    height: var(--header-h);
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.top-header h1 {
    font-size: 17px;
    font-weight: 600;
    flex: 1;
}

.btn-menu {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    color: var(--color-text);
    padding: 4px;
}

/* Zone de contenu */
.content-area {
    padding: 24px;
    flex: 1;
}

/* ==========================================================
   Cards / Widgets
   ========================================================== */
.card {
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}

.card-header h2 {
    font-size: 15px;
    font-weight: 600;
}

/* Stats summary cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-card .stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--color-text-light);
}

.stat-card .stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text);
}

.stat-card .stat-sub {
    font-size: 12px;
    color: var(--color-text-light);
}

.stat-card.success .stat-value { color: var(--color-success); }
.stat-card.danger  .stat-value { color: var(--color-danger); }
.stat-card.warning .stat-value { color: var(--color-warning); }
.stat-card.info    .stat-value { color: var(--color-info); }

/* ==========================================================
   Boutons
   ========================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, box-shadow .15s;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }

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

.btn-success   { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-success:hover { background: #229954; border-color: #229954; color: #fff; }

.btn-danger    { background: var(--color-danger);  color: #fff; border-color: var(--color-danger); }
.btn-danger:hover  { background: #c0392b; color: #fff; }

.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); color: var(--color-text); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }

/* ==========================================================
   Formulaires
   ========================================================== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 13.5px;
    color: var(--color-text);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(52,152,219,.15);
}

select.form-control { cursor: pointer; }

.form-hint {
    margin-top: 4px;
    font-size: 12px;
    color: var(--color-text-light);
}

/* ==========================================================
   Alertes / messages
   ========================================================== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13.5px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.alert-error   { background: #fdecea; border: 1px solid #f5c6cb; color: #721c24; }
.alert-success { background: #d4edda; border: 1px solid #c3e6cb; color: #155724; }
.alert-warning { background: #fff3cd; border: 1px solid #ffeeba; color: #856404; }
.alert-info    { background: #d1ecf1; border: 1px solid #bee5eb; color: #0c5460; }

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

thead th {
    padding: 10px 12px;
    background: var(--color-bg);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--color-text-light);
    border-bottom: 2px solid var(--color-border);
    text-align: left;
    white-space: nowrap;
}

tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

.text-right { text-align: right; }
.text-center { text-align: center; }

.amount-debit  { color: var(--color-danger);  font-weight: 500; }
.amount-credit { color: var(--color-success); font-weight: 500; }

/* Badge catégorie */
.badge-cat {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}

/* ==========================================================
   Page login
   ========================================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-sidebar);
}

.login-box {
    background: var(--color-white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 380px;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo .icon {
    width: 56px; height: 56px;
    background: var(--color-accent);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: #fff;
    margin-bottom: 12px;
}

.login-logo h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text);
}

.login-logo p {
    font-size: 13px;
    color: var(--color-text-light);
    margin-top: 4px;
}

/* ==========================================================
   Import
   ========================================================== */
.upload-zone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    display: block;         /* label doit être block pour occuper toute la surface */
    transition: border-color .2s, background .2s;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--color-accent);
    background: rgba(52,152,219,.04);
}

.upload-zone .upload-icon { font-size: 40px; color: var(--color-text-light); margin-bottom: 12px; }
.upload-zone p { color: var(--color-text-light); font-size: 13.5px; }
.upload-zone strong { color: var(--color-accent); }

/* Progress bar */
.progress {
    height: 8px;
    background: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0;
}

.progress-bar {
    height: 100%;
    background: var(--color-accent);
    border-radius: 4px;
    transition: width .3s ease;
}

.progress-bar.success { background: var(--color-success); }

/* Import rapport */
.import-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.import-stat {
    background: var(--color-bg);
    border-radius: 6px;
    padding: 12px;
    text-align: center;
}

.import-stat .num {
    font-size: 28px;
    font-weight: 700;
}

.import-stat .lbl {
    font-size: 11px;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.import-stat.inserted .num { color: var(--color-success); }
.import-stat.ignored  .num { color: var(--color-text-light); }
.import-stat.reseq    .num { color: var(--color-warning); }
.import-stat.error    .num { color: var(--color-danger); }

/* ==========================================================
   Responsive : mobile
   ========================================================== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.4);
        z-index: 199;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .btn-menu {
        display: block;
    }

    .content-area {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================
   Utilitaires
   ========================================================== */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex  { display: flex; }
.flex-1 { flex: 1; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--color-text-light); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.font-bold { font-weight: 700; }
.font-mono { font-family: 'Consolas', 'Courier New', monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
