/* Form controls: field row, input, select, textarea, checkbox, switch, segmented
 * control, the boxed one-time-code input, and the search box. */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.field-label .optional {
  color: var(--text-3);
  font-weight: 400;
}

.field-help {
  color: var(--text-3);
  font-size: 12.5px;
  line-height: 1.45;
}

.field-error {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 500;
}

.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.field-label-row a {
  font-size: 13px;
  font-weight: 500;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* a horizontal settings row: label + help on the left, control on the right */
.form-row {
  display: grid;
  grid-template-columns: minmax(0, 240px) minmax(0, 1fr);
  gap: 8px 32px;
  padding: 20px 0;
  border-top: 1px solid var(--border);
}

.form-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.form-row-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 440px;
}

@media (max-width: 760px) {
  .form-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
  font-size: 14px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.textarea {
  height: auto;
  min-height: 84px;
  padding: 8px 12px;
  line-height: 1.5;
  resize: vertical;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-3);
  opacity: 1;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--text-3);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: var(--ring);
}

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger-solid);
}

.input[aria-invalid="true"]:focus {
  box-shadow: var(--ring-danger);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--surface-3);
  color: var(--text-3);
  cursor: not-allowed;
}

.select {
  padding-right: 32px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 15px, calc(100% - 12px) 15px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.select-sm,
.input-sm {
  height: 32px;
  font-size: 13.5px;
}

.select-sm {
  background-position: calc(100% - 17px) 13px, calc(100% - 12px) 13px;
}

/* input with a leading icon (search) */
.input-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon > .icon {
  position: absolute;
  left: 10px;
  color: var(--text-3);
  pointer-events: none;
}

.input-icon > .input {
  padding-left: 32px;
}

.search {
  width: 260px;
  max-width: 100%;
}

/* input with an attached suffix, like ".tablepop.app" */
.input-group {
  display: flex;
  align-items: stretch;
}

.input-group > .input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-addon {
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--border-input);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13.5px;
  white-space: nowrap;
}

/* checkbox + label */
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.check input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--primary);
  cursor: pointer;
}

/* switch: a real checkbox, restyled */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.switch input {
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  margin: 0;
  border-radius: 999px;
  background: var(--border-input);
  appearance: none;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.2);
  transition: transform 0.15s ease;
}

.switch input:checked {
  background: var(--primary);
}

.switch input:checked::after {
  transform: translateX(14px);
}

.switch input:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* segmented control: radios in a pill row */
.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label,
.segmented .segment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: none;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.segmented label:hover,
.segmented .segment:hover {
  color: var(--text);
}

.segmented input:checked + label,
.segmented .segment[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented input:focus-visible + label,
.segmented .segment:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* one-time code: ONE real input, drawn over six boxes */
.otp {
  --otp-box: 55px;
  --otp-gap: 10px;
  --otp-pitch: calc(var(--otp-box) + var(--otp-gap));
  position: relative;
  width: calc(6 * var(--otp-box) + 5 * var(--otp-gap));
  height: 52px;
  max-width: 100%;
}

.otp-boxes {
  position: absolute;
  inset: 0;
  display: flex;
  gap: var(--otp-gap);
  pointer-events: none;
}

.otp-box {
  flex: none;
  width: var(--otp-box);
  height: 100%;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.otp-input {
  position: relative;
  /* one pitch wider than the boxes, so the caret after the sixth digit never makes the
     input scroll its text sideways */
  width: calc(100% + var(--otp-pitch));
  height: 100%;
  margin: 0;
  padding: 0 0 0 calc(var(--otp-box) / 2 - 0.5ch);
  border: 0;
  background: transparent;
  color: var(--text);
  font: 600 24px/1 var(--mono);
  letter-spacing: calc(var(--otp-pitch) - 1ch);
  caret-color: var(--primary);
}

.otp-input:focus {
  outline: none;
}

.otp-input::placeholder {
  color: var(--border-input);
}

.otp:focus-within .otp-box.is-active,
html:not(.js) .otp:focus-within .otp-box {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.otp-box.is-filled {
  border-color: var(--text-3);
}

.otp[data-invalid] .otp-box {
  border-color: var(--danger-solid);
}

@media (max-width: 400px) {
  .otp {
    --otp-box: 40px;
    --otp-gap: 6px;
    height: 48px;
  }
}

/* password field with a reveal toggle (password-toggle is JS-only) */
.password {
  position: relative;
}

.password > .input {
  padding-right: 40px;
}

.password-toggle {
  position: absolute;
  top: 3px;
  right: 3px;
  height: 30px;
  width: 30px;
}
