:root {
  --primary: #2f6fed;
  --primary-dark: #1f52c4;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #1c2233;
  --text-muted: #7a8299;
  --border: #e7eaf3;
  --danger: #e2513f;
  --success: #2fae5f;
  --warning: #ffb020;
  --radius: 16px;
  --max-width: 480px;
  --topbar-h: 58px;
  --bottomnav-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #e9ecf5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}

.topbar .topbar-sub {
  font-size: 11px;
  opacity: 0.85;
  font-weight: 400;
  display: block;
}

.topbar a.icon-btn {
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  padding: 6px 8px;
}

/* ---------- Content area ---------- */
.content {
  flex: 1;
  padding: 16px 16px calc(var(--bottomnav-h) + 24px) 16px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 20;
  height: var(--bottomnav-h);
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  max-width: var(--max-width);
  margin: 0 auto;
  width: 100%;
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
}

.bottom-nav a .nav-icon {
  font-size: 20px;
  line-height: 1;
}

.bottom-nav a.active {
  color: var(--primary);
}

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(20,20,50,0.06);
  border: 1px solid var(--border);
}

.card h3 {
  margin: 0 0 4px 0;
  font-size: 15px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
}

.stat-card .stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-dark);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Forms ---------- */
label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin: 12px 0 6px;
  font-weight: 500;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="search"],
select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fbfcfe;
  font-size: 15px;
  color: var(--text);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  margin-top: 14px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { background: #fdeceb; color: var(--danger); }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-sm { width: auto; padding: 8px 14px; font-size: 13px; margin-top: 0; }

.row-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.row-actions form { flex: 1; }
.row-actions .btn { margin-top: 0; }

/* ---------- Product list ---------- */
.product-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.product-item .p-name { font-weight: 600; font-size: 14.5px; }
.product-item .p-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.product-item .p-price { font-size: 13px; color: var(--primary-dark); font-weight: 600; margin-top: 4px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-ok { background: #e6f7ec; color: var(--success); }
.badge-low { background: #fff4e0; color: #b6790a; }
.badge-out { background: #fdeceb; color: var(--danger); }

/* ---------- Search bar ---------- */
.search-bar {
  margin-bottom: 14px;
}

/* ---------- Cart / sell page ---------- */
.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item .ci-name { font-weight: 600; font-size: 14px; }
.cart-item .ci-meta { font-size: 12px; color: var(--text-muted); }
.cart-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 700;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 2px solid var(--border);
}

.remove-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
}

.error-box {
  background: #fdeceb;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 20px;
  padding: 32px 26px;
  box-shadow: 0 8px 30px rgba(30,50,100,0.12);
  text-align: center;
}
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  margin: 0 auto 16px;
}
.login-card h2 { margin: 0 0 4px; font-size: 20px; }
.login-card p.sub { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }

/* ---------- Bill / print ---------- */
.bill-paper {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  border: 1px dashed var(--border);
}
.bill-header { text-align: center; margin-bottom: 12px; }
.bill-header h2 { margin: 0; font-size: 20px; letter-spacing: 0.5px; }
.bill-header p { margin: 2px 0; font-size: 12px; color: var(--text-muted); }
.bill-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin: 10px 0; border-top: 1px dashed var(--border); border-bottom: 1px dashed var(--border); padding: 8px 0; }
.bill-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.bill-table th { text-align: left; font-size: 11px; color: var(--text-muted); padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.bill-table td { padding: 6px 0; border-bottom: 1px solid #f1f2f7; }
.bill-table td.num, .bill-table th.num { text-align: right; }
.bill-total { display: flex; justify-content: space-between; font-size: 17px; font-weight: 700; margin-top: 14px; padding-top: 12px; border-top: 2px dashed var(--border); }
.bill-footer { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 18px; }

@media print {
  .no-print { display: none !important; }
  body, .app-shell { background: #fff; box-shadow: none; }
  .bottom-nav, .topbar { display: none !important; }
  .content { padding: 0; }
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state .emoji { font-size: 40px; display: block; margin-bottom: 10px; }
