/* ==========================================================================
   APPLICATION COMMERCIALE - STYLE PRINCIPAL
   Design : moderne, professionnel, épuré
   ========================================================================== */

:root {
  /* Couleurs principales */
  --color-primary: #1a56db;
  --color-primary-dark: #1442ad;
  --color-primary-light: #e8f0fe;

  /* Couleurs d'état */
  --color-success: #16a34a;
  --color-success-light: #e7f7ed;
  --color-warning: #f97316;
  --color-warning-light: #fff1e6;
  --color-danger: #dc2626;
  --color-danger-light: #fdecec;
  --color-info: #0284c7;

  /* Neutres */
  --color-bg: #f5f7fb;
  --color-white: #ffffff;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;

  /* Structure */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --sidebar-width: 240px;
  --bottom-nav-height: 64px;
  --transition: all 0.2s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, Roboto, Arial, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  text-decoration: none;
  color: inherit;
}

ul {
  list-style: none;
}

img {
  max-width: 100%;
  display: block;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
}

/* ==========================================================================
   LAYOUT GLOBAL
   ========================================================================== */

.app-layout {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 24px 32px;
  max-width: 100%;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
}

.page-subtitle {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

/* ==========================================================================
   SIDEBAR (Ordinateur)
   ========================================================================== */

.sidebar {
  width: var(--sidebar-width);
  background: var(--color-white);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px 8px;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--color-primary);
}

.sidebar-logo .logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  transition: var(--transition);
}

.sidebar-link .icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-link:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.sidebar-link.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 600;
}

.sidebar-footer {
  border-top: 1px solid var(--color-border);
  padding-top: 16px;
  margin-top: 16px;
}

/* ==========================================================================
   BOTTOM NAV (Mobile)
   ========================================================================== */

.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(16, 24, 40, 0.06);
}

.bottom-nav-list {
  display: flex;
  height: 100%;
  list-style: none;
}

.bottom-nav-list li {
  flex: 1;
  min-width: 0;
  display: flex;
}

.bottom-nav-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.65rem;
  color: var(--color-text-muted);
  font-weight: 500;
  text-align: center;
  padding: 4px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bottom-nav-link .icon {
  font-size: 1.15rem;
}

.bottom-nav-link span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  white-space: nowrap;
}

.bottom-nav-link.active {
  color: var(--color-primary);
}

/* Quand il y a plus de 5 onglets (rôle administrateur), on réduit encore
   un peu le texte pour que tout reste aligné et lisible sur mobile. */
.bottom-nav-list:has(li:nth-child(6)) .bottom-nav-link {
  font-size: 0.58rem;
}

.bottom-nav-list:has(li:nth-child(6)) .bottom-nav-link .icon {
  font-size: 1rem;
}

/* ==========================================================================
   TOPBAR MOBILE
   ========================================================================== */

.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.mobile-topbar .logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--color-primary);
  font-size: 1.05rem;
}

/* ==========================================================================
   BOUTONS
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-white);
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-white);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-bg);
}

.btn-danger {
  background: var(--color-danger);
  color: var(--color-white);
}

.btn-login {
  background: var(--color-warning);
  color: var(--color-white);
}

.btn-login:hover {
  background: #c2410c;
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 15px 24px;
  font-size: 1.05rem;
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  background: var(--color-white);
  border: 1px solid var(--color-border);
}

.fab-nouvelle-commande {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + 16px);
  right: 20px;
  z-index: 99;
  box-shadow: var(--shadow-md);
  border-radius: 50px;
}

/* ==========================================================================
   CARTES
   ========================================================================== */

.card {
  background: var(--color-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  border: 1px solid var(--color-border);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.stat-icon.blue { background: var(--color-primary-light); color: var(--color-primary); }
.stat-icon.orange { background: var(--color-warning-light); color: var(--color-warning); }
.stat-icon.green { background: var(--color-success-light); color: var(--color-success); }
.stat-icon.purple { background: #f3e8ff; color: #7c3aed; }

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-label {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

/* ==========================================================================
   BADGES / STATUTS
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 50px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-attente { background: var(--color-warning-light); color: var(--color-warning); }
.badge-validee { background: var(--color-success-light); color: var(--color-success); }
.badge-expediee { background: var(--color-primary-light); color: var(--color-primary); }
.badge-annulee { background: var(--color-danger-light); color: var(--color-danger); }

/* ==========================================================================
   TABLEAUX
   ========================================================================== */

.table-wrapper {
  background: var(--color-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

thead th {
  text-align: left;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.92rem;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr {
  cursor: pointer;
  transition: var(--transition);
}

tbody tr:hover {
  background: var(--color-bg);
}

/* Liste de cartes pour mobile (remplace le tableau) */
.record-cards {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.record-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
}

.record-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.record-card-title {
  font-weight: 700;
}

.record-card-meta {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.record-card-total {
  font-weight: 700;
  color: var(--color-primary);
}

/* ==========================================================================
   FORMULAIRES
   ========================================================================== */

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-white);
  color: var(--color-text);
  transition: var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.search-bar {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-bar input {
  width: 100%;
  padding: 12px 14px 12px 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-white);
}

.search-bar .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
}

/* ==========================================================================
   TABS / FILTRES
   ========================================================================== */

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab-btn {
  padding: 9px 18px;
  border-radius: 50px;
  border: 1px solid var(--color-border);
  background: var(--color-white);
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.tab-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-white);
}

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  align-items: center;
}

/* ==========================================================================
   LOGIN PAGE
   ========================================================================== */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-bg));
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px 32px;
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.login-logo .logo-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
}

.login-logo .logo-image {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  object-fit: contain;
}

.sidebar-logo .logo-image {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.mobile-topbar .logo-image {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.login-card h1 {
  text-align: center;
  font-size: 1.4rem;
  margin-bottom: 24px;
}

.error-message {
  background: var(--color-danger-light);
  color: var(--color-danger);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 16px;
  display: none;
}

.error-message.visible {
  display: block;
}

.demo-hint {
  margin-top: 20px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.5;
}

/* ==========================================================================
   PROFIL
   ========================================================================== */

.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 32px 20px;
}

.profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  overflow: hidden;
}

.profile-info-list {
  width: 100%;
  max-width: 420px;
  margin: 24px auto 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.profile-info-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
}

.profile-info-item span:first-child {
  color: var(--color-text-muted);
}

.profile-info-item span:last-child {
  font-weight: 600;
}

/* ==========================================================================
   PRODUIT / COMMANDE - LISTES SPECIFIQUES
   ========================================================================== */

.product-picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  background: var(--color-white);
}

.product-picker-info .name {
  font-weight: 600;
}

.product-picker-info .meta {
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qty-control button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-white);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--color-primary);
}

.qty-control span {
  min-width: 20px;
  text-align: center;
  font-weight: 600;
}

.order-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 16px;
  margin-top: 16px;
  border-top: 1px dashed var(--color-border);
}

.order-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
}

.order-summary-row.total {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-primary);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--color-text-muted);
}

.empty-state .icon {
  font-size: 2.4rem;
  margin-bottom: 12px;
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid var(--color-primary-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hidden {
  display: none !important;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-box {
  background: var(--color-white);
  border-radius: var(--radius-md);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--color-text-muted);
}
