@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --accent: #f97316;
  --accent-dark: #ea580c;
  --accent-light: rgba(249, 115, 22, 0.15);
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.15);
  --success: #22c55e;
  --success-light: rgba(34, 197, 94, 0.15);

  --bg: #101216;
  --sidebar-bg: #16181d;
  --card: #1b1e24;
  --card-alt: #21252c;
  --text: #f3f4f6;
  --muted: #9aa1ac;
  --border: #2a2e36;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 20px 40px -12px rgba(0,0,0,0.5);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform 0.25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 24px;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.02em;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
}
.brand-sub { display: block; font-size: 10px; font-weight: 700; color: var(--muted); letter-spacing: 0.15em; }

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  overflow-y: auto;
}
.side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.side-link:hover { background: var(--card-alt); color: var(--text); }
.side-link.active { background: var(--accent); color: white; }
.side-icon { font-size: 17px; width: 20px; text-align: center; }

.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); margin-top: 10px; }
.side-logout {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 10px;
  color: var(--danger); text-decoration: none;
  font-size: 14px; font-weight: 600;
}
.side-logout:hover { background: var(--danger-light); }

.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-title { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.topbar-left { display: flex; align-items: center; gap: 14px; }

.hamburger {
  display: none;
  background: none; border: none; color: var(--text);
  font-size: 22px; cursor: pointer; padding: 4px; margin: 0; width: auto;
}

.topbar-user { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  padding: 6px 12px 6px 6px; border-radius: 999px; cursor: pointer;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; color: white; text-transform: uppercase;
}
.user-chip-text { line-height: 1.15; }
.user-chip-name { font-size: 13.5px; font-weight: 700; }
.user-chip-role { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  min-width: 160px; padding: 6px; display: none; z-index: 50;
}
.user-dropdown.open { display: block; }
.user-dropdown a {
  display: block; padding: 10px 12px; border-radius: 8px;
  text-decoration: none; font-size: 13.5px; font-weight: 600; color: var(--danger);
}
.user-dropdown a:hover { background: var(--danger-light); }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 35;
}
.sidebar-overlay.show { display: block; }

