/* References: demo = konfetki/prototip/index.html; kit = prototip/ds/Components.bundle.js.
   Each block cites the source for its visual values. Layout/visibility rules wire up the native controls. */

/* Demo :731–742 (field layout, typography and ring); kit Input :25282–25293 (state tokens). */
.k-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.k-field__label {
  color: var(--typo-primary);
}

.k-field__input {
  width: 100%;
  height: 48px;
  min-width: 0;
  padding: 0 20px;
  border: 0;
  border-radius: calc(var(--rounded-full) * 1px);
  background: var(--control-field-bg);
  box-shadow: inset 0 0 0 1.5px var(--control-field-border);
  color: var(--typo-primary);
}

.k-field__input::placeholder,
.k-listbox__placeholder {
  color: var(--typo-placeholder);
  opacity: 1;
}

.k-field__input:hover {
  box-shadow: inset 0 0 0 1.5px var(--control-field-border-hover);
}

.k-field--error .k-field__input {
  box-shadow: inset 0 0 0 1.5px var(--control-field-border-critical);
}

/* Demo :1604 sets the focus color; B.4 uses the 2px focus ring from base.css. */
.k-field__input:focus,
.k-field--focus .k-field__input {
  outline: 0;
  box-shadow: inset 0 0 0 2px var(--control-field-border-focus);
}

.k-field__input.k-listbox__trigger:focus-visible {
  outline: 0 !important; /* Override the stock/standard button outline with the field ring. */
}

.k-field__input:disabled {
  background: var(--control-disabled-bg);
  box-shadow: inset 0 0 0 1.5px var(--control-disabled-bg);
  color: var(--control-disabled-typo);
}

/* Demo :1604 (phone in the login dialog), :691 (promo code). */
.k-field--dialog .k-field__input:not(.k-field__textarea) {
  height: 56px;
}

.k-phone.k-field--dialog .k-field__input {
  padding-inline: 22px;
}

/* Kit Textarea :36945–36952 for shape/padding; demo :1638 for type and resizing. */
.k-field__textarea {
  min-height: 120px;
  padding: 14px 20px;
  border-radius: calc(var(--rounded-xl) * 1px);
  resize: vertical;
}

/* Demo :739–742, designer rule #105: “от левого края поля, вровень с подписью, без внутреннего отступа”. */
.k-field__error,
.k-field__hint {
  margin-inline: 0;
  padding-inline: 0;
  font-size: 12px;
  line-height: 16px;
}

.k-field__error {
  color: var(--typo-critical);
}

.k-field__hint {
  margin-top: -8px;
  color: var(--typo-secondary);
}

/* Demo :836–903 (gift request and success card). */
.k-feedback {
  display: grid;
  gap: 16px;
  align-content: start;
  width: 100%;
  max-width: 500px;
  min-width: 0;
  padding: clamp(20px, 4vw, 32px);
  border-radius: calc(var(--rounded-4xl) * 1px);
  background: var(--bg-surface);
}

.k-feedback--gift {
  background: var(--bg-brand);
  box-shadow: inset 0 0 0 1px var(--bg-border-glass);
  color: var(--typo-inverted);
}

.k-feedback--gift :is(.k-field__label, .k-field__error) { color: inherit; }
.k-feedback__title, .k-feedback__error, .k-feedback--success p { margin: 0; }

.k-feedback__fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 12px;
}

.k-feedback__field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  grid-column: span 2;
  min-width: 0;
}

.k-feedback__field--half { grid-column: span 1; }
.k-feedback__field--half input { text-overflow: ellipsis; }
.k-feedback__privacy { width: fit-content; color: inherit; text-decoration: underline; }
.k-feedback .k-field--error .k-checkbox__box { outline: 2px solid var(--control-field-border-critical); }
.k-feedback .k-field--error :is(.k-file__drop, .k-file__card) {
  box-shadow: inset 0 0 0 1.5px var(--control-field-border-critical);
}

.k-feedback--success {
  justify-items: center;
  text-align: center;
}

