/*
 * UruShop Engraving: the product-page panel and the "Check your engraving" dialog.
 *
 * The markup is printed by UruShop_Engraving_Frontend::panel_html() and filled by engraving-panel.js.
 * Class names are BEM under .urushop-engraving. The design is the approved mock-up (design page,
 * Product tab, kit.css), rebuilt without its mock frame.
 *
 * Rules this file keeps:
 *  - every control is at least 44px tall and wide to tap; the visible focus ring is a 3px outline on
 *    whatever the keyboard is on (the real inputs are visually transparent, so the ring is drawn on
 *    the label or the box next to them);
 *  - colour is never the only signal: the ticked toggle and the chosen option carry a check mark, an
 *    error is a sentence (with a thicker border), the over-limit counter is bold;
 *  - the preview is a picture: nothing on it takes a pointer, a drag or a selection;
 *  - at 480px and narrower the dialog is a bottom sheet;
 *  - the colours are the shop's tokens, written out here so the file stands on its own.
 */

.urushop-engraving,
.urushop-engraving *,
.urushop-engraving *::before,
.urushop-engraving *::after,
.urushop-engraving-stage,
.urushop-engraving-stage *,
.urushop-engraving-stage *::before,
.urushop-engraving-stage *::after {
  box-sizing: border-box;
}

.urushop-engraving {
  --ue-green: #00a86b;
  --ue-green-dark: #0b7a4f;
  --ue-forest: #1b4332;
  --ue-orange: #ff6b35;
  --ue-ink: #0d0d0d;
  --ue-line: #e8e8e8;
  --ue-muted: #5b6369;
  --ue-soft: #f6f7f5;
  --ue-focus: #1b6ef3;
  --ue-error: #a62b1f;
  --ue-warn: #7a5200;

  /* A full row whether the form is a block, a flex row or a grid. */
  flex: 1 1 100%;
  grid-column: 1 / -1;
  width: 100%;
  max-width: 100%;
  margin: 0 0 16px;
  border: 1.5px solid var(--ue-line);
  border-radius: 10px;
  background: var(--ue-soft);
  color: var(--ue-ink);
  font-size: 14px;
  line-height: 1.5;
  text-align: left;
}

/* The theme's own [hidden] handling cannot be trusted over the display values below. */
.urushop-engraving[hidden],
.urushop-engraving [hidden] {
  display: none !important;
}

/*
 * Where scripts run, the panel (which starts hidden, and which the script reveals) keeps the toggle row's
 * place while it waits, so showing it moves nothing below it (layout shift). It is invisible and takes no
 * focus meanwhile. Where scripts do not run, or the script gave up (data-ready="0"), it takes no room.
 */
@media (scripting: enabled) {
  .urushop-engraving[hidden]:not([data-ready="0"]) {
    display: block !important;
    visibility: hidden;
  }
}

.urushop-engraving p {
  margin: 0;
}

/* -- the toggle row ---------------------------------------------------------------------- */

.urushop-engraving .urushop-engraving__toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  cursor: pointer;
}

