:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --entree: #22c55e;
  --sortie: #ef4444;
  --alerte: #f59e0b;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  padding: 1.5rem 2rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-auth {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-user {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-logout {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.15);
  color: var(--sortie);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 38px;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: var(--sortie);
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 2rem 2rem;
}

.section {
  margin-bottom: 2rem;
}

.section h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card.alert .stat-value { color: var(--alerte); }

.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Alertes */
.alertes-section {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.alerte-list {
  list-style: none;
}

.alerte-list li {
  padding: 0.35rem 0;
  color: var(--alerte);
  font-size: 0.9rem;
}

/* Cards & forms */
.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  margin-top: 0.25rem;
}
.form-label:first-of-type { margin-top: 0; }

.form input,
.form select,
.form button {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.6rem;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.form input::placeholder {
  color: var(--text-muted);
}

.form button {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  margin-top: 0.25rem;
  margin-bottom: 0;
}

.form button:hover {
  background: var(--accent-hover);
}

/* Sélecteur produit avec recherche */
.produit-search-wrap {
  position: relative;
  margin-bottom: 0.6rem;
}
.produit-search-wrap input[type="text"] {
  margin-bottom: 0;
}
.produit-search-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 2px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.produit-search-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.produit-search-item:last-child {
  border-bottom: none;
}
.produit-search-item:hover,
.produit-search-item:focus {
  background: rgba(59, 130, 246, 0.2);
  outline: none;
}
.produit-search-item.produit-search-empty {
  cursor: default;
  color: var(--text-muted);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.06);
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: rgba(255,255,255,0.02);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.entree { background: rgba(34, 197, 94, 0.2); color: var(--entree); }
.badge.sortie { background: rgba(239, 68, 68, 0.2); color: var(--sortie); }

.stock-faible { color: var(--alerte); }

/* Filtres Stock & Mouvements */
.filtres-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.filtre-input,
.filtre-select {
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.12);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
}

.filtre-input[type="text"] {
  min-width: 180px;
}

.filtre-input[type="date"] {
  min-width: 130px;
}

.filtre-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.btn-filtre {
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-filtre:hover {
  background: var(--accent-hover);
}

/* Rapports */
.rapport-filtres {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.rapport-filtres select,
.rapport-filtres input,
.rapport-filtres button {
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.12);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
}

.rapport-filtres button {
  background: var(--accent);
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.rapport-filtres button:hover {
  background: var(--accent-hover);
}

.rapport-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.rapport-label input { margin: 0; }

.section-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: -0.5rem 0 0.75rem;
}

.table-fiche { font-size: 0.85rem; }
.table-fiche .subhead th { font-weight: 500; font-size: 0.8rem; color: var(--text-muted); }
.fiche-inventaire-wrap { overflow-x: auto; }

.rapport-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.btn-export {
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-export:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}

/* Impression : rapports ou fiche inventaire uniquement, sans boutons ni UI */
@media print {
  @page {
    margin: 1cm;
  }
  /* Cacher tous les boutons et barres de filtres à l'impression */
  button, .btn-modifier, .btn-supprimer, .btn-export, .filtres-bar, .rapport-filtres, .rapport-actions {
    display: none !important;
  }
  body * {
    visibility: hidden;
  }
  #sectionRapports,
  #sectionRapports * {
    visibility: visible;
  }
  #sectionRapports {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    padding: 0;
  }
  .table-wrap {
    border: 1px solid #333;
    box-shadow: none;
  }
  .table th, .table td {
    border: 1px solid #333;
    color: #000;
  }
  .table th {
    background: #eee;
  }

  /* Impression fiche inventaire : UNIQUEMENT cette section, rien d'autre */
  body.print-fiche .header,
  body.print-fiche .install-banner,
  body.print-fiche .container > *:not(#sectionFicheInventaire) {
    display: none !important;
    visibility: hidden !important;
  }
  body.print-fiche #sectionRapports {
    display: none !important;
    visibility: hidden !important;
  }
  body.print-fiche .container {
    padding: 0;
    margin: 0;
  }
  body.print-fiche #sectionFicheInventaire {
    display: block !important;
    visibility: visible !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    padding: 0.5rem 0;
    margin: 0;
    page-break-after: avoid;
  }
  body.print-fiche #sectionFicheInventaire * {
    visibility: visible;
  }
  body.print-fiche #sectionFicheInventaire .rapport-filtres {
    display: none !important;
  }
  /* Titre fiche : une seule ligne lisible, pas de chevauchement */
  body.print-fiche #sectionFicheInventaire > h2 {
    font-size: 1rem;
    margin: 0 0 0.5rem 0;
    line-height: 1.3;
    padding: 0;
    page-break-after: avoid;
  }
  /* Rapport compact : une page si peu de lignes */
  body.print-fiche .fiche-inventaire-wrap,
  body.print-fiche #ficheTableWrap {
    overflow: visible;
  }
  body.print-fiche .table-fiche {
    font-size: 0.7rem;
    page-break-inside: auto;
  }
  body.print-fiche .table-fiche th,
  body.print-fiche .table-fiche td {
    padding: 0.2rem 0.35rem;
    border: 1px solid #333;
    color: #000;
  }
  body.print-fiche .table-fiche th {
    background: #eee;
    font-size: 0.7rem;
  }
  body.print-fiche .table-fiche .subhead th {
    font-size: 0.65rem;
  }
}

