/* ============================================================
   Marketplace - Design professionnel
   Palette : bleu marine #0f172a, or #f59e0b, gris clair #f8fafc
   ============================================================ */
:root {
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --secondary: #6b7280;
  --secondary-hover: #4b5563;
  --success: #16a34a;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 10px 20px rgba(0, 0, 0, 0.1);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.site-header {
  background: #0f172a;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: box-shadow 0.2s ease;
}
.site-header.scrolled { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); }
.site-header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #ffffff;
}
.site-header h1 .dot { color: #f59e0b; }
.site-header nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  align-items: center;
}
.site-header nav a {
  text-decoration: none;
  color: #cbd5e1;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.92rem;
  border-bottom: 2px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.site-header nav a:hover {
  color: #ffffff;
  border-bottom-color: #f59e0b;
  background: rgba(255, 255, 255, 0.05);
}
.site-header nav a.active {
  color: #ffffff;
  border-bottom-color: #f59e0b;
  font-weight: 600;
}

/* Layout */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: grid;
  gap: 1.5rem;
}

/* Cartes */
.card, .produit-card, .stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  padding: 1.5rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover, .produit-card:hover, .stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}
.card h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: #0f172a;
}

/* Listes */
.entity-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.entity-list li {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
  font-size: 0.92rem;
}
.entity-list li .name { font-weight: 600; }
.entity-list li .meta { color: var(--text-muted); font-size: 0.85rem; }
.entity-list li.loading, .entity-list li.empty {
  color: var(--text-muted);
  font-style: italic;
  background: transparent;
  border-style: dashed;
}

/* Formulaires */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  align-items: end;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}
.form-grid input, .form-grid select,
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], select, textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-grid input:focus, .form-grid select:focus,
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}
.form-row { display: flex; gap: 0.5rem; align-items: end; flex-wrap: wrap; }

/* Boutons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12); }
.btn:active { transform: translateY(0); }
.btn-primary { background: #f59e0b; color: #0f172a; }
.btn-primary:hover { background: #d97706; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-secondary {
  background: transparent;
  color: #0f172a;
  border: 2px solid #0f172a;
}
.btn-secondary:hover { background: rgba(15, 23, 42, 0.06); }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-small:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Messages */
.message { margin: 0.75rem 0 0; font-size: 0.88rem; min-height: 1.2em; }
.message-success, .message.success { color: var(--success); font-weight: 500; }
.message-error, .message.error { color: var(--danger); font-weight: 500; }

