/* Product detail page — matching SPA detail screen */
.product-detail {
  max-width: min(428px, 100%);
  margin: 0 auto;
  padding: 0 0 calc(var(--tab-bar-height) + var(--space-md));
}

/* Hero area with image band */
.product-hero {
  position: relative;
}

.product-detail-image-wrap {
  width: 100%;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: #FFFFFF;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.product-detail-image {
  max-width: 220px;
  max-height: 240px;
  width: auto;
  height: auto;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

.product-detail-placeholder {
  opacity: 0.4;
}

/* Back button — pill style matching SPA */
.product-back-btn {
  position: absolute;
  top: 18px;
  left: 16px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 20px;
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
}

.product-back-btn svg {
  width: 14px;
  height: 14px;
  stroke: var(--color-text-primary);
  fill: none;
}

.product-back-btn:active {
  opacity: 0.7;
}

/* Favorite button */
.product-fav-btn {
  position: absolute;
  top: 18px;
  right: 16px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 7px;
  border-radius: 20px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-fav-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 1.8;
  fill: none;
  stroke: var(--color-text-primary);
  transition: all 0.15s;
}

.product-fav-btn.faved svg {
  stroke: var(--color-avoid);
  fill: var(--color-avoid);
}

/* Score ring — SVG-based, matching SPA */
.product-detail-header {
  padding: 20px var(--screen-padding) 0;
}

.product-score-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.product-score-ring {
  position: relative;
  width: 68px;
  height: 68px;
  flex-shrink: 0;
}

.product-score-ring svg {
  width: 68px;
  height: 68px;
  transform: rotate(-90deg);
}

.product-score-ring .ring-track {
  fill: none;
  stroke: var(--color-border);
  stroke-width: 5.5;
}

.product-score-ring .ring-progress {
  fill: none;
  stroke-width: 5.5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .product-score-ring .ring-progress {
    transition: none;
  }
}

.product-score-ring .ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.product-score-ring .ring-score {
  font-weight: 700;
  font-size: 18px;
  line-height: 1;
}

.product-score-ring .ring-sub {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-top: 1px;
}

.product-detail-meta {
  flex: 1;
  min-width: 0;
}

.product-detail-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.2;
  margin-bottom: 3px;
}

.product-detail-brand {
  display: block;
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

/* Safety tags — verdict pill row matching SPA */
.product-safety-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.safety-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--badge-radius);
}

.product-detail-tier {
  font-size: 10px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: var(--badge-radius);
}

/* Divider */
.product-divider {
  margin: 18px var(--screen-padding);
  height: 1px;
  background: var(--color-border);
}

.product-detail-description {
  padding: 0 var(--screen-padding) 16px;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 1.75;
}

/* Callout box — green recommendation matching SPA */
.product-callout {
  margin: 0 var(--screen-padding) 14px;
  padding: 12px 14px;
  background: var(--color-good-bg);
  border-radius: var(--badge-radius);
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.product-callout svg {
  flex-shrink: 0;
  stroke: var(--color-good);
  width: 14px;
  height: 14px;
  fill: none;
  margin-top: 1px;
}

.product-callout p {
  color: var(--color-good);
  font-size: 12px;
  line-height: 1.55;
  font-weight: 500;
  margin: 0;
}

/* Ingredient Simplicity Meter */
.simplicity-meter {
  margin: 0 var(--screen-padding) 18px;
  padding: 14px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--badge-radius);
}

.simplicity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.simplicity-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-primary);
}

.simplicity-label {
  font-size: 11px;
  font-weight: 700;
}

.simplicity-bar-track {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.simplicity-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease-out;
}

.simplicity-detail {
  font-size: 11px;
  color: var(--color-text-muted);
}

/* Sections */
.product-section {
  margin-bottom: var(--space-lg);
}

.product-section-title {
  padding: 0 var(--screen-padding) 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--color-score-green);
}

