/* ============================================================
   MERCURIALE CHR — Feuille de style principale
   Mobile-first, pas de dépendance externe
   ============================================================ */

/* ── Variables ── */
:root {
  --primary:   #2563eb;
  --primary-d: #1d4ed8;
  --success:   #16a34a;
  --danger:    #dc2626;
  --warning:   #d97706;
  --gray-50:   #f8fafc;
  --gray-100:  #f1f5f9;
  --gray-200:  #e2e8f0;
  --gray-300:  #cbd5e1;
  --gray-400:  #94a3b8;
  --gray-600:  #475569;
  --gray-700:  #334155;
  --gray-800:  #1e293b;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --nav-h:     56px;
  --font:      system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--gray-50); color: var(--gray-800); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; }
svg { width: 1.1em; height: 1.1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Navbar ── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--gray-800);
  display: flex; align-items: center; gap: 0;
  padding: 0 1rem;
  box-shadow: var(--shadow-md);
}
.nav-brand { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }
.brand-name { color: #fff; font-weight: 700; font-size: 1rem; white-space: nowrap; }
.nav-toggle { background: none; border: none; cursor: pointer; display: flex; flex-direction: column; gap: 5px; padding: 4px; }
.nav-toggle span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; transition: .2s; }

.nav-menu {
  display: none; position: fixed; top: var(--nav-h); left: 0; right: 0;
  background: var(--gray-800); padding: .5rem 0;
  flex-direction: column;
  max-height: calc(100vh - var(--nav-h)); overflow-y: auto;
}
.nav-menu.open { display: flex; }

