/* PartsBench — mobile-first design system on top of Bootstrap 5 */
:root {
  --pb-ink: #0f1b2d;
  --pb-ink-2: #44526a;
  --pb-muted: #6b778c;
  --pb-line: #e3e7ee;
  --pb-bg: #f4f6fa;
  --pb-surface: #ffffff;
  --pb-brand: #1d4ed8;
  --pb-brand-ink: #ffffff;
  --pb-brand-soft: #e7eefe;
  --pb-accent: #f59e0b;
  --pb-ok: #15803d;
  --pb-ok-soft: #e6f6ec;
  --pb-warn: #b45309;
  --pb-warn-soft: #fff4e0;
  --pb-bad: #b91c1c;
  --pb-bad-soft: #fdecec;
  --pb-radius: 14px;
  --pb-shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 4px 16px rgba(15, 27, 45, .06);
  --pb-tabbar-h: 64px;
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bs-primary: var(--pb-brand);
  --bs-primary-rgb: 29, 78, 216;
  --bs-link-color: var(--pb-brand);
  --bs-link-color-rgb: 29, 78, 216;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  background: var(--pb-bg);
  color: var(--pb-ink);
  min-height: 100dvh;
  padding-bottom: calc(var(--pb-tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
body.pb-public { padding-bottom: 0; background: var(--pb-ink); }

/* ---------- App bar ---------- */
.pb-appbar {
  position: sticky; top: 0; z-index: 1030;
  background: var(--pb-surface);
  border-bottom: 1px solid var(--pb-line);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 12px;
}
.pb-brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.02em; color: var(--pb-ink); text-decoration: none; font-size: 1.1rem; }
.pb-brand:hover { color: var(--pb-ink); }
.pb-brand-mark { width: 30px; height: 30px; }
.pb-appbar .pb-user { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--pb-muted); }
.pb-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--pb-brand-soft); color: var(--pb-brand); display: grid; place-items: center; font-weight: 700; font-size: .85rem; border: 0; }

/* ---------- Tabs: bottom bar on phones, top strip on desktop ---------- */
.pb-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  height: calc(var(--pb-tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--pb-surface); border-top: 1px solid var(--pb-line);
  display: flex; justify-content: space-around; align-items: stretch;
}
.pb-tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--pb-muted); text-decoration: none; font-size: .7rem; font-weight: 600; position: relative; }
.pb-tab svg { width: 24px; height: 24px; }
.pb-tab.active { color: var(--pb-brand); }
.pb-tab .pb-count { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--pb-bad); color: #fff; border-radius: 999px; font-size: .62rem; padding: 0 5px; min-width: 16px; text-align: center; }
.pb-tab-cta { flex: 0 0 76px; }
.pb-tab-cta .pb-cta-btn {
  width: 58px; height: 58px; border-radius: 50%; margin-top: -22px;
  background: var(--pb-brand); color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(29, 78, 216, .45); border: 4px solid var(--pb-bg);
}
.pb-tab-cta .pb-cta-btn svg { width: 26px; height: 26px; }

@media (min-width: 992px) {
  body { padding-bottom: 32px; }
  .pb-tabbar { position: sticky; top: 61px; bottom: auto; height: 48px; padding: 0 16px; justify-content: flex-start; gap: 4px; border-top: 0; border-bottom: 1px solid var(--pb-line); }
  .pb-tab { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 0 14px; font-size: .9rem; border-bottom: 2px solid transparent; }
  .pb-tab svg { width: 18px; height: 18px; }
  .pb-tab.active { border-bottom-color: var(--pb-brand); }
  .pb-tab .pb-count { position: static; }
  .pb-tab-cta { flex: 0 0 auto; margin-left: auto; }
  .pb-tab-cta .pb-cta-btn { width: auto; height: 36px; margin: 0; border-radius: 999px; padding: 0 16px; border: 0; display: flex; gap: 8px; box-shadow: none; }
  .pb-tab-cta .pb-cta-btn::after { content: "New request"; font-size: .9rem; }
  .pb-tab-cta .pb-cta-label { display: none; }
}

/* ---------- Layout ---------- */
.pb-main { max-width: 1080px; margin: 0 auto; padding: 16px; }
.pb-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.pb-page-head h1 { font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.pb-sub { color: var(--pb-muted); font-size: .9rem; margin: 2px 0 0; }

.pb-card { background: var(--pb-surface); border: 1px solid var(--pb-line); border-radius: var(--pb-radius); box-shadow: var(--pb-shadow); }
.pb-card-body { padding: 16px; }
.pb-card + .pb-card { margin-top: 12px; }
.pb-section-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--pb-muted); font-weight: 700; margin: 20px 4px 8px; }

