:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #1f2933;
    --muted: #6b7280;
    --border: #d9dee7;
    --primary: #176b5f;
    --primary-dark: #0f4d44;
    --danger: #c0392b;
    --success: #168a4a;
    --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}
body.theme-dark {
    --bg: #111827;
    --surface: #1f2937;
    --text: #f3f4f6;
    --muted: #aeb7c2;
    --border: #374151;
    --primary: #2fb39e;
    --primary-dark: #1f8f7e;
    --danger: #f87171;
    --success: #34d399;
    --shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}
html, body { min-height: 100%; }
body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}
a, a:hover, a:focus { text-decoration: none; }
#wrapper { width: 100%; min-height: 100vh; }
#page-wrapper {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 40px;
    background: transparent;
}
.topbar {
    width: min(1180px, calc(100% - 32px));
    margin: 16px auto 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; min-width: 0; }
.topbar-brand span:not(.offline-note) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-brand i { color: var(--primary); }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.topbar-quick { display: flex; align-items: center; gap: 8px; }
.topbar-toggle { display: none; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; }
.back-btn, .btn { border-radius: 6px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.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-danger { background: var(--danger); border-color: var(--danger); }
.header, .header-title, .page-hero, .alert, .form-container, .panel-card {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px 20px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
    text-align: left;
}
.header h2, .header-title h2, .page-hero h2 { margin: 0; font-size: 26px; font-weight: 700; color: var(--text); }
.header p, .page-hero p { margin: 6px 0 0; color: var(--muted); }
.header-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: auto; }
.header-title a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    min-height: 38px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    padding: 8px 10px;
}
.menu-grid, .row.text-center.pad-top, .dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
}
.menu-item {
    width: auto;
    min-height: 150px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    text-align: left;
    box-shadow: var(--shadow);
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.menu-item:hover { transform: translateY(-2px); border-color: var(--primary); }
.menu-item a { display: block; color: var(--text); }
.menu-item i { font-size: 34px; color: var(--primary); margin-bottom: 14px; }
.menu-item h4 { margin: 0; color: var(--text); font-size: 17px; font-weight: 700; }
.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px;
    box-shadow: var(--shadow);
}
.metric-card span { color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; }
.metric-card strong { display: block; margin-top: 8px; font-size: 28px; color: var(--text); }
.metric-card small { display: block; margin-top: 4px; color: var(--muted); font-weight: 700; }
.metric-card.warning strong { color: var(--danger); }
.notif-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 999px;
    min-width: 16px;
    text-align: center;
}
.notif-item { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; background: var(--surface); }
.notif-item.is-unread { border-left: 4px solid var(--primary); }
.notif-item .notif-titre { font-weight: 700; color: var(--text); }
.notif-item .notif-message { color: var(--muted); margin-top: 4px; }
.notif-item .notif-date { color: var(--muted); font-size: 12px; margin-top: 6px; display: block; }
.no-data { text-align: center; color: var(--muted); font-weight: 700; padding: 18px; }
.table-responsive { width: 100%; overflow-x: auto; }
.table { width: 100%; background: var(--surface); border-collapse: collapse; margin-top: 12px; }
.table th, .table td { padding: 12px 14px; text-align: left; border: 1px solid var(--border); vertical-align: middle; }
.table th { background: #eef3f2; color: var(--text); font-size: 13px; text-transform: uppercase; }
.table td { background: var(--surface); }
.pagination { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.pagination a { padding: 8px 12px; background: var(--surface); color: var(--primary); border: 1px solid var(--border); border-radius: 6px; }
.pagination .active, .pagination a:hover { background: var(--primary); color: #fff; }
.offline-note {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    background: #eef3f2;
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 700;
}
.theme-toggle {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    min-width: 38px;
    min-height: 34px;
}
.theme-toggle:hover { border-color: var(--primary); color: var(--primary); }
.amount-positive { color: var(--success); font-weight: 700; }
.amount-negative { color: var(--danger); font-weight: 700; }
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(23, 107, 95, 0.12), rgba(22, 138, 74, 0.08)),
        var(--bg);
}
.login-shell {
    width: min(940px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 420px;
    min-height: 560px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.16);
}
.login-brand {
    padding: 42px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: #123c36;
    color: #fff;
}
.login-brand i { font-size: 38px; }
.login-brand h1 { margin: 18px 0 10px; font-size: 34px; font-weight: 800; color: #fff; }
.login-brand p { margin: 0; color: rgba(255, 255, 255, 0.76); max-width: 420px; }
.login-badges { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.login-badges span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    color: rgba(255, 255, 255, 0.88);
    font-weight: 700;
    font-size: 12px;
}
.login-card {
    padding: 42px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.login-card h2 { margin: 0 0 6px; font-size: 28px; font-weight: 800; color: var(--text); }
.login-card p { margin: 0 0 26px; color: var(--muted); }
.login-card label { color: var(--text); font-weight: 700; }
.login-card .form-control {
    min-height: 44px;
    border-radius: 6px;
    border-color: var(--border);
    box-shadow: none;
}
.login-card .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(23, 107, 95, 0.14);
}
.login-card .btn {
    width: 100%;
    min-height: 46px;
    font-weight: 800;
}
.login-error {
    margin-top: 16px;
    padding: 12px 14px;
    border: 1px solid rgba(192, 57, 43, 0.28);
    border-radius: 6px;
    background: rgba(192, 57, 43, 0.08);
    color: var(--danger);
    font-weight: 700;
}
@media (max-width: 700px) {
    #page-wrapper, .topbar { width: calc(100% - 20px); }
    .topbar { align-items: center; flex-direction: row; flex-wrap: wrap; position: relative; }
    .topbar-brand { flex: 1 1 auto; }
    .offline-note .btn-label { display: none; }
    .topbar-toggle { display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; }
    .topbar-actions {
        display: none;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        order: 3;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid var(--border);
        gap: 6px;
    }
    .topbar-actions.is-open { display: flex; }
    .topbar-actions .btn {
        width: 100%;
        display: flex;
        align-items: center;
        gap: 10px;
        justify-content: flex-start;
        min-height: 42px;
        padding: 8px 12px;
    }
    .header-title { align-items: flex-start; flex-direction: column; }
    .header h2, .header-title h2, .page-hero h2 { font-size: 22px; }
    .login-page { padding: 14px; place-items: stretch; }
    .login-shell { grid-template-columns: 1fr; min-height: 0; }
    .login-brand { padding: 28px; }
    .login-brand h1 { font-size: 28px; }
    .login-card { padding: 28px; }
    .menu-grid, .row.text-center.pad-top, .dashboard-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
    .menu-item { min-height: 116px; padding: 14px; }
    .menu-item i { font-size: 26px; margin-bottom: 8px; }
    .menu-item h4 { font-size: 14px; }
}

@media (max-width: 420px) {
    .menu-grid, .row.text-center.pad-top, .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
    .topbar-brand span:not(.offline-note) { max-width: 40vw; }
}

/* ---------- Depots, stock et filtres de recherche ---------- */
.stock-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline; }
.action-sep { color: var(--muted); margin: 0 4px; }
.link-danger { background: none; border: 0; padding: 0; color: var(--danger); cursor: pointer; }
.stock-low td { background: rgba(192, 57, 43, 0.08) !important; }
.stock-badge { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; vertical-align: middle; }
.breadcrumb-link { display: inline-block; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.breadcrumb-link:hover { color: var(--primary); }
.depot-place { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 14px; }
.filter-field { position: relative; flex: 1 1 260px; min-width: 0; }
.filter-field i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.filter-field .form-control { padding-left: 34px; height: 40px; }
.filter-select { width: auto; min-width: 180px; height: 40px; flex: 0 1 220px; }
.filter-check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 600; color: var(--text); white-space: nowrap; }
.filter-count { color: var(--muted); font-size: 13px; font-weight: 700; margin-left: auto; white-space: nowrap; }
.filter-empty { text-align: center; color: var(--muted); padding: 18px 0; margin: 0; }

.empty-state { text-align: center; padding: 36px 16px; background: var(--surface); border: 1px dashed var(--border); border-radius: 8px; color: var(--text); }
.empty-state > i { font-size: 40px; color: var(--primary); }
.empty-state h3 { margin: 10px 0 6px; font-size: 20px; }
.empty-state p { color: var(--muted); margin: 0 0 14px; }

.depot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.depot-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.depot-link { display: block; padding: 18px 18px 12px; color: var(--text); flex: 1; border-radius: 8px 8px 0 0; }
.depot-link:hover { background: rgba(23, 107, 95, 0.06); color: var(--text); }
.depot-link h3 { margin: 6px 0 0; font-size: 19px; font-weight: 700; }
.depot-icon { font-size: 26px; color: var(--primary); }
.depot-stats { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; }
.depot-stats span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.depot-stats strong { font-size: 17px; }
.depot-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 18px 16px; border-top: 1px solid var(--border); }
.depot-rename { padding: 16px 18px 0; }
.depot-rename label { margin-top: 6px; }
.depot-rename .depot-actions { padding: 12px 0 16px; border-top: 0; }
.depot-split { list-style: none; padding: 0; margin: 0; border: 1px solid var(--border); border-radius: 6px; }
.depot-split li { display: flex; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.depot-split li:last-child { border-bottom: 0; }
.depot-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.depot-picker label { margin: 0; font-weight: 700; }
.depot-picker select { width: auto; min-width: 220px; }

.qty-input, .price-input { max-width: 170px; }
.row-filled td { background: rgba(22, 138, 74, 0.08) !important; }
.row-filled .qty-input { border-color: var(--success); font-weight: 700; }
.input-changed { border-color: var(--primary) !important; box-shadow: 0 0 0 2px rgba(23, 107, 95, 0.18); font-weight: 700; }
.submit-bar { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px; margin-top: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); }
.submit-bar > span { margin-right: auto; color: var(--muted); font-weight: 600; }

