:root {
  --green: #16a34a;
  --green-dark: #0f7a36;
  --yellow: #facc15;
  --dark: #111827;
  --gray: #6b7280;
  --light: #f8fafc;
  --border: #e5e7eb;
  --white: #ffffff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(135deg, #f8fafc, #eefcf2);
  color: var(--dark);
}
h1, h2, h3 { margin: 0 0 10px; letter-spacing: -0.02em; }
h1 { font-size: 34px; line-height: 1.1; }
h2 { font-size: 22px; line-height: 1.2; }
p { margin: 0 0 12px; color: var(--gray); line-height: 1.5; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 28px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-left { font-weight: 900; color: #0f172a; letter-spacing: -0.02em; font-size: 18px; }
.header-center { position: absolute; left: 50%; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 12px; }
.brand-link { display: inline-flex; align-items: center; text-decoration: none; }
.brand-logo { height: 44px; width: auto; display: block; border-radius: 12px; }
.brand-text { min-width: 0; }
.brand { font-size: 36px; font-weight: 900; color: var(--dark); text-decoration: none; letter-spacing: -1px; line-height: 1; }
.brand span { color: var(--green); }
.tagline { margin: 4px 0 0; color: var(--gray); font-size: 15px; font-weight: 700; }
.nav-links a { text-decoration: none; color: var(--dark); margin-left: 16px; font-weight: 700; }
.page-shell { padding: 24px; max-width: 1400px; margin: 0 auto; }
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(17,24,39,.06);
  padding: 22px;
}
.hero-grid, .stats-grid, .admin-layout { display: grid; gap: 20px; }
.hero-grid { grid-template-columns: 2fr 1fr; margin-bottom: 20px; }
.quick-summary { display: grid; grid-template-columns: 1fr 1fr; align-items: center; }
.quick-summary small, .stat-card small { display: block; color: var(--gray); margin-bottom: 8px; }
.quick-summary strong, .stat-card strong { font-size: 28px; }
.pill {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  margin-right: 8px;
  margin-top: 10px;
  font-size: 13px;
}
.pill.success { background: #dcfce7; color: var(--green-dark); }
.pill.accent { background: #fef9c3; color: #854d0e; }
.pill.dark { background: #e5e7eb; color: #111827; }
.pos-layout { display: grid; grid-template-columns: 1.35fr 0.95fr; gap: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.panel-head input { width: 260px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; margin-bottom: 8px; color: var(--gray); font-size: 14px; }
 .checkbox-field span { margin-bottom: 6px; }
 .check {
   display: flex;
   align-items: center;
   gap: 10px;
   padding: 10px 12px;
   border: 1px solid var(--border);
   border-radius: 14px;
   background: #fff;
   color: #111827;
   font-weight: 800;
 }
 .check input { width: 18px; height: 18px; }
input, select, button {
  font: inherit;
}
input, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
}
input:focus, select:focus {
  outline: none;
  border-color: rgba(22, 163, 74, 0.45);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18);
}
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}
.product-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  background: linear-gradient(180deg, #ffffff, #f8fff9);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.product-card:hover {
  transform: translateY(-2px);
  border-color: rgba(22, 163, 74, 0.28);
  box-shadow: 0 14px 34px rgba(17,24,39,.08);
}
.product-card h3 { margin: 0 0 6px; font-size: 18px; }
.product-card p { margin: 4px 0; color: var(--gray); }
.product-card .price { color: var(--dark); font-weight: 800; font-size: 22px; }
.product-card .srp { text-decoration: line-through; font-size: 14px; color: var(--gray); }
.product-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.product-name { font-size: 18px; line-height: 1.2; font-weight: 900; margin: 0; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  background: #dcfce7;
  color: var(--green-dark);
  white-space: nowrap;
}
.badge.warn { background: #fef9c3; color: #854d0e; }
.badge.muted { background: #e5e7eb; color: #111827; font-weight: 800; }
.product-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: #374151;
  background: #fff;
}
.meta-chip strong { font-weight: 900; color: #111827; }
.product-image {
  width: 100%;
  height: 120px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(229, 231, 235, 0.9);
  background: #f8fafc;
}
.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.price-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding-top: 2px; }
.price-stack { display: flex; flex-direction: column; gap: 2px; }
.price-stack .srp { margin: 0; }
.price-stack .price { margin: 0; }
.discount-line { margin: 0; font-size: 13px; color: #374151; }
.discount-line.muted { color: #6b7280; }
.product-actions { margin-top: 2px; display: flex; gap: 10px; }
.product-card button { width: 100%; }
.product-card.is-out {
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  opacity: 0.72;
}
.product-card.is-out button { background: #e5e7eb; color: #6b7280; cursor: not-allowed; }
.product-card button,
.primary-btn,
.ghost-btn {
  border: none;
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 800;
  cursor: pointer;
}
.product-card button, .primary-btn {
  background: linear-gradient(90deg, var(--green), var(--green-dark));
  color: var(--white);
}
.ghost-btn { background: #f3f4f6; color: var(--dark); }
.product-card button:hover, .primary-btn:hover { filter: brightness(0.98); transform: translateY(-1px); }
.product-card button:active, .primary-btn:active { transform: translateY(0); }
.ghost-btn:hover { background: #e5e7eb; }
.hero-actions { margin-top: 10px; }
.hero-card p { max-width: 60ch; }
.cart-items { min-height: 180px; }
.cart-row {
  display: grid;
  grid-template-columns: 1.6fr 0.7fr 0.7fr auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}
.cart-row strong { display: block; }
.cart-row small { color: var(--gray); }
.cart-row:hover { background: rgba(17, 24, 39, 0.02); }
.cart-row.just-added {
  border-radius: 14px;
  padding: 12px 10px;
  margin: 0 -10px;
  animation: addedPulse 900ms ease-out;
}
@keyframes addedPulse {
  0% { background: rgba(34, 197, 94, 0.20); }
  60% { background: rgba(34, 197, 94, 0.08); }
  100% { background: transparent; }
}
.cart-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.money { font-variant-numeric: tabular-nums; }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: 0 16px 36px rgba(0,0,0,0.22);
  max-width: min(440px, calc(100vw - 40px));
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast strong { display: block; margin-bottom: 2px; }
.toast small { color: rgba(255,255,255,0.82); }
.qty-box {
  display: flex;
  gap: 8px;
  align-items: center;
}
.qty-btn, .remove-btn {
  background: #f3f4f6;
  color: var(--dark);
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 800;
}
.totals-box {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  background: #fcfffc;
}
.totals-box div {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed #e5e7eb;
}
.totals-box div:last-child { border-bottom: 0; }
.totals-box strong { font-size: 18px; }
.empty-state { color: var(--gray); padding: 24px 0; }
.checkout-success {
  margin-top: 14px;
  padding: 14px;
  background: #dcfce7;
  border-radius: 16px;
  color: #166534;
  font-weight: 700;
}
.checkout-error {
  margin-top: 14px;
  padding: 14px;
  background: #fee2e2;
  border-radius: 16px;
  color: #991b1b;
  font-weight: 700;
}
.stats-grid, .admin-layout { grid-template-columns: repeat(4, 1fr); margin: 20px 0; }
.admin-layout { grid-template-columns: 0.95fr 1.4fr; }
.stat-card { background: var(--white); border: 1px solid var(--border); border-radius: 18px; padding: 18px; }
.success-bg { background: linear-gradient(135deg, #dcfce7, #f0fdf4); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid button { grid-column: 1 / -1; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--gray); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.table-thumb {
  width: 54px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: #f8fafc;
  display: block;
}
.table-thumb.placeholder {
  background: linear-gradient(135deg, #e5e7eb, #f8fafc);
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
}
.modal.open { display: block; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
}
.modal-card {
  position: relative;
  max-width: 920px;
  margin: 64px auto;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.22);
  padding: 18px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
@media (max-width: 1024px) {
  .hero-grid, .pos-layout, .admin-layout, .stats-grid { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .panel-head input { width: 100%; }
  .modal-card { margin: 20px; }
}
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; justify-content: center; }
  .header-left { width: 100%; text-align: center; }
  .header-center { position: static; transform: none; width: 100%; justify-content: center; }
  .nav-links { width: 100%; display: flex; justify-content: center; gap: 14px; }
  .nav-links a { margin-left: 0; }
}
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .page-shell { padding: 16px; }
  .cart-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

body.admin-page {
  background: #f5f7fb;
}

body.admin-page main.page-shell {
  padding: 0;
  max-width: none;
  margin: 0;
}

.ad-topbar {
  position: sticky;
  top: 0;
  z-index: 120;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}

.ad-topbar-inner {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
}

.ad-topbar-title strong,
.ad-topbar-title span {
  display: block;
}

.ad-topbar-title strong {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.ad-topbar-title span {
  font-size: 12px;
  color: var(--gray);
  margin-top: 3px;
  font-weight: 700;
}

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

.ad-inline-form {
  margin: 0;
}

.ad-icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: #111827;
  cursor: pointer;
  text-decoration: none;
  font-size: 16px;
}

.ad-icon-btn:hover {
  background: #f3f4f6;
}

.ad-btn {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  font-weight: 900;
  background: #ffffff;
  cursor: pointer;
}

.ad-btn-ghost {
  background: #ffffff;
  color: #111827;
}

.ad-btn-ghost:hover {
  background: #f3f4f6;
}

.ad-user-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #ffffff;
}

.ad-user-chip i {
  color: #0f172a;
}

.ad-user-chip span,
.ad-user-chip small {
  display: block;
  line-height: 1.1;
}

.ad-user-chip span {
  font-weight: 900;
  font-size: 13px;
}

.ad-user-chip small {
  color: var(--gray);
  font-size: 12px;
  font-weight: 700;
  margin-top: 3px;
}

.admin-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 0 28px;
  min-height: calc(100vh - 78px);
}

.ad-sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  z-index: 140;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.admin-sidebar {
  background: #0b1220;
  color: #ffffff;
  border-radius: 18px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 16px 40px rgba(2, 6, 23, 0.22);
  position: sticky;
  top: 96px;
  height: calc(100vh - 114px);
  overflow: auto;
}

.admin-sidebar .sidebar-header {
  padding: 10px 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 12px;
}

.ad-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #ffffff;
}

.ad-brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.10);
}

.ad-brand-title,
.ad-brand-sub {
  display: block;
}

.ad-brand-title {
  font-weight: 900;
  letter-spacing: 0.06em;
  font-size: 14px;
}

.ad-brand-sub {
  font-weight: 700;
  opacity: 0.78;
  font-size: 12px;
  margin-top: 3px;
}

.ad-admin-meta {
  margin-top: 12px;
  display: grid;
  gap: 4px;
}

.ad-admin-meta span {
  font-weight: 900;
  font-size: 13px;
}

.ad-admin-meta small {
  color: rgba(255, 255, 255, 0.68);
  font-weight: 700;
}

.admin-sidebar .sidebar-nav ul {
  list-style: none;
  padding: 10px 0 0;
  margin: 0;
  display: grid;
  gap: 6px;
}

.admin-sidebar .sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 14px;
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  font-weight: 800;
  transition: background-color 0.18s ease, transform 0.18s ease;
}

.admin-sidebar .sidebar-nav li a i {
  width: 18px;
  text-align: center;
}

.admin-sidebar .sidebar-nav li a:hover {
  background: rgba(255, 255, 255, 0.10);
  transform: translateX(2px);
}

.admin-sidebar .sidebar-nav li a.active {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.admin-sidebar .sidebar-nav li a span {
  flex: 1;
}

.admin-main-content {
  padding: 0;
}

body.admin-page .card {
  border: 1px solid rgba(229, 231, 235, 0.85);
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.06);
}

@media (max-width: 1100px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }
  .admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(320px, 86vw);
    border-radius: 0 18px 18px 0;
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    z-index: 150;
  }
  body.ad-sidebar-open .admin-sidebar {
    transform: translateX(0);
  }
  body.ad-sidebar-open .ad-sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 720px) {
  .ad-user-chip {
    display: none;
  }
  .ad-topbar-inner,
  .admin-shell {
    width: min(100% - 20px, 1480px);
  }
}

/* KPI Grid Enhancements */
.kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.kpi-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px;
  border-radius: 16px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 25px rgba(17, 24, 39, 0.1);
}

.kpi-card .kpi-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: rgba(22, 163, 74, 0.1); /* Light green background */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--green-dark);
}

.kpi-card.success-bg .kpi-icon {
  background-color: rgba(34, 197, 94, 0.2);
  color: #166534;
}

.kpi-card .kpi-content {
  display: flex;
  flex-direction: column;
}

.kpi-card .kpi-content small {
  font-size: 13px;
  color: var(--gray);
  margin-bottom: 4px;
}

.kpi-card .kpi-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--dark);
  line-height: 1;
}

.kpi-card.success-bg .kpi-value {
  color: #166534;
}

/* Font Awesome integration (assuming it's linked in header.ejs) */
.fas {
  font-family: "Font Awesome 5 Free";
  font-weight: 900;
}

/* Modular Widget Styling */
.admin-layout {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); /* Responsive grid for widgets */
  align-items: start; /* Align items to the start of their grid area */
}

.widget-card {
  /* Add any specific styling for the widget container if needed */
  /* For now, the inner .card will handle most of the styling */
}
