/* =====================================================================
   DerPest Manager — design system
   Inspiré de l'application mobile Orange : bandeau compte, tuiles d'accès,
   barre de navigation basse ; couleurs DerPest vert & bleu.
   ===================================================================== */
:root {
  --green: #14A44D;
  --green-dark: #0E7D3A;
  --green-soft: #E3F5EA;
  --blue: #0A5DA8;
  --blue-dark: #073F73;
  --blue-soft: #E4EEF8;
  --ink: #12202E;
  --ink-2: #44546A;
  --ink-3: #7A889A;
  --line: #DCE4EC;
  --bg: #EEF3F7;
  --panel: #FFFFFF;
  --amber: #E59A00;
  --amber-soft: #FFF3D6;
  --red: #D23B3B;
  --red-soft: #FCE5E5;
  --violet: #5B46C2;
  --violet-soft: #ECE8FB;
  --radius-lg: 22px;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(18, 32, 46, .06), 0 6px 18px rgba(18, 32, 46, .06);
  --font: "IBM Plex Sans", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sidebar: 268px;
  --bottom-nav: 66px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #E8EEF5; --ink-2: #B4C1D0; --ink-3: #8696AA; --line: #2A3A4C; --bg: #0F1823; --panel: #172433;
    --green-soft: #12351F; --blue-soft: #132C47; --amber-soft: #3A2D0B; --red-soft: #3D1A1A; --violet-soft: #251E48;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #E8EEF5; --ink-2: #B4C1D0; --ink-3: #8696AA; --line: #2A3A4C; --bg: #0F1823; --panel: #172433;
  --green-soft: #12351F; --blue-soft: #132C47; --amber-soft: #3A2D0B; --red-soft: #3D1A1A; --violet-soft: #251E48;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
small, .small { font-size: .85em; }
.muted { color: var(--ink-3); }
.nowrap { white-space: nowrap; }
.right { text-align: right; } [dir="rtl"] .right { text-align: left; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------------- Structure ---------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--blue-dark); color: #DCE8F5;
  display: flex; flex-direction: column; z-index: 40; overflow-y: auto; transition: transform .25s ease;
}
[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; color: #fff; font-weight: 700; font-size: 1.05rem; }
.sidebar .brand img { height: 34px; background: #fff; border-radius: 9px; padding: 3px 6px; }
.sidebar nav { padding: 6px 12px 24px; }
.sidebar .sect { margin: 16px 10px 6px; font-size: .78rem; color: #8FB0D3; font-weight: 600; }
.sidebar a.item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 11px; color: #DCE8F5; font-size: .93rem;
}
.sidebar a.item i { font-size: 1.1rem; width: 22px; text-align: center; color: #9CC2E8; }
.sidebar a.item:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar a.item.active { background: var(--green); color: #fff; }
.sidebar a.item.active i { color: #fff; }
.main { flex: 1; margin-left: var(--sidebar); min-width: 0; display: flex; flex-direction: column; }
[dir="rtl"] .main { margin-left: 0; margin-right: var(--sidebar); }

.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 10px 24px;
  background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar .title { font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .icon-btn { position: relative; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  color: var(--ink); font-size: 1.25rem; cursor: pointer;
}
.icon-btn:hover { background: var(--bg); text-decoration: none; }
.dot { position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: .7rem; font-weight: 700; display: grid; place-items: center; }
.menu-toggle { display: none; }
.content { padding: 24px; max-width: 1320px; width: 100%; margin: 0 auto; flex: 1; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; flex: 1; min-width: 200px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.bottom-nav { display: none; }
.overlay { display: none; }

/* ---------------- Bandeau compte façon Orange ---------------- */
.hero {
  background: var(--blue); color: #fff; border-radius: var(--radius-lg); padding: 22px 24px; position: relative; overflow: hidden; margin-bottom: 18px;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -60px; width: 220px; height: 220px; border-radius: 50%;
  background: var(--green); opacity: .9;
}
[dir="rtl"] .hero::after { right: auto; left: -40px; }
.hero > * { position: relative; z-index: 1; }
.hero .hello { font-size: .95rem; opacity: .9; }
.hero .big { font-size: 2.3rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.hero .sub { opacity: .9; font-size: .92rem; }
.hero .hero-row { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 16px; }
.hero .hero-row div b { display: block; font-size: 1.15rem; }
.hero .hero-row div span { font-size: .82rem; opacity: .85; }
.hero .btn { background: #fff; color: var(--blue); }
.hero .btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }

/* ---------------- Tuiles d'accès rapide ---------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile {
  background: var(--panel); border-radius: var(--radius); padding: 16px 12px 14px; display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  color: var(--ink); box-shadow: var(--shadow); min-height: 104px; position: relative;
}
.tile:hover { text-decoration: none; transform: translateY(-1px); }
.tile i { font-size: 1.35rem; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--green-soft); color: var(--green-dark); }
.tile:nth-child(3n+2) i { background: var(--blue-soft); color: var(--blue); }
.tile span { font-weight: 600; font-size: .9rem; line-height: 1.25; }
.tile .count { position: absolute; top: 12px; right: 12px; background: var(--red); color: #fff; border-radius: 10px; font-size: .72rem; padding: 1px 7px; font-weight: 700; }
[dir="rtl"] .tile .count { right: auto; left: 12px; }

/* ---------------- Panneaux ---------------- */
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.panel > .ph { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel > .ph h2, .panel > .ph h3 { margin: 0; flex: 1; font-size: 1.02rem; }
.panel > .pb { padding: 18px; }
.panel > .pb.flush { padding: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.stat { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat .k { color: var(--ink-3); font-size: .85rem; }
.stat .v { font-size: 1.5rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .d { font-size: .82rem; margin-top: 4px; color: var(--ink-2); }
.stat.accent-green { border-left: 4px solid var(--green); }
.stat.accent-blue { border-left: 4px solid var(--blue); }
.stat.accent-amber { border-left: 4px solid var(--amber); }
.stat.accent-red { border-left: 4px solid var(--red); }

/* ---------------- Listes ---------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .t { font-weight: 600; }
.list .s { color: var(--ink-3); font-size: .85rem; }
.list .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--blue-soft); color: var(--blue); flex: none; }
.list a.row-link { color: inherit; display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.list a.row-link:hover { text-decoration: none; }

/* ---------------- Tableaux ---------------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: .82rem; padding: 10px 14px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 60%, var(--panel)); white-space: nowrap; }
[dir="rtl"] table.t th { text-align: right; }
table.t td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: color-mix(in srgb, var(--blue-soft) 35%, transparent); }
table.t td.actions { white-space: nowrap; text-align: right; }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.thumb { width: 42px; height: 42px; border-radius: 10px; object-fit: cover; background: var(--bg); flex: none; }
.cell-prod { display: flex; align-items: center; gap: 10px; }

/* ---------------- Formulaires ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field .hint { font-size: .8rem; color: var(--ink-3); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=tel], input[type=url], input[type=search], input[type=color], input[type=file], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--panel); border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 44px;
}
input[type=color] { padding: 4px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--green); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; margin-top: 18px; }
.inline-form { display: inline; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { min-width: 150px; flex: 1; }
.filters .field.narrow { flex: 0 0 140px; min-width: 120px; }

/* ---------------- Boutons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 9px 18px; border-radius: 999px;
  border: 1.5px solid transparent; background: var(--green); color: #fff; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--green-dark); text-decoration: none; }
.btn.blue { background: var(--blue); } .btn.blue:hover { background: var(--blue-dark); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--red); } .btn.danger:hover { background: #b02d2d; }
.btn.warn { background: var(--amber); }
.btn.sm { min-height: 34px; padding: 5px 13px; font-size: .86rem; }
.btn.block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue); font: inherit; cursor: pointer; }
.link-btn.danger { color: var(--red); }

/* ---------------- Badges & alertes ---------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--green-soft); color: var(--green-dark); }
.badge-info { background: var(--blue-soft); color: var(--blue); }
.badge-warn { background: var(--amber-soft); color: #8A5A00; }
.badge-danger { background: var(--red-soft); color: var(--red); }
.badge-muted { background: var(--bg); color: var(--ink-3); }
.badge-pro { background: var(--violet-soft); color: var(--violet); }
:root[data-theme="dark"] .badge-warn { color: #F2C14E; }

.alert { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .93rem; }
.alert i { font-size: 1.15rem; margin-top: 1px; }
.alert-success { background: var(--green-soft); color: var(--green-dark); }
.alert-error { background: var(--red-soft); color: var(--red); }
.alert-warning { background: var(--amber-soft); color: #7A5100; }
.alert-info { background: var(--blue-soft); color: var(--blue); }
:root[data-theme="dark"] .alert-warning { color: #F2C14E; }

/* ---------------- Catalogue ---------------- */
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.pcard { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; color: var(--ink); }
.pcard:hover { text-decoration: none; }
.pcard .img { aspect-ratio: 1 / 1; background: var(--bg); position: relative; }
.pcard .img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard .img .badges { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
[dir="rtl"] .pcard .img .badges { left: auto; right: 10px; }
.pcard .body { padding: 13px 14px 15px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.pcard .name { font-weight: 700; line-height: 1.25; }
.pcard .meta { color: var(--ink-3); font-size: .83rem; }
.pcard .price { font-weight: 700; font-size: 1.12rem; margin-top: auto; padding-top: 8px; display: flex; align-items: baseline; gap: 8px; }
.pcard .price s { color: var(--ink-3); font-weight: 400; font-size: .85rem; }
.pcard .stock { font-size: .8rem; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.chip { padding: 8px 16px; border-radius: 999px; background: var(--panel); border: 1.5px solid var(--line); color: var(--ink); white-space: nowrap; font-weight: 600; font-size: .88rem; }
.chip.active, .chip:hover { background: var(--blue); border-color: var(--blue); color: #fff; text-decoration: none; }
.doc-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 8px; }
.doc-row .ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--blue-soft); color: var(--blue); font-weight: 700; font-size: .8rem; }
.doc-row.locked { opacity: .75; border-style: dashed; }
.doc-row.locked .ic { background: var(--bg); color: var(--ink-3); }
.qty-input { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.qty-input button { width: 40px; height: 42px; border: 0; background: var(--bg); font-size: 1.2rem; cursor: pointer; color: var(--ink); }
.qty-input input { width: 64px; border: 0; text-align: center; min-height: 42px; border-radius: 0; }

/* ---------------- Suivi de commande ---------------- */
.track { display: flex; justify-content: space-between; position: relative; margin: 10px 0 6px; }
.track::before { content: ""; position: absolute; top: 15px; left: 6%; right: 6%; height: 4px; background: var(--line); border-radius: 2px; }
.track .step { position: relative; z-index: 1; text-align: center; flex: 1; font-size: .78rem; color: var(--ink-3); }
.track .step .b { width: 34px; height: 34px; border-radius: 50%; margin: 0 auto 6px; background: var(--panel); border: 3px solid var(--line); display: grid; place-items: center; font-size: .95rem; }
.track .step.done { color: var(--ink); font-weight: 600; }
.track .step.done .b { background: var(--green); border-color: var(--green); color: #fff; }
.track .step.current .b { border-color: var(--green); color: var(--green); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 26px; border-left: 2px solid var(--line); margin-left: 8px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--green); }
.timeline li:last-child { border-left-color: transparent; }
[dir="rtl"] .timeline li { padding: 0 26px 16px 0; border-left: 0; border-right: 2px solid var(--line); margin: 0 8px 0 0; }
[dir="rtl"] .timeline li::before { left: auto; right: -7px; }

/* ---------------- Onglets ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 16px; color: var(--ink-2); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* ---------------- Divers ---------------- */
.pager { display: flex; gap: 6px; flex-wrap: wrap; padding: 14px 18px; }
.pager a, .pager span { min-width: 36px; height: 36px; padding: 0 10px; display: grid; place-items: center; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--ink); }
.pager a.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.empty i { font-size: 2.4rem; display: block; margin-bottom: 8px; color: var(--line); }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; font-size: .93rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.progress { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--green); border-radius: 4px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.totals { margin-left: auto; width: min(360px, 100%); }
[dir="rtl"] .totals { margin-left: 0; margin-right: auto; }
.totals .line { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .line.grand { font-weight: 700; font-size: 1.15rem; border-top: 2px solid var(--line); margin-top: 6px; padding-top: 10px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.signature-box { border: 2px dashed var(--line); border-radius: var(--radius-sm); background: #fff; touch-action: none; width: 100%; height: 180px; }
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(10, 20, 30, .5); }
dialog .dh { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
dialog .dh h3 { margin: 0; flex: 1; }
dialog .db { padding: 20px; }
.lines-table input, .lines-table select { min-height: 38px; padding: 6px 8px; }
.lines-table td { padding: 6px 6px; }
.chart-box { position: relative; height: 280px; }
.notice-bar { background: var(--amber-soft); color: #7A5100; padding: 10px 24px; font-size: .9rem; }

/* ---------------- Authentification ---------------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-side { background: var(--blue); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side::before { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; background: var(--green); right: -180px; bottom: -200px; }
.auth-side > * { position: relative; }
.auth-side h1 { font-size: 2.3rem; max-width: 14ch; }
.auth-side p { max-width: 44ch; opacity: .92; font-size: 1.05rem; }
.auth-side .logo { background: #fff; border-radius: 14px; padding: 8px 12px; height: 58px; width: auto; align-self: flex-start; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.auth-card { width: min(440px, 100%); }
.auth-card h2 { font-size: 1.6rem; }
.auth-card .field { margin-bottom: 14px; }
.lang-switch { display: flex; gap: 6px; }
.lang-switch a { padding: 4px 10px; border-radius: 8px; font-size: .85rem; color: var(--ink-2); border: 1px solid var(--line); }
.lang-switch a.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------------- Mobile ---------------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.3); }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .main, [dir="rtl"] .main { margin: 0; }
  .menu-toggle { display: inline-grid; }
  .topbar { padding: 8px 12px; }
  .content { padding: 16px 16px calc(var(--bottom-nav) + 24px); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--bottom-nav) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel); border-top: 1px solid var(--line); z-index: 30;
  }
  .bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--ink-3); font-size: .7rem; font-weight: 600; background: none; border: 0; font-family: inherit; cursor: pointer; }
  .bottom-nav a i, .bottom-nav button i { font-size: 1.35rem; }
  .bottom-nav a.active { color: var(--green); }
  .bottom-nav a:hover { text-decoration: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .hero { border-radius: 0 0 var(--radius-lg) var(--radius-lg); margin: -16px -16px 16px; padding: 20px 18px 24px; }
  .hero .big { font-size: 2rem; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .tile { min-height: 96px; padding: 12px 10px; }
  .tile span { font-size: .8rem; }
  .products { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .pcard .body { padding: 10px 11px 12px; }
  .pcard .name { font-size: .9rem; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { padding: 28px 22px; min-height: 0; }
  .auth-side h1 { font-size: 1.6rem; }
  .auth-side p, .auth-side .foot { display: none; }
  .page-head h1 { font-size: 1.3rem; }
  /* tableaux empilés en cartes */
  table.t.stack thead { display: none; }
  table.t.stack, table.t.stack tbody, table.t.stack tr, table.t.stack td { display: block; width: 100%; }
  table.t.stack tr { border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.t.stack td { border: 0; padding: 4px 14px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.t.stack td::before { content: attr(data-label); color: var(--ink-3); font-size: .82rem; text-align: left; }
  table.t.stack td.actions { justify-content: flex-end; }
  table.t.stack td.actions::before { content: none; }
  table.t.stack tfoot { display: block; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------------- Impression ---------------- */
@media print {
  .sidebar, .topbar, .bottom-nav, .no-print, .form-actions { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0; }
  .panel { box-shadow: none; border: 1px solid #ccc; }
  body { background: #fff; }
}

/* Saisie en arabe ou en français : le sens suit le contenu */
[dir="rtl"] input[type="text"], [dir="rtl"] input[type="search"], [dir="rtl"] input:not([type]), [dir="rtl"] textarea { unicode-bidi: plaintext; }
