:root {
  --bg: #080a0f;
  --panel: rgba(15, 18, 25, 0.74);
  --panel-solid: rgba(10, 12, 18, 0.92);
  --surface: #12151c;
  --surface-2: #1a1e27;
  --thead: #11141b;
  --overlay: rgba(4, 6, 10, 0.6);
  --line: rgba(255, 255, 255, 0.09);
  --ov: 255, 255, 255; /* teinte des surcouches (survols, champs) */
  --sunken: rgba(0, 0, 0, 0.25);
  --sunken-2: rgba(0, 0, 0, 0.2);
  --text: #e9ecf2;
  --muted: #8b93a4;
  --chip-ink: #c5cad6;
  --mark: #a9d2ff;
  --cancel-filter: invert(0.8);
  --accent: #4f9dff;
  --accent-ink: #04111f;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --warn: #ffcf6e;
  --sh-md: 0 10px 40px rgba(0, 0, 0, 0.35);
  --sh-lg: 0 30px 90px rgba(0, 0, 0, 0.6);
  --radius: 14px;
  --left-w: 360px;
  --right-w: 390px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}
:root[data-theme='light'] {
  --bg: #e7ecf4;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-solid: rgba(255, 255, 255, 0.95);
  --surface: #ffffff;
  --surface-2: #ffffff;
  --thead: #f1f4f9;
  --overlay: rgba(30, 41, 59, 0.35);
  --line: rgba(15, 23, 42, 0.12);
  --ov: 15, 23, 42;
  --sunken: rgba(15, 23, 42, 0.05);
  --sunken-2: rgba(15, 23, 42, 0.05);
  --text: #141a27;
  --muted: #5b6577;
  --chip-ink: #3a4456;
  --mark: #0b4aa8;
  --cancel-filter: none;
  --accent: #2f7bf0;
  --accent-ink: #ffffff;
  --danger: #d9363e;
  --ok: #15803d;
  --warn: #a15c00;
  --sh-md: 0 10px 34px rgba(40, 55, 90, 0.18);
  --sh-lg: 0 30px 80px rgba(40, 55, 90, 0.3);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; outline: none; cursor: grab; }

.glass {
  background: var(--panel);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid var(--line);
  box-shadow: var(--sh-md);
}

