/* ============================================================
   Affhaat v38 - variant swatches, mobile card tables, PDP polish
   ------------------------------------------------------------
   Loaded AFTER the theme stylesheets so it can override them.
   Every rule is scoped, so nothing here can affect the admin
   accounting screens' desktop layout.
   ============================================================ */

/* ------------------------------------------------------------
   1. PDP VARIANT SWATCHES  (Color / Size / ...)
   ------------------------------------------------------------
   Replaces the single <select> that could only express ONE option.
   Each group is its own row; a colour group paints a dot, a size
   group renders a text chip.
   ------------------------------------------------------------ */
.pdp-variants {
  padding: 14px 16px;
  margin: 14px 0;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
}

.pdp-option-group + .pdp-option-group {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed #e5e7eb;
}

.pdp-option-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 8px;
  font-size: .9rem;
}

.pdp-option-label {
  color: #64748b;
  font-weight: 600;
}

.pdp-option-chosen {
  color: #0f172a;
  font-weight: 700;
}

.pdp-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pdp-swatch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;              /* comfortable 44px-ish tap target */
  padding: 7px 13px;
  border: 1.5px solid #d7dde5;
  border-radius: 9px;
  background: #fff;
  color: #1f2937;
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.pdp-swatch:hover:not(:disabled) {
  border-color: #94a3b8;
  background: #f8fafc;
}

.pdp-swatch:active:not(:disabled) { transform: scale(.97); }

.pdp-swatch:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.pdp-swatch.is-selected {
  border-color: #0f172a;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .18);
}

.pdp-swatch.is-selected .pdp-swatch-dot {
  box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px #0f172a;
}

/* A value that cannot be combined with the current selection. */
.pdp-swatch.is-unavailable,
.pdp-swatch:disabled {
  opacity: .38;
  cursor: not-allowed;
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.pdp-swatch-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--swatch, #cbd5e1);
  border: 1px solid rgba(15, 23, 42, .22);
  flex: 0 0 auto;
}

.pdp-swatch.is-color .pdp-swatch-text { font-weight: 600; }

.pdp-variant-warning {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: .85rem;
  font-weight: 600;
}

.pdp-buy-box.is-unavailable {
  opacity: .55;
  pointer-events: none;
}

/* Live price/stock/SKU strip under the swatches. */
.pdp-variants .variant-live-info {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #eef2f7;
}

.pdp-variants .variant-live-info > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.pdp-variants .variant-live-info span {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #94a3b8;
  font-weight: 700;
}