/* Tables */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td {
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  font-weight: 600;
  color: #ffffff;
  background: #0f172a;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table tbody tr:nth-child(even) { background: #f8fafc; }
.data-table tbody tr:hover { background: #f1f5f9; }
.data-table td.loading, .data-table td.empty {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
}
.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  text-transform: capitalize;
}
.badge.en_attente { background: #f59e0b; }
.badge.en_transit { background: #2563eb; }
.badge.livree { background: #16a34a; }
.badge.annulee { background: #9ca3af; }

/* Auth */
.auth-form { max-width: 400px; margin: 2rem auto; width: 100%; }
.auth-form h2 { text-align: center; margin-bottom: 1.25rem; }
.auth-form form { display: flex; flex-direction: column; gap: 1rem; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}
.auth-form button { margin-top: 0.25rem; width: 100%; }
.auth-alt { margin-top: 1rem; text-align: center; font-size: 0.88rem; color: var(--text-muted); }
.auth-alt a { color: #0f172a; text-decoration: none; font-weight: 600; }
.auth-alt a:hover { text-decoration: underline; color: #f59e0b; }
.auth-nav { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.auth-nav a {
  text-decoration: none;
  color: #cbd5e1;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  transition: color 0.2s ease, background 0.2s ease;
}
.auth-nav a:hover { color: #ffffff; background: rgba(255, 255, 255, 0.05); }
.user-badge {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Controle d'acces */
body:not(.can-write) .write-only { display: none !important; }

/* Produits */
.filtres {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.25rem;
}
.produits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}
.produit-card { display: flex; flex-direction: column; gap: 0.5rem; }
.produit-card h3 { margin: 0; font-size: 1.1rem; font-weight: 700; color: var(--text); }
.produit-card .description { margin: 0; color: var(--text-muted); font-size: 0.9rem; flex-grow: 1; }
.produit-card .prix { margin: 0; color: var(--success); font-size: 1.4rem; font-weight: 700; }
.produit-card .stock { margin: 0; color: var(--text-muted); font-size: 0.8rem; }
.badge-categorie {
  display: inline-block;
  align-self: flex-start;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
  text-transform: capitalize;
  background: var(--secondary);
}
.badge-categorie.alimentaire { background: #16a34a; }
.badge-categorie.electronique { background: #2563eb; }
.badge-categorie.vetement { background: #db2777; }
.badge-categorie.autre { background: #6b7280; }
.produit-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.produits-grid .loading, .produits-grid .empty {
  color: var(--text-muted);
  font-style: italic;
  grid-column: 1 / -1;
}

/* Panier */
#panier-compteur {
  display: inline-block;
  min-width: 1.2em;
  padding: 0.1rem 0.45rem;
  margin-left: 0.25rem;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.4;
}
.panier-table { width: 100%; }
.panier-table input.panier-quantite {
  width: 60px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}
.panier-recap {
  margin-top: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.panier-total { margin: 0; font-size: 1.4rem; font-weight: 700; color: var(--text); }
.commande-lignes { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; }
.commande-lignes li { margin: 2px 0; }

/* Checkout */
.checkout-steps { display: flex; gap: 0.5rem; margin: 0 0 1.5rem; flex-wrap: wrap; }
.checkout-steps .step {
  padding: 0.5rem 0.9rem;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.checkout-steps .step.active {
  color: #0f172a;
  font-weight: 700;
  border-bottom-color: #f59e0b;
}
.checkout-nav { display: flex; justify-content: space-between; margin-top: 1.5rem; gap: 1rem; }
.card-selectable {
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  border: 2px solid var(--border);
}
.card-selectable.selected {
  border: 3px solid #f59e0b;
  background: rgba(245, 158, 11, 0.06);
}
.adresse-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  margin-top: 0.35rem;
}
.adresse-label {
  display: block;
  margin: 1rem 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}
.checkout-recap p { margin: 0.35rem 0; }

/* Messagerie */
.conv-commande-info { font-size: 0.95rem; color: var(--text-muted); }
.conv-commande-info a { color: #0f172a; text-decoration: none; font-weight: 600; }
.conv-commande-info a:hover { text-decoration: underline; color: #f59e0b; }
.conv-fil {
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.conv-message-item {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
}
.conv-message-item.mine {
  background: rgba(245, 158, 11, 0.1);
  margin-left: auto;
  text-align: right;
  max-width: 80%;
}
.conv-auteur { font-weight: 700; font-size: 0.88rem; color: var(--text); }
.conv-date { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.conv-contenu { margin: 0.25rem 0 0; font-size: 0.92rem; white-space: pre-wrap; word-break: break-word; }
.conv-form { display: flex; flex-direction: column; gap: 0.75rem; }
.conv-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}
.conv-form textarea { width: 100%; min-height: 80px; resize: vertical; }
#messages-compteur {
  display: inline-block;
  min-width: 1.2em;
  padding: 0.1rem 0.45rem;
  margin-left: 0.25rem;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.4;
}
.messages-list { display: flex; flex-direction: column; gap: 0.75rem; }
.message-entry {
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.message-entry-header { display: flex; align-items: center; gap: 0.5rem; }
.message-entry-id { font-weight: 700; font-size: 0.95rem; }
.message-entry-last { font-size: 0.88rem; color: var(--text-muted); }
.badge-non-lu {
  display: inline-block;
  min-width: 1.2em;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}

/* Dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}
.stat-value { font-size: 2rem; font-weight: bold; color: #0f172a; line-height: 1.1; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.top-produits {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

/* Visibilite par role */
.staff-only { display: none; }
body.staff .staff-only { display: inline-block; }
.form-hidden { display: none; }
.transitaire-only, .livreur-only, .admin-only { display: none; }
body.can-write.role-transitaire .transitaire-only,
body.can-write.role-livreur .livreur-only,
body.can-write.role-admin .admin-only,
body.role-transitaire .transitaire-only,
body.role-livreur .livreur-only,
body.role-admin .admin-only { display: block; }
.client-only { display: none; }
body.client-or-admin .client-only { display: inline-block; }

/* Footer */
.site-footer {
  background: #0f172a;
  color: #cbd5e1;
  padding: 40px 20px 20px;
  margin-top: 60px;
}
.footer-content {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 30px;
  max-width: 1200px;
  margin: 0 auto;
}
.footer-col h4 {
  color: #f59e0b;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.footer-col ul { list-style: none; padding: 0; margin: 0; }
.footer-col ul li { margin: 6px 0; font-size: 0.9rem; }
.footer-col a { color: #cbd5e1; text-decoration: none; transition: color 0.2s; }
.footer-col a:hover { color: #f59e0b; }
.footer-logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.footer-logo .dot { color: #f59e0b; }
.footer-desc { font-size: 0.85rem; line-height: 1.6; color: #94a3b8; }
.footer-bottom {
  border-top: 1px solid #1e293b;
  margin-top: 30px;
  padding-top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  font-size: 0.8rem;
  color: #64748b;
}

/* Responsive */
@media (max-width: 768px) {
  .site-header { padding: 1rem; flex-direction: column; align-items: flex-start; }
  .site-header nav { flex-direction: column; width: 100%; gap: 0.25rem; }
  .site-header nav a { width: 100%; padding: 0.6rem 0.75rem; }
  .container { padding: 1rem; grid-template-columns: 1fr; }
  .card { padding: 1rem; }
  .produits-grid, .stats-grid { grid-template-columns: 1fr; }
  .filtres { flex-direction: column; align-items: stretch; }
  .filtres input, .filtres select, .filtres button { width: 100%; }
  .footer-content { grid-template-columns: 1fr; text-align: center; }
  .footer-bottom { flex-direction: column; gap: 8px; }
}

/* ============================================================
   Emplacements publicitaires
   ============================================================ */
.ads-top { max-width: 728px; height: 90px; margin: 20px auto; background: #f1f5f9; border: 2px dashed #cbd5e1; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #64748b; font-size: 0.9rem; text-align: center; padding: 10px; transition: all 0.2s; }
.ads-top:hover { background: #e2e8f0; border-color: #f59e0b; }
.ads-top a { color: #64748b; text-decoration: none; font-weight: 600; }
.ads-sidebar { width: 300px; height: 250px; background: #f1f5f9; border: 2px dashed #cbd5e1; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #64748b; font-size: 0.9rem; text-align: center; padding: 10px; margin-bottom: 20px; transition: all 0.2s; }
.ads-sidebar:hover { background: #e2e8f0; border-color: #f59e0b; }
.ads-sidebar a { color: #64748b; text-decoration: none; font-weight: 600; }
.ads-inline { max-width: 728px; height: 90px; margin: 30px auto; background: #fef3c7; border: 2px dashed #f59e0b; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #92400e; font-size: 0.9rem; text-align: center; padding: 10px; transition: all 0.2s; }
.ads-inline:hover { background: #fde68a; }
.ads-inline a { color: #92400e; text-decoration: none; font-weight: 600; }
.ads-footer { max-width: 728px; height: 90px; margin: 20px auto; background: #0f172a; border: 2px dashed #334155; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 0.9rem; text-align: center; padding: 10px; }
.ads-footer a { color: #f59e0b; text-decoration: none; font-weight: 600; }
.ads-label { position: absolute; top: 4px; right: 8px; font-size: 0.7rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.05em; }
.ads-wrapper { position: relative; }
.ads-grid-layout { display: grid; grid-template-columns: 1fr 320px; gap: 30px; max-width: 1200px; margin: 0 auto; padding: 0 20px; }
@media (max-width: 768px) { .ads-grid-layout { grid-template-columns: 1fr; } .ads-sidebar { width: 100%; } .ads-top, .ads-inline, .ads-footer { max-width: 100%; } }

/* ============================================================
   Publicites (dashboard admin)
   ============================================================ */
.publicite-card {
  background: #fff;
  border: 2px solid #d4af37;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.publicite-card h4 {
  margin: 0;
  color: #333;
  font-size: 1.1rem;
}

.publicite-card .prix {
  font-size: 1.6rem;
  font-weight: bold;
  color: #d4af37;
}

.dashboard-publicites {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
