/* =============================================================================
   Storefront components.

   Vendor storefront tabs, commerce interactions (add to cart, mini cart, quick
   view), product-detail additions, checkout progress and the mobile navigation
   surfaces.

   Kept in its own file rather than appended to theme.css so the components
   added to satisfy the PRD are reviewable in isolation and can be loaded after
   WooCommerce/Dokan styles without touching the base cascade. Uses the existing
   --tv-* token set throughout, so it inherits the theme's palette.
   ========================================================================== */

/* --- Vendor storefront: rating -------------------------------------------- */

.tv-store-rating {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 13px;
  color: var(--tv-muted);
}

.tv-store-rating--empty {
  opacity: 0.75;
}

.tv-stars {
  position: relative;
  display: inline-block;
  width: 82px;
  height: 14px;
  background: currentColor;
  opacity: 0.25;
}

.tv-stars-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: #fbbf24;
  border-radius: 2px;
  opacity: 1;
}

.tv-store-rating-value {
  color: var(--tv-text);
}

.tv-store-header-extras {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.tv-store-save-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 11px;
  font-weight: 800;
}

/* --- Vendor storefront: category chips + tab panels ----------------------- */

.tv-store-cat-filter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0 6px;
}

.tv-store-cat-chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--tv-border);
  background: var(--tv-bg-alt);
  color: var(--tv-muted);
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.tv-store-cat-chip:hover {
  color: var(--tv-text);
  border-color: #c8102e;
}

.tv-store-cat-chip.is-active {
  background: #c8102e;
  border-color: #c8102e;
  color: #fff;
}

.tv-store-tab-panel {
  margin-top: 18px;
}

.tv-store-tab-title {
  margin-top: 0;
}

.tv-store-bio--empty {
  color: var(--tv-muted);
}

.tv-store-about-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 14px 0;
}

.tv-store-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 18px 0 0;
}