/* ───── Loader */
#loader { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--bg); transition: opacity 0.8s ease, visibility 0.8s; }
#loader.done { opacity: 0; visibility: hidden; }
.loader-box { display: flex; align-items: center; gap: 14px; color: var(--muted); letter-spacing: 0.02em; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(var(--ov), 0.12); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───── Top bar */
.topbar {
  position: fixed; z-index: 10; top: 14px; left: 14px; right: 14px; height: 60px;
  display: flex; align-items: center; gap: 16px; padding: 0 12px 0 14px; border-radius: 18px;
  animation: dropIn 0.8s 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
@keyframes dropIn { from { opacity: 0; transform: translateY(-24px); } }
.brand { display: flex; align-items: center; gap: 11px; min-width: 190px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 15px; letter-spacing: 0.01em; }
.brand-text small { color: var(--muted); font-size: 11.5px; }

.search {
  flex: 1; max-width: 760px; margin: 0 auto; height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 8px 0 14px;
  background: rgba(var(--ov), 0.05); border: 1px solid var(--line); border-radius: 12px; color: var(--muted);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(79, 157, 255, 0.14); background: rgba(var(--ov), 0.08); color: var(--accent); }
.search input { flex: 1; background: none; border: 0; outline: 0; color: var(--text); min-width: 0; font-size: 14.5px; }
.search input::-webkit-search-cancel-button { filter: var(--cancel-filter); cursor: pointer; }
.search kbd { font: 600 11px ui-monospace, Consolas, monospace; border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px; color: var(--muted); }
.search:focus-within kbd { display: none; }
.search select { background: rgba(var(--ov), 0.06); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; color: var(--text); font-size: 12.5px; max-width: 150px; outline: 0; }
.search select option { background: var(--surface); }
.actions { display: flex; align-items: center; gap: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); background: rgba(var(--ov), 0.06); padding: 9px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 600; transition: transform 0.15s, background 0.15s, border-color 0.15s, box-shadow 0.15s; }
.btn:hover { background: rgba(var(--ov), 0.12); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 6px 22px rgba(79, 157, 255, 0.3); }
.btn.primary:hover { background: var(--accent); filter: brightness(1.12); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(255, 107, 107, 0.14); border-color: rgba(255, 107, 107, 0.4); }
.btn.icon { padding: 9px; }
.btn.sm { padding: 5px 9px; font-size: 12px; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: rgba(var(--ov), 0.07); }

.seg { display: flex; padding: 3px; background: rgba(var(--ov), 0.06); border: 1px solid var(--line); border-radius: 10px; }
.seg button { border: 0; background: none; padding: 6px 13px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); transition: 0.2s; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* ───── Panneaux latéraux */
.panel {
  position: fixed; z-index: 9; top: 88px; max-height: calc(100vh - 88px - 74px); border-radius: 18px; padding: 0; overflow: hidden;
  display: flex; flex-direction: column;
}
.panel.right { min-height: 220px; }
.panel.left { left: 14px; width: var(--left-w); animation: slideL 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.1) both; }
.panel.right { right: 14px; width: var(--right-w); animation: slideR 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.1) both; }
@keyframes slideL { from { opacity: 0; transform: translateX(-40px); } }
@keyframes slideR { from { opacity: 0; transform: translateX(40px); } }
.panel-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 16px; line-height: 1.25; }
.panel-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.panel-body { flex: 1; overflow-y: auto; padding: 10px; scrollbar-width: thin; scrollbar-color: rgba(var(--ov), 0.15) transparent; }
.panel-foot { padding: 12px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.panel-foot .btn { flex: 1; }
.spacer { flex: 1; }
.loc-badge { font: 700 15px ui-monospace, Consolas, monospace; color: var(--accent-ink); background: var(--accent); padding: 6px 10px; border-radius: 9px; box-shadow: 0 4px 16px rgba(79, 157, 255, 0.3); white-space: nowrap; }
.nav-arrows { display: grid; grid-template-columns: repeat(3, 26px); grid-template-rows: repeat(2, 24px); gap: 3px; }
.nav-arrows button { border: 1px solid var(--line); background: rgba(var(--ov), 0.05); border-radius: 6px; color: var(--muted); font-size: 11px; padding: 0; }
.nav-arrows button:hover { color: var(--text); background: rgba(var(--ov), 0.12); }
.nav-arrows .up { grid-column: 2; grid-row: 1; }
.nav-arrows .lf { grid-column: 1; grid-row: 2; }
.nav-arrows .dn { grid-column: 2; grid-row: 2; }
.nav-arrows .rt { grid-column: 3; grid-row: 2; }

.static .card, .static .row { animation: none !important; }

/* ───── Cartes composant / résultats */
.row {
  display: flex; align-items: center; gap: 11px; padding: 10px 11px; border-radius: 12px; border: 1px solid transparent; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  animation: rowIn 0.35s both;
}
@keyframes rowIn { from { opacity: 0; transform: translateX(-10px); } }
.row:hover, .row.active { background: rgba(var(--ov), 0.07); border-color: var(--line); }
.row.active { border-color: var(--accent); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 10px currentColor; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .name mark { background: rgba(79, 157, 255, 0.28); color: var(--mark); border-radius: 3px; padding: 0 1px; }
.row .meta { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qty { font-weight: 700; font-size: 12px; padding: 3px 8px; border-radius: 99px; background: rgba(var(--ov), 0.08); }
.qty.low { background: rgba(255, 107, 107, 0.18); color: var(--danger); }
.loc { font: 700 12px ui-monospace, Consolas, monospace; padding: 3px 8px; border-radius: 7px; border: 1px solid rgba(79, 157, 255, 0.45); color: var(--accent); background: rgba(79, 157, 255, 0.08); white-space: nowrap; }
.loc.none { border-color: var(--line); color: var(--muted); background: none; font-family: inherit; font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; line-height: 1.5; }
.empty big { display: block; font-size: 34px; margin-bottom: 8px; }

.card { padding: 13px; border-radius: 14px; background: rgba(var(--ov), 0.045); border: 1px solid var(--line); margin-bottom: 9px; animation: rowIn 0.4s both; }
.card-top { display: flex; align-items: flex-start; gap: 10px; }
.card h3 { margin: 0; font-size: 14.5px; line-height: 1.3; }
.card .tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: rgba(var(--ov), 0.08); color: var(--chip-ink); }
.chip.cat { display: inline-flex; align-items: center; gap: 6px; }
.card .notes { color: var(--muted); font-size: 12.5px; margin-top: 8px; white-space: pre-wrap; }
.card .notes a { color: var(--accent); }
.card-actions { display: flex; align-items: center; gap: 8px; margin-top: 11px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--sunken-2); }
.stepper button { border: 0; background: none; width: 30px; height: 30px; font-size: 17px; font-weight: 700; }
.stepper button:hover { background: rgba(var(--ov), 0.1); }
.stepper b { min-width: 38px; text-align: center; font-size: 14px; font-variant-numeric: tabular-nums; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-grid div { background: rgba(var(--ov), 0.05); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.stat-grid b { display: block; font-size: 20px; }
.stat-grid span { font-size: 11px; color: var(--muted); }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 14px 4px 6px; }

/* ───── Barre du bas */
.bottombar { position: fixed; z-index: 8; left: 14px; right: 14px; bottom: 14px; display: flex; align-items: center; justify-content: center; gap: 12px; pointer-events: none; animation: riseIn 0.8s 0.7s both; }
@keyframes riseIn { from { opacity: 0; transform: translateY(24px); } }
.bottombar > * { pointer-events: auto; }
.bottombar .btn { border-radius: 12px; }
.stats, .hint { padding: 9px 14px; border-radius: 12px; font-size: 12.5px; color: var(--muted); }
.stats b { color: var(--text); }
.stats i { font-style: normal; margin: 0 7px; opacity: 0.4; }
.hint { position: absolute; right: 0; opacity: 0.85; }

.tip { position: fixed; z-index: 30; pointer-events: none; padding: 9px 12px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 11px; font-size: 12.5px; box-shadow: var(--sh-md); max-width: 280px; animation: pop 0.15s both; }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(0.97); } }
.tip .t-code { font: 700 12px ui-monospace, Consolas, monospace; color: var(--accent); }
.tip .t-item { margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tip .t-more, .tip .t-empty { color: var(--muted); margin-top: 3px; }

/* ───── Vue liste */
#listView { position: fixed; z-index: 7; top: 88px; bottom: 74px; left: 14px; right: 14px; border-radius: 18px; overflow: auto; background: var(--panel-solid); animation: pop 0.3s both; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { position: sticky; top: 0; background: var(--thead); text-align: left; padding: 12px 14px; font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); cursor: pointer; user-select: none; border-bottom: 1px solid var(--line); z-index: 1; }
thead th:hover { color: var(--text); }
thead th.sorted::after { content: attr(data-dir); margin-left: 6px; color: var(--accent); }
tbody td { padding: 9px 14px; border-bottom: 1px solid rgba(var(--ov), 0.05); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: rgba(var(--ov), 0.05); }
td.num { font-variant-numeric: tabular-nums; }
td .cat { display: inline-flex; align-items: center; gap: 7px; }

/* ───── Modales */
.overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: var(--overlay); backdrop-filter: blur(6px); animation: fade 0.2s both; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--sh-lg); animation: modalIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.15) both; overflow: hidden; }
.modal.wide { width: min(720px, 100%); }
@keyframes modalIn { from { opacity: 0; transform: translateY(18px) scale(0.96); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 4px 20px 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: rgba(var(--ov), 0.02); }
.modal-foot .spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: 0.03em; }
.field input, .field select, .field textarea { background: rgba(var(--ov), 0.06); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: 0; width: 100%; transition: border-color 0.2s, box-shadow 0.2s; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 157, 255, 0.15); }
.field select option { background: var(--surface); }
.field textarea { resize: vertical; min-height: 64px; }
.field .help { font-size: 12px; color: var(--muted); }
.field .help.warn { color: var(--warn); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.picker { display: grid; gap: 4px; padding: 10px; border-radius: 12px; background: var(--sunken); border: 1px solid var(--line); }
.picker button { border: 1px solid var(--line); background: rgba(var(--ov), 0.04); border-radius: 6px; min-height: 28px; font-size: 11px; font-weight: 700; color: var(--muted); padding: 0; transition: 0.12s; }
.picker button.filled { background: rgba(var(--ov), 0.12); color: var(--text); }
.picker button:hover { border-color: var(--accent); }
.picker button.sel { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); transform: scale(1.08); }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; }
.swatches button.on { border-color: var(--text); transform: scale(1.12); }

