:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #111827;
  --accent-hover: #374151;
  --danger: #dc2626;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; }
.brand span { color: var(--muted); font-weight: 400; }

.tabs { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.06); }

.hidden { display: none !important; }

.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 28px;
}

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; align-items: center; }
.toolbar input {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 0.95rem;
}

.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
}
.pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  display: flex;
  flex-direction: column;
}
.product-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.05); }
.product-card.out { opacity: 0.45; cursor: not-allowed; }
.product-card img { width: 100%; height: 140px; object-fit: cover; background: #f3f4f6; }
.product-info { padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.product-name { font-weight: 600; font-size: 0.95rem; }
.product-meta { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); }
.product-price { color: var(--text); font-weight: 600; }

.cart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 110px);
  position: sticky;
  top: 84px;
}

.cart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.cart-header h2 { font-size: 1.05rem; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 0.85rem; }
.link-btn:hover { color: var(--danger); }

.cart-items { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.qty-controls { display: flex; align-items: center; gap: 8px; }
.qty-btn {
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
}

.cart-footer { border-top: 1px solid var(--border); padding-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; justify-content: space-between; font-size: 0.92rem; color: var(--muted); }
.row.total { font-size: 1.05rem; font-weight: 700; color: var(--text); margin-top: 4px; }

.primary-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Inventory View */
.inventory-layout { max-width: 1000px; margin: 24px auto; padding: 0 28px; display: flex; flex-direction: column; gap: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card h2 { font-size: 1.05rem; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; }
.form-grid .full { grid-column: 1 / -1; }

.inv-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.inv-table th, .inv-table td { text-align: left; padding: 12px 8px; border-bottom: 1px solid var(--border); }
.inv-table th { color: var(--muted); font-weight: 500; }
.stock-input { width: 70px; padding: 6px; border: 1px solid var(--border); border-radius: 6px; }
.btn-sm { padding: 6px 10px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; cursor: pointer; font-size: 0.8rem; }
.btn-sm.danger { color: var(--danger); border-color: #fecaca; }

/* Modal & Toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: grid; place-items: center; z-index: 50; }
.modal-card { background: var(--surface); padding: 24px; border-radius: var(--radius); width: 360px; display: flex; flex-direction: column; gap: 12px; }
.receipt-lines { border-top: 1px dashed var(--border); border-bottom: 1px dashed var(--border); padding: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--muted); font-size: 0.85rem; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 60;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .cart { height: auto; position: static; }
}