/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --emerald-50:  #ecfdf5;
  --emerald-100: #d1fae5;
  --emerald-200: #a7f3d0;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --emerald-900: #064e3b;
  --amber-50:  #fffbeb;
  --amber-100: #fef3c7;
  --amber-600: #d97706;
  --amber-700: #b45309;
  --blue-50:   #eff6ff;
  --blue-600:  #2563eb;
  --red-50:    #fef2f2;
  --red-600:   #dc2626;
  --purple-100: #f3e8ff;
  --purple-600: #9333ea;
  --purple-700: #7e22ce;
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-900: #111827;
  --sidebar-w: 280px;
  --sidebar-collapsed: 80px;
  --header-h: 64px;
  --radius: 12px;
  --shadow: 0 1px 3px 0 rgb(0 0 0/.1), 0 1px 2px -1px rgb(0 0 0/.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0/.1), 0 2px 4px -2px rgb(0 0 0/.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0/.1), 0 4px 6px -4px rgb(0 0 0/.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0/.1), 0 8px 10px -6px rgb(0 0 0/.1);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}

/* ─── Layout ───────────────────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--gray-200);
  z-index: 50;
  display: flex; flex-direction: column;
  transition: width .25s ease, transform .25s ease;
  overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar-logo {
  height: var(--header-h);
  display: flex; align-items: center; padding: 0 1.5rem;
  border-bottom: 1px solid var(--gray-100);
  gap: .75rem; overflow: hidden; flex-shrink: 0;
}
.logo-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--emerald-600);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: .9rem;
  flex-shrink: 0;
}
.logo-text {
  font-weight: 700; color: var(--emerald-900);
  white-space: nowrap; overflow: hidden;
  transition: opacity .2s;
}
.sidebar.collapsed .logo-text { opacity: 0; width: 0; }

.sidebar-nav { flex: 1; padding: 1.5rem .75rem; overflow-y: auto; display: flex; flex-direction: column; gap: .25rem; }

.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .625rem .75rem; border-radius: 12px;
  text-decoration: none; font-weight: 500; font-size: .9rem;
  color: var(--gray-500);
  transition: all .15s;
  white-space: nowrap; overflow: hidden;
}
.nav-item:hover { background: var(--gray-50); color: var(--gray-900); }
.nav-item.active { background: var(--emerald-50); color: var(--emerald-700); }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--gray-400); }
.nav-item.active svg { color: var(--emerald-600); }
.nav-item:hover svg { color: var(--gray-600); }
.nav-label { transition: opacity .2s; }
.sidebar.collapsed .nav-label { opacity: 0; width: 0; overflow: hidden; }

.sidebar-footer {
  padding: 1rem; border-top: 1px solid var(--gray-100);
  display: flex; flex-direction: column; gap: .5rem;
}
.user-info {
  display: flex; align-items: center; gap: .75rem; padding: .5rem;
  overflow: hidden;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--gray-100);
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-500); flex-shrink: 0;
}
.user-details { overflow: hidden; }
.user-name { font-size: .875rem; font-weight: 600; color: var(--gray-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .75rem; color: var(--gray-500); text-transform: capitalize; }
.sidebar.collapsed .user-details { display: none; }
.btn-logout {
  display: flex; align-items: center; gap: .75rem;
  width: 100%; padding: .5rem .75rem; border-radius: 12px;
  color: var(--red-600); background: none; border: none;
  cursor: pointer; font-size: .9rem; font-weight: 500;
  transition: background .15s;
  white-space: nowrap; overflow: hidden;
}
.btn-logout:hover { background: var(--red-50); }
.btn-logout svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar.collapsed .btn-logout span { display: none; }

/* ─── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  transition: margin-left .25s ease;
  min-width: 0;
}
.main-content.sidebar-collapsed { margin-left: var(--sidebar-collapsed); }

.top-header {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  background: #fff; border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 1rem; padding: 0 2rem;
}
.btn-toggle {
  padding: .5rem; border-radius: 8px; border: none;
  background: none; cursor: pointer; color: var(--gray-500);
  display: flex; align-items: center;
  transition: background .15s;
}
.btn-toggle:hover { background: var(--gray-100); }
.header-title { font-size: 1.1rem; font-weight: 600; color: var(--gray-900); }

.page-content {
  padding: 2rem;
  max-width: 1280px;
  margin: 0 auto;
}

/* ─── Mobile overlay ───────────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 40;
}
.sidebar-overlay.active { display: block; }

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff; border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 1.5rem; box-shadow: var(--shadow);
}
.card-emerald { background: var(--emerald-600); color: #fff; border: none; }
.card-emerald .label { color: rgba(255,255,255,.8); }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .625rem 1.25rem; border-radius: 10px;
  font-weight: 600; font-size: .875rem; border: none;
  cursor: pointer; text-decoration: none;
  transition: all .15s; white-space: nowrap;
}
.btn-primary {
  background: var(--emerald-600); color: #fff;
}
.btn-primary:hover { background: var(--emerald-700); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-secondary {
  background: #fff; color: var(--gray-700);
  border: 1px solid var(--gray-200);
}
.btn-secondary:hover { background: var(--gray-50); }
.btn-danger { background: var(--red-50); color: var(--red-600); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: .375rem .75rem; font-size: .8rem; border-radius: 8px; }
.btn-icon {
  padding: .5rem; border-radius: 8px; border: none;
  background: none; cursor: pointer; color: var(--gray-400);
  display: inline-flex; align-items: center;
  transition: all .15s;
}
.btn-icon:hover { background: var(--emerald-50); color: var(--emerald-600); }
.btn-icon.danger:hover { background: var(--red-50); color: var(--red-600); }

/* ─── Inputs ───────────────────────────────────────────────────────────────── */
.input {
  width: 100%; padding: .625rem .875rem; border-radius: 10px;
  border: 1px solid var(--gray-200); background: #fff;
  font-size: .9rem; color: var(--gray-900);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.input:focus { border-color: var(--emerald-500); box-shadow: 0 0 0 3px rgba(16,185,129,.15); }
.input-icon-wrap { position: relative; }
.input-icon-wrap .icon {
  position: absolute; left: .75rem; top: 50%; transform: translateY(-50%);
  color: var(--gray-400); pointer-events: none;
  width: 18px; height: 18px;
}
.input-icon-wrap .input { padding-left: 2.25rem; }

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: .875rem 1rem;
  font-size: .8rem; font-weight: 600;
  color: var(--gray-600); text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--gray-100);
}
tbody tr { border-bottom: 1px solid var(--gray-50); transition: background .1s; }
tbody tr:hover { background: var(--gray-50); }
tbody td { padding: 1rem; font-size: .9rem; }
tbody tr:last-child { border-bottom: none; }

