/* =========================================================
   DNP RESPONSIVE LAYER
   Loaded LAST on every storefront page (after style.css and
   ecommerce.css), so it only adds safe, mobile-first fixes:
   - nothing may be wider than the screen
   - comfortable tap targets and no iOS zoom-on-focus
   - forms, cart, checkout, product actions and tracking stack cleanly
   Breakpoints: 1024 (tablet landscape) / 768 (tablet) / 560 (phone) / 360 (small phone)
   ========================================================= */

/* ---------- 1. never wider than the screen ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: clip; }
img, video, canvas, svg, iframe { max-width: 100%; }
img { height: auto; }
.product-image img, .cart-product-image img, .detail-media img, .brand img, .feature-img img, .article img { height: 100%; }
.container { width: min(1180px, 100% - 32px); }
table { max-width: 100%; }
pre, code { white-space: pre-wrap; overflow-wrap: anywhere; }
h1, h2, h3, p, li, a, label, small, span { overflow-wrap: anywhere; }
/* grid/flex children may shrink below their content width (the usual cause of sideways scroll) */
.form-grid > *, .form-layout > *, .detail > *, .cart-layout > *, .contact-grid > *, .account-grid > *,
.form-group, .dnp-lead-form > *, .cart-item > * { min-width: 0; }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field, .form-group input, .form-group select, .form-group textarea,
.dnp-lead-form input, .dnp-lead-form select, .dnp-lead-form textarea,
.dnp-review-form input, .dnp-review-form select, .dnp-review-form textarea { max-width: 100%; min-width: 0; }

/* ---------- 2. forms: type-specific inputs look right ---------- */
select.field { appearance: auto; background-color: #fff; }
textarea.field { min-height: 110px; line-height: 1.5; }
/* validation colour only after the user has visited the field (never on a fresh form) */
.dnp-touched:invalid:not(:focus) { border-color: #c0392b; background-color: #fff8f7; }
input[type="search"] { -webkit-appearance: none; appearance: none; }
input[type="number"] { -moz-appearance: textfield; }
.dnp-qty-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 8px; }
.dnp-qty-row > * { min-width: 0; }
.dnp-lead-form input, .dnp-lead-form select, .dnp-lead-form textarea,
.dnp-review-form input, .dnp-review-form select, .dnp-review-form textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line, #ddd); border-radius: 8px; background: #fff; color: inherit; font: inherit;
}
.dnp-lead-form, .dnp-review-form { display: grid; gap: 10px; }

.toast:not(.show) { visibility: hidden; pointer-events: none; }

