/* ============================================================
   Smart Form — Typeform-style multi-step popup
   ============================================================ */

/* --- Tokens --- */
:root {
  --sf-primary: #3BA5DC;
  --sf-primary-hover: #2B8FC2;
  --sf-text: #1a1c1e;
  --sf-muted: #8d99a4;
  --sf-border: #e0e4e8;
  --sf-bg: #f7f8fa;
  --sf-white: #fff;
  --sf-radius: 16px;
  --sf-radius-sm: 10px;
  --sf-shadow: 0 24px 80px rgba(0,0,0,.12);
  --sf-ease: cubic-bezier(.4, 0, .2, 1);
  --sf-duration: .35s;
}

/* --- Overlay --- */
.sf-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 20, 25, .55);
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--sf-duration) var(--sf-ease),
              visibility var(--sf-duration) var(--sf-ease);
  -webkit-tap-highlight-color: transparent;
}
.sf-overlay.sf-open {
  opacity: 1;
  visibility: visible;
}

/* --- Card --- */
.sf-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 92vh;
  max-height: 92dvh;
  background: var(--sf-white);
  border-radius: var(--sf-radius);
  box-shadow: var(--sf-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  transition: transform var(--sf-duration) var(--sf-ease),
              opacity var(--sf-duration) var(--sf-ease);
}
.sf-open .sf-card {
  transform: translateY(0);
  opacity: 1;
}

/* Desktop: explicit height since steps are position:absolute */
@media (min-width: 601px) {
  .sf-card {
    height: 520px;
  }
}

/* Mobile: full screen */
@media (max-width: 600px) {
  .sf-card {
    max-width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }
}

/* --- Header --- */
.sf-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  flex-shrink: 0;
}
.sf-back,
.sf-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  border-radius: 50%;
  color: var(--sf-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .2s, color .2s;
  padding: 0;
}
.sf-back:hover,
.sf-close:hover {
  background: var(--sf-bg);
  color: var(--sf-text);
}
.sf-back[hidden] { display: none; }

/* --- Progress bar --- */
.sf-progress-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.sf-progress {
  width: 100%;
  height: 4px;
  background: var(--sf-bg);
  border-radius: 2px;
  overflow: hidden;
}
.sf-progress__fill {
  height: 100%;
  width: 0%;
  background: var(--sf-primary);
  border-radius: 2px;
  transition: width .4s var(--sf-ease);
}
.sf-step-counter {
  font-size: 12px;
  color: var(--sf-muted);
  text-align: center;
  letter-spacing: .3px;
}

/* --- Steps container --- */
.sf-steps {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
}

/* --- Single step --- */
.sf-step {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 24px 28px 28px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  transition: transform var(--sf-duration) var(--sf-ease),
              opacity var(--sf-duration) var(--sf-ease);
  pointer-events: none;
  will-change: transform, opacity;
  scrollbar-width: thin;
  scrollbar-color: #d0d5da transparent;
}
.sf-step::-webkit-scrollbar { width: 4px; }
.sf-step::-webkit-scrollbar-thumb { background: #d0d5da; border-radius: 2px; }
.sf-step::-webkit-scrollbar-track { background: transparent; }

.sf-step--right {
  transform: translateX(60px);
  opacity: 0;
}
.sf-step--active {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.sf-step--left {
  transform: translateX(-60px);
  opacity: 0;
}

/* RTL direction flip */
html[dir="rtl"] .sf-step--right { transform: translateX(-60px); }
html[dir="rtl"] .sf-step--left  { transform: translateX(60px); }
html[dir="rtl"] .sf-step--active { transform: translateX(0); }
html[dir="rtl"] .sf-back svg   { transform: scaleX(-1); }

/* --- Step title & subtitle --- */
.sf-step__title {
  font-size: 22px;
  font-weight: 700;
  color: var(--sf-text);
  line-height: 1.3;
  margin: 0 0 6px;
}
.sf-step__subtitle {
  font-size: 15px;
  color: var(--sf-muted);
  line-height: 1.5;
  margin: 0 0 24px;
}

/* --- Input fields --- */
.sf-field {
  margin-bottom: 18px;
  position: relative;
}
.sf-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--sf-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}
.sf-input {
  display: block;
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1.5px solid var(--sf-border);
  border-radius: var(--sf-radius-sm);
  font-family: inherit;
  font-size: 16px;
  color: var(--sf-text);
  background: var(--sf-white);
  outline: none;
  box-sizing: border-box;
  transition: border-color .2s var(--sf-ease), box-shadow .2s var(--sf-ease);
  -webkit-appearance: none;
}
.sf-input:focus {
  border-color: var(--sf-primary);
  box-shadow: 0 0 0 3px rgba(59, 165, 220, .12);
}
.sf-input.sf-input--error {
  border-color: #e74c3c;
  box-shadow: 0 0 0 3px rgba(231, 76, 60, .1);
}
.sf-error-msg {
  font-size: 13px;
  color: #e74c3c;
  margin-top: 6px;
  display: none;
}
.sf-input--error ~ .sf-error-msg {
  display: block;
}

/* --- Country search step --- */
.sf-country-search {
  position: relative;
  margin-bottom: 14px;
}
.sf-country-search .sf-input {
  padding-left: 42px;
}
html[dir="rtl"] .sf-country-search .sf-input {
  padding-left: 16px;
  padding-right: 42px;
}
.sf-country-search__icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--sf-muted);
  pointer-events: none;
}
html[dir="rtl"] .sf-country-search__icon {
  left: auto;
  right: 14px;
}

