/* Phone Input with Country Code — DIG-1651
   Two-column sub-label layout matching GDS reference design. */

/* Hide the AFCC-bound __widget text input (combined value carrier) */
.cmp-adaptiveform-phoneinput .cmp-adaptiveform-textinput__widget {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    margin: 0;
    padding: 0;
    border: 0;
}

/* Row: two columns with a gap */
.cmp-adaptiveform-phoneinput__row {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    column-gap: 16px;
    row-gap: 0;
    align-items: start;
    width: 100%;
}

/* Columns */
.cmp-adaptiveform-phoneinput__col {
    display: contents;
}

/* Sub-labels — match .cmp-adaptiveform-textinput__label from theme.css */
.cmp-adaptiveform-phoneinput__sublabel {
    font-family: var(--font-sans, "Manulife JH Sans Optimized", sans-serif);
    letter-spacing: 0;
    color: var(--gem-color-text-default);
    font-size: 18px;
    font-weight: 600;
    line-height: 24px;
    display: block;
    margin-bottom: 10px;
}

.cmp-adaptiveform-phoneinput__col--code .cmp-adaptiveform-phoneinput__sublabel {
    grid-column: 1;
    grid-row: 1;
}

.cmp-adaptiveform-phoneinput__col--number .cmp-adaptiveform-phoneinput__sublabel {
    grid-column: 2;
    grid-row: 1;
}

/* Country code dropdown */
.cmp-adaptiveform-phoneinput__country-code {
    font-family: var(--font-sans, "Manulife JH Sans Optimized", sans-serif);
    color: var(--gem-color-text-default);
    background-color: var(--gem-color-surface-default);
    border: 1px solid var(--gem-color-border-default);
    border-radius: 0;
    height: 48px;
    width: 100%;
    padding: 0 32px 0 12px;
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    cursor: pointer;
    box-sizing: border-box;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 20 20'%3E%3Cpath d='M10 13.4 6 9.5 7.5 8l2.5 2.6L12.5 8 14 9.5z' fill='%23282B3E'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 24px 24px;
    grid-column: 1;
    grid-row: 2;
}

.cmp-adaptiveform-phoneinput__country-code:hover {
    background-color: var(--gem-color-surface-default);
    border: 2px solid var(--gem-color-border-inverse-surface);
    padding-left: 11px;
    padding-right: 31px;
}

.cmp-adaptiveform-phoneinput__country-code:focus,
.cmp-adaptiveform-phoneinput__country-code:active {
    background-color: var(--gem-color-surface-default);
    border: 2px solid var(--gem-color-border-primary);
    padding-left: 11px;
    padding-right: 31px;
    outline: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 20 20'%3E%3Cpath d='M10 6.6 14 10.5 12.5 12 10 9.4 7.5 12 6 10.5z' fill='%23282B3E'/%3E%3C/svg%3E");
}

/* Disabled dropdown state */
.cmp-adaptiveform-phoneinput__country-code:disabled,
.cmp-adaptiveform-phoneinput__country-code:disabled:hover,
.cmp-adaptiveform-phoneinput__country-code:disabled:focus,
.cmp-adaptiveform-phoneinput__country-code:disabled:active {
    background-color: var(--gem-color-surface-neutral-soft);
    border: 1px solid var(--gem-color-border-default);
    color: var(--gem-color-text-default);
    cursor: default;
    padding-left: 12px;
    padding-right: 32px;
    outline: none;
}

/* Disabled dropdown state */
.cmp-adaptiveform-phoneinput__country-code:disabled,
.cmp-adaptiveform-phoneinput__country-code:disabled:hover,
.cmp-adaptiveform-phoneinput__country-code:disabled:focus,
.cmp-adaptiveform-phoneinput__country-code:disabled:active {
    background-color: var(--gem-color-surface-neutral-soft);
    border: 1px solid var(--gem-color-border-default);
    color: var(--gem-color-text-default);
    cursor: default;
    padding-left: var(--gem-spacing-3, 0.75rem);
    padding-right: var(--gem-spacing-6, 2rem);
    outline: none;
}