.pdp-variants .variant-live-info strong {
  font-size: .9rem;
  color: #0f172a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .pdp-variants { padding: 12px; }
  .pdp-swatch { min-height: 42px; padding: 8px 12px; font-size: .85rem; }
  .pdp-variants .variant-live-info { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ------------------------------------------------------------
   2. MOBILE CARD VIEW FOR TABLES
   ------------------------------------------------------------
   Wide data tables used to force a horizontal scroll on a phone:
   the customer saw the first two columns and had to drag sideways
   to read a price. Below 720px every table marked with
   `.nx-table-cards` (or the storefront order/cart tables) becomes
   a stack of labelled cards instead.

   The label comes from each cell's `data-label` attribute, which
   the views now emit. A table without data-labels still degrades
   gracefully: the cell simply shows its value.
   ------------------------------------------------------------ */
@media (max-width: 720px) {
  .nx-table-cards,
  .table-wrap > table.nx-table-cards,
  table.nx-table-cards {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
  }

  .nx-table-cards thead {
    /* The header row is redundant once every cell is labelled. */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  .nx-table-cards tbody,
  .nx-table-cards tr,
  .nx-table-cards td {
    display: block;
    width: 100%;
  }

  .nx-table-cards tr {
    margin: 0 0 12px;
    padding: 4px 0;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
    overflow: hidden;
  }

  .nx-table-cards tr:last-child { margin-bottom: 0; }

  .nx-table-cards td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 14px;
    border: 0;
    border-bottom: 1px solid #f1f5f9;
    text-align: right;
    font-size: .88rem;
    white-space: normal;
    word-break: break-word;
  }

  .nx-table-cards td:last-child { border-bottom: 0; }

  .nx-table-cards td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    text-align: left;
    font-size: .74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #94a3b8;
    padding-top: 2px;
  }

  /* A cell with no label (actions, thumbnails) spans the full width. */
  .nx-table-cards td:not([data-label])::before { content: none; }
  .nx-table-cards td:not([data-label]) { justify-content: flex-end; }

  /* The first cell of a card is its title: bigger, left aligned. */
  .nx-table-cards td.nx-card-title {
    display: block;
    text-align: left;
    font-size: .95rem;
    font-weight: 700;
    color: #0f172a;
    background: #f8fafc;
    padding: 11px 14px;
  }
  .nx-table-cards td.nx-card-title::before { content: none; }

  /* Kill the horizontal scroll container once the table is a card list. */
  .table-wrap:has(> .nx-table-cards) {
    overflow-x: visible;
    border: 0;
    background: transparent;
  }
}

/* ------------------------------------------------------------
   3. PDP / CART / CHECKOUT mobile polish
   ------------------------------------------------------------ */
@media (max-width: 480px) {
  /* The PDP buy buttons must never overflow a 320px screen. */
  .pdp-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .pdp-actions .btn-buy { width: 100%; }

  .pdp-title { font-size: 1.15rem; line-height: 1.35; }

  .pdp-price-box { flex-wrap: wrap; }

  /* Payment options: one per row, full width, easy to tap. */
  .nx-pay-grid.payment-methods {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }
  .payment-option {
    min-height: 52px;
    padding: 12px 14px;
  }
}

/* ------------------------------------------------------------
   4. AUTH (signup / login) - 320px safety
   ------------------------------------------------------------
   The signup card used a fixed 440px max-width with 12px side
   padding, and the phone row's prefix + input could not shrink
   below their content width, so at 320px the card pushed the page
   wider than the viewport. Everything below is now fluid.
   ------------------------------------------------------------ */
.auth-page {
  width: 100%;
  max-width: 440px;
  margin: 24px auto 40px;
  padding: 0 12px;
  box-sizing: border-box;
}

.auth-card { width: 100%; box-sizing: border-box; }

.auth-form,
.auth-card-head,
.auth-footer-links { box-sizing: border-box; }

.auth-form .form-control,
.auth-form input,
.auth-form select,
.auth-form textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-size: 16px; /* stops iOS Safari from zooming on focus */
}

.phone-row {
  display: flex;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.phone-prefix {
  flex: 0 0 auto;
  padding: 0 10px;
  font-size: .9rem;
}

.phone-input {
  flex: 1 1 auto;
  min-width: 0;   /* the actual fix: let the input shrink below its size */
}

.auth-footer-links {
  flex-wrap: wrap;
  row-gap: 6px;
}

@media (max-width: 360px) {
  .auth-page { padding: 0 10px; margin-top: 14px; }
  .auth-form { padding: 16px 14px; }
  .auth-card-head { padding: 16px 14px; }
  .auth-card-head h1 { font-size: 1.1rem; }
  .auth-footer-links { padding: 0 14px 16px; font-size: .82rem; }
  .phone-prefix { padding: 0 8px; font-size: .85rem; }
}

/* ------------------------------------------------------------
   5. Images: reserve space so lazy loading never shifts layout
   ------------------------------------------------------------ */
.pc-img-wrap img,
.pdp-main-img,
.pdp-thumb,
.pdp-similar-thumb img {
  max-width: 100%;
  height: auto;
}

.pc-img-wrap {
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #f1f5f9;
}

.pc-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ------------------------------------------------------------
   6. ADMIN - option group editor (v38 variant matrix)
   ------------------------------------------------------------ */
.nx-optgroups {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid #dbe3ec;
  border-radius: 12px;
  background: #f8fafc;
}

.nx-optgroups-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
  font-size: .9rem;
}

.nx-optgroups-head .muted,
.nx-optgroups-actions .muted {
  color: #64748b;
  font-size: .8rem;
}

