/* =========================================================
   Express (COD) order form — inline card + popup dialog
   One component, two shells. All colors come from theme tokens
   or the block settings exposed as --ec-* custom properties.
   ========================================================= */
.ec-card--popup { display: none; }

.ec-form {
  --ec-h: 46px;
  --ec-field-r: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: var(--ec-form-border-width, 1px) solid var(--ec-form-border, var(--c-primary));
  border-radius: var(--ec-form-radius, 18px);
  background: var(--ec-form-bg, var(--c-bg));
  color: var(--ec-form-text, var(--c-ink));
  box-shadow: 0 var(--ec-form-shadow-y, 12px) var(--ec-form-shadow-blur, 24px) var(--ec-form-shadow, rgba(17, 24, 39, .06));
}

@media (min-width: 768px) {
  .ec-form { padding: 20px; gap: 14px; }
}

/* ---------- Head: title, hint, progress ---------- */
.ec-form__head {
  display: grid;
  gap: 6px;
}

.ec-form__title {
  color: var(--ec-form-text, var(--c-ink));
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
}

.ec-form__hint {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--c-muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.ec-form__hint .icon { color: var(--c-primary); }

.ec-progress {
  position: relative;
  height: 4px;
  margin-top: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--c-line);
}

.ec-progress__bar {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 100%;
  border-radius: inherit;
  background: var(--c-primary);
  transform: scaleX(var(--ec-progress, 0));
  transform-origin: left center;
  transition: transform .3s ease, background-color .3s ease;
}

[dir=rtl] .ec-progress__bar { transform-origin: right center; }
.ec-progress.is-complete .ec-progress__bar { background: var(--c-success); }

/* ---------- Fields ---------- */
.express-checkout-fields {
  display: grid;
  gap: 10px;
}

.express-checkout-field {
  position: relative;
  display: grid;
  gap: 5px;
}

.ec-field__icon {
  position: absolute;
  top: 0;
  inset-inline-start: 0;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: var(--ec-h);
  color: var(--c-subtle);
  pointer-events: none;
  transition: color .16s ease;
}

.ec-field__icon .icon { width: 17px; height: 17px; }

.express-checkout-field:focus-within .ec-field__icon { color: var(--c-primary); }

.ec-form .express-checkout-field input:not([type=hidden]),
.ec-form .express-checkout-field select,
.ec-form .express-checkout-field textarea {
  min-height: var(--ec-h);
  padding-block: 10px;
  border-color: var(--ec-field-border, var(--c-line-strong));
  border-radius: var(--ec-field-r);
  background-color: var(--ec-field-bg, var(--c-bg));
  color: var(--ec-field-text, var(--c-ink));
}

.ec-form .express-checkout-field.has-icon > input,
.ec-form .express-checkout-field.has-icon > select,
.ec-form .express-checkout-field.has-icon > textarea {
  padding-inline-start: 42px;
}

.ec-form .express-checkout-field textarea {
  min-height: 84px;
  padding-top: 12px;
}

.ec-form .express-checkout-field input:focus,
.ec-form .express-checkout-field select:focus,
.ec-form .express-checkout-field textarea:focus {
  border-color: var(--ec-field-focus, var(--c-primary));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ec-field-focus, var(--c-primary)) 14%, transparent);
}

[dir=rtl] .express-checkout-field input[type=tel] {
  direction: rtl;
  text-align: right;
}

/* Valid state — small check at the field end */
.express-checkout-field.is-valid::after {
  content: "";
  position: absolute;
  top: calc(var(--ec-h) / 2 - 9px);
  inset-inline-end: 12px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--c-success) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6 12.5 4 4 8-9' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat;
  pointer-events: none;
  animation: ecPop .2s ease-out;
}

.express-checkout-field.is-valid > select { background-image: none; }

.ec-form .express-checkout-field.is-valid > input,
.ec-form .express-checkout-field.is-valid > select,
.ec-form .express-checkout-field.is-valid > .phone-fieldset {
  padding-inline-end: 40px;
  border-color: color-mix(in srgb, var(--c-success) 45%, var(--c-line-strong));
}

/* Error state */
.express-checkout-field.is-invalid .ec-field__icon { color: var(--c-danger); }

