:root {
  --primary: #0A7C7A;
  --primary-dark: #075E5C;
  --primary-soft: #E3F2F1;
  --bg: #F5F6F6;
  --card: #FFFFFF;
  --text: #1F2A2A;
  --muted: #6B7676;
  --border: #E2E6E6;
  --positive: #2E9E5B;
  --warning: #E8833A;
  --danger: #D14343;
  --radius: 12px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
button { font: inherit; cursor: pointer; }

/* Champs : 16px minimum pour éviter le zoom auto sur iPhone */
input, select, textarea {
  font: inherit; font-size: 16px; width: 100%;
  padding: .65rem .75rem; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; font-weight: 500; color: var(--muted); }

/* Boutons */
.btn {
  border: none; border-radius: 10px; padding: .7rem 1.1rem; font-weight: 600;
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--positive); color: #fff; }
.btn-ghost { background: var(--primary-soft); color: var(--primary-dark); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: .4rem .8rem; font-size: .85rem; }
.btn-link { background: none; border: none; color: var(--primary); padding: .5rem; font-weight: 500; }
.icon-btn { background: none; border: none; font-size: 1.2rem; width: 40px; height: 40px; border-radius: 50%; color: var(--muted); }
.icon-btn:hover { background: var(--bg); }

/* Marque */
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.15rem; color: var(--primary-dark); }
.brand-lg { font-size: 1.6rem; justify-content: center; }
.logo { width: 40px; height: 40px; display: block; }
.brand-lg .logo { width: 56px; height: 56px; }

/* Connexion */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 18px; padding: 2rem 1.5rem; box-shadow: 0 8px 30px rgba(0,0,0,.06); text-align: center; }
.auth-card form { display: grid; gap: 1rem; margin: 1.5rem 0 .5rem; text-align: left; }
.msg { font-size: .9rem; min-height: 1.2em; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--positive); }

/* ===== Mise en page : MOBILE d'abord ===== */
.layout { min-height: 100dvh; }
.main { padding: 1rem 1rem calc(var(--nav-h) + var(--safe-b) + 1.5rem); max-width: 1200px; margin: 0 auto; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: stretch;
}
.nav .brand, .nav .nav-logout { display: none; }
.nav-item {
  position: relative; flex: 1; background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .7rem; font-weight: 500;
}
.nav-item .ico { font-size: 1.25rem; }
.nav-item.active { color: var(--primary); }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  background: var(--warning); color: #fff; font-size: .65rem; border-radius: 10px; padding: 1px 6px;
}

.view-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: .5rem 0 1rem; }
#btn-add { display: none; }

.fab {
  position: fixed; right: 1rem; bottom: calc(var(--nav-h) + var(--safe-b) + 1rem); z-index: 21;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 1.8rem; box-shadow: 0 6px 18px rgba(10,124,122,.35);
}

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border-radius: var(--radius); padding: .9rem 1rem; border: 1px solid var(--border); }
.kpi .label { font-size: .75rem; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 1.35rem; font-weight: 700; margin-top: .25rem; }
.kpi.pos .value { color: var(--positive); }
.kpi.warn .value { color: var(--warning); }

.cols { display: grid; gap: 1rem; }
.panel { background: var(--card); border-radius: var(--radius); padding: 1rem; border: 1px solid var(--border); }
.mini-list { display: grid; gap: .25rem; }
.mini-row {
  display: flex; justify-content: space-between; align-items: center; gap: .75rem;
  padding: .6rem .5rem; border-radius: 8px; background: none; border: none; width: 100%; text-align: left; color: inherit;
}
button.mini-row:hover { background: var(--bg); }
.mini-row .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); font-size: .9rem; padding: .5rem; }

/* Stock */
.toolbar { display: grid; gap: .75rem; margin-bottom: 1rem; }
.chips { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 999px; padding: .45rem .9rem; font-size: .85rem; font-weight: 500;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.grid { display: grid; grid-template-columns: 1fr; gap: .75rem; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; text-align: left; color: inherit; display: grid; gap: .4rem; width: 100%;
}
.card:hover { border-color: var(--primary); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.card-title { font-weight: 600; }
.card-sub { font-size: .85rem; color: var(--muted); }
.card-bottom { display: flex; justify-content: space-between; align-items: center; font-size: .9rem; }
.price { font-weight: 700; }
.profit-pos { color: var(--positive); font-weight: 600; }
.profit-neg { color: var(--danger); font-weight: 600; }

.tag { font-size: .7rem; font-weight: 600; padding: .2rem .55rem; border-radius: 999px; white-space: nowrap; }
.tag-brouillon { background: #EEF0F0; color: var(--muted); }
.tag-en_ligne { background: var(--primary-soft); color: var(--primary-dark); }
.tag-reserve { background: #E8EEFB; color: #3557B7; }
.tag-vendu { background: #E5F5EC; color: var(--positive); }
.tag-retire { background: #F3F3F3; color: #999; }
.tag-dormant { background: #FDEEE2; color: var(--warning); }

/* Listes (envois, emplacements) */
.list { display: grid; gap: .75rem; }
.row {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
}
.row .info { display: grid; gap: .2rem; min-width: 0; }
.inline-form { display: flex; gap: .5rem; margin-bottom: 1rem; }
.inline-form input { flex: 1; }

/* Dialogues : plein écran en bas sur mobile */
dialog {
  border: none; padding: 0; background: var(--card); color: var(--text);
  width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: 18px 18px 0 0;
}
dialog::backdrop { background: rgba(20,30,30,.45); }
dialog form { display: flex; flex-direction: column; max-height: 92dvh; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1rem .5rem; }
.dlg-head h2 { margin: 0; }
.dlg-body { padding: .5rem 1rem 1rem; overflow-y: auto; }
.dlg-foot {
  display: flex; gap: .5rem; align-items: center; padding: .75rem 1rem calc(.75rem + var(--safe-b));
  border-top: 1px solid var(--border);
}
.spacer { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
.form-grid .span2 { grid-column: 1 / -1; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 1rem); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Tablette ===== */
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  dialog { max-width: 600px; margin: auto; border-radius: 18px; }
}

/* ===== PC : barre latérale ===== */
@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 240px 1fr; }
  .nav {
    position: sticky; top: 0; height: 100dvh; padding: 1.25rem .75rem;
    flex-direction: column; justify-content: flex-start; gap: .25rem;
    border-top: none; border-right: 1px solid var(--border);
  }
  .nav .brand { display: flex; padding: 0 .5rem 1.25rem; }
  .nav-item {
    flex: none; flex-direction: row; justify-content: flex-start; gap: .75rem;
    font-size: .95rem; padding: .7rem .75rem; border-radius: 10px;
  }
  .nav-item:hover { background: var(--bg); }
  .nav-item.active { background: var(--primary-soft); color: var(--primary-dark); }
  .nav-item .ico { font-size: 1.1rem; }
  .nav .nav-logout { display: flex; margin-top: auto; }
  .badge { position: static; margin-left: auto; }
  .main { padding: 2rem 2.5rem; width: 100%; }
  .fab { display: none; }
  #btn-add { display: inline-flex; }
  .kpis { grid-template-columns: repeat(5, 1fr); }
  .cols { grid-template-columns: 1fr 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .toolbar { grid-template-columns: 320px 1fr; align-items: center; }
  .toast { bottom: 2rem; }
  .mobile-only { display: none !important; }
}
