/* ==========================================================================
   MestiDelivery — Phone verification (SMS OTP), Telegram-style flow
   Controls follow the Login page (src/pages/Login.css); the surface is the app's
   premium modal material. Mobile: bottom sheet (tall only on the country list).
   ≥600px: centered panel over a dim.
   ========================================================================== */

#mesti-phone-modal-root {
  --pa-bg: #151514;
  --pa-glass: rgba(255, 255, 255, 0.045);
  --pa-stroke: rgba(255, 255, 255, 0.1);
  --pa-stroke-top: rgba(255, 255, 255, 0.14);
  --pa-hairline: rgba(255, 255, 255, 0.08);
  --pa-text: #ffffff;
  --pa-muted: rgba(255, 255, 255, 0.55);
  --pa-faint: rgba(255, 255, 255, 0.32);
  --pa-green: var(--color-accent, #21ea7c);
  --pa-ease-out: var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1));
  --pa-ease-drawer: var(--ease-drawer, cubic-bezier(0.32, 0.72, 0, 1));
  --pa-display: 'Archivo', 'Inter', -apple-system, 'Noto Sans Georgian', sans-serif;

  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  /* exit */
  transition: opacity 260ms ease, visibility 0s linear 280ms;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Noto Sans Georgian', sans-serif;
  color: var(--pa-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#mesti-phone-modal-root.active {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  /* enter */
  transition: opacity 400ms var(--pa-ease-drawer), visibility 0s;
}

#mesti-phone-modal-root *,
#mesti-phone-modal-root *::before,
#mesti-phone-modal-root *::after {
  box-sizing: border-box;
}

/* ---------- Screen (full-screen cover on mobile) ---------- */
.mesti-phone-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow: hidden;
  background: var(--material-sheet-bg, #141416);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 32px 32px 0 0;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transform: translateY(100%);
  /* exit: faster than entry */
  transition: transform 280ms var(--pa-ease-out);
}

#mesti-phone-modal-root.active .mesti-phone-card {
  transform: translateY(0);
  transition: transform 420ms var(--pa-ease-drawer);
}

#mesti-phone-view-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 72px 24px calc(env(safe-area-inset-bottom, 0px) + 28px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Directional content swap between steps */
#mesti-phone-view-container.mesti-view-fwd > * {
  animation: mestiViewFwd 300ms var(--pa-ease-out);
}

#mesti-phone-view-container.mesti-view-back > * {
  animation: mestiViewBack 300ms var(--pa-ease-out);
}

@keyframes mestiViewFwd {
  from { opacity: 0; transform: translateX(28px); }
  to { opacity: 1; transform: none; }
}

@keyframes mestiViewBack {
  from { opacity: 0; transform: translateX(-28px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Circle buttons (same as .ui-circle-btn on the restaurant page) ---------- */
.mesti-phone-btn-icon {
  position: absolute;
  top: 20px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--pa-green);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 120ms var(--pa-ease-out), background-color 160ms ease;
}

.mesti-phone-btn-icon svg {
  width: 18px;
  height: 18px;
}

.mesti-phone-btn-icon:active {
  transform: scale(0.92);
}

.mesti-phone-btn-close {
  right: 20px;
}

.mesti-phone-btn-back {
  left: 20px;
}

/* ---------- Step layout ---------- */
.mesti-phone-screen,
.mesti-country-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}

.mesti-phone-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 28px;
}

.mesti-phone-brand-logo {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  object-fit: contain;
  filter: drop-shadow(0 0 18px rgba(33, 234, 124, 0.35));
}

.mesti-phone-title {
  margin: 0;
  font-family: var(--pa-display);
  font-weight: 800;
  font-size: 26px;
  line-height: 1.08;
  letter-spacing: -0.03em;
  text-transform: none;
  color: var(--pa-text);
  text-wrap: balance;
}

.mesti-phone-subtitle {
  margin: 10px 0 0;
  max-width: 310px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--pa-muted);
  text-wrap: balance;
}

/* ---------- Grouped field: country row + phone row ---------- */
.mesti-phone-form {
  display: flex;
  flex-direction: column;
}

.mesti-phone-group {
  border-radius: var(--control-radius, 16px);
  background: var(--field-bg, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--field-border, rgba(255, 255, 255, 0.08));
  transition: border-color 200ms ease, background-color 200ms ease, box-shadow 200ms ease;
}

.mesti-phone-group:focus-within {
  border-color: var(--field-border-focus, rgba(33, 234, 124, 0.55));
  background: var(--field-bg-focus, rgba(255, 255, 255, 0.07));
  box-shadow: var(--field-ring-focus, 0 0 0 3px rgba(33, 234, 124, 0.12));
}

.mesti-country-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 0 16px;
  border: 0;
  background: none;
  color: var(--pa-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color 120ms ease;
  border-radius: 15px 15px 0 0;
}

.mesti-country-row:active {
  background: rgba(255, 255, 255, 0.04);
}