.ec-form .express-checkout-field.is-invalid > input,
.ec-form .express-checkout-field.is-invalid > select,
.ec-form .express-checkout-field.is-invalid > textarea,
.ec-form .express-checkout-field.is-invalid > .phone-fieldset {
  border-color: var(--c-danger);
  background-color: color-mix(in srgb, var(--c-danger) 4%, var(--ec-field-bg, var(--c-bg)));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-danger) 12%, transparent);
}

.express-checkout-field.is-shaking { animation: ecShakeX .36s ease; }

.express-checkout-field .validation-error {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-inline-start: 2px;
  font-size: 12.5px;
  line-height: 1.4;
}

.express-checkout-field .validation-error::before {
  content: "!";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 15px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--c-danger);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.express-checkout-field .validation-error:empty { display: none; }

/* Phone with country code */
.phone-fieldset {
  display: flex;
  align-items: stretch;
  min-height: var(--ec-h, var(--control-h));
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--ec-field-border, var(--c-line-strong));
  border-radius: var(--ec-field-r, var(--r));
  background: var(--ec-field-bg, var(--c-bg));
  transition: border-color .16s ease, box-shadow .16s ease;
}

.phone-fieldset:focus-within {
  border-color: var(--ec-field-focus, var(--c-primary));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ec-field-focus, var(--c-primary)) 14%, transparent);
}

.ec-form .express-checkout-field.has-icon > .phone-fieldset { padding-inline-start: 42px; }

.phone-countries-wrapper {
  position: relative;
  flex: 0 0 auto;
  min-width: 78px;
  padding: 0 10px;
  border-inline-end: 1px solid var(--c-line);
  direction: ltr;
}

.phone-countries-wrapper .phone-code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  height: 100%;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
}

.phone-countries-wrapper .phone-code::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}

.phone-countries-wrapper .phone-select-menu {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100% !important;
  min-height: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  opacity: 0;
  cursor: pointer;
}

.phone-fieldset .phone-number {
  flex: 1;
  min-height: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

/* ---------- Total ---------- */
.ec-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px dashed var(--c-primary-line);
  border-radius: var(--ec-field-r);
  background: var(--c-primary-soft);
  font-size: 14px;
}

.ec-total[hidden] { display: none; }
.ec-total__label { color: var(--c-muted); font-weight: 600; }
.ec-total__value { color: #000; /* total in the order form = black */ font-size: 17px; font-weight: 800; }
.ec-total__value.is-bumped { animation: ecPop .25s ease-out; }

/* ---------- Action row: quantity + submit ---------- */
.ec-form__action-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.ec-form__quantity {
  display: flex;
  flex: 0 0 116px;
  min-width: 0;
}

.ec-form__quantity .product-quantity { width: 100%; margin: 0; }
.ec-form__quantity .product-option-title { display: none; }

.ec-form__quantity .quantity-field {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  min-height: 50px;
  overflow: hidden;
  border: 1px solid var(--c-line-strong);
  border-radius: var(--ec-field-r);
  background: var(--ec-field-bg, var(--c-bg));
}

.ec-form__quantity .quantity-field button {
  width: 34px;
  min-width: 34px;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--c-muted);
}

.ec-form__quantity .quantity-field button:hover { color: var(--c-primary); }

.ec-form__quantity .quantity-input {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 0 !important;
  padding: 0 2px;
  border: 0 !important;
  background: transparent;
  box-shadow: none !important;
  font-weight: 700;
  text-align: center;
}