/* Country list */
.sf-country-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #d0d5da transparent;
}
.sf-country-list::-webkit-scrollbar { width: 4px; }
.sf-country-list::-webkit-scrollbar-thumb { background: #d0d5da; border-radius: 2px; }
.sf-country-list::-webkit-scrollbar-track { background: transparent; }

.sf-country-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--sf-radius-sm);
  cursor: pointer;
  transition: background .15s var(--sf-ease);
  font-size: 15px;
  color: var(--sf-text);
}
.sf-country-item:hover {
  background: var(--sf-bg);
}
.sf-country-item:active {
  background: #edf0f3;
}
.sf-country-item--selected {
  background: rgba(59, 165, 220, .08);
}
.sf-country-item__flag {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}
.sf-country-item__name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sf-country-item__code {
  color: var(--sf-muted);
  font-size: 14px;
  flex-shrink: 0;
}
.sf-country-empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--sf-muted);
  font-size: 14px;
}

/* --- Phone step --- */
.sf-phone-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1.5px solid var(--sf-border);
  border-radius: var(--sf-radius-sm);
  overflow: hidden;
  transition: border-color .2s var(--sf-ease), box-shadow .2s var(--sf-ease);
}
.sf-phone-row:focus-within {
  border-color: var(--sf-primary);
  box-shadow: 0 0 0 3px rgba(59, 165, 220, .12);
}
.sf-phone-row.sf-input--error {
  border-color: #e74c3c;
  box-shadow: 0 0 0 3px rgba(231, 76, 60, .1);
}
.sf-phone-prefix {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  background: var(--sf-bg);
  font-size: 15px;
  color: var(--sf-text);
  white-space: nowrap;
  border: none;
  border-right: 1px solid var(--sf-border);
  flex-shrink: 0;
  min-width: 0;
  cursor: pointer;
  transition: background .2s;
  font-family: inherit;
}
.sf-phone-prefix:hover {
  background: #edf0f3;
}
.sf-phone-prefix__arrow {
  color: var(--sf-muted);
  flex-shrink: 0;
}
html[dir="rtl"] .sf-phone-prefix {
  border-right: none;
  border-left: 1px solid var(--sf-border);
}
.sf-phone-prefix__flag {
  font-size: 20px;
  line-height: 1;
}
.sf-phone-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0 16px;
  height: 52px;
  font-family: inherit;
  font-size: 16px;
  color: var(--sf-text);
  background: transparent;
  min-width: 0;
  -webkit-appearance: none;
}

