/* Safari forms normalization
   Работает на iOS Safari и macOS Safari.
*/

/* 1) Общая нормализация внешнего вида (Safari / WebKit) */
@supports (-webkit-appearance: none) {

  /* Текстовые поля и textarea (не трогаем checkbox/radio/file) */
  html body input:not([type]),
  html body input[type="text"],
  html body input[type="search"],
  html body input[type="password"],
  html body input[type="number"],
  html body input[type="email"],
  html body input[type="tel"],
  html body input[type="url"],
  html body textarea {
    -webkit-appearance: none;
    appearance: none;
    background-clip: padding-box;
    border-radius: 10px;
    line-height: 1.5;
  }

  /* select в закрытом состоянии делаем предсказуемым */
  html body select:not([multiple]):not([size]) {
    -webkit-appearance: none;
    appearance: none;
    background-clip: padding-box;
    border-radius: 10px;
    line-height: 1.5;
    padding-right: 40px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5l3.5 3.5 3.5-3.5' fill='none' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    background-size: 14px 14px !important;
  }

  /* Нативные date/time-поля в Safari требуют отдельного выравнивания,
     иначе на macOS Safari внутреннее значение может выбиваться из инпута. */
  html body input[type="date"],
  html body input[type="datetime-local"],
  html body input[type="time"],
  html body input[type="month"],
  html body input[type="week"] {
    min-width: 0;
    padding-right: 12px !important;
    background-clip: padding-box;
  }

  html body input[type="date"]::-webkit-date-and-time-value,
  html body input[type="datetime-local"]::-webkit-date-and-time-value,
  html body input[type="time"]::-webkit-date-and-time-value,
  html body input[type="month"]::-webkit-date-and-time-value,
  html body input[type="week"]::-webkit-date-and-time-value {
    text-align: left;
  }

  html body input[type="date"]::-webkit-datetime-edit,
  html body input[type="datetime-local"]::-webkit-datetime-edit,
  html body input[type="time"]::-webkit-datetime-edit,
  html body input[type="month"]::-webkit-datetime-edit,
  html body input[type="week"]::-webkit-datetime-edit {
    align-items: center;
    min-height: 1.35em;
    padding: 0;
  }

  html body input[type="date"]::-webkit-datetime-edit-fields-wrapper,
  html body input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper,
  html body input[type="time"]::-webkit-datetime-edit-fields-wrapper,
  html body input[type="month"]::-webkit-datetime-edit-fields-wrapper,
  html body input[type="week"]::-webkit-datetime-edit-fields-wrapper {
    align-items: center;
    min-width: 0;
    gap: 0;
  }

  html body input[type="date"]::-webkit-calendar-picker-indicator,
  html body input[type="datetime-local"]::-webkit-calendar-picker-indicator,
  html body input[type="time"]::-webkit-calendar-picker-indicator,
  html body input[type="month"]::-webkit-calendar-picker-indicator,
  html body input[type="week"]::-webkit-calendar-picker-indicator {
    margin-left: 8px;
    opacity: .9;
  }

  /* Убираем стандартные iOS декорации у search */
  html body input[type="search"]::-webkit-search-decoration,
  html body input[type="search"]::-webkit-search-cancel-button,
  html body input[type="search"]::-webkit-search-results-button,
  html body input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none;
  }
}