@media (max-width: 640px) {
    .filter-select, .filter-field { flex: 1 1 100%; }
    .filter-count { margin-left: 0; }
    .submit-bar > span { flex: 1 1 100%; }
    .qty-input, .price-input { max-width: none; min-width: 90px; }
}
.header-title a.breadcrumb-link { display: inline-flex; min-width: 0; min-height: 0; padding: 0; background: none; color: var(--muted); gap: 6px; }
.header-title a.breadcrumb-link:hover { color: var(--primary); }
.header-title a.btn-default { background: var(--surface); color: var(--text); border: 1px solid var(--border); gap: 6px; }
.header-title a.btn-success { background: var(--success); gap: 6px; }
.header-title a.btn { gap: 6px; }
.alert > p + form, .alert > p + .filter-bar, .alert > p + hr { margin-top: 12px; }
@media (max-width: 640px) { .hide-sm { display: none !important; } }
.depot-picker label { color: var(--text) !important; }

/* Barre de recherche compacte : zone de recherche courte + petit bouton filtre cote a cote */
.filter-bar { flex-wrap: wrap; gap: 8px; }
.filter-bar .filter-field { flex: 0 1 260px; }
.filter-bar .filter-field .form-control { height: 34px; }
.filter-toggle { height: 34px; width: 38px; padding: 0; position: relative; }
.filter-toggle.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.filter-toggle.filter-on::after { content: ""; position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.filter-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex-basis: 100%; }
.filter-panel[hidden] { display: none; }
.filter-panel .filter-select { height: 34px; flex: 0 1 220px; }
@media (max-width: 640px) {
    .filter-bar .filter-field { flex: 1 1 auto; }
    .filter-panel .filter-select { flex: 1 1 100%; }
}

