/* =====================================================================
 * Hamyar — the mobile field and its country picker (intl-tel-input v29)
 *
 * One design for every place the picker appears: the account form, Gravity
 * Forms, the sales landings, the checkout and wp-admin. Deliberately not
 * scoped to .hy-forms — on phones the country panel is moved to <body>, and
 * wp-admin has no hy-forms class at all.
 *
 * v29 markup (the class names changed from v18, which is why the old rules
 * never landed):
 *   .iti > .iti__country-container > button.iti__selected-country
 *                                      > .iti__selected-country-primary (flag + arrow)
 *                                      > .iti__selected-dial-code
 *       > input
 *   .iti__country-selector  ← the panel  (NOT .iti__dropdown-content)
 *       > .iti__search-input-wrapper > .iti__search-input
 *       > ul.iti__country-list > li.iti__country > .iti__flag + .iti__country-name
 *                                                  + .iti__dial-code + .iti__country-check
 * ===================================================================== */

.iti {
	--hyp-ink: #1E1C26;
	--hyp-soft: #6F7480;
	--hyp-field: #F5F6F9;
	--hyp-line: #E1E4EC;
	--hyp-red: #EE6B65;
	--hyp-red-soft: #FDEDEC;
	--hyp-red-deep: #B8423C;
	--hyp-radius: 12px;
	--hyp-h: 48px;
	/* the library paints a grey slab on hover; we do our own thing */
	--iti-hover-color: transparent;
	--iti-icon-color: #A9AEBA;
	--iti-border-color: #EDF0F5;
	--iti-arrow-padding: 6px;
	--iti-mobile-popup-margin: 0px;
}

