/* ============================================================
   ERP Platform — Design System (app.css)
   One stylesheet for ERP, Super Admin, Auth and Storefront.
   Vanilla CSS. No frameworks.
   ============================================================ */

:root {
  /* Brand */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-dark: #1e40af;
  --primary-light: #dbeafe;
  --primary-soft: #eff6ff;

  /* Sidebar / dark surfaces */
  --sidebar-bg: #0f172a;
  --sidebar-bg-hover: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-text-dim: #64748b;
  --sidebar-active: #2563eb;

  /* Text */
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #f8fafc;

  /* Surfaces */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --surface-muted: #f8fafc;

  /* Borders */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-focus: #2563eb;

  /* Radius / shadow */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .10);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .16);

  /* Status */
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0284c7;
  --info-bg: #e0f2fe;

  /* Layout */
  --sidebar-width: 248px;
  --topbar-height: 60px;
  --content-max: 1200px;

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg, video { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }
::selection { background: var(--primary-light); }

/* ---------- App layout (sidebar + topbar + content) ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px;
  color: #fff; font-size: 17px; font-weight: 700; letter-spacing: -.01em;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand .logo-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; flex-shrink: 0;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px; }
.sidebar-nav .nav-label {
  padding: 14px 12px 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--sidebar-text-dim);
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-weight: 500;
}
.sidebar-nav a:hover { background: var(--sidebar-bg-hover); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav a .nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-footer {
  padding: 14px 20px; border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 12px; color: var(--sidebar-text-dim);
}

.main { flex: 1; margin-left: var(--sidebar-width); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 30;
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar-user .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.topbar-user .user-meta { line-height: 1.25; text-align: right; }
.topbar-user .user-meta small { display: block; color: var(--text-muted); font-size: 11px; }
.hamburger { display: none; font-size: 20px; padding: 6px 10px; border-radius: var(--radius-sm); }
.hamburger:hover { background: var(--surface-hover); }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5); z-index: 35;
}

.content { padding: 24px; max-width: var(--content-max); width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.page-head p { color: var(--text-secondary); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards & stats ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { font-size: 15px; font-weight: 700; }
.card-head p { color: var(--text-muted); font-size: 12px; }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }

.stat-grid {
  display: grid; gap: 16px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}
.stat-card .stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.stat-card .stat-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 4px; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.stat-card .stat-sub .up { color: var(--success); font-weight: 600; }
.stat-card .stat-sub .down { color: var(--danger); font-weight: 600; }
.stat-card.accent { border-top: 3px solid var(--primary); }
.stat-card.warn { border-top: 3px solid var(--warning); }
.stat-card.danger-card { border-top: 3px solid var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2 .card { margin-bottom: 0; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { font-size: 13.5px; }
table.data th {
  text-align: left; font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-muted); white-space: nowrap;
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-hover); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .nowrap { white-space: nowrap; }
.table-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.table-toolbar .search-input { max-width: 280px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field label .req { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.field .error-text { font-size: 12px; color: var(--danger); margin-top: 5px; font-weight: 500; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], input[type="url"], input[type="date"], input[type="search"],
select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
input.input-error, select.input-error, textarea.input-error { border-color: var(--danger); }
input.input-error:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, .12); }
textarea { min-height: 96px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; line-height: 1.2;
  border: 1px solid transparent; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
/* Primary form actions (Save / Sign in / Place) must be thumb-sized
   (~44px). .btn-sm keeps its compact size for dense row actions. */
