/* ===== Woodmart theme color integration ===== */
:root {
  /* Use Woodmart's primary color with fallback */
  --twp-primary: var(--wd-primary-color, #ec4a5a);
  --twp-primary-600: var(--wd-primary-color-darken, #d63f4e);

  /* Use Woodmart's text colors with fallbacks */
  --twp-gray-900: var(--wd-text-color, #1f2937);
  --twp-gray-700: var(--wd-text-color-alt, #374151);
  --twp-gray-600: var(--color-gray-600, #4b5563);
  --twp-gray-500: var(--color-gray-500, #6b7280);
  --twp-gray-300: var(--brdcolor-gray-300, #d1d5db);
  --twp-gray-200: var(--brdcolor-gray-200, #e5e7eb);
  --twp-gray-100: var(--bgcolor-gray-100, #f3f4f6);

  /* Keep consistent radius and shadows */
  --twp-radius-xl: 22px;
  --twp-shadow-lg: 0 20px 60px rgba(0, 0, 0, .18);
  --twp-shadow-sm: 0 6px 18px rgba(0, 0, 0, .08);
}

.twp-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 9998;
  display: none;
}

.twp-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 9999;
}

.twp-card {
  position: relative;
  background: #fff;
  border-radius: var(--twp-radius-xl);
  width: min(560px, 92vw);
  max-height: 85vh;
  box-shadow: var(--twp-shadow-lg);
  padding: 22px 22px 18px;
  animation: twp-pop .18s ease-out both;
  display: flex;
  flex-direction: column;
}

@keyframes twp-pop {
  from {
    transform: translateY(8px) scale(.98);
    opacity: .0
  }

  to {
    transform: translateY(0) scale(1);
    opacity: 1
  }
}

/* Header */
.twp-logo {
  display: flex;
  justify-content: center;
  margin: 0 0 12px 0;
}

.twp-logo img {
  max-width: 140px;
  max-height: 45px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.twp-logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--twp-gray-900);
  text-align: center;
}

.twp-head h3 {
  margin: 8px 0 6px;
  font-size: 22px;
  line-height: 1.2;
  color: var(--twp-gray-900);
  font-weight: 800;
  letter-spacing: .2px;
}

.twp-sub {
  margin: 0;
  color: var(--twp-gray-500);
  font-size: 14.5px
}

/* Badge (matches “Weekly Discounts” chip look) */
.twp-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #0f5132;
  background: #d1fae5;
  /* minty */
  border: 1px solid #a7f3d0;
  border-radius: 9999px;
  padding: 6px 10px;
}

/* Field */
.twp-row {
  margin-top: 14px
}

.twp-field {
  width: 100%
}

.twp-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--twp-gray-600);
  margin: 10px 0 6px;
}

.twp-row select {
  width: 100%;
  height: 60px;
  padding: 12px 42px 12px 14px;
  border: 1px solid var(--twp-gray-200);
  border-radius: 14px;
  background: #fff;
  color: var(--twp-gray-900);
  font-size: 15px;
  box-shadow: var(--twp-shadow-sm);
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(transparent, transparent),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 20 20' fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 8 10 12 14 8'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center, 0 0;
  background-size: 22px 22px, 0 0;
}

.twp-row select:focus {
  outline: none;
  border-color: var(--twp-primary);
  box-shadow: 0 0 0 4px rgba(236, 74, 90, .12), var(--twp-shadow-sm);
}

/* Actions */
.twp-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--twp-gray-100);
}

.button {
  border: 1px solid var(--twp-gray-200);
  background: #fff;
  color: var(--twp-gray-700);
  padding: 10px 16px;
  border-radius: 9999px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, color .12s ease, border-color .12s ease;
}

.button:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(17, 24, 39, .08)
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: var(--twp-shadow-sm)
}

.button.twp-ghost {
  background: #fafafa;
}

.button.twp-ghost:hover {
  background: #f5f5f5;
}

.button.twp-primary {
  background: var(--twp-primary);
  color: #fff;
  border-color: var(--twp-primary);
  box-shadow: 0 6px 14px rgba(236, 74, 90, .28);
}

.button.twp-primary:hover {
  background: var(--twp-primary-600);
  border-color: var(--twp-primary-600)
}

.button.twp-primary:active {
  transform: translateY(0) scale(.99)
}

/* Close (top-right floating chip) */
.twp-close {
  position: absolute !important;
  top: 16px !important;
  right: 16px !important;
  left: auto !important;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--twp-gray-100);
  color: var(--twp-gray-600);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 11;
  padding: 0;
  margin: 0;
}