/* Number input */
.cmp-adaptiveform-phoneinput__number {
    font-family: var(--font-sans, "Manulife JH Sans Optimized", sans-serif);
    color: var(--gem-color-text-default);
    background-color: var(--gem-color-surface-default);
    border: 1px solid var(--gem-color-border-default);
    border-radius: 0;
    height: 48px;
    width: 100%;
    padding: 12px;
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    box-sizing: border-box;
    grid-column: 2;
    grid-row: 2;
}

.cmp-adaptiveform-phoneinput__number::placeholder {
    color: var(--gem-color-neutral-700);
}

.cmp-adaptiveform-phoneinput__number:hover {
    background-color: var(--gem-color-surface-default);
    border: 2px solid var(--gem-color-border-inverse-surface);
    padding: 11px;
}

.cmp-adaptiveform-phoneinput__number:focus,
.cmp-adaptiveform-phoneinput__number:active {
    background-color: var(--gem-color-surface-default);
    border: 2px solid var(--gem-color-border-primary);
    padding: 11px;
    outline: none;
}

/* Error state */
.cmp-adaptiveform-phoneinput__number--invalid,
.cmp-adaptiveform-phoneinput__number[aria-invalid="true"] {
    background-color: var(--gem-color-surface-status-error-soft);
    border: 2px solid var(--gem-color-border-status-error);
    padding: 11px;
}

/* Hover overrides error state — matches GDS hover behaviour */
.cmp-adaptiveform-phoneinput__number--invalid:hover,
.cmp-adaptiveform-phoneinput__number[aria-invalid="true"]:hover {
    background-color: var(--gem-color-surface-default);
    border: 2px solid var(--gem-color-border-inverse-surface);
    padding: 11px;
}

/* Error message — mirrors .cmp-adaptiveform-textinput__errormessage */
.cmp-adaptiveform-container .cmp-adaptiveform-phoneinput__errormessage {
    font-family: var(--font-sans, "Manulife JH Sans Optimized", sans-serif);
    color: var(--gem-color-text-status-error);
    margin-top: 5px;
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    display: none;
    align-items: center;
    grid-column: 2;
    grid-row: 3;
}

/* Responsive: maintain row layout on smaller screens */
@media (max-width: 767px) {
    .cmp-adaptiveform-phoneinput__row {
        grid-template-columns: 140px minmax(0, 1fr);
        min-width: 100px;
    }

    .cmp-adaptiveform-phoneinput__col--number {
        flex: 1 1 0%;
        min-width: 0;
    }
}

@media (max-width: 519px) {
    .cmp-adaptiveform-phoneinput__row {
        grid-template-columns: 100px minmax(0, 1fr);
    }
}

