:root {
    --font-head: 'Bricolage Grotesque', sans-serif;
    --font-body: 'Manrope', sans-serif;
    --radius: 16px;
    --radius-sm: 11px;
    --shadow: 0 12px 40px rgba(0,0,0,.35);
    --tr: .2s cubic-bezier(.4,0,.2,1);
}

/* ---------- THEMES ---------- */
html[data-theme="dark"] {
    --bg: #0c1015;
    --bg-2: #12181f;
    --panel: #161d26;
    --panel-2: #1c2530;
    --border: #253040;
    --text: #eaf0f6;
    --text-dim: #9db0c2;
    --muted: #6d8299;
    --brand: #2fd4a7;
    --brand-2: #14b88a;
    --accent: #ff7a45;
    --red: #ff5c6c;
    --red-bg: rgba(255,92,108,.14);
    --orange: #ffa236;
    --orange-bg: rgba(255,162,54,.14);
    --green: #35d08a;
    --green-bg: rgba(53,208,138,.14);
    --input: #0e141b;
}
html[data-theme="light"] {
    --bg: #eef2f6;
    --bg-2: #e6ebf1;
    --panel: #ffffff;
    --panel-2: #f4f7fa;
    --border: #dde5ee;
    --text: #14202c;
    --text-dim: #4a5c6e;
    --muted: #78899c;
    --brand: #0e9c78;
    --brand-2: #0b8467;
    --accent: #e5602a;
    --red: #dc3546;
    --red-bg: rgba(220,53,70,.10);
    --orange: #d97a12;
    --orange-bg: rgba(217,122,18,.12);
    --green: #158f5f;
    --green-bg: rgba(21,143,95,.12);
    --input: #ffffff;
    --shadow: 0 12px 34px rgba(30,50,80,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}
::selection { background: var(--brand); color: #04120d; }
a { color: inherit; text-decoration: none; }
h1,h2,h3,h4 { font-family: var(--font-head); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }

/* ---------- APP SHELL ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 248px; flex-shrink: 0; background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 22px 16px;
    position: sticky; top: 0; height: 100vh; z-index: 60;
    transition: transform var(--tr);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 22px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #04120d;
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-text { font-family: var(--font-head); font-size: 1.15rem; font-weight: 600; }
.brand-text strong { font-weight: 800; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
    display: flex; align-items: center; gap: 12px; padding: 11px 13px;
    border-radius: var(--radius-sm); color: var(--text-dim); font-weight: 600; font-size: .95rem;
    transition: background var(--tr), color var(--tr);
}
.nav-link svg { width: 19px; height: 19px; }
.nav-link:hover { background: var(--panel); color: var(--text); }
.nav-link.is-active { background: var(--brand); color: #04120d; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.nav-admin { color: var(--muted); }

/* ---------- MAIN ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 12px; padding: 14px 26px;
    border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 40;
}
.topbar-spacer { flex: 1; }
.menu-toggle { display: none; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--border);
    background: var(--panel); color: var(--text-dim); display: grid; place-items: center;
    cursor: pointer; transition: var(--tr);
}
.icon-btn:hover { color: var(--text); border-color: var(--brand); }
.icon-btn svg { width: 19px; height: 19px; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 5px 12px 5px 5px; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #04120d; font-weight: 800; font-size: .85rem; }
.user-name { font-weight: 600; font-size: .9rem; }
.content { padding: 28px; max-width: 1240px; width: 100%; margin: 0 auto; }

/* ---------- PAGE HEADER ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); }
.page-head p { color: var(--text-dim); margin-top: 4px; }
.eyebrow { color: var(--brand); font-weight: 700; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; }

/* ---------- CARDS / STATS ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 18px 16px; position: relative; overflow: hidden; transition: var(--tr);
}
.stat:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--brand) 50%, var(--border)); }
.stat .stat-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--panel-2); color: var(--brand); margin-bottom: 12px; }
.stat .stat-ico svg { width: 19px; height: 19px; }
.stat .stat-val { font-family: var(--font-head); font-size: 2rem; font-weight: 800; line-height: 1; }
.stat .stat-label { color: var(--text-dim); font-size: .86rem; margin-top: 6px; }
.stat.is-red .stat-ico { color: var(--red); background: var(--red-bg); }
.stat.is-orange .stat-ico { color: var(--orange); background: var(--orange-bg); }
.stat.is-green .stat-ico { color: var(--green); background: var(--green-bg); }

.grid-2 { display: grid; grid-template-columns: 1.2fr .8fr; gap: 20px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.panel-head h3 { font-size: 1.05rem; }
.panel-body { padding: 8px 20px 20px; }
.panel-body.flush { padding: 0; }

/* ---------- ALERTS ---------- */
.alert-bag { border-bottom: 1px solid var(--border); padding: 14px 20px; }
.alert-bag:last-child { border-bottom: 0; }
.alert-bag-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; cursor: pointer; }
.alert-bag-head strong { font-family: var(--font-head); }
.alert-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: .9rem; }
.alert-line .dot { flex-shrink: 0; }