/* The real checkbox covers the whole row (so the tap target is the row) and is not drawn. */
.urushop-engraving .urushop-engraving__check {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.urushop-engraving .urushop-engraving__box {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid #7d868b;
  border-radius: 4px;
  background: #fff;
}

.urushop-engraving .urushop-engraving__check:checked ~ .urushop-engraving__box {
  border-color: var(--ue-green-dark);
  background: var(--ue-green);
}

.urushop-engraving .urushop-engraving__check:checked ~ .urushop-engraving__box::after {
  content: "";
  width: 6px;
  height: 11px;
  margin-top: -2px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.urushop-engraving .urushop-engraving__check:focus-visible ~ .urushop-engraving__box {
  outline: 3px solid var(--ue-focus);
  outline-offset: 2px;
}

.urushop-engraving .urushop-engraving__title {
  font-weight: 700;
}

.urushop-engraving .urushop-engraving__fee {
  margin-left: auto;
  color: var(--ue-forest);
  font-weight: 700;
  white-space: nowrap;
}

/* -- the body ---------------------------------------------------------------------------- */

.urushop-engraving .urushop-engraving__body {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
}

.urushop-engraving .urushop-engraving__figure {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.urushop-engraving .urushop-engraving__guide {
  color: var(--ue-muted);
  font-size: 12px;
  line-height: 1.45;
}

/*
 * The preview: a picture with the wording laid over it. Nothing on it is interactive.
 *
 * It is drawn in two places by the same script: the panel's own picture (inside .urushop-engraving) and, on a wide screen,
 * the box laid over the product photo (.urushop-engraving-stage, outside the panel: see the gallery section at the end).
 * Every rule of the picture therefore has a second selector for the stage; the stage's own extras are in the gallery section.
 */
.urushop-engraving .urushop-engraving__preview,
.urushop-engraving-stage .urushop-engraving__preview {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  isolation: isolate;
  border-radius: 8px;
  background: #fff;
  cursor: default;
  touch-action: auto;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.urushop-engraving .urushop-engraving__photo,
.urushop-engraving-stage .urushop-engraving__photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

.urushop-engraving .urushop-engraving__zone,
.urushop-engraving-stage .urushop-engraving__zone {
  position: absolute;
  display: block;
  pointer-events: none;
}

.urushop-engraving .urushop-engraving__text,
.urushop-engraving-stage .urushop-engraving__text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.12;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.urushop-engraving .urushop-engraving__text span,
.urushop-engraving-stage .urushop-engraving__text span {
  display: block;
}

/* What the laser leaves: a black mark on bare steel, bare steel showing where paint was removed. */
.urushop-engraving .urushop-engraving__preview[data-look="dark"] .urushop-engraving__text,
.urushop-engraving-stage .urushop-engraving__preview[data-look="dark"] .urushop-engraving__text {
  color: #23272b;
  opacity: 0.8;
  mix-blend-mode: multiply;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.55);
}

.urushop-engraving .urushop-engraving__preview[data-look="light"] .urushop-engraving__text,
.urushop-engraving-stage .urushop-engraving__preview[data-look="light"] .urushop-engraving__text {
  color: #dfe2e6;
  opacity: 0.94;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.55), 0 1px 1px rgba(0, 0, 0, 0.65);
}

.urushop-engraving .urushop-engraving__preview[data-look="grey"] .urushop-engraving__text,
.urushop-engraving-stage .urushop-engraving__preview[data-look="grey"] .urushop-engraving__text {
  color: #6f767c;
  opacity: 0.92;
  mix-blend-mode: multiply;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.35);
}

/* -- groups of options: positions and fonts ---------------------------------------------- */

.urushop-engraving .urushop-engraving__group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.urushop-engraving .urushop-engraving__group legend {
  margin-bottom: 4px;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
}

.urushop-engraving .urushop-engraving__options {
  display: grid;
  gap: 6px;
}

.urushop-engraving .urushop-engraving__options--positions {
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
}

.urushop-engraving .urushop-engraving__options--fonts {
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
}

.urushop-engraving .urushop-engraving__option {
  position: relative;
  display: block;
}

/* The real radio covers the option (the tap target) and is not drawn; the label next to it is. */
.urushop-engraving .urushop-engraving__option input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.urushop-engraving .urushop-engraving__option label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 22px;
  border: 1.5px solid #c9ced1;
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.urushop-engraving .urushop-engraving__option--font label {
  flex-direction: column;
  gap: 2px;
  padding: 6px 4px;
  line-height: 1.15;
}

.urushop-engraving .urushop-engraving__option input:checked + label {
  border-color: var(--ue-green-dark);
  background: #f2fbf7;
  box-shadow: 0 0 0 2px #bfeedb;
}

/* A check mark as well as the colour. */
.urushop-engraving .urushop-engraving__option input:checked + label::after {
  content: "\2713";
  position: absolute;
  top: 2px;
  right: 6px;
  color: var(--ue-green-dark);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.urushop-engraving .urushop-engraving__option input:focus-visible + label {
  outline: 3px solid var(--ue-focus);
  outline-offset: 2px;
}

.urushop-engraving .urushop-engraving__sample {
  display: block;
  max-width: 100%;
  padding: 0 2px;
  overflow: hidden;
  font-size: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.urushop-engraving .urushop-engraving__font-name {
  color: var(--ue-muted);
  font-size: 11px;
  font-weight: 600;
}

.urushop-engraving .urushop-engraving__hint {
  margin-top: 6px;
  color: var(--ue-muted);
  font-size: 12px;
  line-height: 1.45;
}

/* -- the text lines ---------------------------------------------------------------------- */

.urushop-engraving .urushop-engraving__line label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 700;
}

.urushop-engraving .urushop-engraving__input {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1.5px solid #b9c0c4;
  border-radius: 8px;
  background: #fff;
  color: var(--ue-ink);
  font-size: 16px;
  line-height: 1.3;
}

.urushop-engraving .urushop-engraving__input[aria-invalid="true"] {
  border: 2.5px solid #c0392b;
}

.urushop-engraving .urushop-engraving__input:focus-visible,
.urushop-engraving .urushop-engraving__btn:focus-visible,
.urushop-engraving .urushop-engraving__close:focus-visible {
  outline: 3px solid var(--ue-focus);
  outline-offset: 2px;
}

.urushop-engraving .urushop-engraving__count {
  margin-top: 2px;
  color: var(--ue-muted);
  font-size: 11.5px;
  text-align: right;
}

.urushop-engraving .urushop-engraving__count.is-over {
  color: var(--ue-error);
  font-weight: 700;
}

.urushop-engraving .urushop-engraving__error {
  min-height: 1.3em;
  color: var(--ue-error);
  font-size: 12.5px;
  font-weight: 600;
}

.urushop-engraving .urushop-engraving__error:empty {
  display: none;
}

.urushop-engraving .urushop-engraving__small {
  padding: 6px 8px;
  border: 1px solid #f0d58a;
  border-radius: 6px;
  background: #fff6df;
  color: var(--ue-warn);
  font-size: 12.5px;
}

/*
 * The rules sit between the position choice and Line 1 (GitHub issue 209, LEG-5): the shopper reads them before typing,
 * and they are not under the keyboard when Line 1 takes focus. The block was five short paragraphs and has held one line
 * since notice version 2026-10-17-draft-5 (the grid gap is for a block that may hold more than one again); it has a little
 * air on both sides so the "Line 1" label under it is not read as its last line.
 */
.urushop-engraving .urushop-engraving__rules {
  display: grid;
  gap: 6px;
  margin: 2px 0 4px;
  padding: 2px 0 2px 9px;
  border-left: 3px solid #c9ced1;
  color: var(--ue-muted);
  font-size: 12px;
  line-height: 1.45;
}

.urushop-engraving .urushop-engraving__notice {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--ue-line);
  border-radius: 8px;
  background: #fff;
  color: #3d4448;
  font-size: 12px;
  line-height: 1.45;
}

.urushop-engraving .urushop-engraving__delivery {
  color: var(--ue-muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.urushop-engraving .urushop-engraving__total {
  color: var(--ue-forest);
  font-size: 13px;
  font-weight: 600;
}

.urushop-engraving .urushop-engraving__total:empty {
  display: none;
}

/* -- the check dialog -------------------------------------------------------------------- */

.urushop-engraving .urushop-engraving__dialog {
  width: min(620px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100vh - 24px);
  max-height: min(94dvh, 860px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
  color: var(--ue-ink);
  font-size: 14px;
  line-height: 1.5;
  text-align: left;
}

.urushop-engraving .urushop-engraving__dialog[open] {
  display: flex;
  flex-direction: column;
}

.urushop-engraving .urushop-engraving__dialog::backdrop {
  background: rgba(8, 12, 14, 0.62);
}

html:has(dialog.urushop-engraving__dialog[open]) {
  overflow: hidden;
}

@media (prefers-reduced-motion: no-preference) {
  .urushop-engraving .urushop-engraving__dialog[open] {
    animation: urushop-engraving-in 0.16s ease-out;
  }

  @keyframes urushop-engraving-in {
    from {
      opacity: 0;
      transform: translateY(14px);
    }
  }
}

.urushop-engraving .urushop-engraving__dialog p {
  margin: 0;
}

.urushop-engraving .urushop-engraving__dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--ue-line);
}

.urushop-engraving .urushop-engraving__dialog-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
}

.urushop-engraving .urushop-engraving__dialog-title:focus {
  outline: 0;
}

.urushop-engraving .urushop-engraving__close {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ue-ink);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.urushop-engraving .urushop-engraving__dialog-body {
  display: grid;
  flex: 1 1 auto;
  align-content: start;
  gap: 12px;
  min-height: 0;
  padding: 12px 14px;
  overflow: auto;
}

.urushop-engraving .urushop-engraving__dialog-main {
  display: grid;
  gap: 12px;
}

@media (min-width: 540px) {
  .urushop-engraving .urushop-engraving__dialog-main {
    grid-template-columns: minmax(0, 280px) minmax(0, 1fr);
    align-items: start;
    gap: 18px;
  }
}

.urushop-engraving .urushop-engraving__dialog-figure {
  width: min(100%, 300px);
  margin: 0 auto;
}

.urushop-engraving .urushop-engraving__dialog-info {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.urushop-engraving .urushop-engraving__wording-block {
  display: grid;
  gap: 4px;
}

.urushop-engraving .urushop-engraving__label {
  color: var(--ue-muted);
  font-size: 11px;
  font-weight: 700;
}

.urushop-engraving .urushop-engraving__wording {
  padding: 8px 12px;
  border: 1.5px solid var(--ue-line);
  border-radius: 8px;
  background: var(--ue-soft);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.urushop-engraving .urushop-engraving__meta {
  color: var(--ue-muted);
  font-size: 12.5px;
}

.urushop-engraving .urushop-engraving__rows {
  display: grid;
  gap: 3px;
  font-size: 14px;
}

.urushop-engraving .urushop-engraving__rows > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.urushop-engraving .urushop-engraving__rows-total {
  margin-top: 2px;
  padding-top: 5px;
  border-top: 1px solid var(--ue-line);
  font-weight: 700;
}

.urushop-engraving .urushop-engraving__dialog-notes {
  display: grid;
  gap: 6px;
  color: #3d4448;
  font-size: 12.5px;
  line-height: 1.45;
}

.urushop-engraving .urushop-engraving__strong {
  color: #1b1f22;
  font-weight: 600;
}

.urushop-engraving .urushop-engraving__dialog-foot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--ue-line);
  background: #fff;
}

/*
 * The new total, pinned above the buttons (GitHub issue 212). engraving-panel.js moves the total's row (the one element, not a
 * copy) from the end of the rows into the footer when the dialog is one column or too short for two (PIN_QUERY there), so it is
 * on screen with the buttons whatever scrolls above; otherwise it stays in the rows, and none of this applies. It is chosen by
 * where the row is, not by a media query, so the stylesheet cannot disagree with the script. The footer's own top border and
 * gap separate it from the buttons, so the row drops the rule it has between the rows, and it spans both columns of a wide
 * footer.
 */
.urushop-engraving .urushop-engraving__dialog-foot > .urushop-engraving__rows-total {
  display: flex;
  grid-column: 1 / -1;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 0;
  border-top: 0;
  font-size: 17px;
  line-height: 1.3;
}

/*
 * The row in the footer is one more line that does not scroll. On a sheet so short that the head and the footer together are
 * taller than it (about 260 px tall or less on a phone sheet: a phone on its side at 150 % page zoom), the dialog's
 * overflow: hidden would cut the lower button off with nothing to bring it back (a wheel or a swipe cannot scroll a hidden
 * box). So while the total is in the footer the dialog scrolls as a whole instead, and only then: when everything fits there
 * is no overflow and no scroll bar, and with the total in the rows the dialog is exactly what it was.
 */
.urushop-engraving .urushop-engraving__dialog:has(> .urushop-engraving__dialog-foot > .urushop-engraving__rows-total) {
  overflow-x: hidden;
  overflow-y: auto;
}

.urushop-engraving .urushop-engraving__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
}