/* ---------- 3. tracking page ---------- */
.tracking-wrap { max-width: 860px; }
.trk-form label { display: block; font-size: 10px; font-weight: 800; letter-spacing: .1em; margin-bottom: 8px; }
.trk-input-row { display: flex; gap: 10px; align-items: stretch; }
.trk-input-row .field { flex: 1 1 auto; text-transform: uppercase; letter-spacing: .04em; }
.trk-input-row .field::placeholder { text-transform: none; letter-spacing: 0; }
.trk-input-row .btn { flex: 0 0 auto; min-width: 110px; }
.trk-help { display: block; margin-top: 10px; color: var(--muted, #6b7a70); font-size: 12px; }
.trk-result { margin-top: 24px; }
.trk-card { padding: clamp(18px, 4vw, 34px); }
.trk-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.trk-code { font-size: clamp(24px, 6vw, 40px) !important; margin: 4px 0 !important; word-break: break-all; }
.trk-sub { color: var(--muted, #6b7a70); }
.trk-warn { margin: 18px 0 0; border-left: 4px solid #d98a00; }
.trk-steps { list-style: none; margin: 28px 0 8px; padding: 0; position: relative; display: grid; gap: 0; }
.trk-step { position: relative; display: flex; gap: 16px; padding: 0 0 22px 0; }
.trk-step:last-child { padding-bottom: 0; }
.trk-step::before { content: ""; position: absolute; left: 15px; top: 32px; bottom: 0; width: 2px; background: var(--line, #e2ddd0); }
.trk-step:last-child::before { display: none; }
.trk-dot { flex: 0 0 32px; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: #fff; border: 2px solid var(--line, #e2ddd0); color: var(--muted, #6b7a70); position: relative; z-index: 1; }
.trk-step strong { display: block; font-size: 14px; line-height: 32px; }
.trk-step small { display: block; margin-top: -4px; color: var(--muted, #6b7a70); font-size: 12px; line-height: 1.45; }
.trk-step.done::before { background: var(--green, #174b25); }
.trk-step.done .trk-dot { background: var(--green, #174b25); border-color: var(--green, #174b25); color: #fff; }
.trk-step.active .trk-dot { border-color: var(--green, #174b25); color: var(--green, #174b25); box-shadow: 0 0 0 5px rgba(23, 75, 37, .14); }
.trk-step.active strong { color: var(--green, #174b25); }
.trk-step:not(.done):not(.active) strong { color: var(--muted, #6b7a70); font-weight: 600; }
.trk-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-top: 26px; }
.trk-facts > div { background: var(--cream, #f5f1e6); padding: 14px 16px; border-radius: 12px; min-width: 0; }
.trk-facts small { display: block; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted, #6b7a70); margin-bottom: 4px; }
.trk-facts b { font-size: 15px; word-break: break-word; text-transform: capitalize; }
.trk-facts b:is(:nth-child(1)) { text-transform: none; }
.trk-pending { grid-column: 1 / -1; }
.trk-pending b { font-size: 13px; font-weight: 600; text-transform: none; }
.trk-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.trk-h { margin: 30px 0 10px; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; }
.trk-events { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line, #e2ddd0); }
.trk-events li { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line, #e2ddd0); font-size: 13px; }
.trk-ev-time { color: var(--muted, #6b7a70); font-size: 12px; }
.trk-events strong { display: block; }
.trk-events small { color: var(--muted, #6b7a70); }
.trk-events p { margin: 4px 0 0; }

/* ---------- 4. tablet (<= 1024px) ---------- */
@media (max-width: 1024px) {
  .section { padding: 72px 0; }
  .form-layout { gap: 32px; }
  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .detail { gap: 36px; }
}

/* ---------- 5. tablet portrait (<= 768px) ---------- */
@media (max-width: 768px) {
  .section { padding: 56px 0; }
  .page-hero { padding: 56px 0; }
  .page-hero .display, .display { font-size: clamp(34px, 9vw, 52px); }
  .form-layout, .contact-grid, .detail, .cart-layout, .account-grid { grid-template-columns: minmax(0, 1fr); }
  .summary, .cart-summary { position: static; }
  .footer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; }
  .footer-bottom { flex-direction: column; gap: 6px; }
  .toolbar { flex-wrap: wrap; }
  .trk-events li { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  /* wide tables scroll inside themselves instead of stretching the page */
  .table-wrap, .prose table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---------- 6. phones (<= 700px): product cards 2 per row ---------- */
/* (must come after the <=1024px 3-column rule, otherwise that rule wins on phones) */
@media (max-width: 700px) {
  .product-grid, .home-product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

/* ---------- 6b. phones (<= 560px) ---------- */
@media (max-width: 560px) {
  .container { width: calc(100% - 28px); }
  .section { padding: 44px 0; }
  .page-hero { padding: 42px 0; }
  .lead { font-size: 15px; }

  /* header: logo + tools on one row, search below */
  .site-header { height: auto; min-height: 64px; padding: 8px 14px; gap: 8px; flex-wrap: wrap; }
  .header-tools { gap: 6px; margin-left: auto; }
  .tool { width: 40px; height: 40px; flex: 0 0 auto; }

  /* forms */
  .form-card { padding: 18px 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .form-group.full { grid-column: auto; }
  .dnp-qty-row { grid-template-columns: minmax(0, 1fr) 96px; }
  input, select, textarea, .field { font-size: 16px; }              /* stops iOS zooming into focused fields */
  .field, .btn, .small-btn, .chip, .qty button { min-height: 44px; } /* comfortable tap targets */
  .qty button { min-width: 44px; }
  .btn { padding: 12px 18px; }
  .form-card > .btn, .form-card form > .btn.primary, #checkoutForm > .btn.primary, #contactForm > .btn.primary { width: 100%; }

  /* tracking */
  .trk-input-row { flex-direction: column; }
  .trk-input-row .btn { width: 100%; }
  .trk-actions .btn { flex: 1 1 100%; }
  .trk-facts { grid-template-columns: minmax(0, 1fr); }

  /* product page buttons: two per row, cart/buy first */
  .detail .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .detail .actions .btn { width: 100%; padding-inline: 10px; text-align: center; }
  .detail .actions .btn.primary:first-child { grid-column: 1 / -1; }
  .pack-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pack-option { min-width: 0; width: 100%; }
  .meta-row { flex-wrap: wrap; gap: 12px 20px; }

  /* cart + checkout */
  .cart-item { grid-template-columns: 24px 70px minmax(0, 1fr); gap: 12px; padding: 16px 0; }
  .cart-item > .cart-product-price { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
  .cart-summary, .summary { padding: 20px 16px; }
  .cart-summary .btn, .summary .btn { width: 100%; }
  .dnp-paybox { width: min(100% - 24px, 420px); }

  /* account + lists */
  .dashboard { grid-template-columns: minmax(0, 1fr); }
  .dnp-account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .dnp-account-actions .btn { flex: 1 1 140px; }
  .footer-grid { grid-template-columns: minmax(0, 1fr); }
  .toast { left: 14px; right: 14px; bottom: 14px; text-align: center; }
}

/* ---------- 7. very small phones (<= 360px) ---------- */
@media (max-width: 360px) {
  .container { width: calc(100% - 20px); }
  .form-card { padding: 16px 12px; }
  .brand img { width: 52px; height: 40px; }
  .detail .actions { grid-template-columns: minmax(0, 1fr); }
  .cart-item { grid-template-columns: 22px 60px minmax(0, 1fr); gap: 10px; }
  .display { font-size: 32px; }
}

/* 360px is the most common Android width, so keep 2 cards per row there; only the smallest phones get 1 */
@media (max-width: 340px) {
  .product-grid, .home-product-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- 8. wide screens ---------- */
@media (min-width: 1600px) { .container { width: min(1360px, 86vw); } }

/* ---------- 9. touch devices: no hover-only effects, bigger targets ---------- */
@media (hover: none) {
  .product-card:hover, .cat:hover, .btn.primary:hover { transform: none; }
}
@media (prefers-reduced-motion: reduce) { .trk-step, .trk-dot { transition: none; } }