main { flex: 1; padding: 24px 28px 60px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ============ Cards ============ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
h2 { margin-top: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }

/* ============ Forms ============ */
label {
  display: block; font-size: 11.5px; font-weight: 700; margin-bottom: 5px; margin-top: 14px;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
}
input, select, button {
  font-family: inherit; font-size: 15px; padding: 11px 12px; border-radius: 10px;
  border: 1.5px solid var(--border); width: 100%;
  background: var(--card-alt); color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: #6b7280; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

button {
  background: var(--accent); color: white; border: none; font-weight: 700;
  cursor: pointer; margin-top: 16px; transition: background 0.15s, transform 0.05s;
}
button:hover { background: var(--accent-dark); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary { background: var(--card-alt); border: 1.5px solid var(--border); color: var(--text); }
button.secondary:hover { background: #2a2f38; }
button.danger { background: var(--danger); }
button.danger:hover { background: #dc2626; }
button.outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
button.outline:hover { background: var(--card-alt); }

/* ============ Tables ============ */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 480px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:hover { background: var(--card-alt); }

.filter-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filter-row > div { flex: 1; min-width: 160px; }
.filter-row label { margin-top: 0; }
.filter-row button { margin-top: 0; width: auto; padding: 11px 16px; white-space: nowrap; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.qr-thumb {
  width: 52px; height: 52px; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border); background: white; padding: 3px; transition: transform 0.15s;
}
.qr-thumb:hover { transform: scale(1.6); box-shadow: var(--shadow-lg); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.low { background: var(--danger-light); color: #f87171; }
.badge.ok { background: var(--success-light); color: #4ade80; }

/* ============ Stat cards ============ */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat-box {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 6px; position: relative;
}
.stat-icon {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent-light);
  display: flex; align-items: center; justify-content: center; font-size: 16px; margin-bottom: 4px;
}
.stat-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.chart-wrap { position: relative; height: 280px; width: 100%; }

/* ============ Category pills ============ */
.category-pills { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.category-pill {
  flex-shrink: 0; padding: 9px 16px; border-radius: 999px; background: var(--card-alt);
  border: 1px solid var(--border); color: var(--muted); font-size: 13px; font-weight: 700;
  cursor: pointer; white-space: nowrap; transition: background 0.15s, color 0.15s;
}
.category-pill:hover { color: var(--text); }
.category-pill.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ============ Product grid (Scan & Sell) ============ */
.pos-layout { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }

.product-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px;
  margin-top: 16px; max-height: 520px; overflow-y: auto; padding-right: 4px;
}
.product-card {
  background: var(--card-alt); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 10px; text-align: center; cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.product-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.product-card:active { transform: scale(0.97); }
.product-card.out-of-stock { opacity: 0.4; cursor: not-allowed; }
.product-icon {
  width: 48px; height: 48px; border-radius: 50%; margin: 0 auto 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; color: white;
}
.product-name { font-size: 12.5px; font-weight: 700; margin-bottom: 3px; line-height: 1.25; }
.product-price { font-size: 12.5px; color: var(--accent); font-weight: 700; }
.product-stock { font-size: 10.5px; color: var(--muted); margin-top: 2px; }

.search-with-icon { position: relative; }
.search-with-icon input { padding-left: 38px; }
.search-with-icon .search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none; font-size: 15px;
}

/* ============ Cart panel ============ */
.cart-header { display: flex; align-items: center; justify-content: space-between; }
.cart-list { max-height: 320px; overflow-y: auto; margin-top: 10px; }
.cart-item {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.cart-item-name { font-size: 13.5px; font-weight: 700; }
.cart-item-sub { font-size: 11.5px; color: var(--muted); }
.qty-control { display: flex; align-items: center; gap: 6px; }
.qty-control button { width: 26px; height: 26px; padding: 0; margin: 0; font-size: 15px; border-radius: 6px; }
.cart-item-total { font-size: 13.5px; font-weight: 700; text-align: right; min-width: 56px; }

.totals-block { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.totals-row { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--muted); padding: 4px 0; }
.totals-row.grand {
  font-size: 21px; font-weight: 800; color: var(--text); margin-top: 6px;
  padding-top: 10px; border-top: 1px solid var(--border);
}
.totals-row.grand .amount { color: var(--accent); }

.cart-actions { display: flex; gap: 10px; margin-top: 16px; }
.cart-actions button { margin-top: 0; }

#reader { width: 100%; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }

/* ============ Toast / Modal ============ */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #0b0c0f; border: 1px solid var(--border); color: white;
  padding: 12px 20px; border-radius: 10px; font-size: 14px; font-weight: 600;
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
  box-shadow: var(--shadow-lg); max-width: 90vw; text-align: center; z-index: 100;
}
.toast.show { opacity: 1; }

.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  align-items: center; justify-content: center; z-index: 60; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px; text-align: center; max-width: 320px; width: 100%; box-shadow: var(--shadow-lg);
}
.modal img { width: 220px; height: 220px; max-width: 100%; border-radius: 10px; background: white; padding: 8px; }

/* ============ Login page ============ */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { width: 360px; text-align: center; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 8px; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .hamburger { display: inline-flex; align-items: center; justify-content: center; }
  .pos-layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { padding: 14px 16px; }
  main { padding: 16px 12px 50px; }
  .card { padding: 16px; border-radius: 10px; }
  .grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 21px; }
  .user-chip-text { display: none; }
}

@media (max-width: 460px) {
  .stat-row { grid-template-columns: 1fr; }
  .filter-row { flex-direction: column; align-items: stretch; }
  .filter-row > div { width: 100%; }
  .filter-row button { width: 100%; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .cart-actions { flex-direction: column; }
}
