/* ==============================
   CSS Variables & Reset
   ============================== */
:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #818cf8;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #4f46e5;
  --sidebar-hover: #334155;
  --topbar-h: 64px;
  --sidebar-w: 240px;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --purple: #8b5cf6;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { text-decoration: none; color: inherit; }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 12px; }

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

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-left: var(--sidebar-w);
  transition: margin-left .25s;
  width: calc(100% - var(--sidebar-w));
}

/* ==============================
   Sidebar
   ============================== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s;
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

.sidebar.collapsed ~ .main {
  margin-left: 0;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid #334155;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 28px;
  color: var(--primary-light);
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.sidebar-nav ul {
  list-style: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  border-radius: 0;
  transition: background .15s, color .15s;
  margin: 2px 8px;
  border-radius: 8px;
}

.nav-link:hover {
  background: var(--sidebar-hover);
  color: #f1f5f9;
}

.nav-link.active {
  background: var(--primary);
  color: white;
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #334155;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-details { min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: #f1f5f9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--sidebar-text); }

.logout-btn {
  font-size: 20px;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: color .15s;
  flex-shrink: 0;
}

.logout-btn:hover { color: var(--danger); }

/* ==============================
   Topbar
   ============================== */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s;
}

.menu-toggle:hover { background: var(--bg); }

.page-title {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ==============================
   Content
   ============================== */
.content {
  padding: 28px 24px;
  flex: 1;
}

/* ==============================
   Cards
   ============================== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

.mt-4 { margin-top: 20px; }

/* ==============================
   Stats Grid
   ============================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon.blue { background: #eff6ff; }
.stat-icon.green { background: #f0fdf4; }
.stat-icon.orange { background: #fff7ed; }
.stat-icon.purple { background: #faf5ff; }

.stat-info h3 {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-info p {
  font-size: 13px;
  color: var(--text-muted);
}

/* ==============================
   Table
   ============================== */
.table-wrapper {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  background: #f8fafc;
}

.table tbody tr:hover {
  background: #f8fafc;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* User cell */
.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-sm {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ==============================
   Badges
   ============================== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.badge-success, .badge-delivered, .badge-active, .badge-in-stock { background: #dcfce7; color: #166534; }
.badge-warning, .badge-processing, .badge-low-stock { background: #fef3c7; color: #92400e; }
.badge-danger, .badge-cancelled, .badge-out-of-stock { background: #fee2e2; color: #991b1b; }
.badge-info, .badge-shipped { background: #dbeafe; color: #1e40af; }
.badge-pending { background: #f3f4f6; color: #374151; }
.badge-purple, .badge-admin { background: #ede9fe; color: #5b21b6; }
.badge-editor { background: #dbeafe; color: #1e40af; }
.badge-viewer { background: #f0fdf4; color: #166534; }

/* Status dot */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--text-muted); }

/* ==============================
   Buttons
   ============================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline-sm {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: background .15s;
}

.btn-outline-sm:hover { background: var(--bg); }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ==============================
   Forms
   ============================== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}

.form-control[readonly] {
  background: var(--bg);
  cursor: default;
}

/* ==============================
   Auth page
   ============================== */
.auth-body {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-wrapper {
  width: 100%;
  max-width: 400px;
  padding: 16px;
}

.auth-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 36px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.logo-icon-lg {
  font-size: 48px;
  color: var(--primary);
  display: block;
  margin-bottom: 8px;
}

.auth-logo h2 {
  font-size: 22px;
  font-weight: 700;
}

.auth-logo p {
  color: var(--text-muted);
  font-size: 13px;
}

.auth-hint {
  margin-top: 20px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.auth-hint p { margin-bottom: 4px; }

/* Alert */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
}

.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ==============================
   Badge role class
   ============================== */
.badge-role {
  padding: 3px 10px;
  border-radius: 20px;
  background: #ede9fe;
  color: #5b21b6;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

/* ==============================
   Settings page
   ============================== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-row p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 24px;
  transition: .2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: .2s;
}

.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ==============================
   Text utilities
   ============================== */
.text-muted { color: var(--text-muted); font-size: 12px; }
.mt-2 { margin-top: 8px; }

/* ==============================
   Dark mode (toggled via JS)
   ============================== */
body.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
}

/* ==============================
   Responsive
   ============================== */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-100%); --sidebar-w: 240px; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0 !important; }
  .content { padding: 16px; }
}

/* ==============================
   Breadcrumb
   ============================== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.breadcrumb a { color: var(--primary); }
.breadcrumb a:hover { text-decoration: underline; }
.bc-sep { color: #cbd5e1; }

/* ==============================
   Alert banners
   ============================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 18px;
  border: 1px solid transparent;
}
.alert-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* ==============================
   Product form layout
   ============================== */
.form-page-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .form-page-grid { grid-template-columns: 1fr; }
}

.form-card .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 600px) {
  .form-row-2 { grid-template-columns: 1fr; }
}

/* Required asterisk */
.req { color: var(--danger); margin-left: 2px; }
.label-hint { font-size: 11px; font-weight: 400; color: var(--text-muted); margin-left: 4px; }

/* Price prefix input */
.input-prefix-wrap { position: relative; }
.input-prefix {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}
.form-control.with-prefix { padding-left: 26px; }

/* Validation states */
.form-group.has-error .form-control {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239,68,68,.12);
}
.form-group.has-error label { color: var(--danger); }
.field-error {
  color: var(--danger);
  font-size: 11.5px;
  margin-top: 4px;
  display: block;
}

/* Char counter */
.char-counter { font-size: 11px; color: var(--text-muted); text-align: right; margin-top: 4px; }

/* Form actions row */
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 8px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}
.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: background .15s;
}
.btn-danger-outline:hover { background: #fef2f2; }

/* Side info card */
.form-side { display: flex; flex-direction: column; gap: 16px; }
.card-body-pad { padding: 16px; }
.side-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 12px; }
.guide-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.guide-list li { font-size: 12.5px; color: var(--text-muted); padding-left: 14px; position: relative; }
.guide-list li::before { content: '•'; position: absolute; left: 0; color: var(--primary); }
.guide-list strong { color: var(--text); }
.meta-card {}
.meta-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); }
.meta-row:last-child { border-bottom: none; }
.meta-row strong, .meta-row code { color: var(--text); }

