:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-2: #eef1f5;
  --accent: #4f46e5;
  --accent-2: #4338ca;
  --accent-soft: #eef2ff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
  --maxw: 1180px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--ink); letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
img { max-width: 100%; display: block; }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 60px;
}
.logo {
  font-weight: 700;
  font-size: 17px;
  color: var(--ink);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.logo:hover { text-decoration: none; }
.logo .dot { color: var(--accent); }
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.topnav a {
  color: var(--ink-2);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
}
.topnav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  position: relative;
}
.iconbtn:hover { background: var(--surface-2); border-color: var(--border); text-decoration: none; }
.iconbtn svg { width: 20px; height: 20px; }

/* ---------- Bottom tab bar (mobile) ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: none;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  max-width: 520px;
  margin: 0 auto;
}
.tabbar a, .tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 0 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}
.tabbar a:hover, .tabbar button:hover { text-decoration: none; color: var(--ink); }
.tabbar svg { width: 22px; height: 22px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--accent-2); border-color: var(--accent-2); text-decoration: none; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.field { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

/* ---------- Layout blocks ---------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 20px 0 18px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 14px; }
.panel h3 { margin: 16px 0 8px; }
.muted { color: var(--muted); }
.note, .hint { font-size: 13px; color: var(--muted); }
.flash {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 14px;
}
main.container { padding-bottom: 96px; }

/* ---------- Toolbar / filters ---------- */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar input, .toolbar select { width: auto; min-width: 0; }
.toolbar .grow { flex: 1; min-width: 180px; }

/* ---------- Product grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  transition: box-shadow .15s, border-color .15s, transform .15s;
}
a.card:hover { text-decoration: none; border-color: #cbd5e1; box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.card .media, .card .ph {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: linear-gradient(135deg, #eef1f5, #e7eaf0);
  display: block;
}
.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card .brand { font-size: 12px; color: var(--muted); text-transform: none; }
.card .title { font-size: 14px; font-weight: 600; color: var(--ink); }
.card .meta { font-size: 12px; color: var(--muted); }
.card .price { font-size: 16px; font-weight: 700; margin-top: auto; padding-top: 6px; }
.card .stock { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Tags / badges ---------- */
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  background: var(--accent-soft);
  color: var(--accent-2);
  padding: 3px 9px;
  border-radius: 999px;
}
.tag.neutral { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); }
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* QR badge button in catalog */
.qr-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
}
.qr-badge:hover { background: #1e293b; }
.qr-badge svg { width: 18px; height: 18px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.table td { padding: 12px; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }

.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.error-box { text-align: center; padding: 70px 16px; }

/* ---------- Product detail ---------- */
.gallery-main { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); }
.gallery-thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.price-big { font-size: 26px; font-weight: 700; margin: 6px 0 14px; }

/* ---------- QR modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  padding: 18px;
  box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; }
#qr-reader { width: 100%; border-radius: var(--radius-sm); overflow: hidden; background: #000; }
#qr-reader video { width: 100% !important; border-radius: var(--radius-sm); }
.qr-manual { display: flex; gap: 8px; margin-top: 12px; }
.qr-manual input { flex: 1; }
.qr-error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .topnav { display: none; }
  .tabbar { display: block; }
  h1 { font-size: 19px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .card .body { padding: 10px; }
  .card .price { font-size: 15px; }
  .split-2 { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .form-row, .form-grid { grid-template-columns: 1fr; }
  .desktop-only { display: none !important; }
}
@media (max-width: 420px) {
  .grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 761px) {
  .mobile-only { display: none !important; }
}