/* ---------- the wrapper IS the field ---------- */
.iti {
	position: relative;
	display: flex !important;
	align-items: stretch;
	width: 100%;
	min-height: var(--hyp-h) !important; /* the same 48px everywhere, whatever the page gives its inputs */
	background: var(--hyp-field);
	border: 1.5px solid transparent;
	border-radius: var(--hyp-radius) !important; /* the theme's field rule says 10px with !important */
	overflow: visible; /* never clip the panel */
	direction: ltr;
	transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.iti:focus-within {
	background: #fff;
	border-color: var(--hyp-line);
	box-shadow: 0 0 0 4px rgba(30, 28, 38, .05);
}
/* the detached panel on phones is itself an .iti — none of the field styling applies to it */
.iti.iti--detached-country-selector {
	display: block;
	width: auto;
	min-height: 0;
	background: transparent;
	border: 0;
	box-shadow: none;
}

/* ---------- country button: flag, dial code, divider ---------- */
.iti .iti__country-container {
	position: static !important;
	inset: auto !important;
	flex: 0 0 auto;
	display: flex;
	padding: 0 !important;
	margin: 0;
	z-index: auto;
}
.iti .iti__selected-country {
	display: flex;
	align-items: center;
	gap: 6px;
	height: auto;
	padding: 0 10px 0 12px;
	margin: 0;
	border: 0;
	border-inline-end: 1.5px solid var(--hyp-line);
	border-radius: 0;
	background: transparent !important;
	box-shadow: none !important;
	color: var(--hyp-ink);
	font: inherit;
	font-size: 14px;
	line-height: 1;
	white-space: nowrap;
	cursor: pointer;
}
/* the library's grey rectangle, in all three of its states */
.iti .iti__selected-country-primary,
.iti .iti__selected-country-primary:hover,
.iti .iti__selected-country:hover .iti__selected-country-primary,
.iti .iti__selected-country[aria-expanded="true"] .iti__selected-country-primary,
.iti .iti__selected-country:hover,
.iti .iti__selected-country:focus,
.iti .iti__selected-country[aria-expanded="true"] {
	background: transparent !important;
	background-color: transparent !important;
	box-shadow: none !important;
}
.iti .iti__selected-country-primary {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 0 !important;
	margin: 0;
	border-radius: 0;
}
.iti .iti__selected-dial-code {
	font-weight: 600;
	font-size: 14px;
	color: var(--hyp-ink);
	font-variant-numeric: tabular-nums;
	transition: color .15s;
}
.iti .iti__arrow {
	margin: 0;
	border-color: #A9AEBA;
	transition: border-color .15s, transform .18s;
}
/* hover says something without a grey box: the mark and the code warm up */
.iti .iti__selected-country:hover .iti__arrow,
.iti .iti__selected-country[aria-expanded="true"] .iti__arrow {
	border-color: var(--hyp-red);
}
.iti .iti__selected-country:hover .iti__selected-dial-code,
.iti .iti__selected-country[aria-expanded="true"] .iti__selected-dial-code {
	color: var(--hyp-red);
}
.iti .iti__selected-country:focus-visible {
	outline: 2px solid var(--hyp-red);
	outline-offset: -2px;
	border-radius: 0 var(--hyp-radius) var(--hyp-radius) 0;
}
.iti .iti__flag {
	border-radius: 3px;
	box-shadow: 0 0 0 1px rgba(20, 24, 40, .1);
}

/* ---------- the digits ---------- */
.iti > input,
.iti > input[type="tel"],
.iti > input[type="text"],
.iti > input.large,
.iti > input.medium,
.iti > input.small,
.iti > input.form-control,
.iti > input.form-control-xl {
	flex: 1 1 0% !important;
	width: 0 !important;
	min-width: 0 !important;
	max-width: none !important;
	height: auto !important;
	min-height: 0 !important;
	margin: 0 !important;
	padding: 0 14px !important;
	border: 0 !important;
	border-radius: 0 !important;
	background: transparent !important;
	box-shadow: none !important;
	direction: ltr;
	text-align: left;
	font-variant-numeric: tabular-nums;
}
.iti > input:focus {
	background: transparent !important;
	box-shadow: none !important;
	outline: 0 !important;
}
/* an empty field shows a Persian placeholder, so it reads right-to-left until there are digits */
.iti > input:placeholder-shown {
	direction: rtl;
	text-align: right;
}
.iti > input:focus::placeholder { opacity: .6; }

/* ---------- the panel ---------- */
.iti .iti__country-selector,
.iti--detached-country-selector .iti__country-selector {
	width: max(100%, 320px);
	min-width: min(320px, calc(100vw - 32px)) !important;
	max-width: min(380px, calc(100vw - 32px));
	padding: 0;
	border: 1px solid #EDF0F5 !important;
	border-radius: 16px;
	background: #fff;
	box-shadow: 0 24px 50px -24px rgba(20, 24, 40, .45), 0 2px 8px -4px rgba(20, 24, 40, .12) !important;
	overflow: hidden;
}
.iti--inline-country-selector:not(.iti--detached-country-selector) .iti__country-selector {
	top: calc(100% + 8px);
	left: 0;
	right: auto;
	z-index: 100001;
}

/* search */
.iti .iti__search-input-wrapper {
	padding: 10px;
	border: 0;
	border-bottom: 1px solid #F0F2F6;
}
.iti .iti__search-input,
.iti .iti__search-input:focus {
	height: 42px !important;
	min-height: 42px !important;
	width: 100% !important;
	margin: 0 !important;
	padding: 0 38px 0 14px !important;
	border: 1.5px solid transparent !important;
	border-radius: 10px !important;
	background: var(--hyp-field) !important;
	box-shadow: none !important;
	color: var(--hyp-ink);
	font: inherit;
	font-size: 14px;
	direction: rtl;
	text-align: right;
}
.iti .iti__search-input:focus {
	border-color: var(--hyp-line) !important;
	background: #fff !important;
}
.iti .iti__search-icon {
	left: auto;
	right: 22px;
	color: var(--hyp-soft);
}
.iti .iti__search-clear {
	right: auto;
	left: 20px;
	color: var(--hyp-soft);
}

/* list */
.iti .iti__country-list {
	max-height: 320px !important;
	padding: 6px !important;
	margin: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
	scrollbar-color: #D8DCE5 transparent;
}
.iti .iti__country-list::-webkit-scrollbar { width: 8px; }
.iti .iti__country-list::-webkit-scrollbar-thumb { background: #D8DCE5; border: 2px solid #fff; border-radius: 99px; }

/* one country, always one line */
.iti .iti__country.hy-off,
.iti .iti__country[hidden] { display: none !important; } /* must outrank the rule below */
.iti .iti__country {
	display: flex !important;
	align-items: center;
	gap: 10px;
	min-height: 52px;
	padding: 6px 12px !important;
	border-radius: 10px;
	direction: rtl;
	white-space: nowrap;
	font-size: 14px;
	line-height: 1.5;
	color: var(--hyp-ink);
	transition: background-color .12s, color .12s;
}
.iti .iti__country .iti__flag {
	margin: 0 !important;
	flex: 0 0 auto;
}
.iti .iti__country-name {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	line-height: 1.45;
}
/* the English name, quietly, under the Persian one */
.iti .iti__country-name small {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	direction: ltr;
	text-align: right;
	font-size: 11.5px;
	font-weight: 400;
	line-height: 1.35;
	color: #9AA0AD;
}
.iti .iti__country[aria-selected="true"] .iti__country-name small { color: #C9817C; }
.iti .iti__dial-code {
	flex: 0 0 auto;
	direction: ltr;
	color: var(--hyp-soft);
	font-size: 13px;
	font-variant-numeric: tabular-nums;
}
.iti .iti__country-check {
	margin: 0 !important;
	flex: 0 0 auto;
	color: var(--hyp-red);
}
.iti .iti__country-check-svg { width: 16px; height: 16px; }
.iti .iti__country:hover,
.iti .iti__country.iti__highlight {
	background-color: var(--hyp-field) !important;
}
.iti .iti__country[aria-selected="true"] {
	background-color: var(--hyp-red-soft) !important;
	color: var(--hyp-red-deep);
	font-weight: 700;
}
.iti .iti__country[aria-selected="true"] .iti__dial-code { color: var(--hyp-red-deep); }
.iti .iti__divider {
	margin: 6px 4px;
	border-color: #F0F2F6;
}
.iti .iti__no-results { padding: 22px 0; color: var(--hyp-soft); font-size: 13.5px; }

/* ---------- phones: the panel becomes a bottom sheet ---------- */
.iti--fullscreen-popup.iti--detached-country-selector {
	display: flex !important; /* the library's own layout — the sheet sits at the bottom */
	flex-direction: column !important;
	padding: 0 !important;
	justify-content: flex-end !important;
	background-color: rgba(20, 24, 40, .45) !important;
	-webkit-backdrop-filter: blur(2px);
	backdrop-filter: blur(2px);
}
.iti--fullscreen-popup .iti__country-selector {
	width: 100% !important;
	max-width: 100% !important;
	max-height: 78vh;
	border: 0 !important;
	border-radius: 20px 20px 0 0;
	padding-top: 10px;
	box-shadow: 0 -10px 40px -18px rgba(20, 24, 40, .5) !important;
	animation: hy-phone-sheet .22s cubic-bezier(.22, .8, .3, 1);
}
/* the grab handle */
.iti--fullscreen-popup .iti__country-selector::before {
	content: "";
	display: block;
	width: 42px;
	height: 4px;
	margin: 0 auto 6px;
	border-radius: 99px;
	background: #DFE3EA;
}
.iti--fullscreen-popup .iti__country-list {
	max-height: calc(78vh - 80px) !important;
	padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
}
.iti--fullscreen-popup .iti__country { min-height: 56px; }
@keyframes hy-phone-sheet {
	from { transform: translateY(14px); opacity: .6; }
	to   { transform: translateY(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
	.iti--fullscreen-popup .iti__country-selector { animation: none; }
}

/* iOS zooms the page when a field under 16px takes focus */
@media (max-width: 767px) {
	.iti > input, .iti .iti__search-input { font-size: 16px !important; }
}

/* a field Gravity Forms marked invalid */
.gfield_error .iti { border-color: var(--hyp-red); background: var(--hyp-red-soft); }
