/* ==========================================================================
   ABK UI · 表单
   输入、选择、开关、滑杆、分段控件。所有控件都保持手写的圆润感。
   ========================================================================== */

/* ================================================================ 字段容器 */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.field__label {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  font-family: var(--font-hand);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--ink-soft);
}

.field__label .optional {
  font-weight: var(--fw-regular);
  color: var(--ink-faint);
  font-size: var(--fs-xs);
}

.field__hint {
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  line-height: 1.5;
}

.field__error {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  color: var(--danger);
  font-weight: var(--fw-bold);
}

.field__error::before {
  content: "!";
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--danger);
  color: var(--danger-ink);
  font-size: 9px;
  font-weight: var(--fw-bold);
}

.field--invalid .input,
.field--invalid .textarea,
.field--invalid .select {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.field--invalid .input:focus,
.field--invalid .textarea:focus,
.field--invalid .select:focus {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--danger) 18%, transparent);
}

/* ================================================================ 输入框 */
.input,
.textarea,
.select {
  width: 100%;
  min-height: 44px;
  padding: 10px var(--sp-4);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--bg-input);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--ink-faint);
}

.input:hover:not(:disabled),
.textarea:hover:not(:disabled),
.select:hover:not(:disabled) {
  border-color: var(--ink-faint);
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-raised);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  opacity: .55;
  cursor: not-allowed;
  background: var(--bg-sunken);
}

.input[readonly] {
  background: var(--bg-sunken);
  border-style: dashed;
}

.textarea {
  min-height: 108px;
  padding-block: var(--sp-3);
  line-height: var(--lh-normal);
  resize: vertical;
}

.select {
  appearance: none;
  padding-inline-end: var(--sp-8);
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 20px) calc(50% + 1px),
    calc(100% - 14px) calc(50% + 1px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group .input {
  padding-inline-start: var(--sp-9);
}

.input-group__icon {
  --icon-size: 20px;
  position: absolute;
  inset-inline-start: var(--sp-4);
  display: grid;
  place-items: center;
  color: var(--ink-muted);
  pointer-events: none;
}

.input-group__suffix {
  position: absolute;
  inset-inline-end: var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.input--sm {
  min-height: 36px;
  font-size: var(--fs-sm);
  padding-block: 6px;
}

/* 带前后缀：金额、单位 */
.input-affix {
  display: flex;
  align-items: stretch;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--bg-input);
  overflow: hidden;
}

.input-affix:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-affix .input {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.input-affix__addon {
  display: grid;
  place-items: center;
  padding-inline: var(--sp-4);
  background: var(--bg-sunken);
  color: var(--ink-muted);
  font-size: var(--fs-sm);
  white-space: nowrap;
}

/* ================================================================ 勾选 / 单选 */
.check {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 32px;
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-md);
}

.check input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.check__box {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.8px solid var(--line-strong);
  border-radius: 7px;
  background: var(--bg-input);
  transition: all var(--dur-fast) var(--ease-out);
}

.check__box::after {
  content: "";
  width: 10px;
  height: 6px;
  border-left: 2.2px solid var(--accent-ink);
  border-bottom: 2.2px solid var(--accent-ink);
  transform: rotate(-45deg) translate(1px, -1px) scale(0);
  transform-origin: center;
  transition: transform var(--dur-fast) var(--ease-spring);
}

.check input:checked + .check__box {
  background: var(--accent);
  border-color: var(--accent);
}

.check input:checked + .check__box::after {
  transform: rotate(-45deg) translate(1px, -1px) scale(1);
}

.check input:indeterminate + .check__box {
  background: var(--accent);
  border-color: var(--accent);
}

.check input:indeterminate + .check__box::after {
  width: 11px;
  height: 0;
  border-left: 0;
  border-bottom: 2.2px solid var(--accent-ink);
  transform: none;
}

.check:hover .check__box {
  border-color: var(--accent);
}

.check input:focus-visible + .check__box {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.check input:disabled + .check__box {
  opacity: .5;
}

.check--radio .check__box {
  border-radius: 50%;
}

.check--radio .check__box::after {
  width: 10px;
  height: 10px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-ink);
  transform: scale(0);
}

.check--radio input:checked + .check__box::after {
  transform: scale(1);
}

.check__label {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.check__desc {
  font-size: var(--fs-xs);
  color: var(--ink-muted);
}

/* 卡片式单选 */
.choice {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-raised);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  position: relative;
}

.choice:hover {
  border-color: var(--line-strong);
  background: var(--bg-sunken);
}

.choice input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}

.choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.choice:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.choice__indicator {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  border: 1.8px solid var(--line-strong);
  border-radius: 50%;
  background: var(--bg-raised);
}

.choice__indicator::after {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  transform: scale(0);
  transition: transform var(--dur-fast) var(--ease-spring);
}

.choice:has(input:checked) .choice__indicator {
  border-color: var(--accent);
}

.choice:has(input:checked) .choice__indicator::after {
  transform: scale(1);
}

/* ================================================================ 开关 */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch__track {
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  border-radius: var(--r-pill);
  background: var(--bg-sunken);
  border: 1.5px solid var(--line-strong);
  transition: all var(--dur-base) var(--ease-out);
}

.switch__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--bg-raised);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-base) var(--ease-spring),
              background-color var(--dur-base);
}

.switch input:checked + .switch__track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + .switch__track .switch__thumb {
  transform: translateX(20px);
  background: var(--accent-ink);
}

.switch input:focus-visible + .switch__track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch input:disabled + .switch__track {
  opacity: .45;
}

.switch__label {
  font-size: var(--fs-md);
}

.switch--sm .switch__track { width: 40px; height: 24px; }
.switch--sm .switch__thumb { width: 16px; height: 16px; top: 2.5px; left: 2.5px; }
.switch--sm input:checked + .switch__track .switch__thumb { transform: translateX(16px); }

/* 设置行：标签在左，开关在右 */
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding-block: var(--sp-3);
}

.setting + .setting {
  border-top: 1px solid var(--line);
}

.setting__body {
  min-width: 0;
}

.setting__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
}

.setting__desc {
  font-size: var(--fs-sm);
  color: var(--ink-muted);
  line-height: 1.45;
  margin-top: 2px;
}

/* ================================================================ 滑杆 */
.slider {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.slider__value {
  font-family: var(--font-hand);
  font-weight: var(--fw-bold);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  cursor: pointer;
  --fill: 50%;
}

.slider input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: var(--r-pill);
  background: linear-gradient(var(--accent), var(--accent)) 0 / var(--fill) 100% no-repeat,
              var(--bg-sunken);
  border: 1px solid var(--line);
}

.slider input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--bg-sunken);
  border: 1px solid var(--line);
}

.slider input[type="range"]::-moz-range-progress {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--accent);
}

.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--bg-raised);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease-spring);
}

.slider input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-raised);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-sm);
}

.slider input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.15);
}

.slider input[type="range"]:focus-visible {
  outline: none;
}

.slider input[type="range"]:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ================================================================ 分段控件 */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--bg-sunken);
}

.segmented__item {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-pill);
  color: var(--ink-muted);
  font-family: var(--font-hand);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}

.segmented__item:hover {
  color: var(--ink);
}

.segmented__item[aria-selected="true"],
.segmented__item.is-selected {
  background: var(--bg-raised);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.segmented--block {
  display: flex;
}

.segmented--block .segmented__item {
  flex: 1;
}

.segmented--sm .segmented__item {
  min-height: 26px;
  font-size: var(--fs-xs);
  padding-inline: var(--sp-3);
}