.urushop-engraving .urushop-engraving__btn--go {
  background: var(--ue-orange);
  color: var(--ue-ink);
}

.urushop-engraving .urushop-engraving__btn--ghost {
  border-color: #9aa2a6;
  background: #fff;
  color: var(--ue-ink);
}

/* A bottom sheet on a phone. */
@media (max-width: 480px) {
  .urushop-engraving .urushop-engraving__dialog {
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    margin: auto auto 0;
    border-radius: 16px 16px 0 0;
  }

  .urushop-engraving .urushop-engraving__dialog-foot {
    grid-template-columns: 1fr;
  }

  .urushop-engraving .urushop-engraving__dialog-figure {
    width: min(100%, 220px);
  }
}

/* -- the gallery: the preview in the product photo's slot (GitHub issue 211) ------------------ */

/*
 * engraving-panel.js lays .urushop-engraving-stage over the photo of the gallery slide that is on show, while engraving is
 * ticked on a wide screen. It is position: absolute, so the slide keeps the height of its own photo and nothing on the page
 * moves. The slide gets .urushop-engraving-swapped and its own children (the photo's link, flexslider's and jquery.zoom's
 * layers) are hidden with visibility, never removed or resized, so smoothHeight keeps its number and unticking puts back
 * exactly what was there. The gallery gets .urushop-engraving-showing while that slide is on show: the magnifier, which
 * opens the lightbox on the photo that is hidden, is hidden too. Nothing in the stage takes a pointer, so a click or a tap
 * goes to the slide as it would on the bare photo (the lightbox opens from a link and from the magnifier, both hidden).
 * No z-index: the box is the last thing in the slide, so it paints over the photo and the zoom layer in document order and does
 * not climb over the theme's badges and the magnifier's neighbours.
 * !important only where the theme's and WooCommerce's gallery rules (width: 100% and height: auto on every img, a shadow,
 * a margin) would otherwise change the geometry the slot percentages depend on.
 */
