/* ============================================
   AMY ERP — Global Stylesheet
   ============================================ */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --secondary: #0f172a;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #6366f1;

  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #2563eb;
  --sidebar-hover: #1e293b;

  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --border: #e2e8f0;
  --border-dark: #cbd5e1;

  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.14);

  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;
  --topbar-height: 60px;

  --font: 'Inter', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }
a { cursor: pointer; text-decoration: none; }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }

/* ====== SCROLLBAR ====== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ====== SIDEBAR ====== */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  transition: width 0.3s ease;
  z-index: 100;
  overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-group-label,
.sidebar.collapsed .nav-item span { display: none; }
.sidebar.collapsed .sidebar-toggle-btn { margin-left: auto; }

.sidebar-logo {
  height: var(--topbar-height);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}
.logo-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.logo-text { color: #fff; font-weight: 700; font-size: 16px; flex: 1; white-space: nowrap; }
.sidebar-toggle-btn {
  background: none; border: none; color: var(--sidebar-text);
  padding: 4px; border-radius: 6px; font-size: 14px;
  transition: color 0.2s;
}
.sidebar-toggle-btn:hover { color: #fff; }

.sidebar-nav {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 12px 0;
}
.nav-group { margin-bottom: 8px; }
.nav-group-label {
  font-size: 9px; font-weight: 600; letter-spacing: 0.08em;
  color: #475569; padding: 8px 16px 4px;
  white-space: nowrap;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  font-size: 13px; font-weight: 400;
  border-radius: 0;
  transition: all 0.15s;
  white-space: nowrap;
  position: relative;
}
.nav-item i { font-size: 14px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
  background: var(--primary);
  color: #fff;
}
.nav-item.active::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent);
  border-radius: 0 2px 2px 0;
}

/* ====== MAIN WRAPPER ====== */
.main-wrapper {
  margin-left: var(--sidebar-width);
  display: flex; flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}
.main-wrapper.collapsed { margin-left: var(--sidebar-collapsed); }

/* ====== TOPBAR ====== */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.mobile-menu-btn {
  display: none; background: none; border: none;
  color: var(--text-muted); font-size: 18px;
}
.breadcrumb { font-size: 14px; font-weight: 600; color: var(--text); }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 14px;
}
.topbar-search i { color: var(--text-muted); font-size: 12px; }
.topbar-search input {
  border: none; background: none; outline: none;
  font-size: 13px; color: var(--text); width: 160px;
}
.topbar-notif {
  position: relative; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer;
  color: var(--text-muted);
  transition: background 0.2s;
}
.topbar-notif:hover { background: var(--bg); }
.topbar-notif .badge {
  position: absolute; top: 4px; right: 4px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--danger); color: #fff;
  font-size: 9px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.topbar-user {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; padding: 4px 10px;
  border-radius: 8px;
  transition: background 0.2s;
  font-size: 13px;
}
.topbar-user:hover { background: var(--bg); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}

/* ====== CONTENT ====== */
.content { flex: 1; padding: 24px; overflow-x: hidden; }