.product-section-content {
  padding-top: var(--space-sm);
}

/* Ingredients — card-style rows with status dots matching SPA */
.ingredient-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--badge-radius);
  margin: 0 var(--screen-padding) 6px;
}

.ingredient-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.ingredient-dot--low { background-color: var(--color-score-green); }
.ingredient-dot--medium { background-color: var(--color-caution); }
.ingredient-dot--high { background-color: var(--color-avoid); }

.ingredient-info {
  flex: 1;
  min-width: 0;
}

.ingredient-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 2px;
}

.ingredient-desc {
  font-size: 11px;
  color: var(--color-text-secondary);
  line-height: 1.45;
}

.ingredient-risk {
  padding: 2px 8px;
  border-radius: var(--badge-radius);
  font-size: 11px;
  font-weight: 700;
  text-transform: capitalize;
  flex-shrink: 0;
}

/* Certifications */
.cert-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border);
}

.cert-row:last-child {
  border-bottom: none;
}

.cert-name {
  font: var(--text-body);
  font-weight: 500;
  color: var(--color-text-primary);
}

.cert-issuer {
  font: var(--text-caption);
  color: var(--color-text-secondary);
}

/* Alternatives */
.alt-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--card-radius);
  margin-bottom: var(--card-gap);
  cursor: pointer;
  transition: transform 0.15s;
}

.alt-row:hover {
  transform: translateY(-1px);
}

.alt-info {
  flex: 1;
  min-width: 0;
}

.alt-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.alt-score {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.alt-score-number {
  font-weight: 700;
  font-size: var(--font-size-lg);
}

.alt-tier {
  padding: 4px 10px;
  border-radius: var(--badge-radius);
  font-size: 11px;
  font-weight: 700;
}

/* Error state */
.product-error-content {
  text-align: center;
  padding: 56px 24px;
  color: var(--color-text-secondary);
}

.product-error-content p {
  margin-bottom: var(--space-md);
}

/* Loading */
.product-detail-loading {
  padding: var(--space-2xl);
}

/* Scan spinner */
.scan-spinner {
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .scan-spinner {
    animation: none;
    opacity: 0.5;
  }
}

/* Where to Buy links */
.buy-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin: 0 var(--screen-padding) 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--badge-radius);
  text-decoration: none;
  color: var(--color-text-primary);
  transition: transform 0.15s, box-shadow 0.15s;
}

.buy-link:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.buy-link:active {
  transform: scale(0.98);
}

.buy-link--amazon {
  border-color: rgba(255, 153, 0, 0.2);
  background: linear-gradient(135deg, rgba(255, 153, 0, 0.04), rgba(255, 153, 0, 0.08));
}

.buy-link-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: #FF9900;
}

.buy-link-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.buy-link-store {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text-primary);
}

.buy-link-action {
  font-size: 11px;
  color: var(--color-text-secondary);
}

.buy-link-arrow {
  flex-shrink: 0;
  color: var(--color-text-muted);
}

/* Bottom padding for scroll */
.product-pad-bottom {
  height: 28px;
}

/* ============================================================
   Product Detail v2 — redesigned card
   Scoped with .pd2-* so it coexists with legacy styles above.
   ============================================================ */
.pd2 {
  max-width: min(460px, 100%);
  margin: 0 auto;
  padding: 16px 16px calc(var(--tab-bar-height, 64px) + 24px);
  background: #F6F5F1;
  min-height: 100vh;
}
.pd2-card {
  background: #FFFFFF;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03), 0 24px 48px -28px rgba(14,21,18,.18);
  border: 1px solid #ECEBE4;
}

.pd2-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #6B7570;
  background: none;
  border: 0;
  font-size: 14px;
  font-weight: 600;
  padding: 4px 0;
  margin-bottom: 14px;
  cursor: pointer;
  font-family: inherit;
}
.pd2-back svg { stroke: currentColor; }
.pd2-back:active { opacity: .7; }

