/* ============================================================
   Smart Gallery — Styles
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:     #1a1a2e;
  --accent:      #e94560;
  --accent2:     #0f3460;
  --bg:          #f8f7f4;
  --surface:     #ffffff;
  --surface2:    #f0ede8;
  --border:      rgba(0,0,0,0.08);
  --text:        #1a1a1a;
  --muted:       #6b6b6b;
  --success:     #2d7a4f;
  --success-bg:  #e8f5ee;
  --warning:     #b45309;
  --warning-bg:  #fef3c7;
  --danger:      #c0392b;
  --danger-bg:   #fde8e8;
  --radius:      12px;
  --shadow:      0 2px 16px rgba(0,0,0,0.09);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---- LOGIN ---- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #0f3460 55%, #e94560 100%);
  padding: 20px;
}
.login-card {
  background: white; border-radius: 24px; padding: 40px;
  width: 100%; max-width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 32px; font-weight: 900; color: var(--primary); letter-spacing: -1px; }
.login-logo h1 span { color: var(--accent); }
.login-logo p { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* ---- TOPBAR ---- */
.topbar {
  background: var(--primary); color: white;
  padding: 13px 20px; display: flex; align-items: center;
  justify-content: space-between; position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 20px; font-weight: 900; letter-spacing: -0.5px; }
.topbar-title span { color: var(--accent); }
.badge-role {
  padding: 3px 10px; border-radius: 20px; font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  background: var(--accent); color: white;
}
.badge-role.commercial { background: #0f3460; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-info { font-size: 13px; color: rgba(255,255,255,0.7); }

/* ---- NAV ---- */
.nav {
  background: white; border-bottom: 1px solid var(--border);
  display: flex; overflow-x: auto; padding: 0 16px;
  -webkit-overflow-scrolling: touch;
}
.nav::-webkit-scrollbar { display: none; }
.nav-item {
  padding: 14px 18px; border-bottom: 3px solid transparent;
  font-size: 14px; font-weight: 600; color: var(--muted);
  cursor: pointer; white-space: nowrap; display: flex;
  align-items: center; gap: 6px; transition: all 0.2s;
  user-select: none; text-decoration: none;
}
.nav-item.active { color: var(--accent); border-bottom-color: var(--accent); }
.nav-item:hover { color: var(--text); }
.nav-badge {
  background: var(--accent); color: white; border-radius: 20px;
  padding: 1px 7px; font-size: 11px;
}

/* ---- CONTENT ---- */
.content { flex: 1; padding: 20px; max-width: 1200px; margin: 0 auto; width: 100%; }

/* ---- FORMS ---- */
.role-tabs { display: flex; gap: 8px; margin-bottom: 24px; background: var(--surface2); border-radius: 10px; padding: 4px; }
.role-tab { flex: 1; padding: 10px; border: none; background: none; border-radius: 8px; font-size: 14px; cursor: pointer; font-weight: 600; color: var(--muted); transition: all 0.2s; font-family: inherit; }
.role-tab.active { background: white; color: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 15px; outline: none;
  transition: border-color 0.2s; background: var(--bg); color: var(--text);
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); background: white; }
.form-group textarea { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 14px; }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; margin-bottom: 14px; }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: 10px; border: none; font-size: 14px;
  font-weight: 600; cursor: pointer; transition: all 0.2s; font-family: inherit;
  text-decoration: none;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: #c73652; transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #e5e0d8; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #236040; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #f5d0d0; }
.btn-dark { background: var(--primary); color: white; }
.btn-dark:hover:not(:disabled) { background: #0f3460; }
.btn-outline-light { background: rgba(255,255,255,0.1); color: white; border: 1px solid rgba(255,255,255,0.25); }
.btn-outline-light:hover { background: rgba(255,255,255,0.2); }
.btn-ghost { background: rgba(255,255,255,0.1); color: white; border: none; }
.btn-full { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 12px; border-radius: 8px; }

/* ---- CARDS & STATS ---- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 22px; font-weight: 800; color: var(--primary); }
.page-subtitle { font-size: 13px; color: var(--muted); margin-top: 3px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: var(--radius); padding: 16px; border: 1px solid var(--border); }
.stat-icon { font-size: 22px; margin-bottom: 8px; }
.stat-val { font-size: 26px; font-weight: 900; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; margin-top: 2px; }

/* ---- SEARCH ---- */
.search-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 14px; outline: none; background: white; font-family: inherit; }
.search-input:focus { border-color: var(--accent); }
.filter-select { padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 14px; outline: none; background: white; font-family: inherit; cursor: pointer; }