/* ---------- Vente : lignes par depot ---------- */
.vente-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 18px; align-items: start; }
.vente-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 18px; color: var(--text); }
.vente-card h3 { margin: 0 0 12px; font-size: 18px; font-weight: 700; }
.vente-card label { color: var(--text) !important; font-weight: 700; font-size: 12px; text-transform: uppercase; margin-bottom: 4px; }
.vente-ligne { display: grid; grid-template-columns: minmax(0, 1fr) 110px 120px 40px; gap: 10px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--border); }
.vente-ligne:last-child { border-bottom: 0; }
.vente-ligne .l-total { height: 34px; display: flex; align-items: center; justify-content: flex-end; font-weight: 700; font-size: 15px; }
.vente-ligne .l-remove { height: 34px; margin-top: 22px; }
.vente-ligne .l-info { display: flex; flex-wrap: wrap; gap: 6px; min-height: 22px; margin-top: 6px; }
.l-chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; background: rgba(23, 107, 95, 0.1); color: var(--primary); font-size: 12px; font-weight: 700; }
.l-chip-error { background: rgba(192, 57, 43, 0.12); color: var(--danger); }
.vente-ligne.l-error .l-qty { border-color: var(--danger); }

/* Autocompletion en cartes : un produit par depot ou il est en stock */
.picker { position: relative; }
.picker-icon { position: absolute; left: 12px; top: 10px; color: var(--muted); pointer-events: none; }
.picker .l-nom { padding-left: 34px; }
.picker-cards { position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 6px); max-height: 340px; overflow-y: auto; padding: 8px; display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18); }
.picker-cards[hidden] { display: none; }
.pc-card { padding: 10px 12px; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 8px; background: var(--surface); cursor: pointer; transition: background .12s, border-color .12s, transform .12s; }
.pc-card:hover, .pc-card.active { background: rgba(23, 107, 95, 0.07); border-color: var(--primary); }
.pc-card.active { transform: translateX(2px); }
.pc-card.disabled { opacity: .55; cursor: not-allowed; border-left-color: var(--muted); }
.pc-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.pc-name { font-weight: 700; font-size: 15px; color: var(--text); }
.pc-name mark { background: rgba(245, 180, 0, 0.35); color: inherit; padding: 0 1px; border-radius: 2px; }
.pc-price { font-weight: 700; color: var(--primary); white-space: nowrap; }
.pc-bottom { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; font-size: 12px; }
.pc-depot { color: var(--muted); font-weight: 600; }
.pc-stock { padding: 2px 9px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.pc-ok { background: rgba(22, 138, 74, 0.12); color: var(--success); }
.pc-low { background: rgba(245, 158, 11, 0.18); color: #b45309; }
.pc-out { background: rgba(192, 57, 43, 0.12); color: var(--danger); }
.pc-empty { padding: 14px; text-align: center; color: var(--muted); }
.vente-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; margin-top: 14px; }
.vente-summary .summary-line { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.vente-summary .summary-line small { display: block; color: var(--muted); font-size: 11px; }
.vente-summary .summary-total { display: flex; justify-content: space-between; margin-top: 12px; font-size: 20px; font-weight: 700; }
.vente-summary .summary-empty { color: var(--muted); font-style: italic; }
.facture-modif { color: var(--muted); font-size: 12px; margin-top: 6px; }
@media (max-width: 900px) {
    .vente-layout { grid-template-columns: 1fr; }
    .vente-ligne { grid-template-columns: 1fr 1fr 40px; }
    .vente-ligne .l-prod-field { grid-column: 1 / -1; }
}

/* Entete : plus de liens (Vente, Stock) -> on compacte sur les ecrans moyens */
@media (min-width: 701px) and (max-width: 1250px) {
    .topbar .offline-note { display: none; }
    .topbar-actions { gap: 6px; }
    .topbar-actions .btn { padding: 6px 9px; font-size: 13px; }
}
@media (min-width: 701px) and (max-width: 1020px) {
    .topbar-actions .btn-label { display: none; }
}