.mesti-country-row-label {
  /* visible to screen readers; Telegram shows only the value */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.mesti-country-row-value {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.mesti-country-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 500;
}

.mesti-country-arrow {
  display: flex;
  color: var(--pa-faint);
}

.mesti-phone-input-group {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 60px;
  margin: 0 0 0 16px;
  border-top: 1px solid var(--pa-hairline);
}

.mesti-country-dial {
  flex-shrink: 0;
  padding-right: 12px;
  margin-right: 12px;
  border-right: 1px solid var(--pa-hairline);
  font-size: 20px;
  font-weight: 600;
  line-height: 28px;
  font-variant-numeric: tabular-nums;
  color: var(--pa-text);
}

.mesti-phone-main-input {
  flex: 1;
  min-width: 0;
  height: 58px;
  padding: 0 16px 0 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--pa-text);
  font: inherit;
  font-size: 20px; /* ≥16px: no iOS focus zoom */
  font-weight: 600;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  caret-color: var(--pa-green);
}

.mesti-phone-main-input::placeholder {
  color: var(--field-placeholder, rgba(255, 255, 255, 0.28));
  font-weight: 500;
}

/* ---------- Flags ---------- */
.mesti-flag-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.mesti-flag-img {
  display: inline-block;
  width: 26px;
  height: 19px;
  border-radius: 4px;
  object-fit: cover;
  vertical-align: middle;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
}

.mesti-flag-emoji-fallback {
  font-size: 22px;
  line-height: 1;
}

.mesti-picker-flag-slot {
  display: inline-flex;
  align-items: center;
}

.mesti-picker-flag-slot.mesti-flag-pop {
  animation: mestiFlagPop 240ms var(--pa-ease-out);
}

@keyframes mestiFlagPop {
  from { transform: scale(0.9); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- Country screen ---------- */
.mesti-phone-card:has(.mesti-country-screen) {
  height: 92dvh;
}

.mesti-country-screen {
  min-height: 0;
}

.mesti-country-title {
  margin-bottom: 16px;
  font-size: 24px;
  text-align: center;
}

.mesti-country-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  height: var(--search-height, 52px);
  margin-bottom: 8px;
  padding: 0 16px;
  border-radius: var(--control-radius, 16px);
  background: var(--search-bg, rgba(255, 255, 255, 0.1));
  transition: background-color 200ms ease;
}

.mesti-search-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  color: var(--pa-green);
  pointer-events: none;
}

.mesti-country-search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--pa-text);
  font: inherit;
  font-size: 17px;
  font-weight: 500;
  -webkit-appearance: none;
  appearance: none;
}

.mesti-country-search-input:focus {
  outline: 0;
}

.mesti-country-search-input::placeholder {
  color: var(--search-placeholder, #aaaaaa);
}

.mesti-country-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 -20px;
  padding: 0 20px 8px;
}

.mesti-country-section {
  margin: 18px 4px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--pa-muted);
}

.mesti-country-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-radius: var(--control-radius, 16px);
  background: var(--field-bg, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--field-border, rgba(255, 255, 255, 0.08));
  overflow: hidden;
}

.mesti-country-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 0 16px;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.mesti-country-item + .mesti-country-item {
  box-shadow: inset 54px 1px 0 -53px var(--pa-hairline);
}

.mesti-country-item:active {
  background: rgba(255, 255, 255, 0.05);
}

.mesti-country-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mesti-country-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 500;
}

.mesti-country-item.selected .mesti-country-item-name {
  color: var(--pa-green);
}

.mesti-country-item-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.mesti-country-item-dial {
  font-size: 15px;
  color: var(--pa-muted);
  font-variant-numeric: tabular-nums;
}

.mesti-country-check {
  display: flex;
  color: var(--pa-green);
}

.mesti-country-empty {
  margin: 32px 0;
  text-align: center;
  font-size: 15px;
  color: var(--pa-muted);
}