.ec-form__submit {
  flex: 1 1 0;
  min-width: 0;
  min-height: 50px;
  margin: 0;
  padding: 10px 14px;
  border-color: var(--ec-submit-bg, var(--c-primary)) !important;
  border-radius: var(--ec-submit-radius, 12px) !important;
  background: var(--ec-submit-bg, var(--c-primary)) !important;
  color: var(--ec-submit-text, #fff) !important;
  white-space: normal;
  line-height: 1.25;
}

.ec-form__submit:hover { filter: brightness(.94); }
.ec-form__submit[data-type=loading] { opacity: .85; cursor: progress; }

.ec-form__submit .btn-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.ec-form__submit .btn-label > .icon { flex: 0 0 18px; width: 18px; height: 18px; }
.ec-form__submit-text { min-width: 0; overflow-wrap: anywhere; text-wrap: balance; }

.ec-form__bundles { width: 100%; }

/* ---------- Trust strip ---------- */
.ec-trust {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ec-trust li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: var(--ec-field-r);
  background: var(--c-surface);
  color: var(--c-muted);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
}

.ec-trust .icon { color: var(--c-primary); }

/* ---------- Popup trigger ---------- */
.ec-open-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  border: 1px solid var(--ec-open-bg, var(--c-primary)) !important;
  border-radius: var(--ec-open-radius, 12px);
  background: var(--ec-open-bg, var(--c-primary)) !important;
  color: var(--ec-open-text, #fff) !important;
}

.ec-open-btn:hover { filter: brightness(.94); }
.ec-open-btn .icon { width: 20px; height: 20px; }

.ec-form__submit:focus-visible,
.ec-open-btn:focus-visible,
.ec-modal__close:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--c-primary) 35%, transparent);
  outline-offset: 3px;
}

.express-checkout-page {
  max-width: 560px !important;
  padding-top: 24px;
  padding-bottom: 48px;
}

/* =========================================================
   Popup dialog — compact card on desktop, bottom sheet on mobile
   ========================================================= */
.ec-modal[hidden] { display: none !important; }

.ec-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: rgba(15, 18, 22, .55);
  animation: ecFade .2s ease-out;
}

.ec-modal__dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 460px);
  max-height: min(92dvh, 860px);
  overflow: hidden;
  border: var(--ec-form-border-width, 1px) solid var(--ec-form-border, var(--c-primary));
  border-radius: var(--ec-form-radius, 18px);
  background: var(--ec-form-bg, var(--c-bg));
  color: var(--ec-form-text, var(--c-ink));
  box-shadow: 0 30px 80px rgba(15, 23, 42, .28);
  animation: ecRise .26s cubic-bezier(.2, .8, .2, 1);
}

.ec-modal__dialog:focus { outline: none; }
.ec-modal__grabber { display: none; }

.ec-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px 18px;
  border-bottom: 1px solid var(--c-line);
}

[dir=rtl] .ec-modal__head { padding: 14px 18px 12px 16px; }

.ec-modal__title {
  margin: 0;
  color: inherit;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.35;
}

.ec-modal__close {
  display: inline-flex;
  flex: 0 0 34px;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--c-line);
  border-radius: 50%;
  background: var(--c-surface);
  color: var(--c-ink);
  transition: border-color .16s ease, color .16s ease, transform .16s ease;
}

.ec-modal__close:hover { border-color: var(--c-hover-line); color: var(--c-primary); transform: rotate(90deg); }

.ec-modal__body {
  display: grid;
  gap: 12px;
  padding: 14px 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Product summary */
.ec-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--c-line);
  border-radius: 12px;
  background: var(--c-surface);
}

.ec-summary__img {
  flex: 0 0 60px;
  width: 60px;
  height: 60px;
  border-radius: 9px;
  background: var(--c-bg);
  object-fit: cover;
}

.ec-summary__info { display: grid; gap: 3px; min-width: 0; }

