/* ============================================================
   B-Stock — Feuille de styles principale
   ============================================================ */

:root {
    --primary:      #4F46E5;
    --primary-dark: #3730a3;
    --primary-light:#EEF2FF;
    --success:      #16a34a;
    --warning:      #d97706;
    --danger:       #dc2626;
    --info:         #0891b2;
    --sidebar-bg:   #1E293B;
    --sidebar-w:    260px;
    --topbar-h:     64px;
    --text:         #1e293b;
    --muted:        #64748b;
    --border:       #e2e8f0;
    --bg:           #F1F5F9;
    --card-bg:      #FFFFFF;
    --radius:       12px;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:    0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
    --shadow-lg:    0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
    --transition:   all .2s ease;
}

/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; }

/* ── Layout ───────────────────────────────────────────── */
.wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    z-index: 1040;
    transition: transform .3s ease;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo-img {
    width: 42px; height: 42px;
    border-radius: 10px;
    object-fit: cover;
}
.sidebar-logo-placeholder {
    width: 42px; height: 42px;
    background: var(--primary);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 20px;
    flex-shrink: 0;
}
.sidebar-title h5 {
    color: #fff; font-size: 14px; font-weight: 600;
    margin: 0; line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 140px;
}
.sidebar-title small { color: rgba(255,255,255,.4); font-size: 11px; }