.nx-optgroup-row {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.nx-optgroup-row .form-control { margin: 0; }

.nx-optgroup-remove {
  width: 34px;
  height: 34px;
  padding: 0;
  line-height: 1;
  font-size: 1.1rem;
}

.nx-optgroups-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

@media (max-width: 720px) {
  .nx-optgroup-row { grid-template-columns: 1fr 40px; }
  .nx-optgroup-row input:nth-child(2) { grid-column: 1 / -1; }
}

/* ============================================================
   Affhaat PDP layout polish — 3 columns + clear variant controls
   Scoped to the storefront product page only.
   ============================================================ */
.pdp-grid {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr) minmax(205px, .62fr) !important;
  align-items: start !important;
  gap: 18px !important;
  padding: 18px !important;
}
.pdp-gallery { min-width: 0; }
.pdp-info {
  min-width: 0;
  display: flex !important;
  flex-direction: column !important;
  gap: 10px !important;
}
.pdp-sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: start;
}
.pdp-sidebar-actions,
.pdp-sidebar-share {
  min-width: 0;
  padding: 12px;
  background: #fff;
  border: 1px solid #e5eaf1;
  border-radius: 14px;
  box-shadow: 0 3px 12px rgba(15, 36, 57, .045);
}
.pdp-sidebar-actions > div:first-child {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px !important;
  margin: 0 0 10px !important;
}
.pdp-sidebar-actions form { min-width: 0; margin: 0; }
.pdp-sidebar-actions .btn-wish,
.pdp-sidebar-actions .btn-compare {
  width: 100%;
  min-height: 38px;
  padding: 8px 6px !important;
  font-size: .78rem !important;
  white-space: nowrap;
}
.pdp-sidebar .pdp-trust {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 8px !important;
  margin: 0 !important;
}
.pdp-sidebar .pdp-trust-item {
  display: flex;
  align-items: flex-start;
  min-width: 0;
  padding: 9px 8px !important;
  gap: 8px !important;
  background: #f8fafc;
  border: 1px solid #edf1f6;
  border-radius: 10px !important;
}
.pdp-sidebar .pdp-trust-item > span { flex: 0 0 22px; text-align: center; }
.pdp-sidebar .pdp-trust-item div { min-width: 0; font-size: .75rem !important; line-height: 1.35 !important; }
.pdp-sidebar .pdp-trust-item strong { display: block; font-size: .79rem !important; line-height: 1.3; margin-bottom: 2px; }
.pdp-sidebar .pdp-share { margin: 0 !important; }
.pdp-sidebar .pdp-share-label {
  display: block;
  margin-bottom: 9px !important;
  color: #334155;
  font-size: .8rem !important;
  font-weight: 800;
  text-transform: none;
}
.pdp-sidebar .pdp-share-btns {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px !important;
}
.pdp-sidebar .pdp-share-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 5px !important;
  min-width: 0 !important;
  min-height: 36px !important;
  padding: 7px 5px !important;
  border-radius: 9px !important;
  font-size: .72rem !important;
  white-space: nowrap;
}
.pdp-sidebar .pdp-share-btn span { overflow: hidden; text-overflow: ellipsis; }
.pdp-sidebar .pdp-share-btn svg { width: 14px !important; height: 14px !important; flex: 0 0 14px; }

/* Variant groups must stack vertically. The older theme made the whole
   variants card a flex row, causing Size and Color choices to run together. */
