/* Upgraded form controls from assets/js/fields.js: searchable select, calendar pickers, phone input. */

.fld-native {
    display: none !important;
}

.fld-select,
.fld-date {
    display: block;
    min-width: 0;
    position: relative;
    width: 100%;
}

.fld-trigger {
    cursor: pointer;
    text-align: start;
    width: 100%;
}

.fld-trigger:disabled {
    cursor: not-allowed;
    opacity: .6;
}

.fld-select-text,
.fld-date-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Keep the layouts written for a bare .select. */
.block-add .fld-select {
    flex: 1;
}

.settings-add-language .fld-select {
    max-width: 280px;
}

/* Shared popover */
.fld-pop {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    color: var(--t-base);
    font-size: 13px;
    max-width: calc(100vw - 16px);
    overflow: auto;
    position: fixed;
    z-index: 1200;
}

/* Dark scrollbars inside dark popovers. */
[data-theme="dark"] .fld-pop,
[data-theme="dark"] .iti__dropdown-content {
    color-scheme: dark;
}

/* Searchable list */
.fld-pop--list {
    display: flex;
    flex-direction: column;
    max-width: min(420px, calc(100vw - 16px));
    overflow: hidden;
    padding: 8px;
}

.fld-search {
    flex: none;
    margin-bottom: 6px;
    width: 100%;
}

.fld-list {
    flex: 1 1 auto;
    list-style: none;
    margin: 0;
    max-height: 240px;
    min-height: 0;
    overflow-y: auto;
    padding: 0;
}

.fld-option {
    border-radius: 8px;
    cursor: pointer;
    padding: 8px 10px;
}

.fld-option.is-active {
    background: var(--bg-hover);
}

.fld-option.is-chosen {
    color: var(--primary);
    font-weight: 600;
}

.fld-empty {
    color: var(--t-muted);
    padding: 12px 10px;
    text-align: center;
}

/* Date and time trigger */
.fld-date-trigger {
    align-items: center;
    display: flex;
    gap: 8px;
    padding-inline-end: 34px;
}

.fld-date-trigger.is-empty .fld-date-text {
    color: var(--t-muted);
}

.fld-date-icon {
    color: var(--t-muted);
    display: flex;
    flex: none;
}

.fld-date-icon svg,
.fld-clear svg,
.fld-cal-nav svg {
    fill: none;
    height: 16px;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    width: 16px;
}

.fld-clear {
    align-items: center;
    background: none;
    border: 0;
    border-radius: 6px;
    color: var(--t-muted);
    cursor: pointer;
    display: flex;
    inset-inline-end: 6px;
    padding: 4px;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.fld-clear[hidden] {
    display: none;
}

.fld-clear:hover {
    background: var(--bg-hover);
    color: var(--t-base);
}

/* Calendar */
.fld-pop-main {
    display: flex;
}

.fld-cal {
    padding: 12px;
    width: 280px;
}

.fld-cal-head {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.fld-cal-nav,
.fld-cal-title,
.fld-cal-day,
.fld-cal-pick,
.fld-time-cell,
.fld-foot-btn {
    background: none;
    border: 0;
    border-radius: 8px;
    color: inherit;
    cursor: pointer;
    font: inherit;
}

.fld-cal-nav {
    align-items: center;
    color: var(--t-muted);
    display: flex;
    height: 32px;
    justify-content: center;
    width: 32px;
}

[dir="rtl"] .fld-cal-nav svg {
    transform: scaleX(-1);
}

.fld-cal-title {
    font-weight: 700;
    padding: 6px 10px;
}

.fld-cal-nav:hover,
.fld-cal-title:hover,
.fld-cal-day:hover,
.fld-cal-pick:hover,
.fld-time-cell:hover:not(:disabled),
.fld-foot-btn:hover:not(:disabled) {
    background: var(--bg-hover);
}

.fld-cal-grid {
    display: grid;
    gap: 2px;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.fld-cal-weekday {
    color: var(--t-muted);
    font-size: 11.5px;
    font-weight: 600;
    padding: 6px 0;
    text-align: center;
}

.fld-cal-day {
    aspect-ratio: 1;
    font-variant-numeric: tabular-nums;
    position: relative;
}

.fld-cal-day.is-outside {
    color: var(--t-light);
}

.fld-cal-day.is-today::after {
    background: var(--primary);
    border-radius: 50%;
    bottom: 4px;
    content: "";
    height: 4px;
    inset-inline-start: calc(50% - 2px);
    position: absolute;
    width: 4px;
}

.fld-cal-day.is-chosen,
.fld-cal-pick.is-chosen,
.fld-time-cell.is-chosen,
.fld-cal-day.is-chosen:hover,
.fld-cal-pick.is-chosen:hover,
.fld-time-cell.is-chosen:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
}

[data-theme="dark"] .fld-cal-day.is-chosen,
[data-theme="dark"] .fld-cal-pick.is-chosen,
[data-theme="dark"] .fld-time-cell.is-chosen {
    color: #0b1220;
}

.fld-cal-day.is-chosen.is-today::after {
    background: currentColor;
}

.fld-cal-day[aria-disabled="true"] {
    background: none;
    color: var(--t-light);
    cursor: not-allowed;
    opacity: .45;
}

.fld-cal-picks {
    display: grid;
    gap: 4px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.fld-cal-pick {
    padding: 12px 0;
}

.fld-cal-day:focus-visible,
.fld-cal-pick:focus-visible,
.fld-cal-nav:focus-visible,
.fld-cal-title:focus-visible,
.fld-time-cell:focus-visible,
.fld-foot-btn:focus-visible,
.fld-clear:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

/* Time columns */
.fld-time {
    display: flex;
    gap: 4px;
    padding: 12px 8px;
}

.fld-cal + .fld-time {
    border-inline-start: 1px solid var(--border-soft);
}

.fld-time-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
    height: 272px;
    overflow-y: auto;
    position: relative;
    scrollbar-width: thin;
    width: 56px;
}

.fld-time-cell {
    flex: none;
    font-variant-numeric: tabular-nums;
    padding: 7px 0;
    text-align: center;
}

.fld-time-cell:disabled {
    color: var(--t-light);
    cursor: not-allowed;
    opacity: .45;
}

.fld-foot {
    border-top: 1px solid var(--border-soft);
    display: flex;
    gap: 4px;
    justify-content: flex-end;
    padding: 8px;
}

.fld-foot:empty {
    display: none;
}

.fld-foot-btn {
    color: var(--primary);
    font-weight: 600;
    padding: 6px 10px;
}

.fld-foot-btn:disabled {
    color: var(--t-light);
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .fld-pop-main {
        flex-direction: column;
    }

    .fld-cal + .fld-time {
        border-inline-start: 0;
        border-top: 1px solid var(--border-soft);
    }

    .fld-time {
        justify-content: center;
    }

    .fld-time-col {
        height: 140px;
    }
}

/* Phone (intl-tel-input): one control that matches the other inputs, in both themes. */
.iti {
    --iti-border-color: var(--border);
    --iti-country-selector-bg: var(--bg-card);
    --iti-dialcode-color: var(--t-muted);
    --iti-hover-color: var(--bg-hover);
    display: block;
    width: 100%;
}

.iti__dropdown-content,
.iti__country-list,
.iti__search-input {
    background: var(--bg-card);
    color: var(--t-base);
}

.iti__dropdown-content {
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.iti__search-input {
    border-color: var(--border-soft);
}

.iti__selected-dial-code,
.iti__dial-code {
    color: var(--t-muted);
}

.iti__country.iti__highlight {
    background: var(--bg-hover);
}