/* ─── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .2rem .6rem; border-radius: 999px;
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
}
.badge-green { background: var(--emerald-100); color: var(--emerald-700); }
.badge-amber { background: var(--amber-100); color: var(--amber-700); }
.badge-purple { background: var(--purple-100); color: var(--purple-700); }
.badge-blue { background: var(--blue-50); color: var(--blue-600); }
.badge-inv { background: var(--emerald-50); color: var(--emerald-700); font-family: monospace; font-size: .75rem; padding: .2rem .5rem; }

/* ─── Stats Grid ───────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; }
.stat-card { display: flex; flex-direction: column; gap: 1rem; }
.stat-header { display: flex; justify-content: space-between; align-items: flex-start; }
.stat-icon { padding: .625rem; border-radius: 10px; display: flex; }
.stat-icon.green { background: var(--emerald-100); color: var(--emerald-600); }
.stat-icon.amber { background: var(--amber-50); color: var(--amber-600); }
.stat-icon.blue { background: var(--blue-50); color: var(--blue-600); }
.stat-label { font-size: .85rem; font-weight: 500; color: rgba(255,255,255,.8); }
.stat-label-dark { font-size: .85rem; font-weight: 500; color: var(--gray-500); }
.stat-value { font-size: 1.75rem; font-weight: 800; margin-top: .25rem; }
.stat-footer { font-size: .8rem; display: flex; align-items: center; gap: .25rem; }

/* ─── Page Headers ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 800; color: var(--gray-900); }
.page-header p { font-size: .9rem; color: var(--gray-500); margin-top: .15rem; }
.page-actions { display: flex; gap: .75rem; flex-shrink: 0; }

/* ─── Modals ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  z-index: 60; align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop.active { display: flex; }
.modal {
  background: #fff; border-radius: 16px;
  box-shadow: var(--shadow-xl);
  width: 100%; max-width: 480px;
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-100);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-footer {
  display: flex; gap: .75rem; padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-100);
}
.modal-footer .btn { flex: 1; justify-content: center; }
.btn-close {
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); padding: .25rem; border-radius: 6px;
  display: flex; transition: color .15s;
}
.btn-close:hover { color: var(--gray-700); }

/* ─── Form Groups ──────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .375rem; }
.form-label { font-size: .875rem; font-weight: 500; color: var(--gray-700); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ─── Alerts & Messages ────────────────────────────────────────────────────── */
.alert {
  padding: .875rem 1rem; border-radius: 10px;
  display: flex; align-items: center; gap: .625rem;
  font-size: .9rem; font-weight: 500; margin-bottom: 1rem;
}
.alert-success { background: var(--emerald-50); color: var(--emerald-700); border: 1px solid var(--emerald-200); }
.alert-error { background: var(--red-50); color: var(--red-600); border: 1px solid #fecaca; }
.alert-warning { background: var(--amber-50); color: var(--amber-700); border: 1px solid var(--amber-100); }

/* ─── Empty State ──────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--gray-400); }
.empty-state svg { width: 48px; height: 48px; opacity: .3; margin: 0 auto .75rem; display: block; }
.empty-state p { font-size: .95rem; }

/* ─── Product Cards ────────────────────────────────────────────────────────── */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .875rem; }
.product-quick-btn {
  padding: .875rem; border-radius: 12px; border: 1px solid var(--gray-100);
  background: #fff; text-align: left; cursor: pointer;
  transition: all .15s; position: relative; overflow: hidden;
}
.product-quick-btn:hover { border-color: var(--emerald-500); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.product-quick-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.product-quick-btn .name { font-weight: 700; font-size: .875rem; color: var(--gray-900); }
.product-quick-btn .price { font-size: .75rem; color: var(--gray-500); margin-top: .15rem; }

/* ─── Order Steps ──────────────────────────────────────────────────────────── */
.step-indicator { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.step {
  padding: .25rem .875rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--gray-100); color: var(--gray-500);
}
.step.active { background: var(--emerald-100); color: var(--emerald-700); }
.step.done { background: var(--emerald-600); color: #fff; }
.step-sep { color: var(--gray-300); font-size: .8rem; }

/* ─── Order Item Row ───────────────────────────────────────────────────────── */
.order-item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1.2fr auto;
  gap: .75rem; padding: .875rem; border-radius: 10px;
  background: var(--gray-50); border: 1px solid var(--gray-100);
  align-items: end;
}
.order-item-row .input { background: #fff; }

/* ─── Report Tabs ──────────────────────────────────────────────────────────── */
.tab-bar { display: flex; border-bottom: 1px solid var(--gray-100); overflow-x: auto; gap: 0; }
.tab-btn {
  display: flex; align-items: center; gap: .5rem;
  padding: .875rem 1.25rem; border: none; border-bottom: 2px solid transparent;
  background: none; cursor: pointer; font-size: .875rem; font-weight: 500;
  color: var(--gray-500); white-space: nowrap;
  transition: all .15s;
}
.tab-btn:hover { color: var(--gray-700); background: var(--gray-50); }
.tab-btn.active { color: var(--emerald-600); border-bottom-color: var(--emerald-500); background: rgba(16,185,129,.04); }

/* ─── User Cards ───────────────────────────────────────────────────────────── */
.user-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; }
.user-card {
  border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 1.25rem; background: #fff;
  transition: border-color .15s; position: relative;
}
.user-card:hover { border-color: var(--emerald-200); }
.user-card .card-actions {
  position: absolute; top: .875rem; right: .875rem;
  display: flex; gap: .25rem; opacity: 1; transition: opacity .2s;
}
.user-card:hover .card-actions { opacity: 1; }

/* ─── Utility ──────────────────────────────────────────────────────────────── */
.text-emerald { color: var(--emerald-600); }
.text-amber { color: var(--amber-600); }
.text-red { color: var(--red-600); }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.font-bold { font-weight: 700; }
.font-mono { font-family: monospace; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.w-full { width: 100%; }
.hidden { display: none; }
.text-right { text-align: right; }
.space-y > * + * { margin-top: 1rem; }
.border-t { border-top: 1px solid var(--gray-100); padding-top: 1rem; }

/* ─── Charts ───────────────────────────────────────────────────────────────── */
#salesChart { max-height: 280px; }

/* ─── Login Page ───────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; background: var(--emerald-900);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.login-card {
  width: 100%; max-width: 420px;
  background: #fff; border-radius: 20px;
  box-shadow: var(--shadow-xl); overflow: hidden;
}
.login-header {
  background: var(--emerald-600); padding: 2rem; text-align: center; color: #fff;
}
.login-logo {
  width: 64px; height: 64px; border-radius: 16px;
  background: rgba(255,255,255,.2); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1rem; font-size: 2rem;
}
.login-header h1 { font-size: 1.4rem; font-weight: 800; }
.login-header p { font-size: .9rem; opacity: .85; margin-top: .25rem; }
.login-body { padding: 2rem; display: flex; flex-direction: column; gap: 1.25rem; }

/* ─── Profile Page ─────────────────────────────────────────────────────────── */
.profile-avatar {
  width: 80px; height: 80px; border-radius: 16px;
  background: var(--emerald-100); color: var(--emerald-600);
  display: flex; align-items: center; justify-content: center;
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content { margin-left: 0 !important; }
  .order-item-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .page-content { padding: 1rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .order-item-row { grid-template-columns: 1fr; }
  .top-header { padding: 0 1rem; }
}

/* ─── Animations ───────────────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn .3s ease both; }
.spinner {
  width: 20px; height: 20px; border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Order Summary Sidebar ────────────────────────────────────────────────── */
.order-layout { display: grid; grid-template-columns: 1fr 300px; gap: 1.5rem; align-items: start; }
@media(max-width: 1024px) { .order-layout { grid-template-columns: 1fr; } }
.order-summary-card { position: sticky; top: calc(var(--header-h) + 1rem); }

/* ─── Invoice Print ────────────────────────────────────────────────────────── */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .main-content { margin: 0; }
  .top-header { display: none; }
  .sidebar { display: none; }
  .page-content { padding: 0; }
}

/* ─── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ─── Success Screen ───────────────────────────────────────────────────────── */
.success-screen { display: flex; flex-direction: column; align-items: center; padding: 4rem 1rem; text-align: center; }
.success-icon {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--emerald-100); color: var(--emerald-600);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 1.5rem;
  animation: popIn .4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }
.success-screen h2 { font-size: 1.75rem; font-weight: 800; }
.success-screen p { color: var(--gray-500); margin-top: .5rem; }
.success-actions { display: flex; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; justify-content: center; }