/* --- Inline phone code picker --- */
.sf-code-picker {
  position: absolute;
  top: 58px;
  left: 0;
  right: 0;
  background: var(--sf-white);
  border: 1px solid var(--sf-border);
  border-radius: var(--sf-radius);
  box-shadow: var(--sf-shadow);
  z-index: 10;
  display: none;
  flex-direction: column;
  max-height: 300px;
  overflow: hidden;
  animation: dropdownFadeIn .2s var(--sf-ease);
}
@keyframes dropdownFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.sf-code-picker--open {
  display: flex;
}
.sf-code-picker__search {
  margin: 10px 12px 6px;
  width: calc(100% - 24px) !important;
  height: 42px !important;
  flex-shrink: 0;
}
.sf-code-picker__list {
  list-style: none;
  margin: 0;
  padding: 0 6px 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: #d0d5da transparent;
}
.sf-code-picker__list::-webkit-scrollbar { width: 4px; }
.sf-code-picker__list::-webkit-scrollbar-thumb { background: #d0d5da; border-radius: 2px; }
.sf-code-picker__list .sf-country-item {
  padding: 10px 10px;
  border-radius: 8px;
  font-size: 14px;
}

/* --- Service cards --- */
.sf-services {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sf-service-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border: 1.5px solid var(--sf-border);
  border-radius: var(--sf-radius-sm);
  cursor: pointer;
  transition: border-color .2s var(--sf-ease),
              background .2s var(--sf-ease),
              transform .15s var(--sf-ease);
  font-size: 16px;
  color: var(--sf-text);
  background: var(--sf-white);
  user-select: none;
}
.sf-service-card:hover {
  border-color: var(--sf-primary);
  background: rgba(59, 165, 220, .04);
}
.sf-service-card:active {
  transform: scale(.98);
}
.sf-service-card--selected {
  border-color: var(--sf-primary);
  background: rgba(59, 165, 220, .08);
}
.sf-service-card__check {
  width: 22px;
  height: 22px;
  border: 2px solid var(--sf-border);
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s, background .2s;
}
.sf-service-card--selected .sf-service-card__check {
  border-color: var(--sf-primary);
  background: var(--sf-primary);
}
.sf-service-card__check svg {
  opacity: 0;
  transition: opacity .2s;
}
.sf-service-card--selected .sf-service-card__check svg {
  opacity: 1;
}
.sf-service-card__label {
  flex: 1;
  line-height: 1.4;
}

/* --- Footer / buttons --- */
.sf-footer {
  padding: 16px 28px 20px;
  flex-shrink: 0;
}
.sf-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 56px;
  border: none;
  border-radius: var(--sf-radius);
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.8px;
  cursor: pointer;
  transition: all 0.7s;
  -webkit-tap-highlight-color: transparent;
}
.sf-btn--continue {
  background: linear-gradient(115deg, #88eaff 0%, #6fbaff 50%, #6fbaff 70%, #88eaff 110%);
  background-size: 200%;
  color: #1a1c1e;
}
.sf-btn--continue:hover {
  background-position: 100% 0;
}
.sf-btn--continue:active {
  transform: scale(.98);
}
.sf-btn--continue:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}
.sf-btn--done {
  background: var(--sf-bg);
  color: var(--sf-text);
}
.sf-btn--done:hover {
  background: #edf0f3;
}

/* --- Thank you step --- */
.sf-thankyou {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding-top: 40px;
  flex: 1;
}
.sf-thankyou__icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, #88eaff 0%, #3BA5DC 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  animation: sfPop .5s var(--sf-ease) both;
}
@keyframes sfPop {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
.sf-thankyou__icon svg {
  animation: sfCheck .4s var(--sf-ease) .3s both;
}
@keyframes sfCheck {
  0%   { stroke-dashoffset: 30; opacity: 0; }
  100% { stroke-dashoffset: 0; opacity: 1; }
}
.sf-thankyou__title {
  font-size: 24px;
  font-weight: 700;
  color: var(--sf-text);
  margin: 0 0 8px;
  animation: sfFadeUp .4s var(--sf-ease) .25s both;
}
.sf-thankyou__text {
  font-size: 15px;
  color: var(--sf-muted);
  margin: 0;
  animation: sfFadeUp .4s var(--sf-ease) .35s both;
}
@keyframes sfFadeUp {
  0%   { transform: translateY(12px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

/* --- Loading spinner (on submit button) --- */
.sf-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: sfSpin .6s linear infinite;
}
@keyframes sfSpin {
  to { transform: rotate(360deg); }
}

/* --- Keyboard hint --- */
.sf-keyboard-hint {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--sf-muted);
  margin-top: 8px;
  justify-content: center;
}
.sf-keyboard-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 2px 6px;
  border: 1px solid var(--sf-border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 11px;
  background: var(--sf-bg);
}
@media (hover: hover) and (pointer: fine) {
  .sf-keyboard-hint { display: flex; }
}

/* --- Mobile spacing --- */
@media (max-width: 600px) {
  .sf-step {
    padding: 20px 20px 20px;
  }
  .sf-steps {
    flex: none;
    overflow: visible;
  }
  .sf-step {
    position: static;
    opacity: 1;
    transform: none;
    display: none;
    pointer-events: auto;
  }
  .sf-step--active {
    display: flex;
  }
  .sf-footer {
    padding: 12px 20px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .sf-header {
    padding: 12px 16px;
  }
  .sf-step__title {
    font-size: 20px;
  }
}