.nav-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .75rem 1.25rem; color: var(--gray-300);
  font-size: .925rem; cursor: pointer;
  background: none; border: none; width: 100%; text-align: left;
  transition: background .15s;
}
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-item.active { color: #93c5fd; }

.nav-group { position: relative; }
.nav-group-toggle { justify-content: space-between; }
.chevron { margin-left: auto; transition: transform .2s; width: .9em; height: .9em; }
.nav-group.open .chevron { transform: rotate(180deg); }
.nav-sub { display: none; background: rgba(0,0,0,.2); }
.nav-group.open .nav-sub { display: block; }
.nav-sub-item { display: block; padding: .6rem 1.25rem .6rem 2.75rem; color: var(--gray-400); font-size: .875rem; }
.nav-sub-item:hover, .nav-sub-item.active { color: #fff; text-decoration: none; }

.nav-user { margin-left: auto; display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.user-name { color: #fff; font-size: .875rem; display: none; }
.btn-logout { color: var(--gray-400); display: flex; padding: .25rem; }
.btn-logout:hover { color: #fff; }

/* ── Badges rôle ── */
.role-badge { font-size: .7rem; padding: .15rem .5rem; border-radius: 99px; font-weight: 600; }
.role-99 { background: #7c3aed; color: #fff; }
.role-30 { background: #0369a1; color: #fff; }
.role-20 { background: #15803d; color: #fff; }
.role-10 { background: var(--gray-400); color: #fff; }

/* ── Desktop nav ── */
@media (min-width: 768px) {
  .nav-toggle { display: none; }
  .nav-menu { display: flex; position: static; flex-direction: row; background: none; padding: 0; overflow: visible; max-height: none; margin-left: 1.5rem; gap: .25rem; }
  .nav-item { padding: .4rem .75rem; border-radius: var(--radius); font-size: .875rem; }
  .nav-group { position: relative; }
  .nav-sub { display: none; position: absolute; top: 100%; left: 0; background: var(--gray-800); min-width: 180px; border-radius: var(--radius); box-shadow: var(--shadow-md); padding: .4rem 0; }
  .nav-group:hover .nav-sub { display: block; }
  .nav-sub-item { padding: .5rem 1rem; }
  .user-name { display: inline; }
}

/* ── Flash ── */
.flash { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1.25rem; font-size: .9rem; font-weight: 500; }
.flash-success { background: #dcfce7; color: #15803d; border-bottom: 2px solid #86efac; }
.flash-error   { background: #fee2e2; color: #b91c1c; border-bottom: 2px solid #fca5a5; }
.flash-warning { background: #fef3c7; color: #92400e; border-bottom: 2px solid #fcd34d; }
.flash-close   { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: inherit; opacity: .6; margin-left: 1rem; }

/* ── Layout principal ── */
.main-content { padding: 1.25rem 1rem; max-width: 1200px; margin: 0 auto; }
@media (min-width: 768px) { .main-content { padding: 1.75rem 1.5rem; } }

.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.5rem; }
.page-title { font-size: 1.35rem; font-weight: 700; color: var(--gray-800); }

/* ── Cards ── */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem; }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; color: var(--gray-700); }

/* ── Formulaires ── */
.form-grid { display: grid; gap: 1rem; }
@media (min-width: 600px) { .form-grid-2 { grid-template-columns: 1fr 1fr; } .form-grid-3 { grid-template-columns: 1fr 1fr 1fr; } }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-label { font-size: .85rem; font-weight: 600; color: var(--gray-700); }
.form-label .required { color: var(--danger); margin-left: .2rem; }
.form-control { padding: .55rem .75rem; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: .925rem; font-family: var(--font); background: #fff; color: var(--gray-800); transition: border-color .15s; width: 100%; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .6rem center; background-size: 1rem; padding-right: 2rem; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .78rem; color: var(--gray-400); }
.form-error { font-size: .8rem; color: var(--danger); }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: .5rem; }

/* ── Boutons ── */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1.1rem; border-radius: var(--radius); font-size: .9rem; font-weight: 600; font-family: var(--font); cursor: pointer; border: none; transition: background .15s, transform .1s; text-decoration: none; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); text-decoration: none; color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-danger:hover { background: #b91c1c; text-decoration: none; color: #fff; }
.btn-outline { background: #fff; color: var(--gray-700); border: 1.5px solid var(--gray-200); }
.btn-outline:hover { background: var(--gray-50); text-decoration: none; }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-icon { padding: .4rem; border-radius: var(--radius); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th { background: var(--gray-50); padding: .65rem .9rem; text-align: left; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-600); border-bottom: 2px solid var(--gray-200); white-space: nowrap; }
tbody td { padding: .7rem .9rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; padding: .2rem .6rem; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-gray   { background: var(--gray-100); color: var(--gray-600); }
.badge-yellow { background: #fef3c7; color: #92400e; }

/* ── Filtres de recherche ── */
.filters { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.25rem; align-items: center; }
.filters .form-control { width: auto; min-width: 160px; }
.search-input { flex: 1; min-width: 200px; }

/* ── Tableau de bord stats ── */
.stats-grid { display: grid; gap: 1rem; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 768px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card { background: #fff; border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: var(--shadow); border-left: 4px solid var(--primary); }
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--gray-800); line-height: 1; }
.stat-label { font-size: .8rem; color: var(--gray-400); margin-top: .3rem; font-weight: 500; }

/* ── Catégorie couleur dot ── */
.cat-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .4rem; flex-shrink: 0; }

/* ── Confirmation suppression ── */
.confirm-delete { background: #fff8f8; border: 1.5px solid #fca5a5; padding: 1.25rem; border-radius: var(--radius); }

/* ── Login page ── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--gray-100); padding: 1rem; }
.login-card { background: #fff; border-radius: 12px; box-shadow: var(--shadow-md); padding: 2rem 2rem; width: 100%; max-width: 400px; }
.login-logo { text-align: center; font-size: 1.4rem; font-weight: 800; color: var(--gray-800); margin-bottom: 1.75rem; }
.login-logo span { color: var(--primary); }

/* ── Utilitaires ── */
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.text-muted { color: var(--gray-400); font-size: .85rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-bold { font-weight: 700; }
.d-flex { display: flex; } .gap-1 { gap: .5rem; } .gap-2 { gap: 1rem; } .align-center { align-items: center; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--gray-400); }
.empty-state svg { width: 3rem; height: 3rem; margin: 0 auto .75rem; opacity: .4; }
.app-footer { text-align: center; padding: 1.5rem; font-size: .78rem; color: var(--gray-400); }

/* ── Emplacement type icon ── */
.empl-froid_positif  { color: #0284c7; }
.empl-froid_negatif  { color: #6366f1; }
.empl-ambiant        { color: #d97706; }

/* ── Prix comparateur ── */
.prix-best  { color: var(--success); font-weight: 700; }
.prix-worse { color: var(--gray-400); }

/* ── Saisie de stock (mobile-first) ── */
.stock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .85rem 1rem;
  margin-bottom: .5rem;
}
.stock-row-info { flex: 1; min-width: 0; }
.stock-row-nom { font-weight: 600; font-size: .95rem; color: var(--gray-800); }
.stock-row-meta { font-size: .75rem; color: var(--gray-400); margin-top: .15rem; }
.stock-row-input { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; }
.stock-qte-input {
  width: 90px;
  text-align: right;
  font-size: 1.15rem;
  font-weight: 700;
  padding: .6rem .5rem;
  border: 2px solid var(--gray-200);
}
.stock-qte-input:focus { border-color: var(--primary); }
.stock-row-unite { font-size: .85rem; color: var(--gray-400); font-weight: 600; min-width: 28px; }

@media (min-width: 768px) {
  .stock-qte-input { width: 110px; font-size: 1.1rem; }
}

/* Champ rempli (différent du placeholder) visuellement distinct */
.stock-qte-input:not(:placeholder-shown) {
  border-color: var(--warning);
  background: #fffbeb;
}

/* ── Badges seuil stock ── */
.badge-stock-ok    { background: #dcfce7; color: #15803d; }
.badge-stock-bas    { background: #fee2e2; color: #b91c1c; }
.badge-stock-aucun  { background: var(--gray-100); color: var(--gray-400); }