.sidebar-toggle-btn {
    background: none; border: none; color: rgba(255,255,255,.5);
    padding: 6px; margin-left: auto; cursor: pointer;
    font-size: 16px;
}
.sidebar-toggle-btn:hover { color: #fff; }

.sidebar-nav { list-style: none; padding: 12px 0; margin: 0; flex: 1; }
.sidebar-nav-section {
    padding: 12px 20px 6px;
    color: rgba(255,255,255,.3);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}
.sidebar-nav-item > a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px;
    color: rgba(255,255,255,.65);
    border-radius: 0;
    transition: var(--transition);
    font-size: 13.5px;
    font-weight: 500;
    position: relative;
}
.sidebar-nav-item > a i {
    width: 18px; text-align: center; font-size: 15px; flex-shrink: 0;
}
.sidebar-nav-item > a span:first-of-type { flex: 1; }
.sidebar-nav-item > a:hover {
    color: #fff;
    background: rgba(255,255,255,.06);
}
.sidebar-nav-item.active > a {
    color: #fff;
    background: var(--primary);
    border-radius: 8px;
    margin: 2px 12px;
    padding: 10px 14px;
}
.sidebar-nav-item.active > a i { color: #fff; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-footer-info { color: rgba(255,255,255,.35); font-size: 11px; display: flex; align-items: center; }

/* ── Main content ─────────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin .3s ease;
}

/* ── Topbar ───────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.breadcrumb-item a { color: var(--muted); font-size: 13px; }
.breadcrumb-item.active { color: var(--text); font-size: 13px; font-weight: 500; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--muted); }

/* ── Page content ─────────────────────────────────────── */
.page-content { padding: 24px; flex: 1; }

/* ── Cards ────────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 15px; font-weight: 600; margin: 0; }
.card-body { padding: 20px; }

/* ── Stat cards ───────────────────────────────────────── */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex; align-items: flex-start; justify-content: space-between;
    transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.stat-card-icon.primary   { background: var(--primary-light); color: var(--primary); }
.stat-card-icon.success   { background: #dcfce7; color: var(--success); }
.stat-card-icon.warning   { background: #fef3c7; color: var(--warning); }
.stat-card-icon.danger    { background: #fee2e2; color: var(--danger); }
.stat-card-icon.info      { background: #cffafe; color: var(--info); }

.stat-card-value {
    font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.2;
    margin-bottom: 2px;
}
.stat-card-label { color: var(--muted); font-size: 12.5px; }

/* ── Badges ───────────────────────────────────────────── */
.badge { font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: 6px; }
.badge-primary   { background: var(--primary-light); color: var(--primary); }
.badge-success   { background: #dcfce7; color: var(--success); }
.badge-warning   { background: #fef3c7; color: #92400e; }
.badge-danger    { background: #fee2e2; color: var(--danger); }
.badge-info      { background: #cffafe; color: #0e7490; }
.badge-secondary { background: #f1f5f9; color: var(--muted); }

/* ── Buttons ──────────────────────────────────────────── */
.btn { border-radius: 8px; font-weight: 500; font-size: 13.5px; transition: var(--transition); }
.btn-primary   { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success   { background: var(--success); border-color: var(--success); }
.btn-success:hover { background: #15803d; border-color: #15803d; }
.btn-danger    { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-icon {
    background: none; border: none; width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px; color: var(--muted);
    padding: 0; cursor: pointer;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-whatsapp {
    background: #25D366; border-color: #25D366; color: #fff;
}
.btn-whatsapp:hover { background: #128C7E; border-color: #128C7E; color: #fff; }

/* ── Forms ────────────────────────────────────────────── */
.form-control, .form-select {
    border-radius: 8px;
    border-color: var(--border);
    font-size: 13.5px;
    transition: var(--transition);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.form-label { font-weight: 500; font-size: 13px; color: var(--text); margin-bottom: 6px; }
.input-group-text { border-radius: 8px; border-color: var(--border); background: var(--bg); font-size: 13px; }

/* ── Tables ───────────────────────────────────────────── */
.table { font-size: 13.5px; }
.table th {
    font-weight: 600; font-size: 12px; letter-spacing: .5px;
    text-transform: uppercase; color: var(--muted);
    border-bottom-width: 1px; white-space: nowrap;
}
.table td { vertical-align: middle; }
.table tbody tr:hover { background: var(--bg); }
.table-responsive { border-radius: var(--radius); }

/* ── Page header ──────────────────────────────────────── */
.page-header {
    margin-bottom: 24px;
    display: flex; align-items: flex-start; justify-content: space-between;
    flex-wrap: wrap; gap: 12px;
}
.page-header-title h4 { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.page-header-title p  { color: var(--muted); margin: 0; font-size: 13px; }

/* ── Facture creator ──────────────────────────────────── */
.facture-product-row { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 8px; }
.facture-total-box {
    background: var(--primary-light);
    border-radius: var(--radius);
    padding: 20px;
}
.facture-total-box .total-item { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.facture-total-box .total-final { display: flex; justify-content: space-between; border-top: 2px solid var(--primary); padding-top: 10px; font-size: 18px; font-weight: 700; color: var(--primary); }

/* ── Invoice print ────────────────────────────────────── */
.invoice-paper {
    background: #fff;
    max-width: 860px;
    margin: 0 auto;
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.invoice-header { display: flex; justify-content: space-between; margin-bottom: 32px; }
.invoice-logo img { max-height: 80px; max-width: 180px; object-fit: contain; }
.invoice-company-info { text-align: right; }
.invoice-company-info h3 { font-size: 18px; font-weight: 700; }
.invoice-title { font-size: 28px; font-weight: 800; color: var(--primary); text-transform: uppercase; letter-spacing: 2px; }
.invoice-items table thead th { background: var(--primary); color: #fff; padding: 10px 12px; }
.invoice-items table tbody td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.invoice-signature { display: flex; justify-content: space-between; margin-top: 40px; }
.signature-box { width: 200px; }
.signature-box label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; border-top: 2px solid var(--border); display: block; padding-top: 8px; margin-top: 60px; }

/* ── Modals ───────────────────────────────────────────── */
.modal-content { border-radius: var(--radius); border: none; box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--border); padding: 16px 20px; }
.modal-footer { border-top: 1px solid var(--border); padding: 14px 20px; }
.modal-title { font-weight: 600; font-size: 16px; }

/* ── Sidebar overlay (mobile) ─────────────────────────── */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.4); z-index: 1035;
}
.sidebar-overlay.show { display: block; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 1199.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0 !important;
    }
}

@media (max-width: 767.98px) {
    .page-content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .invoice-paper { padding: 20px; }
    .stat-card-value { font-size: 18px; }
}

/* ── Animations ───────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn .3s ease; }

/* ── Empty state ──────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 60px 20px; color: var(--muted);
}
.empty-state i { font-size: 48px; opacity: .25; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Search bar ───────────────────────────────────────── */
.search-bar { position: relative; }
.search-bar input { padding-left: 36px; }
.search-bar i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }

/* ── Stock indicator ──────────────────────────────────── */
.stock-ok      { color: var(--success); font-weight: 600; }
.stock-warning { color: var(--warning); font-weight: 600; }
.stock-danger  { color: var(--danger);  font-weight: 600; }

/* ── Chart container ──────────────────────────────────── */
.chart-container { position: relative; height: 280px; }

/* ── Select2 customization ────────────────────────────── */
.select2-container .select2-selection--single {
    height: 38px !important;
    border-color: var(--border) !important;
    border-radius: 8px !important;
}
.select2-container .select2-selection--single .select2-selection__rendered {
    line-height: 38px !important;
    font-size: 13.5px !important;
}
.select2-container .select2-selection--single .select2-selection__arrow {
    height: 36px !important;
}

/* ── Loading spinner ──────────────────────────────────── */
.spinner-overlay {
    position: fixed; inset: 0; background: rgba(255,255,255,.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999; display: none;
}
.spinner-overlay.show { display: flex; }

/* ── Rapport cards ────────────────────────────────────── */
.rapport-kpi {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff; border-radius: var(--radius); padding: 24px;
}
.rapport-kpi h2 { font-size: 28px; font-weight: 800; margin-bottom: 4px; }
.rapport-kpi p  { opacity: .8; font-size: 13px; margin: 0; }

/* ── Progress bar ─────────────────────────────────────── */
.progress { height: 8px; border-radius: 4px; background: var(--bg); }
.progress-bar { border-radius: 4px; }

/* ── Scrollbar global ─────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #cbd5e1; }

/* ── Print styles ─────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .btn, .no-print { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    .invoice-paper { box-shadow: none; padding: 0; }
    body { background: #fff; }
}