.urushop-engraving-stage {
  visibility: hidden;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fff;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.urushop-engraving-stage .urushop-engraving__preview {
  flex: none;
  width: 100%;
  margin: 0;
  border-radius: 0;
}

.urushop-engraving-stage .urushop-engraving__photo {
  position: absolute !important;
  inset: 0 !important;
  display: block !important;
  width: 100% !important;
  max-width: none !important;
  height: 100% !important;
  max-height: none !important;
  margin: 0 !important;
  border: 0 !important;
  box-shadow: none !important;
  object-fit: contain !important;
}

.urushop-engraving-swapped {
  position: relative !important;
}

.urushop-engraving-swapped > :not(.urushop-engraving-stage) {
  visibility: hidden !important;
}

.urushop-engraving-swapped > .urushop-engraving-stage {
  visibility: visible;
}

.urushop-engraving-showing .woocommerce-product-gallery__trigger {
  visibility: hidden !important;
}

@media (prefers-reduced-motion: no-preference) {
  /* The preview fades in over the photo, which goes only when the fade is over. Restoring is at once. */
  .urushop-engraving-swapped > .urushop-engraving-stage {
    animation: urushop-engraving-stage-in 0.18s ease-out;
  }

  .urushop-engraving-swapped > :not(.urushop-engraving-stage) {
    transition: visibility 0s linear 0.18s;
  }

  @keyframes urushop-engraving-stage-in {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }
}

/*
 * The panel's own picture gives way while the gallery holds the preview (data-preview="gallery", set by the script in the same
 * moment the shopper's tick opens the panel, so the fields below it never move afterwards); its note under it stays: it is the
 * guide-only statement that belongs beside the preview, and at this width the gallery is beside the panel. The note is then a
 * plain line of the panel, not a narrow centred block that used to sit under the picture. Only the panel's own figure: the
 * dialog has its own.
 */
.urushop-engraving[data-preview="gallery"] .urushop-engraving__body > .urushop-engraving__figure > .urushop-engraving__preview {
  display: none;
}

.urushop-engraving[data-preview="gallery"] .urushop-engraving__body > .urushop-engraving__figure {
  max-width: none;
  margin: 0;
}