.twp-close svg {
  width: 24px;
  height: 24px;
  display: block;
  flex-shrink: 0;
}

.twp-close:hover {
  background: var(--twp-gray-200);
  color: var(--twp-gray-900);
  transform: scale(1.05);
}

.twp-close:active {
  transform: scale(0.95);
  transform: rotate(90deg);
}

.twp-close:active {
  transform: scale(0.95) rotate(90deg);
}

.twp-close:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(236, 74, 90, 0.12), var(--twp-shadow-sm);
  border-color: var(--twp-primary);
}

/* Show/Hide */
.twp-modal.active,
.twp-modal-backdrop.active {
  display: flex
}

/* Flag Grid - One-Click Country Selector */
.twp-flag-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 18px;
  padding: 5px;
}

.twp-country-flag {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 18px 10px;
  min-height: 95px;
  background: #fff;
  border: 2px solid var(--twp-gray-200);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: inherit;
  box-shadow: var(--twp-shadow-sm);
}

.twp-country-flag:hover {
  border-color: var(--twp-primary);
  background: rgba(236, 74, 90, 0.04);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(236, 74, 90, 0.16);
}

.twp-country-flag:focus {
  outline: none;
  border-color: var(--twp-primary);
  box-shadow: 0 0 0 4px rgba(236, 74, 90, 0.12), var(--twp-shadow-sm);
}

.twp-country-flag:active {
  transform: translateY(0) scale(0.98);
}

.twp-country-flag.twp-current {
  border-color: var(--twp-primary);
  background: rgba(236, 74, 90, 0.08);
  box-shadow: 0 0 0 3px rgba(236, 74, 90, 0.18);
}

.twp-country-flag.twp-current::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  background: var(--twp-primary);
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.twp-flag-icon {
  width: 30px;
  height: 20px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.twp-flag-icon.fi {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.twp-flag-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--twp-gray-900);
  text-align: center;
  line-height: 1.2;
}

.twp-flag-currency {
  font-size: 11px;
  font-weight: 600;
  color: var(--twp-gray-500);
  background: var(--twp-gray-100);
  padding: 2px 8px;
  border-radius: 9999px;
  margin-top: 0;
}

/* Loading Overlay */
.twp-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: var(--twp-radius-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 10;
}

.twp-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--twp-gray-200);
  border-top-color: var(--twp-primary);
  border-radius: 50%;
  animation: twp-spin 0.8s linear infinite;
}

@keyframes twp-spin {
  to {
    transform: rotate(360deg);
  }
}

.twp-loading-text {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--twp-gray-700);
}

/* Responsive Design */
@media (max-width: 640px) {
  .twp-card {
    padding: 16px 14px 14px;
    width: 94vw;
    max-height: 88vh;
  }

  .twp-logo {
    margin: 0 0 10px 0;
  }

  .twp-logo img {
    max-width: 110px;
    max-height: 36px;
  }

  .twp-logo-text {
    font-size: 17px;
  }

  .twp-head h3 {
    font-size: 18px;
    margin: 4px 0 4px;
  }

  .twp-sub {
    font-size: 12px;
  }

  .twp-flag-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-top: 12px;
    max-height: calc(88vh - 90px);
  }

  .twp-country-flag {
    min-height: 68px;
    padding: 8px 5px;
    gap: 4px;
    border-width: 1.5px;
    border-radius: 10px;
  }

  .twp-flag-icon {
    width: 30px;
    height: 22.5px;
  }

  .twp-flag-name {
    font-size: 10px;
    line-height: 1.1;
    font-weight: 600;
  }

  .twp-flag-currency {
    font-size: 8.5px;
    padding: 1px 5px;
    margin-top: 1px;
  }

  .twp-country-flag.twp-current::after {
    width: 18px;
    height: 18px;
    font-size: 11px;
    top: 4px;
    right: 4px;
  }
}

@media (max-width: 380px) {
  .twp-card {
    padding: 12px 10px 10px;
    width: 96vw;
  }

  .twp-logo {
    margin: 0 0 8px 0;
  }

  .twp-logo img {
    max-width: 95px;
    max-height: 32px;
  }

  .twp-logo-text {
    font-size: 15px;
  }

  .twp-head h3 {
    font-size: 16px;
  }

  .twp-sub {
    font-size: 11px;
  }

  .twp-flag-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    margin-top: 10px;
  }

  .twp-country-flag {
    min-height: 62px;
    padding: 6px 4px;
    border-radius: 8px;
  }

  .twp-flag-icon {
    width: 28px;
    height: 21px;
  }

  .twp-flag-name {
    font-size: 9px;
  }

  .twp-flag-currency {
    font-size: 8px;
    padding: 1px 4px;
  }

  .twp-country-flag.twp-current::after {
    width: 16px;
    height: 16px;
    font-size: 10px;
    top: 3px;
    right: 3px;
  }
}