/* ---------- Code step (Telegram-style digits on underlines) ---------- */
.mesti-otp-number {
  color: var(--pa-text);
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.mesti-otp-container {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 0 0 20px;
}

.mesti-otp-cell {
  width: 100%;
  min-width: 0;
  height: 56px;
  padding: 0;
  border-radius: 14px;
  background: var(--field-bg, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--field-border, rgba(255, 255, 255, 0.08));
  outline: 0;
  color: var(--pa-text);
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  caret-color: var(--pa-green);
  transition: border-color 200ms ease, background-color 200ms ease, box-shadow 200ms ease;
}


.mesti-otp-cell:focus {
  border-color: var(--field-border-focus, rgba(33, 234, 124, 0.55));
  background: var(--field-bg-focus, rgba(255, 255, 255, 0.07));
  box-shadow: var(--field-ring-focus, 0 0 0 3px rgba(33, 234, 124, 0.12));
}

.mesti-otp-cell.filled {
  background: var(--field-bg-focus, rgba(255, 255, 255, 0.07));
}

.mesti-otp-cell.filled:focus {
  border-color: var(--field-border-focus, rgba(33, 234, 124, 0.55));
}

.mesti-otp-divider {
  display: none;
}

/* ---------- Footer / actions ---------- */
.mesti-phone-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.mesti-phone-cta {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: var(--control-height, 54px);
  padding: 0 20px;
  border: 0;
  border-radius: var(--control-radius, 16px);
  background: var(--btn-primary-bg, #21ea7c);
  color: var(--btn-primary-text, #0a0a0a);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: var(--btn-primary-shadow, inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 6px 18px rgba(33, 234, 124, 0.18));
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 160ms var(--pa-ease-out), filter 200ms ease, box-shadow 200ms ease;
}

.mesti-phone-cta::before {
  content: '';
  position: absolute;
  z-index: -1;
  left: 18%;
  right: 18%;
  bottom: -6px;
  height: 16px;
  border-radius: 50%;
  background: var(--btn-primary-glow, rgba(33, 234, 124, 0.22));
  filter: blur(14px);
  pointer-events: none;
}

.mesti-phone-cta:disabled::before {
  display: none;
}

.mesti-phone-cta:active:not(:disabled) {
  transform: scale(0.98);
}

.mesti-phone-cta:disabled {
  opacity: 0.55;
  box-shadow: none;
  cursor: default;
}

.mesti-phone-meta {
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--pa-muted);
  font-variant-numeric: tabular-nums;
}

.mesti-phone-meta b {
  color: var(--pa-text);
  font-weight: 600;
}

.mesti-phone-link {
  padding: 10px 8px;
  border: 0;
  background: none;
  color: var(--link, rgba(33, 234, 124, 0.92));
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 160ms ease;
}

.mesti-phone-link:active {
  opacity: 0.6;
}

.mesti-phone-link-muted {
  color: var(--link-muted, rgba(255, 255, 255, 0.45));
  font-size: 0.88rem;
  font-weight: 500;
}

.mesti-phone-error {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--error-bg, rgba(239, 68, 68, 0.12));
  border: 1px solid var(--error-border, rgba(239, 68, 68, 0.28));
  color: var(--error-text, #fca5a5);
  font-size: 0.88rem;
  line-height: 1.4;
  text-align: center;
}

/* ---------- Success ---------- */
.mesti-success-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding-bottom: 12vh;
}

.mesti-success-icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 76px;
  margin-bottom: 20px;
  border-radius: 50%;
  background: rgba(33, 234, 124, 0.1);
  color: var(--pa-green);
  animation: mestiSuccessIn 420ms var(--pa-ease-drawer);
}

.mesti-success-icon-wrap svg {
  width: 34px;
  height: 34px;
}

@keyframes mestiSuccessIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.mesti-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(22, 22, 22, 0.2);
  border-top-color: #161616;
  border-radius: 50%;
  animation: mestiSpin 600ms linear infinite;
}

@keyframes mestiSpin {
  to { transform: rotate(360deg); }
}

/* ---------- Pointer devices ---------- */
@media (hover: hover) and (pointer: fine) {
  .mesti-phone-btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
  }

  .mesti-country-row:hover,
  .mesti-country-item:hover {
    background: rgba(255, 255, 255, 0.04);
  }

  .mesti-phone-cta:hover:not(:disabled) {
    filter: brightness(1.04);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 8px 22px rgba(33, 234, 124, 0.24);
  }

  .mesti-phone-link:not(.mesti-phone-link-muted):hover {
    color: #21ea7c;
  }

  .mesti-phone-link-muted:hover {
    color: rgba(255, 255, 255, 0.65);
  }
}

/* ---------- Larger screens: centered panel over a dim ---------- */
@media (min-width: 600px) {
  #mesti-phone-modal-root {
    align-items: center;
    padding: 24px;
  }

  .mesti-phone-card {
    max-width: 440px;
    max-height: min(720px, calc(100dvh - 48px));
    border-radius: 32px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-top-color: rgba(255, 255, 255, 0.08);
    transform: translateY(16px) scale(0.98);
    transition: transform 260ms var(--pa-ease-out);
  }

  #mesti-phone-modal-root.active .mesti-phone-card {
    transform: none;
    transition: transform 320ms var(--pa-ease-out);
  }

  .mesti-phone-card:has(.mesti-country-screen) {
    height: min(720px, calc(100dvh - 48px));
  }

  #mesti-phone-view-container {
    padding: 76px 28px 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mesti-phone-card,
  #mesti-phone-modal-root.active .mesti-phone-card {
    transform: none;
    transition: opacity 200ms ease;
  }

  #mesti-phone-view-container.mesti-view-fwd > *,
  #mesti-phone-view-container.mesti-view-back > *,
  .mesti-picker-flag-slot.mesti-flag-pop,
  .mesti-success-icon-wrap {
    animation: none;
  }
}
