/* ------------------------------------------------------------------
   CardSnacks — delivery country selector
   Standalone component. No dependencies, no framework.
   Colours reuse the site's own design tokens with hard-coded fallbacks
   so the block can be lifted into the app as-is.

   Flag images: assets/flags/*.png — public-domain flags from
   flagcdn.com (flagpedia.net).
   ------------------------------------------------------------------ */

.cs-country {
  --cs-c-border: var(--color-input, #b6e4e6);
  --cs-c-border-hover: var(--color-secondary, #707f80);
  --cs-c-accent: var(--color-primary, #20b2a4);
  --cs-c-text: var(--color-foreground, #3f3f3f);
  --cs-c-muted: var(--color-muted-foreground, #737373);
  --cs-c-hover-bg: var(--color-very-light-green, #ecfeff);

  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  font-family: inherit;
  text-align: left;
}

/* ---------- closed state (the pill) ---------- */

.cs-country__button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 96px;
  height: 46px;
  padding: 0 12px;
  margin: 0;
  border: 1px solid var(--cs-c-border);
  border-radius: 12px;
  background: #fff;
  color: var(--cs-c-text);
  font: inherit;
  font-size: 16px;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.cs-country__button:hover {
  border-color: var(--cs-c-border-hover);
}

.cs-country__button:focus-visible {
  outline: none;
  border-color: var(--cs-c-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cs-c-accent) 25%, transparent);
}

.cs-country__flag {
  flex: 0 0 auto;
  width: 24px;
  height: 16px;
  aspect-ratio: 3 / 2;
  object-fit: fill;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .08);
  display: block;
}

.cs-country__code {
  flex: 1 1 auto;
  font-weight: 500;
}

.cs-country__chevron {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  opacity: .5;
  transition: transform .15s ease;
}

.cs-country[data-open="true"] .cs-country__chevron {
  transform: rotate(180deg);
}

/* ---------- open state (the list) ---------- */

.cs-country__menu {
  position: absolute;
  z-index: 60;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  padding: 6px;
  border: 1px solid var(--cs-c-border);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .12);
}

.cs-country__menu[hidden] {
  display: none;
}

/* flips to the right edge when the pill sits near the viewport edge */
.cs-country[data-align="end"] .cs-country__menu {
  left: auto;
  right: 0;
}

.cs-country__menu-title {
  margin: 0;
  padding: 8px 10px 6px;
  color: var(--cs-c-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.cs-country__option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--cs-c-text);
  font: inherit;
  font-size: 15px;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  min-height: 44px;
}

.cs-country__option .cs-country__flag {
  width: 27px;
  height: 18px;
}

.cs-country__option:hover,
.cs-country__option:focus-visible {
  outline: none;
  background: var(--cs-c-hover-bg);
}

.cs-country__name {
  flex: 1 1 auto;
}

.cs-country__abbr {
  flex: 0 0 auto;
  color: var(--cs-c-muted);
  font-size: 13px;
  font-weight: 600;
}

.cs-country__check {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--cs-c-accent);
  visibility: hidden;
}

.cs-country__option[aria-selected="true"] .cs-country__check {
  visibility: visible;
}

.cs-country__option[aria-selected="true"] .cs-country__name {
  font-weight: 600;
}

/* ------------------------------------------------------------------
   Placement helpers — the only rules that touch the host pages
   ------------------------------------------------------------------ */

/* These rules deliberately avoid Tailwind utilities: the site ships a
   JIT build, so any class not already used on the page has no CSS. */

/* --- gift-cards listing, mobile: [ country ] [ search ] in one row --- */
.cs-country-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cs-country-row .cs-country__button {
  height: 40px; /* matches the site's h-10 search field */
  border-radius: 9999px;
  min-width: 88px;
}

.cs-country-row .cs-search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

/* --- gift-cards listing, desktop: right-aligned by the section title --- */
.cs-country-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.cs-country-head__aside {
  display: none;
  align-items: center;
  gap: 10px;
}

.cs-country-label {
  color: var(--color-muted-foreground, #737373);
  font-size: 14px;
  white-space: nowrap;
}

@media (min-width: 768px) {
  .cs-country-row--mobile {
    display: none;
  }
  .cs-country-head__aside {
    display: flex;
  }
}

/* --- product page: [ amount ] [ country ] in one row --- */
.cs-amount-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  width: 100%;
}

.cs-amount-row > [role="combobox"] {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

.cs-amount-row .cs-country {
  width: 104px;
}

/* the buy column needs a little more room now that it holds two controls */
.cs-buy-col {
  max-width: 340px;
}

.cs-buy-fields {
  width: 100%;
}

@media (min-width: 768px) {
  .cs-buy-col {
    max-width: none;
  }
  .cs-buy-grid {
    grid-template-columns: 350px 260px 1fr;
  }
  .cs-buy-inner {
    grid-template-columns: 350px 260px;
  }
}
