.field {
  display: block;
  margin-bottom: var(--space-md);
}

.field:not(.switch-field) > span:first-child,
fieldset.field > span {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.field-half { margin-bottom: var(--space-md); }

.field input[type="text"],
.field input[type="number"],
.field input[type="datetime-local"],
.field textarea {
  width: 100%;
  padding: var(--space-md);
  min-height: var(--touch-min);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--text-md);
  font-family: inherit;
  color-scheme: dark;
}

.field textarea {
  min-height: auto;
  resize: vertical;
  font-size: var(--text-base);
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(109, 154, 232, 0.18);
}

.range-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-xs) 0;
}

.range-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  --range-pct: 40%;
}

.range-row input[type="range"]:focus {
  outline: none;
}

.range-row input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(109, 154, 232, 0.22);
}

.range-row input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--primary) 0%,
    var(--primary) var(--range-pct),
    var(--border) var(--range-pct),
    var(--border) 100%
  );
}

.range-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: 0 2px var(--space-sm) rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}

.range-row input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.12);
}

.range-row input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
}

.range-row input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--primary);
}

.range-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: 0 2px var(--space-sm) rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.range-row output {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--primary);
  min-width: 44px;
  text-align: right;
  flex-shrink: 0;
  padding: var(--space-xs) var(--space-sm);
  background: var(--overlay-active);
  border-radius: var(--radius-sm);
}

fieldset.field {
  border: none;
  margin: 0 0 var(--space-md);
  padding: 0;
  min-width: 0;
}

.field-mode .mode-toggle {
  display: flex;
  gap: var(--space-sm);
}

.mode-chip {
  flex: 1;
  cursor: pointer;
  position: relative;
}

.mode-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-chip span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  padding: 0 var(--space-md);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  transition: all 0.2s;
}

.mode-chip input:checked + span {
  background: var(--overlay-active);
  border-color: var(--primary);
  color: var(--primary);
}

.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  min-height: var(--touch-min);
  padding: 0 var(--space-md);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.switch-field:hover {
  border-color: rgba(109, 154, 232, 0.35);
  background: var(--surface-2);
}

.switch-field > .switch-label {
  display: flex;
  align-items: center;
  flex: 1;
  min-height: var(--touch-min);
  margin-bottom: 0;
  font-size: var(--text-md);
  font-weight: var(--font-semibold);
  color: var(--text);
  line-height: 1;
  letter-spacing: 0.02em;
}

.switch-control {
  position: relative;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
  align-self: center;
}

.switch-control input[type="checkbox"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.switch-track {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--border);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.22s ease, background 0.22s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.switch-control input:checked + .switch-track {
  background: linear-gradient(180deg, var(--primary-hover) 0%, var(--primary) 100%);
  border-color: var(--primary);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), 0 0 0 3px rgba(109, 154, 232, 0.15);
}

.switch-control input:checked + .switch-track::after {
  transform: translateX(22px);
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.switch-control input:focus-visible + .switch-track {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.switch-field:has(input:checked) {
  border-color: rgba(109, 154, 232, 0.45);
  background: var(--overlay-active);
}

.switch-field:has(input:checked) .switch-label {
  color: var(--primary);
}

.field .err {
  display: block;
  font-style: normal;
  font-size: var(--text-xs);
  color: var(--danger);
  margin-top: var(--space-xs);
  min-height: 14px;
}

.field-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-sm);
  line-height: var(--leading-snug);
}

.field-hint.warn { color: var(--warning); }
.field-hint.danger { color: var(--danger); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.form-delay-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--text-xs);
  color: var(--text-muted);
  min-height: var(--form-etc-slot-height);
  margin-top: var(--space-sm);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--border);
}

.form-delay-etc {
  flex: 1;
  min-width: 0;
}

.form-delay-avg {
  flex-shrink: 0;
  text-align: right;
  white-space: nowrap;
}

.form-delay-info .good { color: var(--success); }
.form-delay-info .warn { color: var(--warning); }
.form-delay-info .bad { color: var(--danger); }
.form-delay-info .etc { color: var(--accent); font-weight: var(--font-semibold); }

@media (max-width: 640px) {
  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .form-actions {
    flex-direction: column-reverse;
  }

  .form-actions .btn {
    width: 100%;
  }
}
