/* ============================================================
   TopAffaires - Admin CSS
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Cairo:wght@400;600;700&display=swap');

:root {
  --sidebar-w: 260px;
  --topbar-h: 60px;
  --primary: #1a56db;
  --primary-dark: #1245b8;
  --success: #0ea472;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1a56db;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Outfit', sans-serif; background: var(--bg); color: var(--text); overflow-x: hidden; }
body.rtl { font-family: 'Cairo', sans-serif; }

/* ---- SIDEBAR ---- */
.sidebar {
  position: fixed; top: 0; left: 0; width: var(--sidebar-w);
  height: 100vh; background: var(--sidebar-bg);
  overflow-y: auto; overflow-x: hidden;
  transition: transform .3s ease; z-index: 1000;
  display: flex; flex-direction: column;
}
.rtl .sidebar { left: auto; right: 0; }

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-icon {
  width: 38px; height: 38px; background: var(--primary);
  border-radius: 10px; display: flex; align-items: center;
  justify-content: center; font-weight: 700; color: #fff;
  font-size: 14px; flex-shrink: 0;
}
.brand-name { color: #fff; font-weight: 700; font-size: 18px; }

.sidebar-user {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid rgba(255,255,255,.07);
}
.user-avatar {
  width: 36px; height: 36px; background: var(--primary);
  border-radius: 50%; display: flex; align-items: center;
  justify-content: center; color: #fff; font-weight: 700;
  font-size: 14px; flex-shrink: 0;
}
.user-name { color: #fff; font-size: 13px; font-weight: 600; }

.sidebar-nav { list-style: none; padding: 12px 0; flex: 1; }
.nav-section {
  padding: 12px 20px 4px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: #475569; font-weight: 600;
}
.nav-divider { border-top: 1px solid rgba(255,255,255,.07); margin: 8px 0; }

.sidebar-nav li a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; color: var(--sidebar-text);
  text-decoration: none; font-size: 14px; font-weight: 400;
  transition: all .2s; border-radius: 0;
}
.sidebar-nav li a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav li a.active {
  background: var(--primary); color: #fff;
  border-right: 3px solid #60a5fa;
}
.rtl .sidebar-nav li a.active { border-right: none; border-left: 3px solid #60a5fa; }
.sidebar-nav li a i { width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-nav li a .badge { font-size: 10px; padding: 2px 6px; }

/* ---- MAIN ---- */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin .3s ease;
}
.rtl .main-content { margin-left: 0; margin-right: var(--sidebar-w); }

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-h); background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.sidebar-toggle {
  background: none; border: none; cursor: pointer;
  width: 36px; height: 36px; display: flex; align-items: center;
  justify-content: center; border-radius: 8px; color: var(--text-muted);
  display: none;
}
.sidebar-toggle:hover { background: var(--bg); }
.topbar-title { font-weight: 600; font-size: 16px; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-notif {
  position: relative; color: var(--text-muted);
  text-decoration: none; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--bg);
}
.notif-badge {
  position: absolute; top: -2px; right: -2px;
  background: var(--danger); color: #fff;
  font-size: 10px; width: 18px; height: 18px;
  border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-weight: 700;
}
.topbar-user { font-size: 13px; color: var(--text-muted); }

/* ---- PAGE CONTENT ---- */
.page-content { padding: 24px; }
.page-title { font-size: 22px; font-weight: 700; color: var(--text); }

/* ---- CARDS ---- */
.card {
  background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.card-body { padding: 20px; }

/* ---- KPI CARDS ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px; border: 1px solid var(--border);
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0;
  width: 4px; height: 100%;
}
.kpi-card.blue::before { background: var(--primary); }
.kpi-card.green::before { background: var(--success); }
.kpi-card.orange::before { background: var(--warning); }
.kpi-card.red::before { background: var(--danger); }
.kpi-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; margin-bottom: 12px;
}
.kpi-card.blue .kpi-icon { background: #dbeafe; color: var(--primary); }
.kpi-card.green .kpi-icon { background: #d1fae5; color: var(--success); }
.kpi-card.orange .kpi-icon { background: #fef3c7; color: var(--warning); }
.kpi-card.red .kpi-icon { background: #fee2e2; color: var(--danger); }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--text); }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi-trend { font-size: 11px; margin-top: 6px; }
.kpi-trend.up { color: var(--success); }
.kpi-trend.down { color: var(--danger); }

/* ---- TABLES ---- */
.table-card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: #f8fafc; padding: 12px 16px;
  font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody tr { border-bottom: 1px solid #f1f5f9; transition: background .15s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 12px 16px; vertical-align: middle; }

/* ---- PRODUCT THUMB ---- */
.product-thumb {
  width: 44px; height: 44px; border-radius: 8px;
  object-fit: cover; background: #f1f5f9;
  border: 1px solid var(--border);
}
.product-thumb-placeholder {
  width: 44px; height: 44px; border-radius: 8px;
  background: #f1f5f9; display: flex; align-items: center;
  justify-content: center; color: #94a3b8; font-size: 18px;
  border: 1px solid var(--border);
}

/* ---- BADGES ---- */
.badge { font-size: 11px; padding: 4px 10px; border-radius: 20px; font-weight: 600; }

/* ---- FORMS ---- */
.form-label { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-control, .form-select {
  border: 1.5px solid var(--border); border-radius: 8px;
  padding: 9px 13px; font-size: 14px; color: var(--text);
  transition: border .2s, box-shadow .2s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.1);
  outline: none;
}
.form-section {
  background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 20px; margin-bottom: 20px;
}
.form-section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--primary); margin-bottom: 16px;
  padding-bottom: 10px; border-bottom: 2px solid #dbeafe;
}

/* ---- PHOTO UPLOAD ---- */
.photo-upload-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.photo-upload-box {
  aspect-ratio: 1; border: 2px dashed var(--border);
  border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: pointer; position: relative; overflow: hidden;
  transition: border-color .2s, background .2s; background: #f8fafc;
}
.photo-upload-box:hover { border-color: var(--primary); background: #eff6ff; }
.photo-upload-box input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.photo-upload-box img {
  width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0;
}
.photo-upload-box .upload-icon { font-size: 28px; color: #94a3b8; }
.photo-upload-box .upload-text { font-size: 11px; color: #94a3b8; margin-top: 6px; }
.photo-delete-btn {
  position: absolute; top: 6px; right: 6px; z-index: 10;
  background: var(--danger); color: #fff; border: none;
  border-radius: 50%; width: 24px; height: 24px;
  font-size: 11px; cursor: pointer; display: none;
  align-items: center; justify-content: center;
}
.photo-upload-box:hover .photo-delete-btn { display: flex; }

/* ---- ÉTAT PIPELINE ---- */
.pipeline { display: flex; align-items: center; gap: 0; margin: 20px 0; }
.pipeline-step {
  flex: 1; text-align: center; position: relative;
  padding: 12px 8px;
}
.pipeline-step::after {
  content: ''; position: absolute; right: 0; top: 50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  border-left: 12px solid var(--border);
  z-index: 2;
}
.pipeline-step:last-child::after { display: none; }
.pipeline-step.active { background: var(--primary); color: #fff; }
.pipeline-step.done { background: var(--success); color: #fff; }
.pipeline-step .step-label { font-size: 11px; font-weight: 600; }

/* ---- AUDIT LOG ---- */
.audit-item {
  display: flex; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}
.audit-item:last-child { border-bottom: none; }
.audit-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary); flex-shrink: 0; margin-top: 4px;
}
.audit-time { font-size: 11px; color: var(--text-muted); }
.audit-action { font-size: 13px; font-weight: 500; }

/* ---- STOCK REPARTITION ---- */
.stock-bar { height: 24px; border-radius: 12px; overflow: hidden; display: flex; }
.stock-segment { height: 100%; transition: width .4s ease; }

/* ---- BTNS ---- */
.btn { border-radius: 8px; font-size: 13px; font-weight: 600; padding: 8px 16px; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

/* ---- LOGIN PAGE ---- */
.login-page {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}
.login-card {
  background: #fff; border-radius: 20px; padding: 40px;
  width: 100%; max-width: 420px; box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center; margin-bottom: 28px;
}
.login-logo-icon {
  width: 64px; height: 64px; background: var(--primary);
  border-radius: 16px; display: flex; align-items: center;
  justify-content: center; font-size: 26px; font-weight: 800;
  color: #fff; margin: 0 auto 12px;
}
.login-title { font-size: 24px; font-weight: 700; text-align: center; }
.login-sub { text-align: center; color: var(--text-muted); font-size: 14px; margin-top: 4px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); }
  .rtl .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0 !important; margin-right: 0 !important; }
  .sidebar-toggle { display: flex; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar-overlay { display: block !important; }
}
@media (max-width: 576px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
  .photo-upload-grid { grid-template-columns: repeat(3, 1fr); }
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 999;
}