/* List rows (tappable) */
.pb-list { list-style: none; margin: 0; padding: 0; }
.pb-row { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--pb-line); color: inherit; text-decoration: none; min-height: 64px; }
.pb-row:last-child { border-bottom: 0; }
.pb-row:hover { background: #fafbfd; color: inherit; }
.pb-row-main { flex: 1; min-width: 0; }
.pb-row-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-row-meta { color: var(--pb-muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--pb-bg); flex: 0 0 auto; border: 1px solid var(--pb-line); }
.pb-thumb-lg { width: 88px; height: 88px; object-fit: contain; background: #fff; }
.pb-thumb-ph { display: grid; place-items: center; color: var(--pb-muted); }
.pb-chevron { color: #b8c0cd; }

/* Status pills */
.pb-pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: .72rem; font-weight: 700; white-space: nowrap; background: var(--pb-bg); color: var(--pb-ink-2); }
.pb-pill.s-Submitted, .pb-pill.s-Analyzing { background: var(--pb-brand-soft); color: var(--pb-brand); }
.pb-pill.s-PendingReview { background: var(--pb-warn-soft); color: var(--pb-warn); }
.pb-pill.s-NeedsInfo { background: #fde7f3; color: #a3195b; }
.pb-pill.s-Approved, .pb-pill.s-Ordered, .pb-pill.s-Received { background: var(--pb-ok-soft); color: var(--pb-ok); }
.pb-pill.s-Rejected, .pb-pill.s-Cancelled { background: var(--pb-bad-soft); color: var(--pb-bad); }
.pb-pill.s-Draft { background: var(--pb-bg); }
.pb-pill.s-Sent, .pb-pill.s-PartiallyReceived { background: var(--pb-brand-soft); color: var(--pb-brand); }
.pb-pill.u-Critical { background: var(--pb-bad); color: #fff; }
.pb-pill.u-Soon { background: var(--pb-warn-soft); color: var(--pb-warn); }
.pb-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.pb-pulse { animation: pb-pulse 1.2s ease-in-out infinite; }
@keyframes pb-pulse { 50% { opacity: .3; } }

/* Segmented filter (scrolls horizontally on phones) */
.pb-seg { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -16px 4px; padding-left: 16px; scrollbar-width: none; }
.pb-seg::-webkit-scrollbar { display: none; }
.pb-seg a { flex: 0 0 auto; padding: 7px 14px; border-radius: 999px; background: var(--pb-surface); border: 1px solid var(--pb-line); color: var(--pb-ink-2); text-decoration: none; font-weight: 600; font-size: .85rem; }
.pb-seg a.active { background: var(--pb-ink); border-color: var(--pb-ink); color: #fff; }
.pb-seg .n { opacity: .65; margin-left: 4px; }

/* Forms: big touch targets, 16px font to stop iOS zoom */
.form-control, .form-select { font-size: 16px; min-height: 48px; border-radius: 10px; border-color: #d5dbe5; }
textarea.form-control { min-height: 96px; }
.form-label { font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.btn { min-height: 44px; border-radius: 10px; font-weight: 650; }
.btn-lg { min-height: 54px; font-size: 1.05rem; }
.btn-primary { --bs-btn-bg: var(--pb-brand); --bs-btn-border-color: var(--pb-brand); --bs-btn-hover-bg: #1a43bd; --bs-btn-hover-border-color: #1a43bd; --bs-btn-active-bg: #163aa3; }
.pb-sticky-actions { position: sticky; bottom: calc(var(--pb-tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 5; background: linear-gradient(transparent, var(--pb-bg) 30%); padding-top: 16px; }
@media (min-width: 992px) { .pb-sticky-actions { bottom: 8px; } }

/* Camera capture tile */
.pb-capture { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pb-capture-btn {
  grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 170px; border: 2px dashed #b9c6e6; border-radius: var(--pb-radius); background: var(--pb-brand-soft);
  color: var(--pb-brand); font-weight: 700; cursor: pointer; text-align: center; padding: 16px;
}
.pb-capture-btn svg { width: 44px; height: 44px; }
.pb-capture-btn small { color: var(--pb-ink-2); font-weight: 500; }
.pb-capture.has-photos .pb-capture-btn { min-height: 0; grid-column: auto; aspect-ratio: 1; flex-direction: column; font-size: .8rem; }
.pb-capture.has-photos .pb-capture-btn small { display: none; }
.pb-capture.has-photos .pb-capture-btn svg { width: 28px; height: 28px; }
.pb-shot { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: #000; }
.pb-shot img { width: 100%; height: 100%; object-fit: cover; }
.pb-shot button { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; min-height: 0; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; line-height: 1; padding: 0; }

/* Photo strip on details */
.pb-photos { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; }
.pb-photos a { flex: 0 0 auto; scroll-snap-align: start; }
.pb-photos img { height: 180px; border-radius: 12px; border: 1px solid var(--pb-line); object-fit: cover; max-width: 80vw; }

/* AI match cards */
.pb-match { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--pb-line); align-items: flex-start; }
.pb-match:last-child { border-bottom: 0; }
.pb-match.selected { background: #f6f9ff; box-shadow: inset 3px 0 0 var(--pb-brand); }
.pb-match-img { width: 84px; height: 84px; border-radius: 10px; object-fit: contain; background: #fff; border: 1px solid var(--pb-line); flex: 0 0 auto; }
.pb-match-body { flex: 1; min-width: 0; }
.pb-item-no { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; font-size: .85rem; color: var(--pb-brand); }
.pb-conf { height: 6px; border-radius: 3px; background: var(--pb-line); overflow: hidden; width: 90px; display: inline-block; vertical-align: middle; }
.pb-conf > span { display: block; height: 100%; background: var(--pb-ok); }
.pb-conf.mid > span { background: var(--pb-accent); }
.pb-conf.low > span { background: var(--pb-bad); }
.pb-specs { font-size: .8rem; color: var(--pb-ink-2); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pb-rationale { font-size: .85rem; margin-top: 6px; color: var(--pb-ink); }

/* Hero for AI result */
.pb-ai { border-radius: var(--pb-radius); padding: 16px; background: linear-gradient(135deg, #1d4ed8, #4338ca); color: #fff; }
.pb-ai .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; opacity: .8; font-weight: 700; }
.pb-ai p { margin: 6px 0 0; }
.pb-analyzing { display: flex; align-items: center; gap: 14px; }
.pb-spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: pb-spin .9s linear infinite; flex: 0 0 auto; }
@keyframes pb-spin { to { transform: rotate(360deg); } }

/* Timeline */
.pb-timeline { list-style: none; padding: 0; margin: 0; }
.pb-timeline li { position: relative; padding: 0 0 14px 22px; font-size: .85rem; }
.pb-timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--pb-brand); }
.pb-timeline li::after { content: ""; position: absolute; left: 8.5px; top: 16px; bottom: 0; width: 1px; background: var(--pb-line); }
.pb-timeline li:last-child::after { display: none; }
.pb-timeline .when { color: var(--pb-muted); font-size: .75rem; }

/* Key/value */
.pb-kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: .9rem; margin: 0; }
.pb-kv dt { color: var(--pb-muted); font-weight: 500; }
.pb-kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Catalog grid */
.pb-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .pb-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 992px) { .pb-grid { grid-template-columns: repeat(4, 1fr); } }
.pb-tile { background: var(--pb-surface); border: 1px solid var(--pb-line); border-radius: 12px; overflow: hidden; color: inherit; text-decoration: none; display: flex; flex-direction: column; }
.pb-tile:hover { color: inherit; box-shadow: var(--pb-shadow); }
.pb-tile-img { aspect-ratio: 4/3; background: #fff; display: grid; place-items: center; border-bottom: 1px solid var(--pb-line); }
.pb-tile-img img { max-width: 90%; max-height: 90%; object-fit: contain; }
.pb-tile-body { padding: 10px; font-size: .82rem; }
.pb-tile-name { font-weight: 650; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .88rem; }

/* Item photo with placeholder fallback (see _ItemImage) */
.pb-imgwrap { position: relative; display: grid; place-items: center; overflow: hidden; color: #c3cbd8; background: #fff; }
.pb-imgwrap > svg { width: 40%; height: 40%; max-width: 48px; max-height: 48px; }
.pb-imgwrap > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.pb-tile-img.pb-imgwrap > img { inset: 5%; width: 90%; height: 90%; }
.pb-detail-img { width: 100%; aspect-ratio: 1; max-height: 340px; }

/* Search field */
.pb-search { position: relative; }
.pb-search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--pb-muted); }
.pb-search input { padding-left: 42px; border-radius: 999px; }

/* Picker results */
.pb-picker-results { max-height: 50vh; overflow-y: auto; }
.pb-pick { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--pb-line); cursor: pointer; align-items: center; }
.pb-pick:hover, .pb-pick:focus { background: var(--pb-brand-soft); outline: none; }

.validation-summary-valid { display: none; }

/* Toasts / alerts */
.pb-toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--pb-tabbar-h) + env(safe-area-inset-bottom) + 14px); z-index: 2000; background: var(--pb-ink); color: #fff; border-radius: 12px; padding: 12px 18px; box-shadow: 0 8px 30px rgba(0,0,0,.25); font-weight: 600; font-size: .9rem; max-width: calc(100vw - 32px); animation: pb-toast 4s ease forwards; }
@keyframes pb-toast { 0% { opacity: 0; transform: translate(-50%, 10px); } 8%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

.pb-empty { text-align: center; padding: 40px 20px; color: var(--pb-muted); }
.pb-empty svg { width: 48px; height: 48px; color: #c3cbd8; margin-bottom: 10px; }
.pb-money { font-variant-numeric: tabular-nums; }

/* Purchase order document */
.pb-po { background: #fff; color: #111; border: 1px solid var(--pb-line); border-radius: 8px; padding: 24px; font-size: .9rem; }
.pb-po h2 { font-size: 1.6rem; font-weight: 800; letter-spacing: .02em; }
.pb-po table { width: 100%; }
.pb-po th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: #555; border-bottom: 2px solid #111; padding: 6px 4px; }
.pb-po td { padding: 8px 4px; border-bottom: 1px solid #e5e5e5; vertical-align: top; }
.pb-po-table-wrap { overflow-x: auto; }
@media (max-width: 575.98px) {
  .pb-po { padding: 16px; font-size: .82rem; }
  .pb-po h2 { font-size: 1.2rem; }
  .pb-po .pb-po-opt { display: none; }
  .pb-po td, .pb-po th { padding: 6px 3px; }
}
@media print {
  body { background: #fff; padding: 0; }
  .pb-appbar, .pb-tabbar, .no-print, .pb-toast { display: none !important; }
  .pb-main { max-width: none; padding: 0; }
  .pb-po { border: 0; padding: 0; }
}

/* ---------- Public "coming soon" page ---------- */
.pb-hero { min-height: 100dvh; color: #e8edf7; display: flex; flex-direction: column; position: relative; overflow: hidden;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(59,130,246,.35), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(245,158,11,.18), transparent 60%), #0b1424; }
.pb-hero-grid { position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px); background-size: 40px 40px; mask-image: linear-gradient(to bottom, black, transparent 85%); pointer-events: none; }
.pb-hero-nav { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top) + 18px) 20px 18px; position: relative; z-index: 1; max-width: 1080px; width: 100%; margin: 0 auto; }
.pb-hero-nav .pb-brand { color: #fff; }
.pb-hero-nav a.signin { color: #c7d2e6; text-decoration: none; font-weight: 600; font-size: .9rem; border: 1px solid rgba(255,255,255,.18); padding: 8px 16px; border-radius: 999px; }
.pb-hero-nav a.signin:hover { color: #fff; border-color: rgba(255,255,255,.4); }
.pb-hero-body { flex: 1; display: flex; align-items: center; position: relative; z-index: 1; padding: 20px; max-width: 1080px; width: 100%; margin: 0 auto; }
.pb-hero-inner { max-width: 640px; }
.pb-badge-soon { display: inline-flex; align-items: center; gap: 8px; background: rgba(245,158,11,.12); color: #fbbf24; border: 1px solid rgba(245,158,11,.35); padding: 6px 12px; border-radius: 999px; font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.pb-hero h1 { font-size: clamp(2.2rem, 7vw, 3.8rem); font-weight: 850; letter-spacing: -.035em; line-height: 1.04; margin: 18px 0 16px; color: #fff; }
.pb-hero h1 em { font-style: normal; background: linear-gradient(90deg, #60a5fa, #a78bfa); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pb-hero .lead { color: #aab6cc; font-size: 1.1rem; max-width: 560px; }
.pb-join { display: flex; gap: 8px; margin-top: 26px; flex-wrap: wrap; }
.pb-join input { flex: 1 1 240px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.16); color: #fff; }
.pb-join input::placeholder { color: #8090a8; }
.pb-join input:focus { background: rgba(255,255,255,.1); color: #fff; border-color: #60a5fa; box-shadow: 0 0 0 .2rem rgba(96,165,250,.25); }
.pb-join .btn { flex: 0 0 auto; padding: 0 22px; }
.pb-steps { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 40px; }
@media (min-width: 720px) { .pb-steps { grid-template-columns: repeat(3, 1fr); } }
.pb-step { background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08); border-radius: 14px; padding: 16px; }
.pb-step .n { width: 28px; height: 28px; border-radius: 8px; background: rgba(96,165,250,.15); color: #93c5fd; display: grid; place-items: center; font-weight: 800; font-size: .85rem; margin-bottom: 10px; }
.pb-step h3 { font-size: 1rem; color: #fff; margin: 0 0 4px; font-weight: 700; }
.pb-step p { color: #93a1b8; font-size: .88rem; margin: 0; }
.pb-hero-foot { position: relative; z-index: 1; text-align: center; color: #6b7a93; font-size: .8rem; padding: 20px; }

/* Auth page */
.pb-auth { max-width: 420px; margin: 24px auto; }
.pb-auth .pb-brand { justify-content: center; font-size: 1.4rem; margin-bottom: 18px; }