/* 2) iOS: предотвращаем zoom при фокусе (font-size >= 16px обязательно) */
@supports (-webkit-touch-callout: none) {
  html { -webkit-text-size-adjust: 100%; }

  html body input:not([type]),
  html body input[type="text"],
  html body input[type="search"],
  html body input[type="password"],
  html body input[type="number"],
  html body input[type="email"],
  html body input[type="tel"],
  html body input[type="url"],
  html body input[type="date"],
  html body input[type="datetime-local"],
  html body input[type="time"],
  html body input[type="month"],
  html body input[type="week"],
  html body textarea,
  html body select {
    font-size: 15px !important;
  }

  html body input[type="date"],
  html body input[type="datetime-local"],
  html body input[type="time"],
  html body input[type="month"],
  html body input[type="week"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding-right: 36px !important;
    padding-inline-end: 36px !important;
  }

  html body input[type="date"]::-webkit-date-and-time-value,
  html body input[type="datetime-local"]::-webkit-date-and-time-value,
  html body input[type="time"]::-webkit-date-and-time-value,
  html body input[type="month"]::-webkit-date-and-time-value,
  html body input[type="week"]::-webkit-date-and-time-value {
    display: block;
    width: 100%;
    min-width: 0;
    white-space: nowrap;
  }

  html body input[type="date"]::-webkit-datetime-edit,
  html body input[type="datetime-local"]::-webkit-datetime-edit,
  html body input[type="time"]::-webkit-datetime-edit,
  html body input[type="month"]::-webkit-datetime-edit,
  html body input[type="week"]::-webkit-datetime-edit {
    display: block;
    width: 100%;
    min-width: 0;
    overflow: hidden;
  }

  html body input[type="date"]::-webkit-datetime-edit-fields-wrapper,
  html body input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper,
  html body input[type="time"]::-webkit-datetime-edit-fields-wrapper,
  html body input[type="month"]::-webkit-datetime-edit-fields-wrapper,
  html body input[type="week"]::-webkit-datetime-edit-fields-wrapper {
    display: block;
    width: 100%;
    min-width: 0;
  }

  html body input[type="date"]::-webkit-calendar-picker-indicator,
  html body input[type="datetime-local"]::-webkit-calendar-picker-indicator,
  html body input[type="time"]::-webkit-calendar-picker-indicator,
  html body input[type="month"]::-webkit-calendar-picker-indicator,
  html body input[type="week"]::-webkit-calendar-picker-indicator {
    margin-left: 4px;
  }
}

html.ios-safari input[type="date"],
html.ios-safari input[type="datetime-local"],
html.ios-safari input[type="time"],
html.ios-safari input[type="month"],
html.ios-safari input[type="week"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding-right: 28px;
  padding-inline-end: 28px;
  overflow: hidden;
  background-clip: padding-box;
}

html.ios-safari input[type="date"]::-webkit-date-and-time-value,
html.ios-safari input[type="datetime-local"]::-webkit-date-and-time-value,
html.ios-safari input[type="time"]::-webkit-date-and-time-value,
html.ios-safari input[type="month"]::-webkit-date-and-time-value,
html.ios-safari input[type="week"]::-webkit-date-and-time-value {
  display: block;
  min-width: 0;
  width: auto;
  max-width: 100%;
  text-align: left;
  white-space: nowrap;
}

html.ios-safari input[type="date"]::-webkit-datetime-edit,
html.ios-safari input[type="datetime-local"]::-webkit-datetime-edit,
html.ios-safari input[type="time"]::-webkit-datetime-edit,
html.ios-safari input[type="month"]::-webkit-datetime-edit,
html.ios-safari input[type="week"]::-webkit-datetime-edit {
  display: block;
  min-width: 0;
  width: auto;
  max-width: 100%;
  padding: 0;
  line-height: inherit;
  white-space: nowrap;
}

html.ios-safari input[type="date"]::-webkit-datetime-edit-fields-wrapper,
html.ios-safari input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper,
html.ios-safari input[type="time"]::-webkit-datetime-edit-fields-wrapper,
html.ios-safari input[type="month"]::-webkit-datetime-edit-fields-wrapper,
html.ios-safari input[type="week"]::-webkit-datetime-edit-fields-wrapper {
  display: block;
  min-width: 0;
  width: auto;
  max-width: 100%;
  padding: 0;
}

html.ios-safari input[type="date"]::-webkit-calendar-picker-indicator,
html.ios-safari input[type="datetime-local"]::-webkit-calendar-picker-indicator,
html.ios-safari input[type="time"]::-webkit-calendar-picker-indicator,
html.ios-safari input[type="month"]::-webkit-calendar-picker-indicator,
html.ios-safari input[type="week"]::-webkit-calendar-picker-indicator {
  margin: 0;
  flex: 0 0 auto;
}

html.ios-safari .field,
html.ios-safari .control,
html.ios-safari .filter-field,
html.ios-safari .filter-item {
  min-width: 0;
  max-width: 100%;
}

html.ios-safari .field > input[type="date"],
html.ios-safari .field > input[type="datetime-local"],
html.ios-safari .field > input[type="time"],
html.ios-safari .field > input[type="month"],
html.ios-safari .field > input[type="week"],
html.ios-safari .control > input[type="date"],
html.ios-safari .control > input[type="datetime-local"],
html.ios-safari .control > input[type="time"],
html.ios-safari .control > input[type="month"],
html.ios-safari .control > input[type="week"] {
  max-width: 100%;
}