/* ---- ARTICLES ---- */
.articles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.article-card { background: white; border-radius: var(--radius); overflow: hidden; border: 2px solid var(--border); cursor: pointer; transition: all 0.2s; position: relative; }
.article-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.article-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(233,69,96,0.15); }
.article-card.out-of-stock { opacity: 0.6; }
.article-img { width: 100%; height: 155px; background: var(--surface2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.article-img img { width: 100%; height: 100%; object-fit: cover; }
.article-emoji { font-size: 52px; }
.article-body { padding: 12px; }
.article-ref { font-size: 10px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.article-name { font-size: 14px; font-weight: 700; color: var(--primary); margin: 2px 0 6px; line-height: 1.3; }
.article-price { font-size: 18px; font-weight: 900; color: var(--accent); }
.article-stock { font-size: 12px; margin-top: 4px; font-weight: 600; }
.stock-ok { color: var(--success); }
.stock-low { color: var(--warning); }
.stock-out { color: var(--danger); }
.article-cat { display: inline-block; font-size: 10px; padding: 2px 8px; border-radius: 20px; font-weight: 600; margin-top: 6px; text-transform: uppercase; letter-spacing: 0.3px; }
.add-to-order-btn { position: absolute; top: 8px; right: 8px; background: var(--accent); color: white; border: none; border-radius: 8px; width: 32px; height: 32px; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.2s; font-weight: 700; }
.article-card:hover .add-to-order-btn { opacity: 1; }
.in-order-badge { position: absolute; top: 8px; left: 8px; background: var(--success); color: white; border-radius: 20px; padding: 3px 8px; font-size: 11px; font-weight: 700; }

/* ---- TABLE ---- */
.table-wrap { background: white; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 500px; }
th { background: var(--surface2); padding: 12px 14px; text-align: left; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }
.td-img { width: 48px; height: 48px; border-radius: 8px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.td-img img { width: 100%; height: 100%; object-fit: cover; }

/* ---- COMMANDES ---- */
.commande-card { background: white; border-radius: var(--radius); padding: 20px; border: 1px solid var(--border); margin-bottom: 12px; transition: box-shadow 0.2s; }
.commande-card:hover { box-shadow: var(--shadow); }
.commande-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.commande-id { font-size: 12px; font-weight: 700; color: var(--muted); }
.commande-client { font-size: 18px; font-weight: 800; color: var(--primary); }
.commande-total { font-size: 22px; font-weight: 900; color: var(--accent); }
.commande-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.status-badge { padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 700; display: inline-block; }
.status-brouillon  { background: #f0f0f0; color: #666; }
.status-confirmee  { background: var(--success-bg); color: var(--success); }
.status-en_cours   { background: var(--warning-bg); color: var(--warning); }
.status-livree     { background: #dbeafe; color: #1d4ed8; }
.status-annulee    { background: var(--danger-bg); color: var(--danger); }

/* ---- ORDER PANEL ---- */
.order-panel { position: fixed; right: 0; top: 0; bottom: 0; width: 340px; background: white; box-shadow: -4px 0 24px rgba(0,0,0,0.15); z-index: 200; display: flex; flex-direction: column; transform: translateX(100%); transition: transform 0.3s ease; }
.order-panel.open { transform: translateX(0); }
.order-panel-header { padding: 20px; border-bottom: 1px solid var(--border); background: var(--primary); color: white; display: flex; align-items: center; justify-content: space-between; }
.order-panel-header h3 { font-size: 16px; font-weight: 700; }
.order-panel-body { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
.order-panel-footer { padding: 16px; border-top: 1px solid var(--border); background: var(--bg); }
.order-item { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--bg); border-radius: 8px; margin-bottom: 8px; }
.order-item-img { width: 42px; height: 42px; border-radius: 6px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.order-item-img img { width: 100%; height: 100%; object-fit: cover; }
.order-item-info { flex: 1; min-width: 0; }
.order-item-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-item-price { font-size: 12px; color: var(--accent); font-weight: 700; margin-top: 2px; }
.qty-control { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.qty-btn { width: 26px; height: 26px; border: 1.5px solid var(--border); background: white; border-radius: 6px; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.qty-btn:hover { background: var(--surface2); }
.qty-val { font-size: 14px; font-weight: 800; min-width: 22px; text-align: center; }
.order-total-line { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; color: var(--muted); }
.order-total-line.grand { font-weight: 900; font-size: 18px; color: var(--primary); border-top: 2px solid var(--border); margin-top: 8px; padding-top: 10px; }

/* ---- FAB ---- */
.fab { position: fixed; bottom: 24px; right: 24px; width: 58px; height: 58px; background: var(--accent); color: white; border: none; border-radius: 50%; font-size: 24px; cursor: pointer; box-shadow: 0 4px 20px rgba(233,69,96,0.45); z-index: 150; display: flex; align-items: center; justify-content: center; transition: transform 0.2s; }
.fab:hover { transform: scale(1.1); }
.fab-badge { position: absolute; top: -2px; right: -2px; background: white; color: var(--accent); border-radius: 50%; width: 20px; height: 20px; font-size: 11px; font-weight: 900; display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,0.2); }

/* ---- MODAL ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 300; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease; }
.modal { background: white; border-radius: 20px; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; animation: slideUp 0.25s ease; }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: white; z-index: 1; border-radius: 20px 20px 0 0; }
.modal-header h3 { font-size: 18px; font-weight: 800; color: var(--primary); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; position: sticky; bottom: 0; background: white; border-radius: 0 0 20px 20px; }

/* ---- IMAGE UPLOAD ---- */
.img-upload { border: 2px dashed var(--border); border-radius: 10px; padding: 20px; text-align: center; cursor: pointer; transition: border-color 0.2s; min-height: 100px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 6px; }
.img-upload:hover { border-color: var(--accent); background: #fff8f9; }
.img-preview { width: 100%; max-height: 150px; object-fit: cover; border-radius: 8px; }

/* ---- CATEGORIES ---- */
.categories-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.category-card { background: white; border-radius: var(--radius); border: 1.5px solid var(--border); padding: 20px; display: flex; flex-direction: column; gap: 12px; transition: box-shadow 0.2s; }
.category-card:hover { box-shadow: var(--shadow); }
.category-card-header { display: flex; align-items: center; gap: 14px; }
.category-icon-box { width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 26px; flex-shrink: 0; }
.color-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; background: var(--surface2); border-radius: 10px; }
.emoji-btn { width: 38px; height: 38px; border: 2px solid transparent; border-radius: 8px; background: white; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: border-color 0.1s; }
.emoji-btn.active { border-color: var(--accent); background: #fff8f9; }
.color-grid { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; background: var(--surface2); border-radius: 10px; align-items: center; }
.color-btn { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; transition: transform 0.1s, border-color 0.1s; }
.color-btn.active { border-color: #1a1a2e; transform: scale(1.15); }
.cat-preview { width: 80px; height: 80px; border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 40px; margin: 0 auto 20px; transition: background 0.2s; }

/* ---- TOAST ---- */
.toast-container { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1a1a2e; color: white; padding: 12px 22px; border-radius: 10px; font-size: 14px; font-weight: 600; animation: slideUp 0.3s ease; box-shadow: 0 4px 20px rgba(0,0,0,0.25); white-space: nowrap; }
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

/* ---- EMPTY STATE ---- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-icon { font-size: 52px; margin-bottom: 12px; }
.empty-state p { font-size: 16px; font-weight: 500; margin-bottom: 6px; }

/* ---- LOADING ---- */
.loading-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 200px; gap: 14px; color: var(--muted); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }

/* ---- PRINT ---- */
#print-area { display: none; }
@media print {
  body > *         { display: none !important; }
  #print-area      { display: block !important; position: static !important; }
}

/* ---- ANIMATIONS ---- */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin    { to { transform: rotate(360deg); } }

/* ---- RESPONSIVE ---- */
@media (max-width: 600px) {
  .articles-grid { grid-template-columns: repeat(2, 1fr); }
  .order-panel   { width: 100%; max-width: 100%; }
  .stats-grid    { grid-template-columns: repeat(2, 1fr); }
  .page-title    { font-size: 18px; }
  .topbar-title  { font-size: 17px; }
  .content       { padding: 14px; }
  .modal         { border-radius: 16px; }
  .user-info     { display: none; }
}
@media (max-width: 360px) {
  .articles-grid { gap: 10px; }
  .article-img   { height: 120px; }
}