.tabs { flex: none; display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.minimap { display: grid; gap: 6px; padding: 12px; background: var(--sunken); border-radius: 14px; border: 1px solid var(--line); margin: 6px 0 14px; }
.minimap button { min-height: 0; border-radius: 9px; border: 1px dashed rgba(var(--ov), 0.2); background: none; color: var(--muted); font-size: 12px; font-weight: 700; line-height: 1.25; padding: 4px; }
.minimap button.has { border-style: solid; border-color: transparent; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.minimap button:hover { filter: brightness(1.2); transform: scale(1.03); }
.cat-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.cat-row input[type="color"] { width: 38px; height: 34px; padding: 2px; border-radius: 8px; border: 1px solid var(--line); background: none; }
.cat-row input[type="text"] { flex: 1; background: rgba(var(--ov), 0.06); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; outline: 0; }
.data-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.data-grid .btn { justify-content: flex-start; padding: 14px; }

#toasts { position: fixed; z-index: 60; bottom: 76px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--surface-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 13.5px; box-shadow: var(--sh-md); animation: toastIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
.toast.out { animation: toastOut 0.3s both; }
.toast.err { border-color: rgba(255, 107, 107, 0.5); }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(0.95); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ───── Responsive */
@media (max-width: 1100px) {
  .hint { display: none; }
  .brand-text small { display: none; }
  .brand { min-width: 0; }
  .btn.primary span { display: none; }
}
@media (max-width: 860px) {
  .brand-text { display: none; }
  .search select, .search kbd { display: none; }
  .panel { top: auto; bottom: 70px; max-height: 44vh; width: auto !important; left: 10px !important; right: 10px !important; }
  .stats { display: none; }
  body.has-detail #results { display: none; }
}

/* indicateur de synchronisation */
.syncbtn { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--muted); padding: 7px 10px; }
.syncbtn i { width: 8px; height: 8px; border-radius: 50%; background: #7d8594; flex: none; }
.syncbtn[data-s='synced'] i { background: #34d399; box-shadow: 0 0 8px #34d39988; }
.syncbtn[data-s='saving'] i { background: var(--accent); animation: syncpulse 0.9s ease-in-out infinite; }
.syncbtn[data-s='offline'] i { background: #f87171; }
.syncbtn[data-s='locked'] i { background: #f5c451; }
@keyframes syncpulse { 50% { opacity: 0.25; } }
@media (max-width: 860px) { .syncbtn span { display: none; } }

/* ───── Étiquettes QR (aperçu + impression) */
.lbl { box-sizing: border-box; display: flex; align-items: center; flex: none; background: #fff; color: #000; overflow: hidden; line-height: 1.15; font-family: Inter, "Segoe UI", system-ui, sans-serif; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.lbl.tall { flex-direction: column; justify-content: flex-start; }
.lbl .qr { flex: none; line-height: 0; }
.lbl .qr svg { display: block; }
.lbl .txt { min-width: 0; flex: 1; display: flex; flex-direction: column; justify-content: center; align-self: stretch; overflow: hidden; }
.lbl.tall .txt { align-items: center; text-align: center; align-self: stretch; justify-content: flex-start; }
.lbl .code { font: 800 1em ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: -0.01em; white-space: nowrap; }
.lbl .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.lbl .it { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; color: #222; }
.lblprev { display: flex; flex-wrap: wrap; gap: 12px; padding: 14px; background: #c9d1de; border-radius: 12px; max-height: 380px; overflow: auto; }
.lblwrap { zoom: var(--z, 1); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); border-radius: 1mm; overflow: hidden; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--text); text-transform: none; letter-spacing: 0; font-weight: 500; }
.check input { width: auto; accent-color: var(--accent); }
#printRoot { display: none; }
@media print {
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; }
  body > *:not(#printRoot) { display: none !important; }
  #printRoot { display: block !important; }
  #printRoot .lbl { break-after: page; page-break-after: always; }
  #printRoot .lbl:last-child { break-after: auto; page-break-after: auto; }
  #printRoot.sheet { display: flex !important; flex-wrap: wrap; align-content: flex-start; }
  #printRoot.sheet .lbl { break-after: auto; page-break-after: auto; outline: 0.15mm dashed #888; outline-offset: -0.15mm; }
}

/* ───────── thème clair / sombre */
#themeBtn .ico-moon { display: none; }
:root[data-theme='light'] #themeBtn .ico-sun { display: none; }
:root[data-theme='light'] #themeBtn .ico-moon { display: block; }

/* ───────── « Où ranger ça ? » */
.sug { display: flex; flex-direction: column; gap: 6px; }
.sugitem { display: flex; align-items: center; gap: 10px; text-align: left; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 11px; background: rgba(var(--ov), 0.04); transition: border-color 0.15s, background 0.15s; }
.sugitem:hover { border-color: var(--accent); }
.sugitem.sel { border-color: var(--accent); background: rgba(79, 157, 255, 0.14); }
.sugitem .code { font: 700 12px ui-monospace, Consolas, monospace; padding: 3px 8px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); white-space: nowrap; }
.sugitem .why { flex: 1; font-size: 12.5px; color: var(--text); line-height: 1.3; min-width: 0; }
.sugitem small { color: var(--accent); font-weight: 700; font-size: 11px; white-space: nowrap; }

/* ───────── Téléphone */
:root { --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); }
.topbar { top: calc(14px + var(--safe-t)); left: calc(14px + var(--safe-l)); right: calc(14px + var(--safe-r)); }
.bottombar { bottom: calc(14px + var(--safe-b)); }

@media (max-width: 860px) {
  .panel { bottom: calc(66px + var(--safe-b)); max-height: 46vh; max-height: 46dvh; }
  .bottombar { left: 10px; right: 10px; }
  #listView { top: calc(88px + var(--safe-t)); bottom: calc(66px + var(--safe-b)); left: 10px; right: 10px; }
  #toasts { bottom: calc(76px + var(--safe-b)); max-width: calc(100vw - 24px); }
}

@media (max-width: 640px) {
  /* barre du haut sur 2 lignes : recherche + synchro, puis les boutons */
  .topbar { height: auto; flex-wrap: wrap; align-content: flex-start; justify-content: space-between; gap: 8px 6px; padding: 8px; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); border-radius: 16px; }
  .brand { display: none; }
  .actions { display: contents; }
  .search { order: 1; flex: 1 1 calc(100% - 52px); min-width: 0; margin: 0; height: 44px; } /* + synchro = ligne 1 ; le reste passe à la ligne */
  .syncbtn { order: 2; padding: 10px; }
  .seg { order: 3; }
  #addBtn { order: 4; }
  .seg button { padding: 8px 14px; }
  .btn.icon, #addBtn { min-width: 38px; min-height: 40px; }
  .btn.icon { padding: 8px; }
  #addBtn { padding: 9px 11px; }
  #assistantBtn { order: 5; }
  #labelsBtn { order: 6; }
  #themeBtn { order: 7; }
  #settingsBtn { order: 8; }
  .panel { left: 8px !important; right: 8px !important; }
  #listView { top: calc(112px + var(--safe-t)); left: 8px; right: 8px; }
  #listView table { font-size: 13px; }
  #listView th:nth-child(2), #listView td:nth-child(2), #listView th:nth-child(3), #listView td:nth-child(3) { display: none; } /* catégorie / valeur : reprises sous le nom */
  #listView td .m-only { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: var(--muted); font-size: 11.5px; }
  #listView td .m-only .dot { flex: none; }
  thead th, tbody td { padding: 9px 10px; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .grid3 > :first-child { grid-column: 1 / -1; }
  .data-grid { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; flex: none; padding: 0 10px; scrollbar-width: none; }
  .tabs button { white-space: nowrap; padding: 10px 12px; }
  /* modales : feuille qui monte du bas */
  .overlay { place-items: end center; padding: 0; }
  .modal, .modal.wide { width: 100%; max-height: 94vh; max-height: 94dvh; border-radius: 20px 20px 0 0; animation: sheetIn 0.32s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
  .modal-head { padding: 16px 16px 10px; }
  .modal-body { padding: 4px 16px 16px; }
  .modal-foot { padding: 12px 16px calc(12px + var(--safe-b)); }
  .lblprev { max-height: 260px; }
  .modal .lbgrid { grid-template-columns: minmax(0, 1fr); }
}
@keyframes sheetIn { from { transform: translateY(40px); opacity: 0; } }

/* écrans tactiles : cibles plus grandes, champs ≥ 16 px (évite le zoom automatique d'iOS) */
@media (pointer: coarse) {
  .field input, .field select, .field textarea, .search input, .cat-row input[type='text'] { font-size: 16px; }
  .btn { min-height: 40px; }
  .btn.sm { min-height: 34px; }
  .picker button { min-height: 36px; font-size: 12px; }
  .sugitem { padding: 11px 12px; }
  .search kbd, .hint { display: none; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .panel { max-height: 62vh; }
}

.m-only { display: none; }
.lbgrid { display: grid; grid-template-columns: minmax(250px, 320px) minmax(0, 1fr); gap: 18px; align-items: start; }

/* ───────── Assistant (IA, courses, nettoyage) */
#assistantBtn { position: relative; color: var(--accent); }
.btn-badge { position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font: 700 10.5px/17px Inter, system-ui, sans-serif; text-align: center; box-shadow: 0 0 0 2px var(--panel-solid); }
.tab-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; line-height: 18px; text-align: center; }
.lbl-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; }
.ds-link { font-size: 11.5px; font-weight: 600; color: var(--accent); text-decoration: none; letter-spacing: 0; }
.ds-link:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.del { text-decoration: line-through; opacity: 0.7; }
.ai-loading { display: flex; align-items: center; gap: 12px; color: var(--muted); padding: 14px 4px; }
.ai-loading .spin { flex: none; }
.ai-error { padding: 12px 14px; border-radius: 12px; background: rgba(255, 107, 107, 0.1); border: 1px solid rgba(255, 107, 107, 0.35); color: var(--danger); font-size: 13.5px; }
.ai-note { padding: 12px 14px; margin: 0 0 12px; border-radius: 12px; background: rgba(79, 157, 255, 0.1); border: 1px solid rgba(79, 157, 255, 0.28); line-height: 1.55; font-size: 13.5px; }
.ai-note .ai-loading { padding: 0; }
.ai-tag { color: var(--accent); font-weight: 700; }
.notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; margin-bottom: 12px; border-radius: 12px; background: rgba(var(--ov), 0.05); border: 1px solid var(--line); font-size: 13px; }
.notice.ok { color: var(--ok); justify-content: flex-start; }
.empty-note { padding: 18px 10px; color: var(--muted); text-align: center; font-size: 13.5px; line-height: 1.5; }

.plan-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.plan-count { padding: 4px 10px; border-radius: 999px; background: rgba(var(--ov), 0.06); border: 1px solid var(--line); font-size: 13px; font-weight: 700; }
.plan-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 12px; background: rgba(var(--ov), 0.03); }
.plan-row.st-missing { border-color: rgba(255, 107, 107, 0.3); }
.plan-row.st-partial { border-color: rgba(255, 190, 80, 0.35); }
.plan-row .st { font-size: 16px; line-height: 1.4; }
.pr-main { flex: 1; min-width: 0; }
.pr-found { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 5px 9px; border-radius: 9px; border: 1px solid var(--line); background: rgba(var(--ov), 0.06); font-size: 12.5px; text-align: left; }
.chip-btn:hover:not(:disabled) { border-color: var(--accent); }
.chip-btn:disabled { opacity: 0.6; cursor: default; }
.chip-btn code, .cl-row code, .sug code { font: 700 11.5px ui-monospace, Consolas, monospace; color: var(--accent); }

.shop-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.shop-row .sq { width: 62px; flex: none; padding: 8px; text-align: center; border-radius: 9px; border: 1px solid var(--line); background: rgba(var(--ov), 0.06); outline: 0; }
.shop-row .sn { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.shop-row .sn small { color: var(--muted); font-size: 12px; }
.shop-row .shops a { color: var(--accent); text-decoration: none; }
.shop-row .shops a:hover { text-decoration: underline; }
.shop-row .su { margin-top: 3px; width: 100%; padding: 7px 10px; font-size: 12.5px; border-radius: 9px; border: 1px solid var(--line); background: rgba(var(--ov), 0.05); outline: 0; }
.shop-row .su:focus, .shop-row .sq:focus, .shop-add input:focus { border-color: var(--accent); }
.shop-row .sa { display: flex; flex-direction: column; gap: 6px; flex: none; }
.shop-add { display: flex; gap: 8px; margin-top: 14px; }
.shop-add input { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(var(--ov), 0.06); outline: 0; min-width: 0; }
.shop-add input[name='qty'] { width: 64px; flex: none; text-align: center; }
.shop-add input[name='name'] { flex: 1; }
.shop-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.shop-foot .help { font-size: 12px; color: var(--muted); flex: 1 1 200px; }

.cl-sec { margin-bottom: 18px; }
.cl-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; min-height: 30px; }
.cl-act { display: flex; gap: 6px; }
.cl-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; background: rgba(var(--ov), 0.03); font-size: 13.5px; }
.cl-row.check { cursor: pointer; }
.cl-row.check input { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.cl-main { flex: 1; min-width: 0; line-height: 1.45; overflow-wrap: anywhere; }
.cl-sub { margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.5; }

@media (max-width: 640px) {
  .plan-row { flex-wrap: wrap; }
  .plan-row .pr-act { width: 100%; padding-left: 28px; }
  .shop-row { flex-wrap: wrap; }
  .shop-row .sa { flex-direction: row; width: 100%; padding-left: 72px; flex-wrap: wrap; }
  .cl-row { flex-wrap: wrap; }
}