/* ---------- BADGES / DOTS ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.grey { background: var(--panel-2); color: var(--text-dim); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.red { background: var(--red); box-shadow: 0 0 0 4px var(--red-bg); }
.dot.orange { background: var(--orange); box-shadow: 0 0 0 4px var(--orange-bg); }
.dot.green { background: var(--green); box-shadow: 0 0 0 4px var(--green-bg); }
.dot.grey { background: var(--muted); }

/* ---------- TABLES ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; padding: 12px 16px; color: var(--muted); font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr { transition: background var(--tr); }
table.data tbody tr:hover { background: var(--panel-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- BAG CARDS ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.bag-card { display: block; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: var(--tr); position: relative; }
.bag-card:hover { transform: translateY(-4px); border-color: color-mix(in srgb, var(--brand) 55%, var(--border)); box-shadow: var(--shadow); }
.bag-card .ref { color: var(--brand); font-weight: 700; font-size: .8rem; letter-spacing: .04em; }
.bag-card h3 { font-size: 1.2rem; margin: 4px 0 10px; }
.bag-meta { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: .88rem; margin-bottom: 6px; }
.bag-meta svg { width: 15px; height: 15px; }
.bag-card-foot { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- BUTTONS ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 11px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-family: var(--font-body); font-weight: 700; font-size: .9rem; cursor: pointer; transition: var(--tr); white-space: nowrap; }
.btn svg { width: 17px; height: 17px; }
.btn:hover { border-color: var(--brand); }
.btn-primary { background: var(--brand); color: #04120d; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: .82rem; }

/* ---------- FORMS ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--text-dim); }
input, select, textarea {
    font-family: var(--font-body); font-size: .95rem; padding: 11px 13px; border-radius: 11px;
    border: 1px solid var(--border); background: var(--input); color: var(--text); width: 100%; transition: var(--tr);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
textarea { resize: vertical; min-height: 72px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check { flex-direction: row; align-items: center; gap: 10px; }
.check input { width: auto; }

/* ---------- MODAL ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(4,8,12,.66); backdrop-filter: blur(4px); display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 120; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 560px; box-shadow: var(--shadow); animation: pop .22s ease; }
.modal.wide { max-width: 820px; }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 1.15rem; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ---------- MISC ---------- */
.muted { color: var(--text-dim); }
.small { font-size: .82rem; }
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty svg { width: 42px; height: 42px; margin-bottom: 10px; opacity: .5; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tab { padding: 12px 16px; font-weight: 700; color: var(--text-dim); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.is-active { color: var(--text); border-bottom-color: var(--brand); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); font-size: .85rem; font-weight: 600; cursor: pointer; color: var(--text-dim); transition: var(--tr); }
.chip.is-active { background: var(--brand); color: #04120d; border-color: var(--brand); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 20px; }
.toolbar .search { flex: 1; min-width: 200px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- TOAST ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(30px); background: var(--panel); border: 1px solid var(--border); color: var(--text); padding: 13px 20px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; z-index: 200; opacity: 0; pointer-events: none; transition: var(--tr); max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55; display: none; }
.scrim.show { display: block; }

/* ---------- AUTH ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-wrap { display: grid; grid-template-columns: 1.05fr .95fr; max-width: 980px; width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 24px; overflow: hidden; box-shadow: var(--shadow); }
.auth-side { padding: 46px 42px; background: linear-gradient(160deg, var(--bg-2), var(--panel-2)); display: flex; flex-direction: column; }
.auth-hero { font-size: 2rem; margin: 40px 0 14px; }
.auth-sub { color: var(--text-dim); max-width: 34ch; }
.auth-points { list-style: none; margin-top: 30px; display: flex; flex-direction: column; gap: 14px; }
.auth-points li { display: flex; align-items: center; gap: 11px; color: var(--text-dim); font-weight: 600; font-size: .92rem; }
.auth-points svg { width: 19px; height: 19px; color: var(--brand); }
.auth-card-zone { padding: 46px 42px; display: flex; align-items: center; }
.auth-card { width: 100%; position: relative; }
.auth-card h2 { font-size: 1.7rem; }
.auth-card .muted { margin-bottom: 22px; }
.auth-theme { position: absolute; top: -10px; right: 0; }
.auth-error { color: var(--red); font-size: .88rem; min-height: 20px; margin-bottom: 8px; font-weight: 600; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .auth-wrap { grid-template-columns: 1fr; max-width: 440px; }
    .auth-side { display: none; }
    .auth-card-zone { padding: 36px 28px; }
}
@media (max-width: 760px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); box-shadow: var(--shadow); }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: grid; }
    .content { padding: 18px 16px 60px; }
    .form-grid { grid-template-columns: 1fr; }
    .user-name { display: none; }
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dt { margin-top: 8px; }
}

/* ---------- PRINT (export PDF via le navigateur) ---------- */
@media print {
    html {
        --bg: #fff; --bg-2: #fff; --panel: #fff; --panel-2: #f4f4f4;
        --border: #bbb; --text: #000; --text-dim: #333; --muted: #555;
    }
    .sidebar, .topbar, .scrim, #toast, .tabs, .btn, .row-actions, .menu-toggle, #modalOverlay { display: none !important; }
    .app-shell, .main, .content { display: block; padding: 0; max-width: 100%; }
    .panel { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
    body { background: #fff; }
}