/* Locked shipping country field */
.twp-locked-field input[readonly],
.twp-locked-field select[disabled] {
  background-color: #f5f5f5 !important;
  cursor: not-allowed !important;
  opacity: 0.7;
}

.twp-locked-field .description {
  font-size: 0.875em;
  color: #666;
  margin-top: 0.5em;
}

.twp-change-country {
  color: #2271b1;
  text-decoration: underline;
  font-weight: 500;
}

.twp-change-country:hover {
  color: #135e96;
}

/* ===== Floating Country Flag Button ===== */
.twp-float-flag {
  position: fixed !important;
  bottom: 3em !important;
  left: 1em !important;
  width: 60px !important;
  height: 60px !important;
  border-radius: 50% !important;
  background: #fff !important;
  box-shadow: var(--twp-shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.04) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  border: 2px solid var(--twp-gray-100) !important;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
  z-index: 9997 !important;
  overflow: visible !important;
  padding: 0 !important;
}

.twp-float-flag:hover {
  transform: translateY(-4px) scale(1.08) !important;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22), 0 0 0 3px var(--twp-primary) !important;
  border-color: var(--twp-primary) !important;
}

.twp-float-flag:active {
  transform: translateY(-1px) scale(1.02) !important;
  transition: all 0.12s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.twp-float-flag .twp-flag-icon {
  font-size: 36px !important;
  line-height: 1 !important;
  border-radius: 50% !important;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.twp-float-flag:hover .twp-flag-icon {
  transform: scale(1.1) rotate(5deg) !important;
}

.twp-float-flag .fi {
  width: 44px !important;
  height: 44px !important;
  border-radius: 50% !important;
  object-fit: cover !important;
  background-size: cover !important;
  background-position: center !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

/* Elegant tooltip */
.twp-float-flag::before {
  content: attr(aria-label);
  position: absolute;
  left: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%) translateX(-8px);
  background: var(--twp-gray-900);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* Tooltip arrow */
.twp-float-flag::after {
  content: '';
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%) translateX(-8px);
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 6px 8px 6px 0;
  border-color: transparent var(--twp-gray-900) transparent transparent;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.twp-float-flag:hover::before,
.twp-float-flag:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* Pulse animation on page load */
@keyframes twp-pulse {

  0%,
  100% {
    transform: scale(1);
    box-shadow: var(--twp-shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.04);
  }

  50% {
    transform: scale(1.05);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22), 0 0 0 3px var(--twp-primary);
  }
}

.twp-float-flag {
  animation: twp-pulse 2s ease-in-out 1s 2;
}

/* Loading state */
.twp-float-flag.twp-loading {
  pointer-events: none !important;
  animation: none !important;
}

.twp-float-flag.twp-loading .twp-flag-icon {
  opacity: 0 !important;
  transform: scale(0.5) rotate(180deg) !important;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Hide tooltips when loading */
.twp-float-flag.twp-loading::before,
.twp-float-flag.twp-loading::after {
  display: none !important;
}

/* Real spinner element */
.twp-spinner-el {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  width: 32px !important;
  height: 32px !important;
  margin: -16px 0 0 -16px !important;
  border: 4px solid var(--twp-gray-200) !important;
  border-top-color: var(--twp-primary) !important;
  border-radius: 50% !important;
  background: #fff !important;
  animation: twp-spin 0.7s linear infinite !important;
}

@keyframes twp-spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Privacy Notice */
.twp-privacy-notice {
  margin-top: 24px;
  padding: 12px 16px;
  background: var(--twp-gray-50);
  border-left: 3px solid var(--twp-primary);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--twp-gray-600);
  text-align: left;
}

.twp-privacy-notice svg {
  color: var(--twp-primary);
  opacity: 0.8;
}

/* Mobile adjustments */
@media (max-width: 640px) {
  .twp-float-flag {
    bottom: 5em !important;
    left: 12px !important;
    width: 60px !important;
    height: 60px !important;
  }

  .twp-float-flag .fi {
    width: 38px !important;
    height: 38px !important;
  }

  .twp-float-flag::before {
    font-size: 12px !important;
    padding: 8px 12px !important;
    border-radius: 10px !important;
  }
}

/* Tablet adjustments */
@media (max-width: 1024px) and (min-width: 641px) {
  .twp-float-flag {
    width: 64px !important;
    height: 64px !important;
  }
}