.tv-store-fact dt {
  color: var(--tv-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tv-store-fact dd {
  margin: 4px 0 0;
  font-weight: 700;
}

.tv-store-review-list {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  gap: 14px;
}

.tv-store-review {
  padding: 14px;
  border: 1px solid var(--tv-border);
  border-radius: 12px;
  background: var(--tv-bg-alt);
}

.tv-store-review-head {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.tv-store-review-author {
  font-weight: 800;
}

.tv-store-review-product {
  display: inline-block;
  margin: 6px 0;
  font-size: 13px;
  color: var(--tv-muted);
}

.tv-store-review-date {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: var(--tv-muted);
}

/* --- Product card: add to cart + quick view ------------------------------- */

.tv-card-add {
  position: relative;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: #c8102e;
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.2s ease;
}

.tv-card-add:hover {
  filter: brightness(1.12);
}

.tv-card-add:active {
  transform: scale(0.96);
}

.tv-card-add.is-loading {
  opacity: 0.6;
  pointer-events: none;
}

.tv-card-add.is-added {
  background: #16a34a;
}

.tv-quick-view {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translate(-50%, 8px);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--tv-border);
  border-radius: 999px;
  background: rgba(10, 10, 10, 0.86);
  backdrop-filter: blur(6px);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.tv-wc-card:hover .tv-quick-view,
.tv-wc-card:focus-within .tv-quick-view {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

/* Touch devices never hover — keep Quick View permanently reachable. */
@media (hover: none) {
  .tv-quick-view {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
  }
}

/* --- Modal shell ---------------------------------------------------------- */

body.tv-modal-open {
  overflow: hidden;
}

.tv-qv-modal {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.tv-qv-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
}

.tv-qv-panel {
  position: relative;
  z-index: 1;
  width: min(880px, 100%);
  max-height: 88vh;
  overflow: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #111;
  border: 1px solid var(--tv-border);
  border-radius: 18px;
  animation: tvQvIn 0.22s ease both;
}

@keyframes tvQvIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tv-qv-content {
  display: contents;
}

.tv-qv-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--tv-border);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  cursor: pointer;
}

.tv-qv-media {
  position: relative;
  background: var(--tv-bg-alt);
  min-height: 240px;
}

.tv-qv-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tv-qv-media .tv-pill {
  position: absolute;
  top: 12px;
  left: 12px;
}

.tv-qv-body {
  padding: 26px;
}

.tv-qv-title {
  margin: 0 0 6px;
  font-size: 22px;
}

.tv-qv-vendor {
  margin: 0 0 10px;
  color: var(--tv-muted);
  font-size: 13px;
}

.tv-qv-price {
  font-size: 20px;
  font-weight: 800;
  margin: 12px 0;
}

.tv-qv-excerpt {
  color: var(--tv-muted);
  font-size: 14px;
}

.tv-qv-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.tv-qv-loading {
  grid-column: 1 / -1;
  padding: 60px;
  text-align: center;
  color: var(--tv-muted);
}

@media (max-width: 720px) {
  .tv-qv-panel {
    grid-template-columns: 1fr;
  }
  .tv-qv-media {
    max-height: 38vh;
  }
}

/* --- Mini cart ------------------------------------------------------------ */

.tv-mini-cart {
  position: fixed;
  right: 18px;
  top: 84px;
  z-index: 2900;
  width: min(340px, calc(100vw - 36px));
  padding: 16px;
  border: 1px solid var(--tv-border);
  border-radius: 16px;
  background: #111;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.tv-mini-cart.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.tv-mini-cart-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.tv-mini-cart-tick {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #16a34a;
  color: #fff;
  font-size: 13px;
}

.tv-mini-cart-close {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--tv-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.tv-mini-cart-item {
  display: flex;
  gap: 12px;
  align-items: center;
}

.tv-mini-cart-item img {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
}

.tv-mini-cart-name {
  margin: 0;
  font-weight: 700;
  font-size: 14px;
}

.tv-mini-cart-total {
  margin: 4px 0 0;
  color: var(--tv-muted);
  font-size: 12px;
}

.tv-mini-cart-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

@media (max-width: 640px) {
  .tv-mini-cart {
    right: 12px;
    left: 12px;
    width: auto;
    top: 72px;
  }
}

/* --- Toast ---------------------------------------------------------------- */

.tv-toast-host {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translate(-50%, 12px);
  z-index: 3100;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--tv-border);
  background: #16a34a;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.tv-toast-host.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tv-toast-host.is-error {
  background: #dc2626;
}

/* --- Product detail additions --------------------------------------------- */

.tv-pdp-type {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  flex-wrap: wrap;
}

.tv-pdp-type-note {
  color: var(--tv-muted);
  font-size: 13px;
  font-weight: 600;
}

.tv-vendor-trust {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
  font-size: 12px;
}

.tv-vendor-trust-sep {
  color: var(--tv-muted);
}

.tv-vendor-trust-count {
  color: var(--tv-muted);
  font-weight: 700;
}

.tv-digital-file-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.tv-digital-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--tv-border);
  border-radius: 10px;
  background: var(--tv-bg-alt);
}

.tv-digital-file-name {
  font-weight: 700;
  font-size: 14px;
}

.tv-digital-file .tv-pill {
  margin-left: auto;
}

.tv-digital-note {
  margin: 12px 0 0;
  color: var(--tv-muted);
  font-size: 13px;
}

/* --- Checkout step indicator ---------------------------------------------- */

.tv-checkout-steps {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  flex-wrap: wrap;
}

.tv-checkout-step {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--tv-muted);
  font-weight: 700;
  font-size: 13px;
}

.tv-checkout-step + .tv-checkout-step::before {
  content: "";
  width: 28px;
  height: 2px;
  background: var(--tv-border);
  margin-right: 8px;
}

.tv-checkout-step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--tv-border);
  font-size: 12px;
  transition: background 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

.tv-checkout-step.is-current {
  color: var(--tv-text);
}

.tv-checkout-step.is-current .tv-checkout-step-dot {
  border-color: #c8102e;
  background: #c8102e;
  color: #fff;
}

.tv-checkout-step.is-done .tv-checkout-step-dot {
  border-color: #16a34a;
  background: #16a34a;
  color: transparent;
}

.tv-checkout-step.is-done .tv-checkout-step-dot::after {
  content: "\2713";
  color: #fff;
  font-size: 13px;
}

/* --- Order confirmation ---------------------------------------------------- */

.tv-order-success {
  text-align: center;
  padding: 30px 20px 10px;
}

.tv-order-success-mark {
  width: 84px;
  height: 84px;
  margin: 0 auto 16px;
}

.tv-order-success-mark svg {
  width: 100%;
  height: 100%;
}