.k-feedback--success .k-feedback__title { font: 400 28px/36px "Yeseva One", serif; }
.k-feedback--success p { max-width: 360px; }

.k-feedback__check {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg-success-surface);
  color: var(--typo-success);
}

@media (width < 768px) {
  .k-feedback__field--half { grid-column: span 2; }
  .k-feedback__title { font-size: 28px; line-height: 36px; }
}

/* Demo :886–889 (native control/box/label), kit Checkbox :12604–12610 (8px radius). */
.k-checkbox,
.k-radio {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  max-width: 100%;
  cursor: pointer;
}

.k-checkbox__input,
.k-radio__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.k-checkbox__box,
.k-radio__box {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  background: var(--control-field-bg);
}

.k-checkbox__box {
  border-radius: calc(var(--rounded-sm) * 1px);
  box-shadow: inset 0 0 0 1.5px var(--control-check-border);
  color: var(--white);
}

.k-checkbox--corporate .k-checkbox__box {
  border-radius: 6px; /* Demo :888 (corporate logo opt-in). */
}

.k-checkbox__box .k-icon {
  visibility: hidden;
}

/* Demo :888, :3031 (checked state: raspberry-600, no ring, white check). */
.k-checkbox__input:checked + .k-checkbox__box {
  background: var(--control-check-bg-active);
  box-shadow: none;
}

.k-checkbox__input:checked + .k-checkbox__box .k-icon {
  visibility: visible;
}

/* B.4 generic radio dimensions/colors; kit Radio :34169–34175 supplies the 24px circular box. */
.k-radio {
  --k-radio-ring: 2px var(--control-field-border-focus);
  --k-radio-ring-checked: var(--k-radio-ring);
  --k-radio-dot-size: 0px;
  --k-radio-dot-color: transparent;
  --k-radio-dot-checked-size: 7px;
  --k-radio-dot-checked-color: var(--control-check-bg-active);
}

/* Demo :2155–2156 (delivery-specific ring and dot, including the unselected dot). */
.k-radio--delivery {
  --k-radio-ring: 1.5px var(--control-field-border);
  --k-radio-ring-checked: 2px var(--control-field-border-focus);
  --k-radio-dot-size: 1.5px;
  --k-radio-dot-color: var(--control-check-border);
  --k-radio-dot-checked-size: 6px;
  --k-radio-dot-checked-color: var(--control-field-border-focus);
}

.k-radio__box {
  border-radius: 50%;
  box-shadow: inset 0 0 0 var(--k-radio-ring);
}

.k-radio__box::after {
  content: "";
  width: var(--k-radio-dot-size);
  height: var(--k-radio-dot-size);
  background: var(--k-radio-dot-color);
  border-radius: 50%;
}

.k-radio__input:checked + .k-radio__box {
  box-shadow: inset 0 0 0 var(--k-radio-ring-checked);
}

.k-radio__input:checked + .k-radio__box::after {
  width: var(--k-radio-dot-checked-size);
  height: var(--k-radio-dot-checked-size);
  background: var(--k-radio-dot-checked-color);
}

/* Kit Checkbox :12900–12911 and Radio :34459–34470 (hover/disabled). Focus uses base.css's ring. */
.k-checkbox:hover .k-checkbox__input:not(:disabled) + .k-checkbox__box,
.k-radio:hover .k-radio__input:not(:disabled) + .k-radio__box,
.k-checkbox__input:focus-visible + .k-checkbox__box,
.k-radio__input:focus-visible + .k-radio__box {
  outline: 2px solid var(--control-field-border-focus);
  outline-offset: 2px;
}

.k-checkbox:has(:disabled),
.k-radio:has(:disabled) {
  cursor: default;
  color: var(--control-disabled-typo);
}

.k-checkbox__input:disabled + .k-checkbox__box,
.k-radio__input:disabled + .k-radio__box {
  background: var(--control-disabled-bg);
  box-shadow: inset 0 0 0 1.5px var(--control-check-border);
  color: var(--control-disabled-typo);
}