.pdp-info .pdp-variants {
  display: block !important;
  width: 100%;
  min-width: 0;
  padding: 13px !important;
  margin: 3px 0 !important;
  border: 1px solid #e3e8ef !important;
  border-radius: 13px !important;
  background: #fff !important;
  box-sizing: border-box;
}
.pdp-info .pdp-option-group { display: block !important; width: 100%; min-width: 0; }
.pdp-info .pdp-option-group + .pdp-option-group {
  margin-top: 13px !important;
  padding-top: 12px !important;
  border-top: 1px solid #eef1f5 !important;
}
.pdp-info .pdp-option-head { margin-bottom: 8px !important; gap: 5px; flex-wrap: wrap; }
.pdp-info .pdp-swatches {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center;
  gap: 7px !important;
  width: 100%;
}
.pdp-info .pdp-swatch {
  display: inline-flex !important;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-height: 38px !important;
  max-width: 100%;
  padding: 7px 11px !important;
  border: 1px solid #d5dce6 !important;
  border-radius: 9px !important;
  background: #fff !important;
  color: #1e293b !important;
  box-shadow: none !important;
  font-size: .82rem !important;
  line-height: 1.2;
}
/* Size and non-colour options use clear radio-like chips. */
.pdp-info .pdp-swatch:not(.is-color).is-selected {
  border: 2px solid #0f172a !important;
  background: #f1f5f9 !important;
  color: #0f172a !important;
  padding: 6px 10px !important;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, .06) !important;
}
/* Colour options show the actual swatch plus the colour name. */
.pdp-info .pdp-swatch.is-color { gap: 8px; }
.pdp-info .pdp-swatch.is-color .pdp-swatch-dot {
  width: 19px !important;
  height: 19px !important;
  background: var(--swatch, #cbd5e1) !important;
  border: 1px solid rgba(15, 23, 42, .24) !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
}
.pdp-info .pdp-swatch.is-color.is-selected {
  border: 2px solid #0f172a !important;
  background: #f8fafc !important;
  color: #0f172a !important;
  padding: 6px 10px !important;
}
.pdp-info .pdp-swatch.is-color.is-selected .pdp-swatch-dot {
  outline: 2px solid #fff;
  box-shadow: 0 0 0 2px #0f172a !important;
}
.pdp-info .pdp-swatch.is-unavailable,
.pdp-info .pdp-swatch:disabled { opacity: .38 !important; }
.pdp-info .variant-live-info { margin-top: 12px !important; }

@media (max-width: 1100px) {
  .pdp-grid {
    grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr) !important;
    gap: 16px !important;
  }
  .pdp-sidebar { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .pdp-sidebar .pdp-trust { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}
@media (max-width: 720px) {
  .pdp-grid { grid-template-columns: minmax(0, 1fr) !important; padding: 11px !important; gap: 13px !important; }
  .pdp-sidebar { grid-column: auto; display: flex; }
  .pdp-sidebar .pdp-trust { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .pdp-info .pdp-variants { padding: 11px !important; }
  .pdp-info .pdp-swatch { min-height: 40px !important; font-size: .82rem !important; }
}


/* Product option selectors: clear, clickable Color swatches and Size chips. */
.pdp-variants .pdp-option-group { min-width: 0; }
.pdp-variants .pdp-option-head { gap: 6px; flex-wrap: wrap; }
.pdp-variants .pdp-option-label { font-size: .82rem; letter-spacing: .01em; }
.pdp-variants .pdp-option-chosen { font-size: .88rem; }
.pdp-variants .pdp-swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pdp-variants .pdp-swatch:not(.is-color) {
  min-width: 48px; min-height: 42px; justify-content: center; padding: 9px 14px;
  border: 1.5px solid #d6dee8; border-radius: 9px; background: #fff;
  color: #172033; font-weight: 750; box-shadow: 0 1px 2px rgba(15,23,42,.035);
}
.pdp-variants .pdp-swatch:not(.is-color).is-selected {
  border-color: #172033; background: #172033; color: #fff;
  box-shadow: 0 0 0 2px rgba(23,32,51,.12);
}
.pdp-variants .pdp-swatch.is-color {
  min-height: 42px; padding: 7px 11px; border-radius: 999px;
  border: 1.5px solid #d6dee8; background: #fff; color: #253047;
}
.pdp-variants .pdp-swatch.is-color .pdp-swatch-dot {
  width: 21px; height: 21px; border: 1px solid rgba(15,23,42,.25);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.pdp-variants .pdp-swatch.is-color.is-selected {
  color: #172033; background: #f8fafc; border-color: #172033;
  box-shadow: 0 0 0 2px rgba(23,32,51,.12);
}
.pdp-variants .pdp-swatch.is-color.is-selected .pdp-swatch-dot {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #172033;
}
.pdp-variants .pdp-swatch.is-unavailable,
.pdp-variants .pdp-swatch:disabled { opacity: .35; }
@media (max-width: 480px) {
  .pdp-variants .pdp-swatch:not(.is-color) { min-width: 44px; min-height: 40px; padding: 8px 11px; }
  .pdp-variants .pdp-swatch.is-color { min-height: 40px; padding: 6px 9px; }
}