/* Custom ARIA listbox for country code (replaces native <select> open UI) */
.cmp-adaptiveform-phoneinput__code-custom {
    position: relative;
    height: 48px;
    width: 100%;
    box-sizing: border-box;
    cursor: pointer;
    background-color: var(--gem-color-surface-default, #ffffff);
    border: 1px solid var(--gem-color-neutral-700, #8e90a2);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 20 20'%3E%3Cpath d='M10 13.4 6 9.5 7.5 8l2.5 2.6L12.5 8 14 9.5z' fill='%23282B3E'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 24px 24px;
    outline: none;
    grid-column: 1;
    grid-row: 2;
}

.cmp-adaptiveform-phoneinput__code-custom:focus,
.cmp-adaptiveform-phoneinput__code-custom--open {
    border: 2px solid var(--gem-color-border-status-success, #06874e);
    outline: none;
}

.cmp-adaptiveform-phoneinput__code-custom--open {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 20 20'%3E%3Cpath d='M10 6.6 14 10.5 12.5 12 10 9.4 7.5 12 6 10.5z' fill='%23282B3E'/%3E%3C/svg%3E");
}

.cmp-adaptiveform-phoneinput__code-custom:hover:not(.cmp-adaptiveform-phoneinput__code-custom--disabled):not(.cmp-adaptiveform-phoneinput__code-custom--open) {
    border: 2px solid var(--gem-color-neutral-1000, #1e2530);
    background-color: var(--gem-color-surface-default, #ffffff);
}

.cmp-adaptiveform-phoneinput__code-custom--disabled {
    background-color: var(--gem-color-surface-disabled);
    border: 1px solid var(--gem-color-neutral-700, #8e90a2);
    cursor: default;
}

.cmp-adaptiveform-phoneinput__code-trigger {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 32px 0 12px;
    font-family: var(--font-sans, "Manulife JH Sans Optimized", sans-serif);
    font-size: var(--gem-font-size-base, 1rem);
    font-weight: var(--gem-font-weight-regular, 400);
    line-height: var(--gem-line-height-xl, 1.5rem);
    color: var(--gem-color-neutral-dark-default);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

.cmp-adaptiveform-phoneinput__code-list {
    position: absolute;
    top: 100%;
    left: -2px;
    right: -2px;
    z-index: 9999;
    margin: 0;
    padding: 0;
    background: var(--gem-color-surface-default, #ffffff);
    border: 2px solid var(--gem-color-neutral-700, #8e90a2);
    border-top: none;
    max-height: 200px;
    overflow-y: auto;
    list-style: none;
    box-shadow: 0 4px 8px rgba(0,0,0,0.12);
    box-sizing: border-box;
}

.cmp-adaptiveform-phoneinput__code-option {
    padding: 10px 12px;
    font-family: var(--font-sans, "Manulife JH Sans Optimized", sans-serif);
    font-size: var(--gem-font-size-base, 1rem);
    font-weight: var(--gem-font-weight-regular, 400);
    line-height: var(--gem-line-height-xl, 1.5rem);
    color: var(--gem-color-neutral-dark-default);
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 -0.5px 0 0 var(--gem-color-neutral-dark-light-4, #8e90a2) inset;
}

.cmp-adaptiveform-phoneinput__code-option:hover,
.cmp-adaptiveform-phoneinput__code-option[data-focused="true"] {
    background: var(--gem-color-surface-default-hover, #f5f5f5);
    box-shadow: inset 0 0 0 2px var(--gem-color-border-status-success, #06874e);
}

.cmp-adaptiveform-phoneinput__code-option--selected {
    background: var(--gem-color-surface-default, #ffffff);
    box-shadow: inset 3px 0 0 var(--gem-color-border-status-success, #06874e), 0 -0.5px 0 0 var(--gem-color-neutral-dark-light-4, #8e90a2) inset;
}

.cmp-adaptiveform-phoneinput__code-option--selected::after {
    content: "";
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-left: 8px;
    background-color: var(--gem-color-neutral-dark-default, #282b3e);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 20 20'%3E%3Cpath d='M8.8 11 6.9 9.1l-1.2 1.2 3 3 5.6-5.6-1.2-1.2z' fill='currentColor'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
    mask-position: center;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 20 20'%3E%3Cpath d='M8.8 11 6.9 9.1l-1.2 1.2 3 3 5.6-5.6-1.2-1.2z' fill='currentColor'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
}

.cmp-adaptiveform-phoneinput__code-option--selected:hover,
.cmp-adaptiveform-phoneinput__code-option--selected[data-focused="true"] {
    background: var(--gem-color-surface-default-hover, #f5f5f5);
    box-shadow: inset 0 0 0 2px var(--gem-color-border-status-success, #06874e);
}

/* Warning icon — matches theme's textinput error icon */
.cmp-adaptiveform-phoneinput__errormessage::before {
    content: "";
    width: 20px;
    height: 20px;
    background-color: var(--gem-color-surface-status-error);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 60'%3E%3Cpath d='M27.5 21.684h5v14h-5zm0 16.027h5v5h-5z' fill='currentColor'/%3E%3Cpath d='M30 3.238 3 50h54zm0 10L48.339 45H11.661z' fill='currentColor'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
    mask-position: center;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 60'%3E%3Cpath d='M27.5 21.684h5v14h-5zm0 16.027h5v5h-5z' fill='currentColor'/%3E%3Cpath d='M30 3.238 3 50h54zm0 10L48.339 45H11.661z' fill='currentColor'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
    flex-shrink: 0;
    margin-right: 8px;
}