form button[type="submit"].btn-primary:not(.btn-sm) { min-height: 44px; }
/* Topbar logout is a secondary action but still needs a thumb target. */
.topbar-user .btn { min-height: 36px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-link { color: var(--primary); font-weight: 600; padding: 0; }
.btn-link:hover { text-decoration: underline; }
.inline-form { display: inline; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: var(--radius-full);
  font-size: 11.5px; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.badge-green { background: var(--success-bg); color: #166534; }
.badge-amber { background: var(--warning-bg); color: #92400e; }
.badge-red { background: var(--danger-bg); color: #991b1b; }
.badge-blue { background: var(--primary-light); color: var(--primary-dark); }
.badge-grey { background: #e2e8f0; color: #475569; }

/* ---------- Alerts / toasts ---------- */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  margin-bottom: 16px; font-size: 13.5px;
  border: 1px solid transparent;
  display: flex; gap: 10px; align-items: flex-start;
}
.alert-success { background: var(--success-bg); border-color: #86efac; color: #14532d; }
.alert-error { background: var(--danger-bg); border-color: #fca5a5; color: #7f1d1d; }
.alert-warning { background: var(--warning-bg); border-color: #fcd34d; color: #78350f; }
.alert-info { background: var(--info-bg); border-color: #7dd3fc; color: #0c4a6e; }
.alert .alert-close { margin-left: auto; font-weight: 700; opacity: .6; line-height: 1; }
.alert .alert-close:hover { opacity: 1; }

#toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px; max-width: min(360px, calc(100vw - 40px));
}
.toast {
  background: var(--sidebar-bg); color: #fff;
  padding: 12px 16px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); font-size: 13.5px;
  display: flex; gap: 10px; align-items: flex-start;
  animation: toast-in .25s ease;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info { border-left: 4px solid var(--info); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity .3s, transform .3s; }

/* ---------- Modal & drawer ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  display: none; align-items: center; justify-content: center;
  z-index: 90; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); max-width: 440px; width: 100%; padding: 24px;
}
.modal h3 { font-size: 17px; margin-bottom: 8px; }
.modal p { color: var(--text-secondary); font-size: 13.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 92vw);
  background: var(--surface); box-shadow: var(--shadow-lg); z-index: 90;
  transform: translateX(100%); transition: transform .25s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }

/* ---------- Empty state / skeleton / chart ---------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-secondary); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 10px; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 4px; }
.empty-state p { font-size: 13.5px; max-width: 420px; margin: 0 auto 16px; }

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  color: transparent !important;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.chart-bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding: 8px 4px 0; }
.chart-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; height: 100%; justify-content: flex-end; }
.chart-bar-col .bar-value { font-size: 11px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.chart-bar-col .bar {
  width: 100%; max-width: 44px; min-height: 3px;
  background: var(--primary); border-radius: 4px 4px 0 0;
}
.chart-bar-col .bar-label { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.chart-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 10px; }

.top-list { display: flex; flex-direction: column; }
.top-list .top-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px; border-bottom: 1px solid var(--border);
}
.top-list .top-row:last-child { border-bottom: 0; }
.top-list .rank {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary-dark);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.top-list .top-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.top-list .top-meta { color: var(--text-muted); font-size: 12.5px; white-space: nowrap; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 14px 20px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 6px 11px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); color: var(--text-secondary); background: var(--surface);
}
.pagination a:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.pagination .current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .disabled { opacity: .45; }

/* ---------- Auth pages ---------- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--sidebar-bg);
  background-image: radial-gradient(ellipse at 20% 10%, rgba(37, 99, 235, .35), transparent 55%),
                    radial-gradient(ellipse at 80% 90%, rgba(37, 99, 235, .22), transparent 55%);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 32px 28px;
}
.auth-card .auth-logo { text-align: center; margin-bottom: 20px; }
.auth-card .auth-logo .logo-mark {
  width: 48px; height: 48px; border-radius: 12px; margin: 0 auto 12px;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800;
}
.auth-card h1 { font-size: 20px; text-align: center; }
.auth-card .auth-sub { text-align: center; color: var(--text-secondary); font-size: 13.5px; margin: 6px 0 22px; }
.auth-footer { text-align: center; font-size: 13px; color: var(--text-muted); margin-top: 20px; }
.auth-row-between { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; font-size: 13px; }

/* ---------- Storefront landing ---------- */
.landing { background: var(--surface); color: var(--text); }
.landing-header {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 1080px; margin: 0 auto; padding: 20px 24px;
}
.landing-header .brand { font-size: 19px; font-weight: 800; color: var(--text); display: flex; gap: 10px; align-items: center; }
.landing-header .brand:hover { text-decoration: none; }
.landing-header .brand .logo-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 800;
}
.landing-hero { max-width: 1080px; margin: 0 auto; padding: 72px 24px 56px; text-align: center; }
.landing-hero h1 { font-size: clamp(30px, 5vw, 48px); line-height: 1.15; letter-spacing: -.02em; }
.landing-hero p { font-size: 17px; color: var(--text-secondary); max-width: 640px; margin: 18px auto 28px; }
.landing-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.landing-features {
  max-width: 1080px; margin: 0 auto; padding: 24px 24px 72px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px;
}
.landing-feature { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px; background: var(--surface); }
.landing-feature h3 { font-size: 15px; margin-bottom: 6px; }
.landing-feature p { font-size: 13.5px; color: var(--text-secondary); }
.landing-footer { border-top: 1px solid var(--border); padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ---------- Misc ---------- */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12.5px; }
.text-right { text-align: right; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 20px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 20px; }
.flex { display: flex; } .gap-2 { gap: 8px; } .items-center { align-items: center; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filter-bar .field { margin-bottom: 0; min-width: 170px; }
.filter-bar .field label { font-size: 12px; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--text-muted); font-weight: 600; }
.kv dd { word-break: break-word; }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 10px; } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .sidebar-backdrop.show { display: block; }
  .main { margin-left: 0; }
  .hamburger { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 8px 14px; height: auto; min-height: var(--topbar-height); }
  .topbar-title { font-size: 15px; line-height: 1.3; }
  .topbar-user .user-meta { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card .stat-value { font-size: 21px; }
  .page-head h1 { font-size: 19px; }
}
/* Phone tap targets: .btn-sm is 29px tall (Logout, View store, wishlist).
   36px is the minimum comfortable tap height; desktop keeps 29px. */
@media (max-width: 700px) {
  .btn-sm { min-height: 36px; padding: 8px 12px; }
}
