:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e6eb;
  --text: #1b1f24;
  --muted: #6b7280;
  --brand: #0559c9;
  --brand-dark: #044196;
  --accent: #00a1e4;
  --danger: #d1364a;
  --ok: #1a8f4c;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff; font-weight: 800; letter-spacing: .5px;
  display: grid; place-items: center; font-size: 14px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.search input {
  width: 280px; max-width: 40vw;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); outline: none;
}
.search input:focus { border-color: var(--brand); background: #fff; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font-weight: 600;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--danger); background: transparent; }
.pill {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  background: rgba(255,255,255,.25); border-radius: 999px; font-size: 12px; margin-left: 4px;
}
.icon-btn {
  border: none; background: transparent; font-size: 24px; line-height: 1;
  cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Navbar ---------- */
.navbar {
  position: sticky; top: 61px; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.nav-scroll {
  display: flex; gap: 4px; overflow-x: auto; flex: 1 1 auto; min-width: 0;
  scrollbar-width: thin;
}
.navbar button {
  white-space: nowrap; border: none; background: transparent; cursor: pointer;
  padding: 8px 14px; border-radius: 8px; font-weight: 600; color: var(--muted);
}
.navbar button:hover { background: var(--surface-2); color: var(--text); }
.navbar button.active { background: var(--brand); color: #fff; }

/* ---------- Subbar ---------- */
.subbar {
  position: sticky; top: 108px; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 20px; background: var(--bg); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.subnav { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: thin; }
.subnav button {
  white-space: nowrap; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; padding: 5px 11px; border-radius: 999px; font-size: 12.5px; color: var(--muted);
}
.subnav button:hover { border-color: var(--brand); color: var(--brand); }
.subnav button.active { background: var(--text); color: #fff; border-color: var(--text); }
.toolbar { display: flex; align-items: center; gap: 14px; }
.sort { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sort select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.result-count { font-size: 12.5px; color: var(--muted); }

/* ---------- Grid ---------- */
.grid {
  display: grid; gap: 16px; padding: 20px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  max-width: 1600px; margin: 0 auto;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .1s;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.card-media {
  position: relative; aspect-ratio: 1 / 1; background: #fff; cursor: pointer;
  display: grid; place-items: center; padding: 14px;
}
.card-media img { max-width: 100%; max-height: 100%; object-fit: contain; }
.badge {
  position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.badge.soon { background: #fdecc8; color: #92600a; }
.badge.out { background: #f7d4d9; color: #92132a; }
.card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-sku { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: .3px; }
.card-name { font-size: 14px; font-weight: 700; cursor: pointer; }
.card-name:hover { color: var(--brand); }
.card-desc {
  font-size: 12.5px; color: var(--muted); flex: 1;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.price { font-size: 16px; font-weight: 800; }
.price small { font-size: 11px; font-weight: 600; color: var(--muted); }
.price.na { font-size: 13px; color: var(--muted); font-weight: 600; }
.add-btn {
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  border-radius: 8px; padding: 7px 12px; font-weight: 700; cursor: pointer;
}
.add-btn:hover { background: var(--brand-dark); }
.add-btn:disabled { background: var(--surface-2); border-color: var(--border); color: var(--muted); cursor: default; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 420px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  z-index: 60; transform: translateX(100%); transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 17px; }
.quote-meta { padding: 12px 18px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; }
.quote-meta label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 3px; font-weight: 600; }
.quote-meta input { padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2); }
.meta-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quote-items { flex: 1; overflow-y: auto; padding: 6px 12px; }
.qitem { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 9px 6px; border-bottom: 1px solid var(--border); }
.qitem img { width: 44px; height: 44px; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--border); }
.qitem .qi-name { font-weight: 700; font-size: 12.5px; }
.qitem .qi-sku { font-size: 11px; color: var(--muted); }
.qitem .qi-line { font-weight: 700; text-align: right; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; margin-top: 4px; }
.qty button { border: none; background: var(--surface-2); width: 24px; height: 24px; cursor: pointer; font-weight: 700; }
.qty button:hover { background: var(--border); }
.qty input { width: 34px; text-align: center; border: none; border-left: 1px solid var(--border); border-right: 1px solid var(--border); height: 24px; }
.qi-remove { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 11px; }
.qi-remove:hover { color: var(--danger); }
.quote-empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 13px; }
.quote-totals { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }
.trow { display: flex; justify-content: space-between; padding: 3px 0; }
.trow.muted { color: var(--muted); font-size: 13px; }
.trow.total { font-size: 17px; font-weight: 800; padding-top: 8px; margin-top: 4px; border-top: 1px dashed var(--border); }
.quote-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 14px 18px; }
.quote-actions .btn-ghost { grid-column: 1 / -1; }

/* ---------- Scrim ---------- */
.scrim { position: fixed; inset: 0; background: rgba(16,24,40,.4); z-index: 50; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 24px; background: rgba(16,24,40,.5); }
.modal-card {
  position: relative; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: min(920px, 100%); max-height: 90vh; overflow-y: auto;
}
.modal-close { position: absolute; top: 12px; right: 14px; z-index: 2; }
.modal-body { padding: 26px; }
.pd-head { display: grid; grid-template-columns: 300px 1fr; gap: 24px; }
.pd-gallery { }
.pd-gallery .main { aspect-ratio: 1/1; background: #fff; border: 1px solid var(--border); border-radius: 12px; display: grid; place-items: center; padding: 16px; }
.pd-gallery .main img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pd-thumbs { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.pd-thumbs img { width: 48px; height: 48px; object-fit: contain; border: 1px solid var(--border); border-radius: 6px; padding: 3px; cursor: pointer; background: #fff; }
.pd-thumbs img.active { border-color: var(--brand); }
.pd-title { font-size: 22px; font-weight: 800; margin: 2px 0 4px; }
.pd-sku { color: var(--muted); font-weight: 700; font-size: 12px; }
.pd-price { font-size: 26px; font-weight: 800; margin: 10px 0; }
.pd-desc { color: #374151; font-size: 13.5px; margin: 8px 0 14px; }
.pd-desc p { margin: 0 0 8px; }
.pd-actions { display: flex; gap: 10px; align-items: center; }
.pd-section-title { font-size: 15px; font-weight: 800; margin: 22px 0 8px; padding-top: 16px; border-top: 1px solid var(--border); }
.spec-group { margin-bottom: 14px; }
.spec-group h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--brand); }
.spec-table { width: 100%; border-collapse: collapse; }
.spec-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 13px; }
.spec-table td:first-child { color: var(--muted); width: 40%; }
.spec-table td:last-child { white-space: pre-line; }

/* ---------- Misc ---------- */
.hidden { display: none !important; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.loading { text-align: center; color: var(--muted); padding: 80px 20px; font-size: 15px; }

@media (max-width: 640px) {
  .pd-head { grid-template-columns: 1fr; }
  .search input { width: 160px; }
  .brand-text span { display: none; }
}

/* ---------- Refresh button ---------- */
.btn-refresh { border-color: var(--border); color: var(--muted); }
.btn-refresh:hover { border-color: var(--brand); color: var(--brand); }
.btn-refresh .ricon { display: inline-block; font-weight: 700; }
.btn-refresh.busy { color: var(--brand); border-color: var(--brand); cursor: default; }
.btn-refresh.busy .ricon { animation: spin 0.9s linear infinite; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ---------- Build button ---------- */
.btn-build { border-color: var(--border); color: var(--text); }
.btn-build:hover { border-color: var(--brand); color: var(--brand); }
.btn-build .pill { background: var(--text); color: #fff; }

/* ---------- Services nav tab (pinned right, always visible) ---------- */
.navbar button.nav-services {
  flex: 0 0 auto; color: var(--brand);
  border-left: 1px solid var(--border); border-radius: 0 8px 8px 0; padding-left: 16px;
  margin-left: 4px;
}
.navbar button.nav-services.active { background: var(--brand); color: #fff; }

/* service card icon (no product photo) */
.card-service .card-media { background: linear-gradient(135deg, #f2f6fc, #eaf0f8); }
.svc-icon { font-size: 56px; line-height: 1; }
.qi-icon {
  width: 44px; height: 44px; display: grid; place-items: center; font-size: 22px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
}

/* ---------- Build blade ---------- */
.build-intro { padding: 12px 18px; margin: 0; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--border); }
.build-scroll { flex: 1; overflow-y: auto; }
.build-storage { padding: 12px 18px; border-bottom: 1px solid var(--border); background: #fffdf3; }
.build-storage label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 6px; }
.storage-row { display: flex; align-items: center; gap: 8px; }
.storage-row input { width: 90px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; font-weight: 700; }
.storage-note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.build-section { border-bottom: 1px solid var(--border); }
.build-section.store { background: #eaf2fd; }
.build-section.service { background: #fdeef0; }
.build-section-head { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; padding: 8px 18px 2px; }
.build-section.store .build-section-head { color: #0a5bc4; }
.build-section.service .build-section-head { color: #c02b45; }
.build-items { padding: 4px 12px 10px; }
.build-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 8px 6px; }
.build-row + .build-row { border-top: 1px solid rgba(0,0,0,.06); }
.build-row img { width: 44px; height: 44px; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--border); }
.build-row .qi-name { font-weight: 700; font-size: 12.5px; }
.build-row .qi-sku { font-size: 11px; color: var(--muted); }
.build-row .qi-line { font-weight: 700; }
.build-empty { color: var(--muted); font-size: 12.5px; padding: 8px 6px; }
.build-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface); }
.build-foot .trow.total { border: none; padding: 0 0 10px; }
.build-foot .btn-primary { width: 100%; padding: 11px; }
.build-hint { text-align: center; font-size: 11px; color: var(--muted); margin: 8px 0 0; }

/* quote items that came from the Build blade */
.qitem.from-build-store { background: #eaf2fd; }
.qitem.from-build-service { background: #fdeef0; }

/* ---------- Admin button ---------- */
.btn-admin { border-color: var(--border); color: var(--muted); }
.btn-admin:hover { color: var(--brand); border-color: var(--brand); }
.btn-admin.unlocked { color: var(--brand); border-color: var(--brand); background: #eaf2ff; }

/* ---------- PIN modal ---------- */
.pin-card { width: min(360px, 100%); }
.pin-body { padding: 34px 30px 30px; text-align: center; }
.pin-lock { font-size: 34px; }
.pin-body h2 { margin: 8px 0 4px; font-size: 19px; }
.pin-body p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.pin-body input {
  width: 100%; text-align: center; letter-spacing: 8px; font-size: 24px;
  padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.pin-body input:focus { border-color: var(--brand); background: #fff; outline: none; }
.pin-error { color: var(--danger); font-size: 12.5px; margin: 10px 0 0; font-weight: 600; }
.pin-body .btn-primary { width: 100%; margin-top: 16px; padding: 11px; }

/* ---------- Admin view ---------- */
.admin-view {
  position: fixed; inset: 0; z-index: 80; background: var(--bg); overflow-y: auto;
  display: flex; flex-direction: column;
}
.admin-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.admin-head h1 { margin: 0; font-size: 20px; }
.admin-head span { font-size: 12.5px; color: var(--muted); }
.admin-controls {
  display: flex; align-items: flex-end; gap: 24px; flex-wrap: wrap;
  padding: 20px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.admin-controls label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 6px; }
.mult-input { display: inline-flex; align-items: center; gap: 6px; }
.mult-input span { font-size: 18px; color: var(--muted); font-weight: 700; }
.mult-input input {
  width: 110px; font-size: 20px; font-weight: 800; padding: 8px 10px;
  border: 2px solid var(--brand); border-radius: 10px; background: #fff;
}
.mult-alt .mult-input input { width: 80px; border-color: var(--border); font-size: 16px; }
.mult-input input:focus { outline: none; box-shadow: 0 0 0 3px rgba(5,89,201,.15); }
.mult-example { font-size: 13px; color: var(--muted); align-self: center; padding-bottom: 8px; }
.mult-example b { color: var(--text); }
.admin-controls .btn-ghost { margin-left: auto; align-self: center; }
.admin-toolbar { display: flex; align-items: center; gap: 14px; padding: 14px 24px; }
.admin-toolbar input {
  flex: 1; max-width: 360px; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface);
}
.admin-table-wrap { padding: 0 24px 40px; overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.admin-table th, .admin-table td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.admin-table thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); z-index: 1; }
.admin-table th.num, .admin-table td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.admin-table tbody tr:hover { background: var(--surface-2); }
.admin-table .cat-cell { color: var(--muted); font-size: 12px; }
.admin-table .sku-cell { color: var(--muted); font-weight: 700; font-size: 12px; }
.admin-table .adj { font-weight: 800; color: var(--brand); }
.admin-table .store { color: var(--muted); }

/* ---------- Print ---------- */
@media print {
  .topbar, .navbar, .subbar, .grid, .scrim, #openQuote, .quote-actions, .icon-btn { display: none !important; }
  body { background: #fff; }
  .drawer { position: static; transform: none; width: 100%; max-width: 100%; box-shadow: none; border: none; height: auto; }
  .quote-items { overflow: visible; }
  .drawer, .drawer * { visibility: visible; }
}