.tv-osm-circle {
  stroke: #16a34a;
  stroke-width: 2;
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  animation: tvStroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.tv-osm-check {
  stroke: #16a34a;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: tvStroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.6s forwards;
}

@keyframes tvStroke {
  to { stroke-dashoffset: 0; }
}

.tv-order-success-title {
  margin: 0 0 6px;
  font-size: 24px;
}

.tv-order-success-meta {
  margin: 0 0 18px;
  color: var(--tv-muted);
  font-weight: 700;
}

/* --- Mobile: bottom navigation --------------------------------------------- */

.tv-bottom-nav {
  display: none;
}

@media (max-width: 820px) {
  .tv-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2500;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: rgba(12, 12, 12, 0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--tv-border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .tv-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 9px 4px;
    min-height: 56px;
    border: 0;
    background: none;
    color: var(--tv-muted);
    font-size: 10px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
  }

  .tv-bottom-nav-item svg {
    width: 22px;
    height: 22px;
  }

  .tv-bottom-nav-item.is-active {
    color: #c8102e;
  }

  .tv-bottom-nav-icon {
    position: relative;
    display: inline-flex;
  }

  .tv-bottom-nav-icon .tv-cart-count {
    position: absolute;
    top: -4px;
    right: -8px;
  }

  /* Clear the fixed bar so footer content stays reachable. */
  body {
    padding-bottom: 60px;
  }

  .tv-toast-host {
    bottom: 130px;
  }
}

/* --- Mobile: header collapse + drawer -------------------------------------- */

.tv-menu-btn {
  display: none;
}

@media (max-width: 820px) {
  .tv-menu-btn {
    display: inline-flex;
  }

  /* The drawer carries these links; inline nav would overflow the row. */
  .tv-header .tv-nav {
    display: none;
  }

  .tv-header-actions .tv-btn {
    display: none;
  }

  .tv-header-actions .tv-icon-btn {
    display: inline-flex;
  }
}

.tv-drawer {
  position: fixed;
  inset: 0;
  z-index: 2800;
}

.tv-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.66);
}

.tv-drawer-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(320px, 86vw);
  overflow-y: auto;
  padding: 18px;
  background: #111;
  border-left: 1px solid var(--tv-border);
  animation: tvDrawerIn 0.22s ease both;
}

@keyframes tvDrawerIn {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.tv-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.tv-drawer-title {
  font-weight: 800;
  font-size: 16px;
}

.tv-drawer-nav {
  display: grid;
  gap: 2px;
}

.tv-drawer-link {
  display: block;
  padding: 12px 10px;
  border-radius: 10px;
  color: var(--tv-text);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
}

.tv-drawer-link:hover,
.tv-drawer-link:focus-visible {
  background: var(--tv-bg-alt);
}

.tv-drawer-sub {
  padding-left: 22px;
  font-weight: 600;
  font-size: 14px;
  color: var(--tv-muted);
}

.tv-drawer-label {
  margin: 14px 0 4px;
  padding-left: 10px;
  color: var(--tv-muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* --- Mobile: filter sheet --------------------------------------------------- */

.tv-filters-fab {
  display: none;
}

.tv-filters-sheet-head {
  display: none;
}

@media (max-width: 980px) {
  .tv-filters-fab {
    position: fixed;
    left: 50%;
    bottom: 74px;
    transform: translateX(-50%);
    z-index: 2400;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 20px;
    border: 0;
    border-radius: 999px;
    background: #c8102e;
    color: #fff;
    font-weight: 800;
    font-size: 14px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    cursor: pointer;
  }

  /*
   * The sidebar becomes a bottom sheet rather than stacking above the product
   * grid, which previously forced mobile users to scroll past the whole filter
   * form before reaching a single product.
   */
  .tv-woo-filters {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2850;
    max-height: 82vh;
    overflow-y: auto;
    margin: 0;
    border-radius: 18px 18px 0 0;
    border-top: 1px solid var(--tv-border);
    box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
    transition: transform 0.26s ease;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .tv-woo-filters.tv-filters-sheet-open {
    transform: translateY(0);
  }

  .tv-filters-sheet-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0 12px;
    margin-bottom: 8px;
    background: inherit;
    border-bottom: 1px solid var(--tv-border);
    font-size: 16px;
  }
}

/* --- Reduced motion -------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .tv-osm-circle,
  .tv-osm-check {
    animation: none;
    stroke-dashoffset: 0;
  }

  .tv-drawer-panel,
  .tv-qv-panel {
    animation: none;
  }

  .tv-woo-filters {
    transition: none;
  }
}