/* ====== PAGE HEADER ====== */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ====== CARDS ====== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ====== STATS CARDS ====== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.stat-icon.blue { background: #dbeafe; color: var(--primary); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.orange { background: #fef3c7; color: var(--warning); }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.cyan { background: #cffafe; color: var(--accent); }
.stat-icon.red { background: #fee2e2; color: var(--danger); }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-change { font-size: 11px; margin-top: 4px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ====== BUTTONS ====== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #4f46e5; }
.btn-ghost { background: none; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-icon { padding: 7px; border-radius: 8px; }

/* ====== BADGES ====== */
.badge-pill {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #ede9fe; color: #4c1d95; }
.badge-muted { background: #f1f5f9; color: var(--text-muted); }

/* ====== TABLE ====== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
thead tr { background: #f8fafc; }
thead th {
  padding: 11px 14px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td {
  padding: 11px 14px;
  font-size: 13px;
  color: var(--text);
}
tfoot td {
  padding: 11px 14px;
  font-size: 13px;
  color: var(--text);
  border-top: 2px solid var(--border);
  white-space: nowrap;
}
.table-actions { display: flex; gap: 6px; }
.action-btn {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-muted);
  transition: all 0.15s;
}
.action-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.action-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: #fee2e2; }

/* ====== TOOLBAR ====== */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px; flex: 1; min-width: 200px;
}
.toolbar-search i { color: var(--text-muted); font-size: 12px; }
.toolbar-search input {
  border: none; background: none; outline: none;
  font-size: 13px; width: 100%;
}
.filter-group { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-select {
  border: 1px solid var(--border); background: var(--bg);
  border-radius: 8px; padding: 7px 12px;
  font-size: 13px; color: var(--text); outline: none;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--primary); }

/* ====== FORM ====== */
.form-grid { display: grid; gap: 16px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.form-label.required::after { content: ' *'; color: var(--danger); }
.form-control {
  border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px;
  font-size: 13px; color: var(--text);
  background: var(--bg-card); outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }
.form-control:disabled { background: #f8fafc; color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-hint { font-size: 11px; color: var(--text-muted); }
.form-section { margin-bottom: 24px; }
.form-section-title {
  font-size: 13px; font-weight: 600;
  color: var(--primary); margin-bottom: 14px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}

/* ====== PRODUIT AUTOCOMPLETE ====== */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border-dark);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  max-height: 260px;
  overflow-y: auto;
  z-index: 500;
}
.autocomplete-item {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--primary-light); color: var(--primary-dark); }
.autocomplete-item.autocomplete-empty { color: var(--text-muted); cursor: default; }
.autocomplete-item.autocomplete-empty:hover { background: none; color: var(--text-muted); }

/* ====== TABS ====== */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; gap: 4px; flex-wrap: wrap; }
.tab-btn {
  padding: 8px 18px; border: none; background: none;
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  border-radius: 8px 8px 0 0; transition: all 0.2s;
}
.tab-btn:hover { color: var(--text); background: var(--bg); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: none; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ====== MODAL ====== */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 200;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: block; }
.modal {
  display: none; position: fixed;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); z-index: 201;
  width: 90vw; max-width: 900px; max-height: 90vh;
  flex-direction: column; overflow: hidden;
}
.modal.open { display: flex; }
.modal.modal-xl { max-width: 1100px; }
.modal.modal-sm { max-width: 480px; }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-header button {
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; width: 30px; height: 30px;
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.modal-header button:hover { background: #fee2e2; color: var(--danger); }
.modal-body { flex: 1; overflow-y: auto; padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
}

/* ====== PRODUCT IMAGE UPLOAD ====== */
.img-upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px; text-align: center;
  cursor: pointer; transition: all 0.2s;
  position: relative;
}
.img-upload-zone:hover { border-color: var(--primary); background: var(--primary-light); }
.img-upload-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.img-preview { width: 80px; height: 80px; border-radius: 10px; object-fit: cover; margin: 0 auto 8px; display: block; }

/* ====== QTE INDICATORS ====== */
.qte-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.qte-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
  text-align: center;
}
.qte-card .qte-val { font-size: 22px; font-weight: 700; }
.qte-card .qte-lbl { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.qte-card.total .qte-val { color: var(--primary); }
.qte-card.reserved .qte-val { color: var(--warning); }
.qte-card.available .qte-val { color: var(--success); }
.qte-card.pending .qte-val { color: var(--info); }

/* ====== DOCUMENT ====== */
.doc-type-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.doc-type-tab {
  padding: 8px 16px; border-radius: 20px;
  font-size: 12px; font-weight: 600; border: 1.5px solid var(--border);
  background: var(--bg); color: var(--text-muted);
  cursor: pointer; transition: all 0.2s;
}
.doc-type-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.doc-type-tab.Q-ACHAT { border-color: #f59e0b; }
.doc-type-tab.Q-VENTE { border-color: #10b981; }
.doc-type-tab.Q-STOCK { border-color: #6366f1; }
.doc-type-tab.active.Q-ACHAT { background: #f59e0b; border-color: #f59e0b; }
.doc-type-tab.active.Q-VENTE { background: #10b981; border-color: #10b981; }
.doc-type-tab.active.Q-STOCK { background: #6366f1; border-color: #6366f1; }

/* ====== MARGE INDICATOR ====== */
.marge-indicator {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-radius: var(--radius);
  background: var(--bg); border: 1px solid var(--border);
  margin-bottom: 16px;
}
.marge-bar-wrap { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.marge-bar { height: 100%; border-radius: 4px; transition: width 0.4s; }
.marge-bar.good { background: var(--success); }
.marge-bar.medium { background: var(--warning); }
.marge-bar.bad { background: var(--danger); }
.marge-pct { font-size: 15px; font-weight: 700; min-width: 56px; text-align: right; }
.marge-pct.good { color: var(--success); }
.marge-pct.medium { color: var(--warning); }
.marge-pct.bad { color: var(--danger); }

/* ====== PRODUCT DETAIL TABS ====== */
.product-detail-layout {
  display: grid; grid-template-columns: 280px 1fr;
  gap: 20px;
}

/* ====== EMPTY STATE ====== */
.empty-state {
  text-align: center; padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state i { font-size: 48px; margin-bottom: 12px; opacity: 0.3; }
.empty-state h4 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.empty-state p { font-size: 13px; }

/* ====== ALERT ====== */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 13px; display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ====== TOAST ====== */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--secondary); color: #fff;
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s ease;
  min-width: 240px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ====== RESPONSIVE ====== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); width: var(--sidebar-width); }
  .main-wrapper { margin-left: 0 !important; }
  .mobile-menu-btn { display: flex; }
  .topbar-search { display: none; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .product-detail-layout { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ---- LOGIN SCREEN ---- */
.login-screen {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 100%; max-width: 360px; padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 20px; font-weight: 700; color: var(--text);
  margin-bottom: 4px;
}
.login-logo .logo-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.login-logo .logo-text { color: var(--text); }
.login-logo.has-img { flex-direction: column; justify-content: center; margin-bottom: 12px; }
.login-logo-img { max-height: 110px; max-width: 100%; object-fit: contain; }
.login-subtitle { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 12px; }
.topbar-user { cursor: pointer; }