/* Hero */
.pd2-hero {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.pd2-hero-wrap {
  width: 108px;
  height: 108px;
  border-radius: 16px;
  background: #FAF8F1;
  border: 1px solid #ECEBE4;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.pd2-hero-img { max-width: 82%; max-height: 82%; object-fit: contain; mix-blend-mode: multiply; }
.pd2-hero-ph { opacity: .4; }
.pd2-hero-meta { flex: 1; min-width: 0; }

.pd2-title {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: -0.01em;
  color: #0F1512;
  margin: 2px 0 8px;
}

.pd2-brand-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: #6B7570;
}
.pd2-brand-line b { color: #3A403C; font-weight: 600; }
.pd2-brand-line .pd2-sep { color: #ECEBE4; }

/* Owned-by — tiny inline chip */
.pd2-owned-wrap { margin-top: 8px; }
.pd2-owned {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #6B7570;
  padding: 3px 8px;
  border: 1px solid #ECEBE4;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s;
  background: transparent;
}
.pd2-owned:hover { background: #F1EFE7; }
.pd2-owned b { color: #3A403C; font-weight: 600; }
.pd2-owned-pct { color: #1E5B3E; font-weight: 700; font-variant-numeric: tabular-nums; }
.pd2-owned-chev { color: #6B7570; font-size: 10px; }

/* Score + quick hits row */
.pd2-score-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 22px 0 4px;
  padding-top: 18px;
  border-top: 1px solid #ECEBE4;
}
.pd2 .product-score-ring { flex-shrink: 0; width: 116px; height: 116px; }
.pd2 .product-score-ring svg { width: 116px; height: 116px; }
.pd2 .product-score-ring .ring-score { font-size: 30px; }
.pd2 .product-score-ring .ring-sub { font-size: 12px; margin-top: 2px; }

.pd2-hits {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 11px;
  min-width: 0;
}
.pd2-hit {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #3A403C;
}
.pd2-hit b { font-weight: 600; }
.pd2-hit .pd2-n {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: #0F1512;
}
.pd2-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.pd2-dot--beneficial { background: #15803D; box-shadow: 0 0 0 3px rgba(21,128,61,.15); }
.pd2-dot--neutral { background: #6B7280; box-shadow: 0 0 0 3px rgba(107,114,128,.15); }
.pd2-dot--safe { background: #2FB86B; box-shadow: 0 0 0 3px rgba(47,184,107,.15); }
.pd2-dot--warn { background: #D97706; box-shadow: 0 0 0 3px rgba(217,119,6,.15); }
.pd2-dot--bad  { background: #DC2626; box-shadow: 0 0 0 3px rgba(220,38,38,.15); }

/* Description */
.pd2-desc {
  font-size: 14px;
  color: #3A403C;
  line-height: 1.55;
  margin: 18px 0 0;
}

/* Section */
.pd2-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #ECEBE4;
}
.pd2-sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.pd2-sec-head h2 {
  font-size: 16px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.01em;
  color: #0F1512;
}
.pd2-sec-meta {
  font-size: 11px;
  color: #6B7570;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

/* Ingredient card (with colored left rail) */
.pd2-ings { display: flex; flex-direction: column; gap: 10px; }
.pd2-ing {
  border: 1px solid #ECEBE4;
  border-radius: 14px;
  padding: 14px 16px;
  background: #FFFFFF;
  position: relative;
  overflow: hidden;
}
.pd2-ing::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #2FB86B;
}
.pd2-ing--beneficial::before { background: #15803D; }
.pd2-ing--neutral::before { background: #6B7280; }
.pd2-ing--warn::before { background: #D97706; }
.pd2-ing--bad::before  { background: #DC2626; }

.pd2-ing-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.pd2-ing-title { min-width: 0; flex: 1; }
.pd2-ing-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.005em;
  color: #0F1512;
}
.pd2-ing-amt {
  font-size: 12px;
  color: #6B7570;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.pd2-ing-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 4px 9px;
  border-radius: 999px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.pd2-ing-badge--beneficial { background: #DCFCE7; color: #15803D; }
.pd2-ing-badge--neutral { background: #F3F4F6; color: #4B5563; }
.pd2-ing-badge--safe { background: #E8F7EF; color: #13794B; }
.pd2-ing-badge--warn { background: #FEF3C7; color: #8A5A00; }
.pd2-ing-badge--bad  { background: #FEE2E2; color: #9A1A1A; }

.pd2-ing-body {
  font-size: 13px;
  color: #3A403C;
  line-height: 1.55;
  margin-top: 8px;
}
.pd2-clip {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pd2-clip--open {
  -webkit-line-clamp: unset;
  display: block;
  overflow: visible;
}
.pd2-ing-more {
  background: none;
  border: 0;
  color: #1E5B3E;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 0 0;
  cursor: pointer;
  font-family: inherit;
}

.pd2-empty {
  font-size: 13px;
  color: #6B7570;
  margin: 0;
}

.pd2-legend {
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: #6B7570;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed #ECEBE4;
  flex-wrap: wrap;
}
.pd2-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Reuse existing .product-section for "Where to Buy" inside pd2-card */
.pd2 .product-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #ECEBE4;
}

/* ============================================================
   Ownership tree modal (window.rbShowOwnership)
   ============================================================ */
#rh-ownership-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
}
.rh-own-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(14, 21, 18, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: rh-own-fade-in 0.18s ease-out;
}
.rh-own-modal {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 32px);
  max-width: 400px;
  max-height: calc(100vh - 80px);
  background: #FFFFFF;
  border-radius: 20px;
  box-shadow: 0 24px 64px -12px rgba(14, 21, 18, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: rh-own-pop-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes rh-own-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes rh-own-pop-in {
  from { opacity: 0; transform: translate(-50%, -46%) scale(0.96); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.rh-own-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid #ECEBE4;
}
.rh-own-head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #0F1512;
}
.rh-own-close {
  background: none;
  border: 0;
  color: #6B7570;
  padding: 4px;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rh-own-close:hover { background: #F1EFE7; color: #0F1512; }

.rh-own-body {
  padding: 16px 20px 22px;
  overflow-y: auto;
}
.rh-own-lede {
  font-size: 13px;
  color: #6B7570;
  line-height: 1.5;
  margin: 0 0 16px;
}
.rh-own-foot {
  font-size: 11px;
  color: #9B948A;
  line-height: 1.5;
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px dashed #ECEBE4;
}

.rh-own-chain {
  display: flex;
  flex-direction: column;
}
.rh-own-node {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #ECEBE4;
  border-radius: 14px;
  background: #FAF9F4;
}
.rh-own-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #FFFFFF;
  border: 1px solid #ECEBE4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  font-weight: 800;
  color: #1E5B3E;
  font-size: 13px;
}
.rh-own-logo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.rh-own-info {
  flex: 1;
  min-width: 0;
}
.rh-own-name {
  font-size: 15px;
  font-weight: 700;
  color: #0F1512;
  letter-spacing: -0.005em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rh-own-role {
  font-size: 10px;
  color: #6B7570;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  margin-top: 2px;
}
.rh-own-pct {
  font-size: 12px;
  font-weight: 800;
  color: #FFFFFF;
  background: #0F1512;
  padding: 4px 10px;
  border-radius: 999px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.rh-own-pct--full {
  background: transparent;
  color: #6B7570;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0;
}
.rh-own-connector {
  display: flex;
  justify-content: center;
  padding: 6px 0;
}
.rh-own-connector span {
  display: block;
  width: 2px;
  height: 16px;
  background: linear-gradient(to bottom, #ECEBE4, #1E5B3E);
  border-radius: 1px;
}