/* Espace quand la bannière d'installation est visible */
body.install-banner-visible .container {
  padding-bottom: 5rem;
}

/* Bannière installation PWA */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  border-top: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  padding: 0.75rem 1rem;
}

.install-banner-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.install-banner-text {
  font-size: 0.9rem;
  color: var(--text);
  margin: 0;
  flex: 1;
  min-width: 200px;
}

.install-banner-actions {
  display: flex;
  gap: 0.5rem;
}

.install-btn {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.install-btn:hover {
  background: var(--accent-hover);
}

.install-dismiss {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
}

.install-dismiss:hover {
  color: var(--text);
}

/* Bouton Modifier produit */
.btn-modifier {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  border: 1px solid rgba(59, 130, 246, 0.4);
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
  border-radius: 6px;
  white-space: nowrap;
}
.btn-modifier:hover {
  background: rgba(59, 130, 246, 0.25);
}

.btn-supprimer {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.2);
  color: var(--sortie);
  border-radius: 6px;
  white-space: nowrap;
  display: inline-block;
  min-width: 4.5rem;
}
.btn-supprimer:hover {
  background: rgba(239, 68, 68, 0.35);
}

.table .td-actions {
  min-width: 200px;
  white-space: nowrap;
  visibility: visible;
  opacity: 1;
}
.table .td-actions .btn-modifier,
.table .td-actions .btn-supprimer {
  display: inline-block;
  visibility: visible;
  opacity: 1;
  vertical-align: middle;
}
.table .td-actions .btn-modifier { margin-right: 0.35rem; }
.table .td-actions .btn-supprimer { margin-left: 0; }

/* Modal modifier produit */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 400px;
  width: 100%;
}
.modal-title {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}
.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}
.modal-actions button { flex: 1; }
.btn-secondary {
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text-muted);
}
.btn-secondary:hover {
  color: var(--text);
  border-color: rgba(255,255,255,0.25);
}

@media (max-width: 768px) {
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  .table { font-size: 0.85rem; min-width: 600px; }
  .table th, .table td { padding: 0.5rem 0.5rem; }
  .table .td-actions {
    min-width: 200px;
    position: sticky;
    right: 0;
    background: var(--surface);
    box-shadow: -4px 0 8px rgba(0,0,0,0.15);
  }
  .table .td-actions .btn-modifier,
  .table .td-actions .btn-supprimer {
    display: inline-block;
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
  }
  .filtres-bar, .rapport-filtres { gap: 0.4rem; }
  .filtre-input[type="text"] { min-width: 120px; }
  .rapport-filtres input, .rapport-filtres select, .rapport-filtres button { min-width: 0; }
}

@media (max-width: 600px) {
  .header, .container {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  .header-top { flex-direction: column; align-items: flex-start; }
  .header-auth { width: 100%; justify-content: space-between; }
  .stats-grid { grid-template-columns: 1fr; }
  .actions-grid { grid-template-columns: 1fr; }
  .install-banner-inner { flex-direction: column; align-items: stretch; }
  .form input, .form select, .form button { min-height: 44px; }
  .card { padding: 1rem; }
  .section h2 { font-size: 1rem; }
  .table .td-actions { min-width: 200px; }
  .table .td-actions .btn-modifier, .table .td-actions .btn-supprimer { padding: 0.35rem 0.5rem; font-size: 0.75rem; }
}