.ec-summary__name {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.ec-summary__prices {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  font-size: 15px;
}

.ec-summary__prices .price-compare { font-size: 13px; }
.ec-summary__prices .discount-slot:empty,
.ec-summary__prices .price-compare:empty { display: none; }
.ec-summary__prices .badge { min-height: 20px; padding: 2px 7px; font-size: 11px; }

.ec-modal__options:empty { display: none; }

/* The real form moves into the dialog: drop its card chrome and duplicate title. */
.ec-modal__form-slot .ec-form {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.ec-modal__form-slot .ec-form__title { display: none; }

html.has-ec-modal { overflow: hidden; }
html.has-ec-modal .sticky-buy { display: none !important; }

@media (max-width: 640px) {
  .ec-modal { align-items: flex-end; padding: 0; }

  .ec-modal__dialog {
    width: 100%;
    max-height: 94dvh;
    border-width: 0;
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    animation: ecSheet .28s cubic-bezier(.2, .8, .2, 1);
  }

  .ec-modal__grabber {
    display: block;
    width: 40px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 999px;
    background: var(--c-line-strong);
  }

  .ec-modal__head { padding-top: 8px; }
}

@media (max-width: 560px) {
  .ec-form { padding: 14px; }
  .ec-form__action-row { gap: 8px; }
  .ec-form__quantity { flex-basis: 100px; }
  .ec-form__quantity .quantity-field button { width: 30px; min-width: 30px; }
  .ec-form__submit { padding-inline: 10px; font-size: 14px; }
}

@media (max-width: 360px) {
  .ec-form__quantity { flex-basis: 90px; }
  .ec-form__quantity .quantity-field button { width: 26px; min-width: 26px; }
  .ec-form__submit { font-size: 13px; }
  .ec-trust li { font-size: 10.5px; }
}

/* ---------- Motion ---------- */
@keyframes ecFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ecRise { from { opacity: 0; transform: translateY(12px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes ecSheet { from { transform: translateY(100%); } to { transform: none; } }
@keyframes ecPop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes ecShakeX { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

/* Button attention animations — shared by popup trigger, submit and sticky bar */
.express-anim--pulse { animation: ecPulse 2s ease-in-out infinite; }
.express-anim--shine { position: relative; overflow: hidden; isolation: isolate; }
.express-anim--shine::after { content: ""; position: absolute; inset: -30% auto -30% -45%; width: 35%; transform: skewX(-22deg); background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent); animation: ecShine 3.2s ease-in-out infinite; pointer-events: none; }
.express-anim--bounce { animation: ecBounce 2.4s ease-in-out infinite; }
.express-anim--glow { animation: ecGlow 2s ease-in-out infinite; }
.express-anim--shake { animation: ecShake 4.5s ease-in-out infinite; }
.express-anim--heartbeat { animation: ecHeartbeat 1.8s ease-in-out infinite; }
.express-anim--wobble { animation: ecWobble 3.5s ease-in-out infinite; }
.express-anim--tada { animation: ecTada 4s ease-in-out infinite; }
.express-anim--float { animation: ecFloat 2.8s ease-in-out infinite; }
.express-anim--slide { animation: ecSlide 3.2s ease-in-out infinite; }
.ec-form__submit[data-type=loading] { animation: none; }
@keyframes ecPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.025); } }
@keyframes ecShine { 0%, 65% { left: -45%; } 100% { left: 130%; } }
@keyframes ecBounce { 0%, 85%, 100% { transform: translateY(0); } 90% { transform: translateY(-3px); } 95% { transform: translateY(0); } }
@keyframes ecGlow { 0%,100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--ec-submit-bg, var(--c-primary)) 18%, transparent); } }
@keyframes ecShake { 0%, 90%, 100% { transform: translateX(0); } 92% { transform: translateX(-2px); } 94% { transform: translateX(2px); } 96% { transform: translateX(-2px); } 98% { transform: translateX(0); } }
@keyframes ecHeartbeat { 0%, 35%, 65%, 100% { transform: scale(1); } 15%, 50% { transform: scale(1.045); } }
@keyframes ecWobble { 0%, 82%, 100% { transform: translateX(0) rotate(0); } 86% { transform: translateX(-3px) rotate(-1deg); } 90% { transform: translateX(3px) rotate(1deg); } 94% { transform: translateX(-2px) rotate(-.5deg); } 98% { transform: translateX(0) rotate(0); } }
@keyframes ecTada { 0%, 80%, 100% { transform: scale(1) rotate(0); } 84% { transform: scale(.96) rotate(-2deg); } 88% { transform: scale(1.06) rotate(2deg); } 92% { transform: scale(1.04) rotate(-1deg); } 96% { transform: scale(1) rotate(0); } }
@keyframes ecFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes ecSlide { 0%, 78%, 100% { transform: translateX(0); } 84% { transform: translateX(3px); } 90% { transform: translateX(-3px); } 96% { transform: translateX(0); } }

@media (prefers-reduced-motion: reduce) {
  .ec-modal, .ec-modal__dialog, .express-checkout-field.is-shaking,
  .express-checkout-field.is-valid::after, .ec-total__value.is-bumped,
  [class*="express-anim--"], .express-anim--shine::after { animation: none !important; }
  .ec-progress__bar { transition: none; }
}
