:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #1d2130;
  --muted: #6b7189;
  --line: #e3e5ee;
  --primary: #5b3df5;
  --primary-dark: #4527d6;
  --green: #12a150;
  --red: #d93a3a;
  --amber: #c98a00;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}
input, select, textarea, button { font: inherit; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select { margin-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.green { color: var(--green); }
.red { color: var(--red); }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f0f1f6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 12px; }
.btn.icon { padding: 4px 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--card); padding: 32px; border-radius: 14px; width: 100%; max-width: 380px;
  box-shadow: 0 10px 40px rgba(30, 20, 90, .08);
}
.login-logo { display: block; width: 100%; max-width: 260px; height: auto; margin: 0 auto 6px; }
.login-title { text-align: center; margin: 0 0 2px; font-size: 20px; }
.login-card > p.muted:first-of-type { text-align: center; margin-top: 0; }
.error { color: var(--red); min-height: 20px; margin-bottom: 8px; font-size: 14px; }

/* Layout */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.logo { object-fit: contain; background: #fff !important; padding: 3px;
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: #171a2b; color: #dfe1ee; padding: 18px 12px;
  display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { color: #fff; padding: 0 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; color: #c4c7d8; text-decoration: none;
}
.sidebar nav a:hover { background: #24283d; color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .me { border-top: 1px solid #2c3048; padding: 12px 8px 0; }
.sidebar .me .btn { margin-top: 8px; background: transparent; color: #dfe1ee; border-color: #3a3f5c; }
main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; margin: 0; }
#menuBtn { display: none; }
.view { padding: 22px 24px; }

/* Cards & tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; flex: 0 1 220px; }
.toolbar .grow { flex: 1; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfe; }
tr:last-child td { border-bottom: 0; }
td .btn + .btn { margin-left: 4px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: #eef0f7; }
.badge.low { background: #fdeaea; color: var(--red); }
.badge.admin { background: #ece8ff; color: var(--primary); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bars .bar { flex: 1; max-width: 48px;background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .bar span { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }

/* POS */
.pos { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.pcard {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; cursor: pointer; text-align: left; transition: border-color .15s, transform .1s;
}
.pcard:hover { border-color: var(--primary); }
.pcard:active { transform: scale(.98); }
.pcard .n { font-weight: 600; font-size: 14px; line-height: 1.3; min-height: 36px; }
.pcard .p { color: var(--primary); font-weight: 700; margin-top: 6px; }
.pcard .s { font-size: 12px; color: var(--muted); }
.pcard.out { opacity: .45; cursor: not-allowed; }
.cart { position: sticky; top: 16px; }
.cart-items { max-height: 38vh; overflow-y: auto; margin: 0 -16px; }
.cart-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.cart-row .n { font-size: 14px; font-weight: 600; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty input { width: 52px; text-align: center; padding: 4px; }
.qty .btn { padding: 2px 8px; }
.totals { margin-top: 12px; }
.totals .row { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-size: 22px; font-weight: 800; border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row label { margin-bottom: 8px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 17, 30, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-bg[hidden] { display: none; }
.modal { background: var(--card); border-radius: 12px; padding: 20px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h3 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

#toast { position: fixed; bottom: 20px; right: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
#toast div { background: #171a2b; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
#toast div.err { background: var(--red); }

/* Receipt */
.receipt { font-family: "Courier New", monospace; font-size: 13px; max-width: 300px; margin: 0 auto; color: #000; }
.receipt h2 { text-align: center; margin: 0; font-size: 17px; }
.receipt .c { text-align: center; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.receipt table td, .receipt table th { padding: 2px 0; border: 0; font-size: 12px; background: none; color: #000; text-transform: none; letter-spacing: 0; }
.receipt .tot td { font-weight: 700; font-size: 14px; }
#print-area { display: none; }

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display: block; position: absolute; left: 0; top: 0; width: 80mm; }
  @page { margin: 4mm; }
}

@media (max-width: 960px) {
  .pos { grid-template-columns: 1fr; }
  .cart { position: static; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: -250px; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; }
  #menuBtn { display: inline-block; }
  .view { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .toolbar input, .toolbar select { flex: 1 1 140px; }
}