.k-radio__input:disabled:checked + .k-radio__box::after {
  background: var(--control-disabled-typo);
}

/* Demo :432, :866 (chevrons); kit Select :34582–34589 (native control uses the same shell). */
.k-select__control,
.k-listbox .k-listbox__control {
  position: relative;
}

.k-select select {
  appearance: none;
  padding-inline-end: 48px;
  cursor: pointer;
}

.k-select select:disabled {
  cursor: default;
}

.k-select__icon {
  position: absolute;
  inset-inline-end: 20px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.k-select__icon,
.k-listbox__icon {
  color: var(--typo-secondary);
}

.k-listbox__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  text-align: start;
}

.k-listbox__trigger[aria-expanded="true"] .k-listbox__icon {
  transform: rotate(180deg);
}

/* Demo :868–869 (budget list), :431–437 (sorting dropdown); kit Dropdown :39941–39945. */
.k-listbox__popup {
  margin-top: 8px;
  padding: 8px;
  border-radius: calc(var(--rounded-xl) * 1px);
  background: var(--control-field-bg);
}

.k-listbox__options {
  display: grid;
  gap: 2px;
}

.k-listbox__option,
.k-listbox__title {
  display: flex;
  align-items: center;
  padding-inline: 12px;
}

.k-listbox__option {
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  border: 0;
  border-radius: calc(var(--rounded-md) * 1px);
  background: transparent;
  color: var(--typo-primary);
  cursor: pointer;
  text-align: start;
}

.k-listbox__option:hover {
  background: var(--bg-tertiary);
}

.k-listbox__option .k-icon {
  visibility: hidden;
  color: var(--control-check-bg-active);
}

.k-listbox__option[aria-selected="true"] .k-icon {
  visibility: visible;
}

.k-listbox--sort .k-listbox__trigger {
  padding-inline: 18px;
  font-size: 14px;
}

.k-listbox--sort .k-listbox__popup {
  position: absolute;
  inset-inline: 0;
  top: 100%; /* 48px trigger + 8px margin = 56px in demo :435. */
  z-index: 20;
  box-shadow: var(--k-shadow-dropdown);
}

.k-listbox__title {
  height: 32px;
  color: var(--typo-secondary);
  font-size: 12px;
  font-weight: 500;
}

.k-listbox--sort .k-listbox__option {
  gap: 16px;
}

.k-listbox--sort .k-listbox__option[aria-selected="true"] {
  background: var(--raspberry-100); /* Demo :2464 (selected sort order). */
}

.k-listbox--sort .k-listbox__option .k-icon {
  color: var(--typo-primary);
}

/* Demo :1489–1499 (number fields, gap, track); :33–36 (native overlay/thumbs). */
.k-range {
  --k-range-left: 0%;
  --k-range-right: 0%;
  --k-range-thumb: 20px;
  --k-range-thumb-shadow: 0 2px 6px rgba(37, 37, 37, 0.15);
  display: grid;
  gap: 12px;
}

.k-range__values {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--typo-secondary);
  font-size: 14px;
}

.k-range__input {
  flex: 1;
  min-width: 0;
  height: 44px;
  appearance: textfield;
  border: 0;
  border-radius: calc(var(--rounded-md) * 1px);
  background: var(--control-field-bg);
  box-shadow: inset 0 0 0 1px var(--control-field-border);
  color: var(--typo-primary);
  font-size: 14px;
  text-align: center;
}

.k-range__input::-webkit-inner-spin-button,
.k-range__input::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.k-range__input:focus {
  outline: 0;
  box-shadow: inset 0 0 0 2px var(--control-field-border-focus); /* B.4 field focus. */
}

.k-range__slider {
  position: relative;
  height: 24px;
}

.k-range__track,
.k-range__fill {
  position: absolute;
  height: 4px;
  border-radius: 4px;
}

.k-range__track {
  /* Inset by the thumb radius so fill percentages match the browser's thumb travel. */
  inset-inline: calc(var(--k-range-thumb) / 2);
  top: 10px;
  background: var(--control-field-border);
}

