@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;
    
    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-light: #f8fafc;
    
    --border-color: #e2e8f0;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
    
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── SIDEBAR ──────────────────────────────────────── */
aside#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    background: #0f172a;
    color: #e2e8f0;
    padding: 0;
    box-shadow: 4px 0 24px rgba(0,0,0,0.25);
    z-index: 50;
    display: flex;
    flex-direction: column;
    /* PAS de overflow:hidden — ça coupe le contenu */
}

/* Logo */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 15px;
    color: #ffffff;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(59,130,246,0.4);
    line-height: 1;
}

.logo-text {
    font-size: 19px;
    font-weight: 800;
    /* Fallback simple si gradient pas supporté */
    color: #93c5fd;
    letter-spacing: -0.5px;
}

/* Gradient text uniquement si supporté */
@supports (-webkit-background-clip: text) {
    .logo-text {
        background: linear-gradient(135deg, #60a5fa, #a78bfa);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
}

/* Company selector */
.comp-selector {
    background: rgba(255,255,255,0.05);
    padding: 9px 12px;
    margin: 10px 12px 4px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.comp-selector-label {
    font-size: 10px;
    text-transform: uppercase;
    color: #94a3b8;
    margin-bottom: 5px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.comp-selector-ro {
    color: #e2e8f0;
    font-weight: 600;
    font-size: 13px;
    text-align: center;
}

.comp-select {
    flex: 1;
    padding: 5px 6px;
    border-radius: 5px;
    border: 1px solid #94a3b8;
    background: #ffffff;
    font-weight: 600;
    font-size: 12px;
    color: #1e293b;
    cursor: pointer;
    min-width: 0;
}

.comp-manage-btn {
    padding: 5px 8px !important;
    font-size: 12px !important;
    background: #475569 !important;
    text-decoration: none;
    flex-shrink: 0;
    border-radius: 5px;
}

/* Scrollable nav area */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 8px 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.12) transparent;
    min-height: 0; /* important pour que flex:1 + overflow-y fonctionne */
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
    border-radius: 3px;
}

/* ─── ACCORDION SECTIONS ──────────────────────────── */

/* Conteneur de section */
.nav-section {
    margin-bottom: 2px;
}

/* Bouton toggle (titre de section cliquable) */
.nav-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 10px 5px;
    color: #64748b;
    font-family: inherit;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    user-select: none;
    transition: color 0.15s ease;
    border-radius: 5px;
}

.nav-section-toggle:hover {
    color: #94a3b8;
    background: rgba(255,255,255,0.03);
}

/* Chevron SVG — tourne quand ouvert */
.nst-chevron {
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    transform: rotate(-90deg); /* fermé = pointant à droite */
}

.nav-section.open .nst-chevron {
    transform: rotate(0deg); /* ouvert = pointant vers le bas */
}

/* Label du toggle */
.nst-label {
    flex: 1;
    text-align: left;
}

/* Corps collapsible */
.nav-section-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ligne de séparation subtile entre sections fermées */
.nav-section:not(.open) + .nav-section .nav-section-toggle {
    border-top: 1px solid rgba(255,255,255,0.03);
    padding-top: 9px;
}

/* Nav links */
.nav-link {
    display: flex;
    align-items: center;
    gap: 9px;
    color: #94a3b8;
    text-decoration: none;
    padding: 8px 11px;
    border-radius: 7px;
    margin-bottom: 1px;
    font-weight: 500;
    font-size: 13px;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
    /* PAS de overflow:hidden ici — c'est un flex container */
}

.nav-link:hover {
    background: rgba(255,255,255,0.06);
    color: #cbd5e1;
}

.nav-link.nav-active {
    background: rgba(59,130,246,0.15);
    color: #93c5fd;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #3b82f6;
    border-radius: 0 7px 7px 0;
    margin-left: -8px;
    padding-left: 19px;
}

.nav-link.nav-active .nav-icon {
    color: #60a5fa;
}

/* Nav label — texte qui peut tronquer */
.nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

/* Sub-links (indented) */
.nav-link.nav-sub {
    padding-left: 32px;
    font-size: 12px;
    color: #64748b;
    margin-bottom: 0;
    padding-top: 6px;
    padding-bottom: 6px;
}

.nav-link.nav-sub:hover { color: #94a3b8; background: rgba(255,255,255,0.04); }
.nav-link.nav-sub.nav-active { color: #93c5fd; }

/* Icon */
.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    color: #64748b;
    transition: color 0.15s ease;
}

.nav-link:hover .nav-icon { color: #94a3b8; }

/* Logout button */
.nav-logout {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #f87171;
    text-decoration: none;
    padding: 13px 20px;
    font-size: 13px;
    font-weight: 600;
    border-top: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-logout:hover {
    background: rgba(239,68,68,0.08);
    color: #fca5a5;
}

main {
    margin-left: 260px;
    padding: 30px 40px;
    min-height: 100vh;
}


header {
    background: var(--bg-card);
    padding: 18px 25px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border-color);
}

header b {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-main);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 25px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-head, .toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.card-head h2, .card-head h3, .card h2, .card h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-weight: 700;
    color: var(--text-main);
}

strong {
    font-size: 28px;
    font-weight: 800;
    color: var(--primary);
    display: block;
    margin-top: 5px;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-top: 15px;
}

th {
    background: #f8fafc;
    text-align: left;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    padding: 15px;
}

td {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 14px;
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: #f8fafc;
}

.badge {
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
    text-transform: capitalize;
}

.btn, button, .btn-small {
    border: 0;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: white;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.btn:hover, button:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.3);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.btn.secondary {
    background: #e2e8f0;
    color: #334155;
    box-shadow: none;
}
.btn.secondary:hover {
    background: #cbd5e1;
    transform: translateY(0);
}

input, select, textarea {
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin: 5px 0;
    width: 100%;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-main);
    background: #fff;
    transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
    min-height: 100px;
    resize: vertical;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
}
.form-grid label { display: flex; flex-direction: column; font-weight: 600; font-size: 13px; color: var(--text-main); }
.form-grid input, .form-grid select { margin-top: 6px; font-weight: 400; }
.form-grid .wide { grid-column: 1 / -1; }
.inline-form { display: inline; margin: 0; }

/* Alerts */
.alert { padding: 15px 20px; border-radius: var(--radius-md); margin: 0 0 20px; display: flex; align-items: center; font-weight: 500; font-size: 14px; }
.alert.success { background: #dcfce7; border: 1px solid #bbf7d0; color: #166534; }
.alert.error { background: #fee2e2; border: 1px solid #fecaca; color: #991b1b; }
.alert.warning { background: #fef9c3; border: 1px solid #fef08a; color: #854d0e; }
.ok-text { color: var(--success); font-weight: 700; }
.error-text { color: var(--danger); font-weight: 700; }
.muted { color: var(--text-muted); font-size: 14px; }

/* Invoices Document Preview (Keep minimal styling so it fits standard printed invoice) */
.invoice {
    background: white;
    max-width: 850px;
    margin: 20px auto;
    padding: 60px;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
    position: relative;
}
.invoice-header { display: flex; justify-content: space-between; align-items: flex-start; }
.logo-area h1 { margin: 0; font-weight: 800; font-size: 32px; color: var(--primary); }
.date-area { font-weight: 600; font-size: 14px; margin-top: 10px; color: var(--text-muted); }
.invoice-title { text-align: center; margin: 40px 0; }
.invoice-title h2 { font-size: 36px; font-weight: 800; margin: 0; letter-spacing: 1px; color: var(--text-main); }
.invoice-title p { font-size: 16px; margin: 5px 0 0; color: var(--text-muted); }
.invoice-cols { display: flex; justify-content: space-between; margin-bottom: 40px; font-size: 14px; line-height: 1.6; }
.invoice-cols div { width: 45%; }
.invoice-cols b { font-size: 12px; text-transform: uppercase; display: block; margin-bottom: 5px; color: var(--text-muted); letter-spacing: 0.5px;}

.invoice-table { width: 100%; border-collapse: collapse; margin-bottom: 30px; box-shadow: none; border-radius: 0; border: none; margin-top: 0; }
.invoice-table th { background: #f8fafc; color: var(--text-muted); padding: 12px; text-align: center; font-size: 13px; border-bottom: 2px solid var(--border-color); border-radius: 0;}
.invoice-table td { padding: 15px 12px; text-align: center; font-size: 14px; border-bottom: 1px solid var(--border-color); border-radius: 0;}
.invoice-table .separator-row td { padding: 10px 0; color: transparent; border: none; }

.invoice-summary { display: flex; justify-content: flex-end; margin-top: 20px; }
.totals-box { background: #f8fafc; padding: 25px 30px; width: 350px; font-size: 15px; border-radius: var(--radius-md); border: 1px solid var(--border-color); }
.tot-row { display: flex; justify-content: space-between; margin-bottom: 12px; }
.tot-row b { font-weight: 700; color: var(--text-muted); }
.tot-row.ttc { font-size: 20px; margin-top: 15px; margin-bottom: 0; padding-top: 15px; border-top: 1px solid var(--border-color); color: var(--text-main); font-weight: 800;}

.invoice-footer { margin-top: 60px; padding-top: 20px; border-top: 1px solid var(--border-color); }
.invoice-footer h3 { font-size: 16px; font-weight: 700; margin-bottom: 15px; }
.footer-cols { display: flex; justify-content: space-between; font-size: 12px; line-height: 1.6; color: var(--text-muted); }

/* OCR grids */
.ocr-grid { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(420px, 1.2fr); gap: 20px; align-items: start; }
.preview-card { position: sticky; top: 20px; }
.pdf-preview { width: 100%; height: 820px; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: #f1f5f9; }
.doc-preview { display: block; max-width: 100%; max-height: 850px; margin: auto; object-fit: contain; }

/* Statuses */
.status-validated, .status-payé { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.status-ocr_failed, .status-annulé { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.status-to_review, .status-brouillon, .status-partiel { background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }
.status-envoyé { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }
.status-en_retard { background: #ffedd5; color: #9a3412; border: 1px solid #fed7aa; }

details summary { cursor: pointer; font-weight: 700; }
pre { white-space: pre-wrap; word-break: break-word; background: #1e293b; color: #f8fafc; padding: 15px; border-radius: var(--radius-md); overflow: auto; }
code { background: #e2e8f0; color: #334155; padding: 3px 6px; border-radius: 4px; font-size: 13px; }

@media (max-width: 900px) {
    aside#sidebar { position: static; width: 100%; height: auto; display: block; padding: 15px; }
    main { margin: 0; padding: 15px; }
    .grid { grid-template-columns: 1fr; }
    .ocr-grid { grid-template-columns: 1fr; }
    .preview-card { position: static; }
    .invoice { padding: 20px; }
    .invoice-header, .invoice-cols, .footer-cols { display: block; margin-bottom: 20px; }
    .invoice-cols div { width: 100%; margin-bottom: 20px; }
    .totals-box { width: 100%; }
}

@media print {
    aside, header, .no-print, form, button, .btn { display: none !important; }
    main { margin: 0; padding: 0; }
    .invoice { box-shadow: none; max-width: 100%; padding: 0; margin: 0; border: none; }
    body { background: white; }
    .totals-box, .invoice-table th { background: #f8fafc !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