.k-range__fill {
  left: var(--k-range-left);
  right: var(--k-range-right);
  background: linear-gradient(90deg, #D8365E, #F26F24);
}

.k-range__handle {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  appearance: none;
  background: transparent;
  pointer-events: none;
  touch-action: none;
  z-index: 2;
}

.k-range__handle--from {
  z-index: 1;
}

.k-range--overlap .k-range__handle--from,
.k-range__handle:focus-visible {
  z-index: 3;
}

.k-range__handle::-webkit-slider-thumb {
  width: var(--k-range-thumb);
  height: var(--k-range-thumb);
  appearance: none;
  border: 2px solid var(--control-check-bg-active);
  border-radius: calc(var(--rounded-full) * 1px);
  background: var(--control-field-bg);
  box-shadow: var(--k-range-thumb-shadow);
  pointer-events: auto;
  cursor: grab;
}

.k-range__handle::-moz-range-thumb {
  box-sizing: border-box; /* Demo :35 uses 16px + a 2px border per side. */
  width: var(--k-range-thumb);
  height: var(--k-range-thumb);
  border: 2px solid var(--control-check-bg-active);
  border-radius: calc(var(--rounded-full) * 1px);
  background: var(--control-field-bg);
  box-shadow: var(--k-range-thumb-shadow);
  pointer-events: auto;
  cursor: grab;
}

.k-range__handle::-moz-range-track {
  background: transparent;
  border: 0;
}

/* Demo :1352–1365 (drop area, prompt, button and file card). */
.k-file {
  display: grid;
  min-width: 0;
}

.k-file__drop,
.k-file__card {
  margin-top: 10px;
  display: flex;
  align-items: center;
  min-width: 0;
}

.k-file__drop[hidden],
.k-file__card[hidden] {
  display: none;
}

.k-file__drop {
  width: 100%;
  flex-direction: column;
  gap: 8px;
  padding: 20px 16px;
  border: 0;
  border-radius: calc(var(--rounded-xl) * 1px);
  background: var(--bg-surface);
  box-shadow: inset 0 0 0 1.5px var(--control-field-border);
  color: var(--typo-primary);
  text-align: center;
  cursor: pointer;
}

.k-file__drop:hover,
.k-file--dragover .k-file__drop {
  box-shadow: inset 0 0 0 1.5px var(--control-field-border-hover);
}

/* B.4 upload errors use the demo's field error ring, :739. */
.k-file--error-format .k-file__drop,
.k-file--error-size .k-file__drop {
  box-shadow: inset 0 0 0 1.5px var(--control-field-border-critical);
}

.k-file__prompt {
  color: var(--typo-secondary);
}

.k-file__browse {
  display: flex;
  align-items: center;
  height: 36px;
  padding-inline: 18px;
  border-radius: calc(var(--rounded-full) * 1px);
  background: var(--control-field-bg);
  box-shadow: inset 0 0 0 1.5px var(--control-field-border);
}

.k-file__card {
  gap: 10px;
  padding: 12px 16px;
  border-radius: calc(var(--rounded-lg) * 1px);
  background: var(--control-field-bg);
  box-shadow: inset 0 0 0 1px var(--control-field-border);
}

.k-file__icon,
.k-file__remove {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: calc(var(--rounded-md) * 1px);
  background: var(--bg-tertiary);
}

.k-file__drop .k-file__icon {
  width: 44px;
  height: 44px;
  border-radius: calc(var(--rounded-full) * 1px);
}

.k-file__remove {
  border: 0;
  border-radius: calc(var(--rounded-full) * 1px);
  color: var(--typo-primary);
  cursor: pointer;
}

.k-file__info {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.k-file__size {
  color: var(--typo-secondary);
  font-size: 12px;
  line-height: 16px;
}

.k-file [data-file-error]:not([hidden]) {
  display: block;
  margin-top: 8px; /* Demo :739 (gap before the field error). */
}
